/** {@inheritDoc} */
  @Override
  public final void write(final double[] input, final double[] ideal, final double significance) {
    final StringBuilder builder = new StringBuilder();
    builder.append("1");
    builder.append(":");
    builder.append(this.inputCount + this.idealCount);
    this.xmlOut.addAttribute("spans", builder.toString());
    this.xmlOut.addAttribute("r", "" + (this.row++));
    this.xmlOut.beginTag("row");
    int index = 0;
    for (int i = 0; i < this.inputCount; i++) {
      this.xmlOut.addAttribute("r", toColumn(index++));
      this.xmlOut.beginTag("c");
      this.xmlOut.beginTag("v");
      this.xmlOut.addText(CSVFormat.EG_FORMAT.format(input[i], Encog.DEFAULT_PRECISION));
      this.xmlOut.endTag();
      this.xmlOut.endTag();
    }

    for (int i = 0; i < this.idealCount; i++) {
      this.xmlOut.addAttribute("r", toColumn(index++));
      this.xmlOut.beginTag("c");
      this.xmlOut.beginTag("v");
      this.xmlOut.addText(CSVFormat.EG_FORMAT.format(ideal[i], Encog.DEFAULT_PRECISION));
      this.xmlOut.endTag();
      this.xmlOut.endTag();
    }

    this.xmlOut.endTag();
  }
 /**
  * Generate a table, in BIF format.
  *
  * @param event The event to write.
  * @return The string form of the table.
  */
 public static String generateTable(BayesianEvent event) {
   StringBuilder s = new StringBuilder();
   int tableIndex = 0;
   int[] args = new int[event.getParents().size()];
   do {
     for (int result = 0; result < event.getChoices().size(); result++) {
       TableLine line = event.getTable().findLine(result, args);
       if (s.length() > 0) {
         s.append(" ");
       }
       s.append(CSVFormat.EG_FORMAT.format(line.getProbability(), Encog.DEFAULT_PRECISION));
     }
   } while (BIFUtil.rollArgs(event, args));
   return s.toString();
 }
  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());
    result.append(':');
    result.append(node.getTemplate().getChildNodeCount());

    for (int i = 0; i < node.getTemplate().getDataSize(); i++) {
      result.append(':');
      ValueType t = node.getData()[i].getExpressionType();
      if (t == ValueType.booleanType) {
        result.append(node.getData()[i].toBooleanValue() ? 't' : 'f');
      } else if (t == ValueType.floatingType) {
        result.append(
            CSVFormat.EG_FORMAT.format(node.getData()[i].toFloatValue(), Encog.DEFAULT_PRECISION));
      } else if (t == ValueType.intType) {
        result.append(node.getData()[i].toIntValue());
      } else if (t == ValueType.enumType) {
        result.append(node.getData()[i].getEnumType());
        result.append("#");
        result.append(node.getData()[i].toIntValue());
      } else if (t == ValueType.stringType) {
        result.append("\"");
        result.append(node.getData()[i].toStringValue());
        result.append("\"");
      }
    }
    result.append(']');

    return result.toString().trim();
  }
Exemple #4
0
 /**
  * Set a property as a double.
  *
  * @param name The name of the property.
  * @param d The value of the property.
  */
 @Override
 public void setProperty(final String name, final double d) {
   this.properties.put(name, "" + CSVFormat.EG_FORMAT.format(d, Encog.DEFAULT_PRECISION));
   updateProperties();
 }