Package org.encog.ml.prg.expvalue

Examples of org.encog.ml.prg.expvalue.ExpressionValue


   * @param node The node to check.
   * @return True if the value is a true const.
   */
  private boolean isTrue(ProgramNode node) {
    if (node.getTemplate() == StandardExtensions.EXTENSION_CONST_SUPPORT) {
      ExpressionValue v = node.evaluate();
      if (v.isBoolean()) {
        if (v.toBooleanValue()) {
          return true;
        }
      }
    }
    return false;
View Full Code Here


   * @param node The node to check.
   * @return True if the value is a false const.
   */
  private boolean isFalse(ProgramNode node) {
    if (node.getTemplate() == StandardExtensions.EXTENSION_CONST_SUPPORT) {
      ExpressionValue v = node.evaluate();
      if (v.isBoolean()) {
        if (!v.toBooleanValue()) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

   * @param node The node to mutate.
   */
  private void mutateNode(final Random rnd, final ProgramNode node) {
    if (node.getTemplate() == StandardExtensions.EXTENSION_CONST_SUPPORT) {
      if (rnd.nextDouble() < this.frequency) {
        final ExpressionValue v = node.getData()[0];
        if (v.isFloat()) {
          final double adj = rnd.nextGaussian() * this.sigma;
          node.getData()[0] = new ExpressionValue(v.toFloatValue()
              + adj);
        }
      }
    }

View Full Code Here

   */
  private ProgramNode createNumericConst(final EncogProgram prg,
      final double v) {
    final ProgramNode result = prg.getFunctions().factorProgramNode("#const",
        prg, new ProgramNode[] {});
    result.getData()[0] = new ExpressionValue(v);
    return result;
  }
View Full Code Here

   * @return The newly created node.
   */
  private ProgramNode createNumericConst(final EncogProgram prg, final int v) {
    final ProgramNode result = prg.getFunctions().factorProgramNode("#const",
        prg, new ProgramNode[] {});
    result.getData()[0] = new ExpressionValue(v);
    return result;
  }
View Full Code Here

    if (parent.getName().equals("-") && parent.getChildNodes().size() == 2) {
      final ProgramNode child1 = parent.getChildNode(0);
      final ProgramNode child2 = parent.getChildNode(1);

      if (child2.getName().equals("#const")) {
        final ExpressionValue v = child2.getData()[0];
        if (v.isFloat()) {
          final double v2 = v.toFloatValue();
          if (v2 < 0) {
            child2.getData()[0] = new ExpressionValue(-v2);
            parent = parent
                .getOwner()
                .getContext()
                .getFunctions()
                .factorProgramNode("+", parent.getOwner(),
                    new ProgramNode[] { child1, child2 });
          }
        } else if (v.isInt()) {
          final long v2 = v.toIntValue();
          if (v2 < 0) {
            child2.getData()[0] = new ExpressionValue(-v2);
            parent = parent
                .getOwner()
                .getContext()
                .getFunctions()
                .factorProgramNode("+", parent.getOwner(),
View Full Code Here

                "-",
                parent.getOwner(),
                new ProgramNode[] { child1,
                    child2.getChildNode(0) });
      } else if (child2.getName().equals("#const")) {
        final ExpressionValue v = child2.getData()[0];
        if (v.isFloat()) {
          final double v2 = v.toFloatValue();
          if (v2 < 0) {
            child2.getData()[0] = new ExpressionValue(-v2);
            parent = parent
                .getOwner()
                .getContext()
                .getFunctions()
                .factorProgramNode("-", parent.getOwner(),
                    new ProgramNode[] { child1, child2 });
          }
        } else if (v.isInt()) {
          final long v2 = v.toIntValue();
          if (v2 < 0) {
            child2.getData()[0] = new ExpressionValue(-v2);
            parent = parent
                .getOwner()
                .getContext()
                .getFunctions()
                .factorProgramNode("-", parent.getOwner(),
View Full Code Here

    if (parentNode.isLeaf()) {
      return null;
    }

    if (parentNode.allConstDescendants()) {
      ExpressionValue v = parentNode.evaluate();
      double ck = v.toFloatValue();
     
      // do not rewrite if it produces a div by 0 or other bad result.
      if( Double.isNaN(ck) || Double.isInfinite(ck) ) {
        return result;
      }
     
      result = parentNode
          .getOwner()
          .getContext()
          .getFunctions()
          .factorProgramNode("#const", parentNode.getOwner(),
              new ProgramNode[] {});
     
      // is it an integer?
      if( Math.abs( ck- ((int)ck))<Encog.DEFAULT_DOUBLE_EQUAL) {
        result.getData()[0] = new ExpressionValue((int)ck);
      } else {
        result.getData()[0] = v;
      }
    }
    return result;
View Full Code Here

 
  private void processRow(PrintWriter tw) {
    StringBuilder line = new StringBuilder();
   
    for(EncogProgram prg: this.expressionFields) {
      ExpressionValue result = prg.evaluate();
     
      BasicFile.appendSeparator(line, this.getFormat());
     
      if( result.isString() ) {
        line.append("\"");
      }
     
      line.append(result.toStringValue());
     
      if( result.isString() ) {
        line.append("\"");
      }
    }
    tw.println(line.toString());
  }
View Full Code Here

    for (int i = 0; i < input.size(); i++) {
      this.variables.setVariable(i, input.getData(i));
    }

    final ExpressionValue v = this.rootNode.evaluate();
    final VariableMapping resultMapping = getResultType();

    final MLData result = new BasicMLData(1);
    boolean success = false;

    switch (resultMapping.getVariableType()) {
    case floatingType:
      if (v.isNumeric()) {
        result.setData(0, v.toFloatValue());
        success = true;
      }
      break;
    case stringType:
      result.setData(0, v.toFloatValue());
      success = true;
      break;
    case booleanType:
      if (v.isBoolean()) {
        result.setData(0, v.toBooleanValue() ? 1.0 : 0.0);
        success = true;
      }
      break;
    case intType:
      if (v.isNumeric()) {
        result.setData(0, v.toIntValue());
        success = true;
      }
      break;
    case enumType:
      if (v.isEnum()) {
        result.setData(0, v.toIntValue());
        success = true;
      }
      break;
    }

    if (!success) {
      throw new EARuntimeError("EncogProgram produced "
          + v.getExpressionType().toString() + " but "
          + resultMapping.getVariableType().toString()
          + " was expected.");
    }

    return result;
View Full Code Here

TOP

Related Classes of org.encog.ml.prg.expvalue.ExpressionValue

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.