Package org.encog.ml.prg

Examples of org.encog.ml.prg.EncogProgramContext


        MLTrainFactory.TYPE_EPL_GA);
    this.script.getProperties().setProperty(
        ScriptProperties.ML_TRAIN_TARGET_ERROR, this.maxError);
   
    // add in the opcodes
    EncogProgramContext context = new EncogProgramContext();
   
    if( this.getGoal()==AnalystGoal.Regression) {
      StandardExtensions.createNumericOperators(context);
    } else {
      StandardExtensions.createNumericOperators(context);
      StandardExtensions.createBooleanOperators(context);
    }
    for(ProgramExtensionTemplate temp : context.getFunctions().getOpCodes() ) {
      this.script.getOpcodes().add(new ScriptOpcode(temp));
    }
  }
View Full Code Here


    final int populationSize = holder.getInt(
        MLMethodFactory.PROPERTY_POPULATION_SIZE, false, 1000);
    String variables = holder.getString("vars", false, "x");
    String funct = holder.getString("funct", false, null);
   
    EncogProgramContext context = new EncogProgramContext();
    StringTokenizer tok = new StringTokenizer(variables,",");
    while(tok.hasMoreElements()) {
      context.defineVariable(tok.nextToken());
    }

    if( "numeric".equalsIgnoreCase(funct) ) {
      StandardExtensions.createNumericOperators(context);
    }
   
    PrgPopulation pop = new PrgPopulation(context,populationSize);
   
    if( context.getFunctions().size()>0 ) {
      (new RampedHalfAndHalf(context,2,6)).generate(new Random(), pop);
    }
    return pop;
  }
View Full Code Here

  @Override
  public void performOperation(final Random rnd, final Genome[] parents,
      final int parentIndex, final Genome[] offspring,
      final int offspringIndex) {
    final EncogProgram program = (EncogProgram) parents[0];
    final EncogProgramContext context = program.getContext();
    final EncogProgram result = context.cloneProgram(program);
    mutateNode(rnd, result.getRootNode());
    offspring[0] = result;
  }
View Full Code Here

      final int offspringIndex) {
    final EncogProgram parent1 = (EncogProgram) parents[0];
    final EncogProgram parent2 = (EncogProgram) parents[1];
    offspring[0] = null;

    final EncogProgramContext context = parent1.getContext();
    final int size1 = parent1.getRootNode().size();
    final int size2 = parent2.getRootNode().size();

    boolean done = false;
    int tries = 100;

    while (!done) {
      final int p1Index = rnd.nextInt(size1);
      final int p2Index = rnd.nextInt(size2);

      final LevelHolder holder1 = new LevelHolder(p1Index);
      final LevelHolder holder2 = new LevelHolder(p2Index);

      final List<ValueType> types = new ArrayList<ValueType>();
      types.add(context.getResult().getVariableType());

      findNode(rnd, parent1.getRootNode(), types, holder1);
      findNode(rnd, parent2.getRootNode(), types, holder2);

      if (LevelHolder.compatibleTypes(holder1.getTypes(),
          holder2.getTypes())) {
        final EncogProgram result = context.cloneProgram(parent1);
        final ProgramNode resultNode = parent1.findNode(p1Index);
        final ProgramNode p2Node = parent2.findNode(p2Index);
        final ProgramNode newInsert = context.cloneBranch(result,
            p2Node);
        result.replaceNode(resultNode, newInsert);
        offspring[0] = result;
        done = true;
      } else {
View Full Code Here

  @Override
  public void performOperation(final Random rnd, final Genome[] parents,
      final int parentIndex, final Genome[] offspring,
      final int offspringIndex) {
    final EncogProgram program = (EncogProgram) parents[0];
    final EncogProgramContext context = program.getContext();
    final EncogProgram result = context.cloneProgram(program);

    final List<ValueType> types = new ArrayList<ValueType>();
    types.add(context.getResult().getVariableType());
    final int[] globalIndex = new int[1];
    globalIndex[0] = rnd.nextInt(result.getRootNode().size());
    findNode(rnd, result, result.getRootNode(), types, globalIndex);

    offspring[0] = result;
View Full Code Here

import org.encog.parse.expression.common.RenderCommonExpression;

public class TestRewriteAlgebraic extends TestCase {
 
  public void eval(String start, String expect) {
    EncogProgramContext context = new EncogProgramContext();
    StandardExtensions.createNumericOperators(context);
    PrgPopulation pop = new PrgPopulation(context,1);
    CalculateScore score = new ZeroEvalScoreFunction();

    TrainEA genetic = new TrainEA(pop, score);
View Full Code Here

  public final File EG_FILENAME = TEMP_DIR.createFile("encogtest.eg");
  public final File SERIAL_FILENAME = TEMP_DIR.createFile("encogtest.ser");
   
  private PrgPopulation create()
  {
    EncogProgramContext context = new EncogProgramContext();
    context.defineVariable("x");
    StandardExtensions.createAll(context);
    PrgPopulation pop = new PrgPopulation(context,10);
    EncogProgram prg1 = new EncogProgram(context);
    EncogProgram prg2 = new EncogProgram(context);
    prg1.compileExpression("x+1");
View Full Code Here

import org.encog.parse.expression.common.RenderCommonExpression;

public class TestGenerate extends TestCase {

  public void testDepth() {
    EncogProgramContext context = new EncogProgramContext();
    context.defineVariable("x");
   
    StandardExtensions.createAll(context);
   
    PrgGrowGenerator rnd = new PrgGrowGenerator(context,2);
    EncogProgram prg = rnd.generate(new Random());
View Full Code Here

TOP

Related Classes of org.encog.ml.prg.EncogProgramContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.