Package org.encog.ml.prg

Examples of org.encog.ml.prg.EncogProgram


   */
  @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


    int index = 0;
    for (final Species species : getSpecies()) {
      System.out.println("** Species: " + species.toString());
      for (final Genome obj : species.getMembers()) {
        final EncogProgram prg = (EncogProgram) obj;
        System.out.println(index + ": Score " + prg.getScore() + " : "
            + render.render(prg));
        index++;
        if (index > i) {
          break;
        }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Genome factor() {
    final EncogProgram result = new EncogProgram(this.context,
        new EncogProgramVariables());
    return result;
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Genome factor(final Genome other) {
    final EncogProgram result = new EncogProgram(this.context,
        new EncogProgramVariables());
    result.copy(other);
    return result;
  }
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

import org.encog.ml.prg.EncogProgram;

public class TestRenderEPL extends TestCase {
 
  public void testRenderBasic() {
    EncogProgram expression = new EncogProgram("(2+6)");
    RenderEPL render = new RenderEPL();
    String result = render.render(expression);
    Assert.assertEquals("[#const:0:2][#const:0:6][+:2]", result);
  }
View Full Code Here

    String result = render.render(expression);
    Assert.assertEquals("[#const:0:2][#const:0:6][+:2]", result);
  }
 
  public void testRenderComplex() {
    EncogProgram expression = new EncogProgram("((a+25)^3/25)-((a*3)^4/250)");
    RenderEPL render = new RenderEPL();
    String result = render.render(expression);
    Assert.assertEquals("[#var:0:0][#const:0:25][+:2][#const:0:3][^:2][#const:0:25][/:2][#var:0:0][#const:0:3][*:2][#const:0:4][^:2][#const:0:250][/:2][-:2]", result);
  }
View Full Code Here

    String result = render.render(expression);
    Assert.assertEquals("[#var:0:0][#const:0:25][+:2][#const:0:3][^:2][#const:0:25][/:2][#var:0:0][#const:0:3][*:2][#const:0:4][^:2][#const:0:250][/:2][-:2]", result);
  }
 
  public void testRenderFunction() {
    EncogProgram expression = new EncogProgram("(sin(x)+cos(x))/2");
    RenderEPL render = new RenderEPL();
    String result = render.render(expression)
    Assert.assertEquals("[#var:0:0][sin:1][#var:0:0][cos:1][+:2][#const:0:2][/:2]", result);   
  }
View Full Code Here

import org.encog.Encog;
import org.encog.ml.prg.EncogProgram;

public class TestExpressionVar extends TestCase {
  public void testAssignment() {
    EncogProgram expression = new EncogProgram("a");
    expression.getVariables().setVariable("a",5);
    Assert.assertEquals(5,expression.evaluate().toFloatValue(),Encog.DEFAULT_DOUBLE_EQUAL);
  }
View Full Code Here

    String result = render.render(expression);
    Assert.assertEquals("a 25 [+] 3 [^] 25 [/] a 3 [*] 4 [^] 250 [/] [-]", result);
  }
 
  public void testRenderFunction() {
    EncogProgram expression = new EncogProgram("(sin(x)+cos(x))/2");
    RenderRPN render = new RenderRPN();
    String result = render.render(expression);   
    Assert.assertEquals("x [sin] x [cos] [+] 2 [/]", result);   
  }
View Full Code Here

TOP

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

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.