Package org.encog.ml.prg

Examples of org.encog.ml.prg.ProgramNode


    if (neg) {
      value = -value;
    }

    ProgramNode v = this.holder.getFunctions().factorProgramNode("#const",
        holder, new ProgramNode[] {});

    if (isFloat) {
      v.getData()[0] = new ExpressionValue(value);
    } else {
      v.getData()[0] = new ExpressionValue((int) value);
    }

    outputQueue(v);
  }
View Full Code Here


    if (varName.toString().equals("true")) {
      if (neg) {
        throw new EACompileError("Invalid negative sign.");
      }
      ProgramNode v = this.holder.getFunctions().factorProgramNode("#const",
          holder, new ProgramNode[] {});
      v.getData()[0] = new ExpressionValue(true);
      outputQueue(v);
    } else if (varName.toString().equals("false")) {
      if (neg) {
        throw new EACompileError("Invalid negative sign.");
      }
      ProgramNode v = this.holder.getFunctions().factorProgramNode("#const",
          holder, new ProgramNode[] {});
      v.getData()[0] = new ExpressionValue(false);
      outputQueue(v);
    } else if (this.parser.peek() != '(') {
      ProgramNode v;
      // either a variable or a const, see which
      if (this.holder.getFunctions().isDefined(varName.toString(), 0)) {
        v = this.holder.getFunctions().factorProgramNode(
            varName.toString(), holder, new ProgramNode[] {});
      } else {
        this.holder.getVariables().setVariable(varName.toString(),
            new ExpressionValue(0));
        v = this.holder.getFunctions().factorProgramNode("#var", holder,
            new ProgramNode[] {});
        v.getData()[0] = new ExpressionValue((int) this.holder.getVariables()
            .getVariableIndex(varName.toString()));
      }

      if (neg) {
        v = this.holder.getFunctions().factorProgramNode("-", holder,
View Full Code Here

    if (ch != 34) {
      throw (new EACompileError("Unterminated string"));
    }

    ProgramNode v = this.holder.getFunctions().factorProgramNode("#const",
        holder, new ProgramNode[] {});
    v.getData()[0] = new ExpressionValue(str.toString());
    outputQueue(v);
  }
View Full Code Here

  public RenderCommonExpression() {
  }

  public String render(final EncogProgram theHolder) {
    this.holder = theHolder;
    ProgramNode node = theHolder.getRootNode();
    return renderNode(node);
  }
View Full Code Here

    result.append('(');
    for(int i=0;i<node.getChildNodes().size();i++) {
      if( i>0 ) {
        result.append(',');
      }
      ProgramNode childNode = node.getChildNode(i);
      result.append(renderNode(childNode));
    }
    result.append(')');   
    return result.toString();
  }
View Full Code Here

 
  private String renderNode(ProgramNode node) {
    StringBuilder result = new StringBuilder();

    for(int i=0;i<node.getChildNodes().size();i++) {
      ProgramNode childNode = node.getChildNode(i);
      result.append(renderNode(childNode));
    }
   
    result.append('[');
    result.append(node.getName());
View Full Code Here

      for(int i=args.length-1;i>=0;i--) {
        args[i] = this.nodeStack.pop();
      }
     
      // factor the node
      ProgramNode node = this.holder.getFunctions().factorProgramNode(name, this.holder, args);
      this.nodeStack.push(node);
     
      // add any needed data to the node
      for(int i=0;i<temp.getDataSize();i++) {
        String str = tok.nextToken().trim();
        int idx = str.indexOf('#');
        if( idx!=-1) {
          int enumType = Integer.parseInt(str.substring(0,idx));
          int enumVal = Integer.parseInt(str.substring(idx+1));
          node.getData()[0] = new ExpressionValue(enumType,enumVal);
         
        }
        // is it boolean?
        else if( str.length()==1 && "tf".indexOf(Character.toLowerCase(str.charAt(0)))!=-1 ) {
          node.getData()[i] = new ExpressionValue(str.equalsIgnoreCase("t"));
        }
        // is it a string?
        else if( str.charAt(0)=='\"' ) {
          node.getData()[i] = new ExpressionValue(str.substring(1,str.length()-1));
        }
        // is it an integer
        else if( str.indexOf('.')==-1 && str.toLowerCase().indexOf('e')==-1) {
          long l;
          try {
            l = Long.parseLong(str);
          } catch(NumberFormatException ex) {
            // sometimes Java will output a long value that is larger than can be parsed
            // this is very likely not a useful genome and we just set it to zero so that
            // the population load does not fail.
            l=0;
          }
          node.getData()[i] = new ExpressionValue(l);
        }
        // At this point, must be a float
        else {
          node.getData()[i] = new ExpressionValue(CSVFormat.EG_FORMAT.parse(str));
        }
      }
    }
   
    return this.nodeStack.pop();
View Full Code Here

    StringBuilder result = new StringBuilder();
   
    ExpressionNodeType t = this.determineNodeType(node);
   
    for(int i=0;i<node.getChildNodes().size();i++) {
      ProgramNode childNode = node.getChildNode(i);
      if( result.length()>0 ) {
        result.append(" ");
      }
      result.append(renderNode(childNode));
    }
View Full Code Here

TOP

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

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.