本文整理汇总了Java中com.github.chen0040.gp.treegp.TreeGP类的典型用法代码示例。如果您正苦于以下问题:Java TreeGP类的具体用法?Java TreeGP怎么用?Java TreeGP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeGP类属于com.github.chen0040.gp.treegp包,在下文中一共展示了TreeGP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWithDepth
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
public void createWithDepth(int allowableDepth, TreeGP manager, TGPInitializationStrategy initializationStrategy){
final int constantCount = manager.getConstants().size();
for(int i=0; i < constantCount; ++i){
constantSet.add(new Terminal("c" + i, manager.constant(i), manager.constantText(i), true), manager.constantWeight(i));
}
final int registerCount = manager.getVariableCount();
for(int i=0; i < registerCount; ++i) {
variableSet.add(new Terminal("v" + i, 0.0, "", false), 1.0);
}
final int operatorCount = manager.getOperatorSet().size();
for(int i=0; i < operatorCount; ++i) {
Primitive operator = manager.getOperatorSet().get(i);
operatorSet.add(operator, manager.getOperatorSet().getWeight(i));
}
root = TreeGenerator.createWithDepth(this, allowableDepth, manager, initializationStrategy);
calcLength();
calcDepth();
}
示例2: apply
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
public static void apply(Solution solution1, Solution solution2, TreeGP manager)
{
RandEngine randEngine = manager.getRandEngine();
int tree_count = solution1.getTrees().size();
for (int i = 0; i < tree_count; ++i)
{
if (tree_count > 1 && randEngine.uniform() < 0.5)
{
Program temp = solution2.getTrees().get(i);
solution2.getTrees().set(i, solution1.getTrees().get(i));
solution1.getTrees().set(i, temp);
}
else
{
apply(solution1.getTrees().get(i), solution2.getTrees().get(i), manager);
}
}
solution1.invalidateCost();
solution2.invalidateCost();
}
示例3: test_symbolic_regression
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_symbolic_regression() {
List<Observation> data = Tutorials.mexican_hat();
CollectionUtils.shuffle(data);
TupleTwo<List<Observation>, List<Observation>> split_data = CollectionUtils.split(data, 0.9);
List<Observation> trainingData = split_data._1();
List<Observation> testingData = split_data._2();
TreeGP tgp = createTreeGP();
tgp.setDisplayEvery(2);
Solution program = tgp.fit(trainingData);
logger.info("global: {}", program.mathExpression());
test(program, testingData, false);
}
示例4: createTreeGP
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
private TreeGP createTreeGP(){
TreeGP tgp = TreeGP.defaultConfig();
tgp.setVariableCount(2);
tgp.setCostEvaluator((program, observations)->{
double error = 0;
for(Observation observation : observations){
program.execute(observation);
error += Math.pow(observation.getOutput(0) - observation.getPredictedOutput(0), 2.0);
}
return error;
});
tgp.setPopulationSize(1000);
tgp.setMaxGeneration(10); // should be 1000 for full evolution
return tgp;
}
示例5: test_symbolic_regression_with_crossover_subtree_no_bias
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_symbolic_regression_with_crossover_subtree_no_bias() {
List<Observation> data = Tutorials.mexican_hat();
CollectionUtils.shuffle(data);
TupleTwo<List<Observation>, List<Observation>> split_data = CollectionUtils.split(data, 0.9);
List<Observation> trainingData = split_data._1();
List<Observation> testingData = split_data._2();
TreeGP tgp = createTreeGP();
tgp.setCrossoverStrategy(TGPCrossoverStrategy.CROSSVOER_SUBTREE_NO_BIAS);
Solution program = tgp.fit(trainingData);
test(program, testingData, true);
}
示例6: test_symbolic_regression_with_mutation_hoist
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_symbolic_regression_with_mutation_hoist() {
List<Observation> data = Tutorials.mexican_hat();
CollectionUtils.shuffle(data);
TupleTwo<List<Observation>, List<Observation>> split_data = CollectionUtils.split(data, 0.9);
List<Observation> trainingData = split_data._1();
List<Observation> testingData = split_data._2();
TreeGP tgp = createTreeGP();
tgp.setMutationStrategy(TGPMutationStrategy.MUTATION_HOIST);
Solution program = tgp.fit(trainingData);
test(program, testingData, true);
}
示例7: test_symbolic_regression_with_mutation_subtree_kinnear
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_symbolic_regression_with_mutation_subtree_kinnear() {
List<Observation> data = Tutorials.mexican_hat();
CollectionUtils.shuffle(data);
TupleTwo<List<Observation>, List<Observation>> split_data = CollectionUtils.split(data, 0.9);
List<Observation> trainingData = split_data._1();
List<Observation> testingData = split_data._2();
TreeGP tgp = createTreeGP();
tgp.setMutationStrategy(TGPMutationStrategy.MUTATION_SUBTREE_KINNEAR);
Solution program = tgp.fit(trainingData);
test(program, testingData, true);
}
示例8: test_symbolic_regression_replacement_mu_plus_lambda
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_symbolic_regression_replacement_mu_plus_lambda() {
List<Observation> data = Tutorials.mexican_hat();
CollectionUtils.shuffle(data);
TupleTwo<List<Observation>, List<Observation>> split_data = CollectionUtils.split(data, 0.9);
List<Observation> trainingData = split_data._1();
List<Observation> testingData = split_data._2();
TreeGP tgp = createTreeGP();
tgp.setReplacementStrategy(TGPPopulationReplacementStrategy.MuPlusLambda);
Solution program = tgp.fit(trainingData);
test(program, testingData, true);
}
示例9: test_symbolic_regression_pop_init_ptc_1
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_symbolic_regression_pop_init_ptc_1() {
List<Observation> data = Tutorials.mexican_hat();
CollectionUtils.shuffle(data);
TupleTwo<List<Observation>, List<Observation>> split_data = CollectionUtils.split(data, 0.9);
List<Observation> trainingData = split_data._1();
List<Observation> testingData = split_data._2();
TreeGP tgp = createTreeGP();
tgp.setPopulationInitializationStrategy(TGPInitializationStrategy.INITIALIZATION_METHOD_PTC1);
Solution program = tgp.fit(trainingData);
test(program, testingData, true);
}
示例10: apply
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
public static void apply(Solution solution, TreeGP manager)
{
List<Program> trees = solution.getTrees();
int count = trees.size();
for (int i = 0; i < count; ++i)
{
apply(trees.get(i), manager);
}
solution.invalidateCost();
}
示例11: apply
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
public static void apply(Program program, TreeGP manager)
{
RandEngine randEngine = manager.getRandEngine();
TreeNode node = program.anyNode(randEngine)._1();
if (node.isTerminal())
{
Primitive terminal = program.anyTerminal(randEngine);
int trials = 0;
int max_trials = 50;
while (node.getPrimitive() == terminal)
{
terminal = program.anyTerminal(randEngine);
trials++;
if (trials > max_trials) break;
}
if (terminal != null)
{
node.setPrimitive(terminal);
}
}
else
{
int parameter_count = node.arity();
Primitive op = program.getOperatorSet().anyOther(parameter_count, node.getPrimitive(), randEngine);
if (op != null)
{
node.setPrimitive(op);
}
}
}
示例12: apply
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
public static void apply(List<Solution> solutions, TreeGP programManager){
TGPInitializationStrategy initializationStrategy = programManager.getPopulationInitializationStrategy();
if(initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_FULL
|| initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_GROW
|| initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_PTC1
|| initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_RANDOM_BRANCH){
initializeNotRamped(solutions, programManager);
} else if(initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_RAMPED_FULL
|| initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_RAMPED_GROW){
initializeRamped(solutions, programManager);
} else if(initializationStrategy == TGPInitializationStrategy.INITIALIZATION_METHOD_RAMPED_HALF_HALF){
initializeRampedHalfHalf(solutions, programManager);
}
}
示例13: initializeNotRamped
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
private static void initializeNotRamped(List<Solution> solutions, TreeGP programManager) {
int iPopulationSize = programManager.getPopulationSize();
for (int i = 0; i < iPopulationSize; i++)
{
Solution solution = createSolution(programManager, programManager.getMaxDepthForCreation(), programManager.getPopulationInitializationStrategy());
solutions.add(solution);
}
}
示例14: createSolution
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
private static Solution createSolution(TreeGP programManager, int maxDepth, TGPInitializationStrategy initializationStrategy){
final int treeCount = programManager.getTreeCountPerSolution();
return new Solution(treeCount, (index) -> {
Program tree = new Program();
tree.createWithDepth(maxDepth, programManager, initializationStrategy);
return tree;
});
}
示例15: test_simple
import com.github.chen0040.gp.treegp.TreeGP; //导入依赖的package包/类
@Test
public void test_simple(){
TreeGP tgp = new TreeGP();
tgp.getOperatorSet().addAll(new Concat());
tgp.addConstants("Hello", "World", "Hi", "There", "Morning", "Me", "Good", "You", "to", "!");
tgp.setVariableCount(0);
tgp.setCostEvaluator((program, observations)->{
double error = 0;
for(Observation obs : observations){
TextObservation observation = (TextObservation)obs;
program.executeWithText(observation);
String predicted_text = observation.getPredictedTextOutput(0);
error += Math.max(0, observation.text.length() - evaluate(observation.text, predicted_text));
error += (double)(predicted_text.length() - observation.text.length()) / observation.text.length();
}
return error;
});
tgp.setPopulationSize(1000);
tgp.setDisplayEvery(2);
tgp.setMaxGeneration(100); // should be 1000 for full evolution
List<Observation> trainingData = new ArrayList<>();
TextObservation target = new TextObservation("Hello World Good Morning to You !");
trainingData.add(target);
Solution solution = tgp.fit(trainingData);
solution.executeWithText(target);
System.out.println(target.getPredictedTextOutput(0));
}