Exemplo n.º 1
0
  /**
   * Save segregate info.
   *
   * @param out The output file.
   */
  private void saveSegregate(final EncogWriteHelper out) {
    saveSubSection(out, "SEGREGATE", "CONFIG");
    out.addSubSection("FILES");
    out.addColumn("file");
    out.addColumn("percent");
    out.writeLine();

    for (final AnalystSegregateTarget target : this.script.getSegregate().getSegregateTargets()) {
      out.addColumn(target.getFile());
      out.addColumn(target.getPercent());
      out.writeLine();
    }
  }
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final NEATPopulation pop = (NEATPopulation) obj;
    out.addSection("NEAT-POPULATION");
    out.addSubSection("CONFIG");
    out.writeProperty(PersistConst.ACTIVATION_CYCLES, pop.getActivationCycles());

    if (pop.isHyperNEAT()) {
      out.writeProperty(NEATPopulation.PROPERTY_NEAT_ACTIVATION, PersistNEATPopulation.TYPE_CPPN);
    } else {
      final ActivationFunction af = pop.getActivationFunctions().getList().get(0).getObj();
      out.writeProperty(NEATPopulation.PROPERTY_NEAT_ACTIVATION, af);
    }

    out.writeProperty(PersistConst.INPUT_COUNT, pop.getInputCount());
    out.writeProperty(PersistConst.OUTPUT_COUNT, pop.getOutputCount());
    out.writeProperty(NEATPopulation.PROPERTY_CYCLES, pop.getActivationCycles());
    out.writeProperty(NEATPopulation.PROPERTY_POPULATION_SIZE, pop.getPopulationSize());
    out.writeProperty(NEATPopulation.PROPERTY_SURVIVAL_RATE, pop.getSurvivalRate());
    out.addSubSection("INNOVATIONS");
    if (pop.getInnovations() != null) {
      for (final String key : pop.getInnovations().getInnovations().keySet()) {
        final NEATInnovation innovation = pop.getInnovations().getInnovations().get(key);
        out.addColumn(key);
        out.addColumn(innovation.getInnovationID());
        out.addColumn(innovation.getNeuronID());
        out.writeLine();
      }
    }

    out.addSubSection("SPECIES");

    // make sure the best species goes first
    final Species bestSpecies = pop.determineBestSpecies();
    if (bestSpecies != null) {
      saveSpecies(out, bestSpecies);
    }

    // now write the other species, other than the best one
    for (final Species species : pop.getSpecies()) {
      if (species != bestSpecies) {
        saveSpecies(out, species);
      }
    }
    out.flush();
  }
  /** {@inheritDoc} */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final BasicNetwork net = (BasicNetwork) obj;
    final FlatNetwork flat = net.getStructure().getFlat();
    out.addSection("BASIC");
    out.addSubSection("PARAMS");
    out.addProperties(net.getProperties());
    out.addSubSection("NETWORK");

    out.writeProperty(BasicNetwork.TAG_BEGIN_TRAINING, flat.getBeginTraining());
    out.writeProperty(BasicNetwork.TAG_CONNECTION_LIMIT, flat.getConnectionLimit());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_OFFSET, flat.getContextTargetOffset());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_SIZE, flat.getContextTargetSize());
    out.writeProperty(BasicNetwork.TAG_END_TRAINING, flat.getEndTraining());
    out.writeProperty(BasicNetwork.TAG_HAS_CONTEXT, flat.getHasContext());
    out.writeProperty(PersistConst.INPUT_COUNT, flat.getInputCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_COUNTS, flat.getLayerCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_FEED_COUNTS, flat.getLayerFeedCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_CONTEXT_COUNT, flat.getLayerContextCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_INDEX, flat.getLayerIndex());
    out.writeProperty(PersistConst.OUTPUT, flat.getLayerOutput());
    out.writeProperty(PersistConst.OUTPUT_COUNT, flat.getOutputCount());
    out.writeProperty(BasicNetwork.TAG_WEIGHT_INDEX, flat.getWeightIndex());
    out.writeProperty(PersistConst.WEIGHTS, flat.getWeights());
    out.writeProperty(BasicNetwork.TAG_BIAS_ACTIVATION, flat.getBiasActivation());
    out.addSubSection("ACTIVATION");
    for (final ActivationFunction af : flat.getActivationFunctions()) {
      String sn = af.getClass().getSimpleName();
      // if this is an Encog class then only add the simple name, so it works with C#
      if (sn.startsWith("org.encog.")) {
        out.addColumn(sn);
      } else {
        out.addColumn(af.getClass().getName());
      }
      for (int i = 0; i < af.getParams().length; i++) {
        out.addColumn(af.getParams()[i]);
      }
      out.writeLine();
    }

    out.flush();
  }
  /** {@inheritDoc} */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final RBFNetwork net = (RBFNetwork) obj;
    final FlatNetworkRBF flat = (FlatNetworkRBF) net.getFlat();
    out.addSection("RBF-NETWORK");
    out.addSubSection("PARAMS");
    out.addProperties(net.getProperties());
    out.addSubSection("NETWORK");
    out.writeProperty(BasicNetwork.TAG_BEGIN_TRAINING, flat.getBeginTraining());
    out.writeProperty(BasicNetwork.TAG_CONNECTION_LIMIT, flat.getConnectionLimit());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_OFFSET, flat.getContextTargetOffset());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_SIZE, flat.getContextTargetSize());
    out.writeProperty(BasicNetwork.TAG_END_TRAINING, flat.getEndTraining());
    out.writeProperty(BasicNetwork.TAG_HAS_CONTEXT, flat.getHasContext());
    out.writeProperty(PersistConst.INPUT_COUNT, flat.getInputCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_COUNTS, flat.getLayerCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_FEED_COUNTS, flat.getLayerFeedCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_CONTEXT_COUNT, flat.getLayerContextCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_INDEX, flat.getLayerIndex());
    out.writeProperty(PersistConst.OUTPUT, flat.getLayerOutput());
    out.writeProperty(PersistConst.OUTPUT_COUNT, flat.getOutputCount());
    out.writeProperty(BasicNetwork.TAG_WEIGHT_INDEX, flat.getWeightIndex());
    out.writeProperty(PersistConst.WEIGHTS, flat.getWeights());
    out.writeProperty(BasicNetwork.TAG_BIAS_ACTIVATION, flat.getBiasActivation());
    out.addSubSection("ACTIVATION");
    for (final ActivationFunction af : flat.getActivationFunctions()) {
      out.addColumn(af.getClass().getSimpleName());
      for (int i = 0; i < af.getParams().length; i++) {
        out.addColumn(af.getParams()[i]);
      }
      out.writeLine();
    }
    out.addSubSection("RBF");
    for (final RadialBasisFunction rbf : flat.getRBF()) {
      out.addColumn(rbf.getClass().getSimpleName());
      out.addColumn(rbf.getWidth());
      out.addColumn(rbf.getPeak());
      for (int i = 0; i < rbf.getCenters().length; i++) {
        out.addColumn(rbf.getCenters()[i]);
      }
      out.writeLine();
    }

    out.flush();
  }
  private void saveSpecies(final EncogWriteHelper out, final Species species) {
    out.addColumn("s");
    out.addColumn(species.getAge());
    out.addColumn(species.getBestScore());
    out.addColumn(species.getGensNoImprovement());
    out.writeLine();

    for (final Genome genome : species.getMembers()) {
      final NEATGenome neatGenome = (NEATGenome) genome;
      out.addColumn("g");
      out.addColumn(neatGenome.getAdjustedScore());
      out.addColumn(neatGenome.getScore());
      out.addColumn(neatGenome.getBirthGeneration());
      out.writeLine();

      for (final NEATNeuronGene neatNeuronGene : neatGenome.getNeuronsChromosome()) {
        out.addColumn("n");
        out.addColumn(neatNeuronGene.getId());
        out.addColumn(neatNeuronGene.getActivationFunction());
        out.addColumn(PersistNEATPopulation.neuronTypeToString(neatNeuronGene.getNeuronType()));
        out.addColumn(neatNeuronGene.getInnovationId());
        out.writeLine();
      }
      for (final NEATLinkGene neatLinkGene : neatGenome.getLinksChromosome()) {
        out.addColumn("l");
        out.addColumn(neatLinkGene.getId());
        out.addColumn(neatLinkGene.isEnabled());
        out.addColumn(neatLinkGene.getFromNeuronID());
        out.addColumn(neatLinkGene.getToNeuronID());
        out.addColumn(neatLinkGene.getWeight());
        out.addColumn(neatLinkGene.getInnovationId());
        out.writeLine();
      }
    }
  }
Exemplo n.º 6
0
  /**
   * Save the normalization data.
   *
   * @param out The output file.
   */
  private void saveNormalize(final EncogWriteHelper out) {
    saveSubSection(out, "NORMALIZE", "CONFIG");

    out.addSubSection("RANGE");
    out.addColumn("name");
    out.addColumn("io");
    out.addColumn("timeSlice");
    out.addColumn("action");
    out.addColumn("high");
    out.addColumn("low");
    out.writeLine();
    for (final AnalystField field : this.script.getNormalize().getNormalizedFields()) {
      out.addColumn(field.getName());
      if (field.isInput()) {
        out.addColumn("input");
      } else {
        out.addColumn("output");
      }
      out.addColumn(field.getTimeSlice());
      switch (field.getAction()) {
        case Ignore:
          out.addColumn("ignore");
          break;
        case Normalize:
          out.addColumn("range");
          break;
        case PassThrough:
          out.addColumn("pass");
          break;
        case OneOf:
          out.addColumn("oneof");
          break;
        case Equilateral:
          out.addColumn("equilateral");
          break;
        case SingleField:
          out.addColumn("single");
          break;
        default:
          throw new AnalystError("Unknown action: " + field.getAction());
      }

      out.addColumn(field.getNormalizedHigh());
      out.addColumn(field.getNormalizedLow());
      out.writeLine();
    }
  }
Exemplo n.º 7
0
  /**
   * Save the data fields.
   *
   * @param out The output file.
   */
  private void saveData(final EncogWriteHelper out) {
    saveSubSection(out, "DATA", "CONFIG");
    out.addSubSection("STATS");
    out.addColumn("name");
    out.addColumn("isclass");
    out.addColumn("iscomplete");
    out.addColumn("isint");
    out.addColumn("isreal");
    out.addColumn("amax");
    out.addColumn("amin");
    out.addColumn("mean");
    out.addColumn("sdev");
    out.writeLine();

    for (final DataField field : this.script.getFields()) {
      out.addColumn(field.getName());
      out.addColumn(field.isClass());
      out.addColumn(field.isComplete());
      out.addColumn(field.isInteger());
      out.addColumn(field.isReal());
      out.addColumn(field.getMax());
      out.addColumn(field.getMin());
      out.addColumn(field.getMean());
      out.addColumn(field.getStandardDeviation());
      out.writeLine();
    }
    out.flush();

    out.addSubSection("CLASSES");
    out.addColumn("field");
    out.addColumn("code");
    out.addColumn("name");
    out.writeLine();

    for (final DataField field : this.script.getFields()) {
      if (field.isClass()) {
        for (final AnalystClassItem col : field.getClassMembers()) {
          out.addColumn(field.getName());
          out.addColumn(col.getCode());
          out.addColumn(col.getName());
          out.addColumn(col.getCount());
          out.writeLine();
        }
      }
    }
  }