Used to write an Encog EG/EGA file. EG files are used to hold Encog objects. EGA files are used to hold Encog Analyst scripts.
        /// <summary>
        /// Save the script to a stream.
        /// </summary>
        ///
        /// <param name="stream">The output stream.</param>
        public void Save(Stream stream)
        {
            var xout = new EncogWriteHelper(stream);
            SaveSubSection(xout, "HEADER", "DATASOURCE");
            SaveConfig(xout);

            if (_script.Fields != null)
            {
                SaveData(xout);
                SaveNormalize(xout);
            }

            SaveSubSection(xout, "RANDOMIZE", "CONFIG");
            SaveSubSection(xout, "CLUSTER", "CONFIG");
            SaveSubSection(xout, "BALANCE", "CONFIG");

            if (_script.Segregate.SegregateTargets != null)
            {
                SaveSegregate(xout);
            }
            SaveSubSection(xout, "GENERATE", "CONFIG");
            SaveMachineLearning(xout);
            SaveTasks(xout);
            xout.Flush();
        }
Beispiel #2
0
 public void Save(Stream stream)
 {
     EncogWriteHelper helper = new EncogWriteHelper(stream);
     if (0 == 0)
     {
         this.x4ec53e22935ca8a4(helper, "HEADER", "DATASOURCE");
         goto Label_00BF;
     }
     Label_000D:
     this.xb65907545d46dd44(helper);
     this.x3d1973763c1ba5f6(helper);
     helper.Flush();
     return;
     Label_0094:
     this.x4ec53e22935ca8a4(helper, "RANDOMIZE", "CONFIG");
     if (-2 == 0)
     {
         goto Label_00C8;
     }
     goto Label_00DD;
     Label_00BF:
     this.x2cf4bfede7840d5b(helper);
     if (this._x594135906c55045c.Fields == null)
     {
         goto Label_0094;
     }
     Label_00C8:
     this.x80a029c2a0fbca61(helper);
     this.x6f59fa9537dbb843(helper);
     if (2 != 0)
     {
         if (0 != 0)
         {
             goto Label_00BF;
         }
         goto Label_0094;
     }
     Label_00DD:
     if (0 == 0)
     {
         this.x4ec53e22935ca8a4(helper, "CLUSTER", "CONFIG");
         this.x4ec53e22935ca8a4(helper, "BALANCE", "CONFIG");
         if (this._x594135906c55045c.Segregate.SegregateTargets != null)
         {
             this.x312a5c458079831e(helper);
         }
         else if (0 != 0)
         {
             goto Label_00BF;
         }
         this.x4ec53e22935ca8a4(helper, "GENERATE", "CONFIG");
     }
     goto Label_000D;
 }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var art1 = (ART1) obj;
            xout.AddSection("ART1");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(art1.Properties);
            xout.AddSubSection("NETWORK");

            xout.WriteProperty(BasicART.PropertyA1, art1.A1);
            xout.WriteProperty(BasicART.PropertyB1, art1.B1);
            xout.WriteProperty(BasicART.PropertyC1, art1.C1);
            xout.WriteProperty(BasicART.PropertyD1, art1.D1);
            xout.WriteProperty(PersistConst.PropertyF1Count, art1.F1Count);
            xout.WriteProperty(PersistConst.PropertyF2Count, art1.F2Count);
            xout.WriteProperty(BasicART.PropertyNoWinner, art1.NoWinner);
            xout.WriteProperty(BasicART.PropertyL, art1.L);
            xout.WriteProperty(BasicART.PropertyVigilance, art1.Vigilance);
            xout.WriteProperty(PersistConst.PropertyWeightsF1F2,
                               art1.WeightsF1ToF2);
            xout.WriteProperty(PersistConst.PropertyWeightsF2F1,
                               art1.WeightsF2ToF1);

            xout.Flush();
        }
Beispiel #4
0
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var svm2 = (SupportVectorMachine) obj;
            xout.AddSection("SVM");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(svm2.Properties);
            xout.AddSubSection("SVM-PARAM");
            xout.WriteProperty(PersistConst.InputCount, svm2.InputCount);
            xout.WriteProperty(ParamC, svm2.Params.C);
            xout.WriteProperty(ParamCacheSize,
                               svm2.Params.cache_size);
            xout.WriteProperty(ParamCoef0, svm2.Params.coef0);
            xout.WriteProperty(ParamDegree, svm2.Params.degree);
            xout.WriteProperty(ParamEps, svm2.Params.eps);
            xout.WriteProperty(ParamGamma, svm2.Params.gamma);
            xout.WriteProperty(ParamKernelType,
                               svm2.Params.kernel_type);
            xout.WriteProperty(ParamNumWeight,
                               svm2.Params.nr_weight);
            xout.WriteProperty(ParamNu, svm2.Params.nu);
            xout.WriteProperty(ParamP, svm2.Params.p);
            xout.WriteProperty(ParamProbability,
                               svm2.Params.probability);
            xout.WriteProperty(ParamShrinking,
                               svm2.Params.shrinking);
            /* xout.WriteProperty(PersistSVM.PARAM_START_ITERATIONS,
                    svm2.Params.statIterations); */
            xout.WriteProperty(ParamSVMType, svm2.Params.svm_type);
            xout.WriteProperty(ParamWeight, svm2.Params.weight);
            xout.WriteProperty(ParamWeightLabel,
                               svm2.Params.weight_label);
            if (svm2.Model != null)
            {
                xout.AddSubSection("SVM-MODEL");
                try
                {
                    var ba = new MemoryStream();
                    var w = new StreamWriter(ba);
                    svm.svm_save_model(w, svm2.Model);
                    var enc = new ASCIIEncoding();
                    xout.Write(enc.GetString(ba.ToArray()));
                    w.Close();
                    ba.Close();
                }
                catch (IOException ex)
                {
                    throw new PersistError(ex);
                }
            }

            xout.Flush();
        }
Beispiel #5
0
 public void Save(Stream os, object obj)
 {
     CPNNetwork network;
     EncogWriteHelper helper = new EncogWriteHelper(os);
     if (0 == 0)
     {
         network = (CPNNetwork) obj;
         goto Label_00A8;
     }
     Label_000D:
     helper.WriteProperty("inputToInstar", network.WeightsInputToInstar);
     helper.WriteProperty("instarToInput", network.WeightsInstarToOutstar);
     helper.WriteProperty("winnerCount", network.WinnerCount);
     if (-1 != 0)
     {
         helper.Flush();
         return;
     }
     Label_0052:
     helper.AddProperties(network.Properties);
     if (0 == 0)
     {
         helper.AddSubSection("NETWORK");
         helper.WriteProperty("inputCount", network.InputCount);
         helper.WriteProperty("instar", network.InstarCount);
         helper.WriteProperty("outputCount", network.OutputCount);
         goto Label_00C5;
     }
     Label_00A8:
     helper.AddSection("CPN");
     helper.AddSubSection("PARAMS");
     if (15 != 0)
     {
         goto Label_0052;
     }
     Label_00C5:
     if (0 == 0)
     {
         goto Label_000D;
     }
 }
        /// <summary>
        /// Save a subsection.
        /// </summary>
        ///
        /// <param name="xout">The output file.</param>
        /// <param name="section">The section.</param>
        /// <param name="subSection">The subsection.</param>
        private void SaveSubSection(EncogWriteHelper xout,
                                    String section, String subSection)
        {
            if (!section.Equals(xout.CurrentSection))
            {
                xout.AddSection(section);
            }
            xout.AddSubSection(subSection);
            List<PropertyEntry> list = PropertyConstraints.Instance
                .GetEntries(section, subSection);
            list.Sort();

            foreach (PropertyEntry entry  in  list)
            {
                String key = section + ":" + subSection + "_"
                             + entry.Name;
                String v = _script.Properties.GetPropertyString(
                    key);
                xout.WriteProperty(entry.Name, v ?? "");
            }
        }
        /// <summary>
        /// Save the normalization data.
        /// </summary>
        ///
        /// <param name="xout">The output file.</param>
        private void SaveNormalize(EncogWriteHelper xout)
        {
            SaveSubSection(xout, "NORMALIZE", "CONFIG");

            xout.AddSubSection("RANGE");
            xout.AddColumn("name");
            xout.AddColumn("io");
            xout.AddColumn("timeSlice");
            xout.AddColumn("action");
            xout.AddColumn("high");
            xout.AddColumn("low");
            xout.WriteLine();

            foreach (AnalystField field  in  _script.Normalize.NormalizedFields)
            {
                xout.AddColumn(field.Name);
                xout.AddColumn(field.Input ? "input" : "output");
                xout.AddColumn(field.TimeSlice);
                switch (field.Action)
                {
                    case NormalizationAction.Ignore:
                        xout.AddColumn("ignore");
                        break;
                    case NormalizationAction.Normalize:
                        xout.AddColumn("range");
                        break;
                    case NormalizationAction.PassThrough:
                        xout.AddColumn("pass");
                        break;
                    case NormalizationAction.OneOf:
                        xout.AddColumn("oneof");
                        break;
                    case NormalizationAction.Equilateral:
                        xout.AddColumn("equilateral");
                        break;
                    case NormalizationAction.SingleField:
                        xout.AddColumn("single");
                        break;
                    default:
                        throw new AnalystError("Unknown action: " + field.Action);
                }

                xout.AddColumn(field.NormalizedHigh);
                xout.AddColumn(field.NormalizedLow);
                xout.WriteLine();
            }
        }
        /// <summary>
        /// Save the data fields.
        /// </summary>
        ///
        /// <param name="xout">The output file.</param>
        private void SaveData(EncogWriteHelper xout)
        {
            SaveSubSection(xout, "DATA", "CONFIG");
            xout.AddSubSection("STATS");
            xout.AddColumn("name");
            xout.AddColumn("isclass");
            xout.AddColumn("iscomplete");
            xout.AddColumn("isint");
            xout.AddColumn("isreal");
            xout.AddColumn("amax");
            xout.AddColumn("amin");
            xout.AddColumn("mean");
            xout.AddColumn("sdev");
            xout.WriteLine();


            foreach (DataField field  in  _script.Fields)
            {
                xout.AddColumn(field.Name);
                xout.AddColumn(field.Class);
                xout.AddColumn(field.Complete);
                xout.AddColumn(field.Integer);
                xout.AddColumn(field.Real);
                xout.AddColumn(field.Max);
                xout.AddColumn(field.Min);
                xout.AddColumn(field.Mean);
                xout.AddColumn(field.StandardDeviation);
                xout.WriteLine();
            }
            xout.Flush();

            xout.AddSubSection("CLASSES");
            xout.AddColumn("field");
            xout.AddColumn("code");
            xout.AddColumn("name");
            xout.WriteLine();


            foreach (DataField field  in  _script.Fields)
            {
                if (field.Class)
                {
                    foreach (AnalystClassItem col  in  field.ClassMembers)
                    {
                        xout.AddColumn(field.Name);
                        xout.AddColumn(col.Code);
                        xout.AddColumn(col.Name);
                        xout.AddColumn(col.Count);
                        xout.WriteLine();
                    }
                }
            }
        }
Beispiel #9
0
 public void Save(Stream os, object obj)
 {
     EncogWriteHelper helper = new EncogWriteHelper(os);
     BAMNetwork network = (BAMNetwork) obj;
     helper.AddSection("BAM");
     if (0 == 0)
     {
         helper.AddSubSection("PARAMS");
         helper.AddProperties(network.Properties);
         if (0 == 0)
         {
             helper.AddSubSection("NETWORK");
             helper.WriteProperty("f1Count", network.F1Count);
             helper.WriteProperty("f2Count", network.F2Count);
             helper.WriteProperty("weightsF1F2", network.WeightsF1ToF2);
             helper.WriteProperty("weightsF2F1", network.WeightsF2ToF1);
             helper.Flush();
         }
     }
 }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var boltz = (BoltzmannMachine) obj;
            xout.AddSection("BOLTZMANN");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(boltz.Properties);
            xout.AddSubSection("NETWORK");
            xout.WriteProperty(PersistConst.Weights, boltz.Weights);
            xout.WriteProperty(PersistConst.Output, boltz.CurrentState.Data);
            xout.WriteProperty(PersistConst.NeuronCount, boltz.NeuronCount);

            xout.WriteProperty(PersistConst.Thresholds, boltz.Threshold);
            xout.WriteProperty(BoltzmannMachine.ParamAnnealCycles,
                               boltz.AnnealCycles);
            xout.WriteProperty(BoltzmannMachine.ParamRunCycles, boltz.RunCycles);
            xout.WriteProperty(PersistConst.Temperature, boltz.Temperature);

            xout.Flush();
        }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var net = (RBFNetwork) obj;
            var flat = (FlatNetworkRBF) net.Flat;
            xout.AddSection("RBF-NETWORK");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(net.Properties);
            xout.AddSubSection("NETWORK");
            xout.WriteProperty(BasicNetwork.TagBeginTraining,
                               flat.BeginTraining);
            xout.WriteProperty(BasicNetwork.TagConnectionLimit,
                               flat.ConnectionLimit);
            xout.WriteProperty(BasicNetwork.TagContextTargetOffset,
                               flat.ContextTargetOffset);
            xout.WriteProperty(BasicNetwork.TagContextTargetSize,
                               flat.ContextTargetSize);
            xout.WriteProperty(BasicNetwork.TagEndTraining, flat.EndTraining);
            xout.WriteProperty(BasicNetwork.TagHasContext, flat.HasContext);
            xout.WriteProperty(PersistConst.InputCount, flat.InputCount);
            xout.WriteProperty(BasicNetwork.TagLayerCounts, flat.LayerCounts);
            xout.WriteProperty(BasicNetwork.TagLayerFeedCounts,
                               flat.LayerFeedCounts);
            xout.WriteProperty(BasicNetwork.TagLayerContextCount,
                               flat.LayerContextCount);
            xout.WriteProperty(BasicNetwork.TagLayerIndex, flat.LayerIndex);
            xout.WriteProperty(PersistConst.Output, flat.LayerOutput);
            xout.WriteProperty(PersistConst.OutputCount, flat.OutputCount);
            xout.WriteProperty(BasicNetwork.TagWeightIndex, flat.WeightIndex);
            xout.WriteProperty(PersistConst.Weights, flat.Weights);
            xout.WriteProperty(BasicNetwork.TagBiasActivation,
                               flat.BiasActivation);
            xout.AddSubSection("ACTIVATION");

            foreach (IActivationFunction af  in  flat.ActivationFunctions)
            {
                xout.AddColumn(af.GetType().Name);
                foreach (double t in af.Params)
                {
                    xout.AddColumn(t);
                }
                xout.WriteLine();
            }
            xout.AddSubSection("RBF");

            foreach (IRadialBasisFunction rbf  in  flat.RBF)
            {
                xout.AddColumn(rbf.GetType().Name);
                xout.AddColumn(rbf.Width);
                xout.AddColumn(rbf.Peak);
                foreach (double t in rbf.Centers)
                {
                    xout.AddColumn(t);
                }
                xout.WriteLine();
            }

            xout.Flush();
        }
 /// <summary>
 /// 
 /// </summary>
 ///
 public void Save(Stream os, Object obj)
 {
     var xout = new EncogWriteHelper(os);
     var hopfield = (HopfieldNetwork) obj;
     xout.AddSection("HOPFIELD");
     xout.AddSubSection("PARAMS");
     xout.AddProperties(hopfield.Properties);
     xout.AddSubSection("NETWORK");
     xout.WriteProperty(PersistConst.Weights, hopfield.Weights);
     xout.WriteProperty(PersistConst.Output, hopfield.CurrentState.Data);
     xout.WriteProperty(PersistConst.NeuronCount, hopfield.NeuronCount);
     xout.Flush();
 }
Beispiel #13
0
 public void Save(Stream os, object obj)
 {
     EncogWriteHelper helper = new EncogWriteHelper(os);
     BoltzmannMachine machine = (BoltzmannMachine) obj;
     helper.AddSection("BOLTZMANN");
     Label_00C6:
     helper.AddSubSection("PARAMS");
     Label_00D1:
     helper.AddProperties(machine.Properties);
     if (0 != 0)
     {
         return;
     }
     Label_0094:
     helper.AddSubSection("NETWORK");
     helper.WriteProperty("weights", machine.Weights);
     helper.WriteProperty("output", machine.CurrentState.Data);
     if (0 == 0)
     {
         helper.WriteProperty("neurons", machine.NeuronCount);
         helper.WriteProperty("thresholds", machine.Threshold);
         helper.WriteProperty("annealCycles", machine.AnnealCycles);
         helper.WriteProperty("runCycles", machine.RunCycles);
         helper.WriteProperty("temperature", machine.Temperature);
         helper.Flush();
         if (0 != 0)
         {
             goto Label_00D1;
         }
         if (0 == 0)
         {
             return;
         }
         goto Label_0094;
     }
     goto Label_00C6;
 }
Beispiel #14
0
        /**
	 * {@inheritDoc}
	 */

        public void Save(Stream os, Object obj)
        {
            var writer = new EncogWriteHelper(os);
            var som = (SOMNetwork) obj;
            writer.AddSection("SOM");
            writer.AddSubSection("PARAMS");
            writer.AddProperties(som.Properties);
            writer.AddSubSection("NETWORK");
            writer.WriteProperty(PersistConst.Weights, som.Weights);
            writer.WriteProperty(PersistConst.InputCount, som.InputCount);
            writer.WriteProperty(PersistConst.OutputCount, som.OutputCount);
            writer.Flush();
        }
Beispiel #15
0
        /// <summary>
        /// Save the object.
        /// </summary>
        /// <param name="os">The output stream.</param>
        /// <param name="obj">The object to save.</param>
        public virtual void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var neat = (NEATNetwork) obj;
            xout.AddSection("NEAT");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(neat.Properties);
            xout.AddSubSection("NETWORK");

            xout.WriteProperty(PersistConst.InputCount, neat.InputCount);
            xout.WriteProperty(PersistConst.OutputCount, neat.OutputCount);
            xout.WriteProperty(PersistConst.ActivationFunction,
                               neat.ActivationFunction);
            xout.WriteProperty(NEATPopulation.PropertyOutputActivation,
                               neat.OutputActivationFunction);
            xout.WriteProperty(PersistConst.Depth, neat.NetworkDepth);
            xout.WriteProperty(PersistConst.Snapshot, neat.Snapshot);

            xout.AddSubSection("NEURONS");

            foreach (NEATNeuron neatNeuron  in  neat.Neurons)
            {
                xout.AddColumn((int)neatNeuron.NeuronID);
                xout.AddColumn(PersistNEATPopulation.NeuronTypeToString(neatNeuron.NeuronType));
                xout.AddColumn(neatNeuron.ActivationResponse);
                xout.AddColumn(neatNeuron.SplitX);
                xout.AddColumn(neatNeuron.SplitY);
                xout.WriteLine();
            }

            xout.AddSubSection("LINKS");

            foreach (NEATNeuron neatNeuron  in  neat.Neurons)
            {
                foreach (NEATLink link  in  neatNeuron.OutputboundLinks)
                {
                    WriteLink(xout, link);
                }
            }

            xout.Flush();
        }
Beispiel #16
0
 private static void WriteLink(EncogWriteHelper xout, NEATLink link)
 {
     xout.AddColumn((int) link.FromNeuron.NeuronID);
     xout.AddColumn((int) link.ToNeuron.NeuronID);
     xout.AddColumn(link.Recurrent);
     xout.AddColumn(link.Weight);
     xout.WriteLine();
 }
Beispiel #17
0
 public void Save(Stream os, object obj)
 {
     ART1 art;
     EncogWriteHelper helper = new EncogWriteHelper(os);
     goto Label_010B;
     Label_000C:
     helper.Flush();
     if (2 != 0)
     {
         return;
     }
     Label_0019:
     helper.WriteProperty("noWinner", art.NoWinner);
     do
     {
         helper.WriteProperty("L", art.L);
     }
     while (0 != 0);
     helper.WriteProperty("VIGILANCE", art.Vigilance);
     helper.WriteProperty("weightsF1F2", art.WeightsF1ToF2);
     helper.WriteProperty("weightsF2F1", art.WeightsF2ToF1);
     goto Label_000C;
     Label_010B:
     art = (ART1) obj;
     if (0 == 0)
     {
         helper.AddSection("ART1");
         helper.AddSubSection("PARAMS");
         if (0 == 0)
         {
             helper.AddProperties(art.Properties);
             helper.AddSubSection("NETWORK");
             helper.WriteProperty("A1", art.A1);
         }
         helper.WriteProperty("B1", art.B1);
         helper.WriteProperty("C1", art.C1);
         if (0 != 0)
         {
             goto Label_000C;
         }
         helper.WriteProperty("D1", art.D1);
         helper.WriteProperty("f1Count", art.F1Count);
     }
     helper.WriteProperty("f2Count", art.F2Count);
     if (3 != 0)
     {
         if (0 != 0)
         {
             return;
         }
         goto Label_0019;
     }
     goto Label_010B;
 }
Beispiel #18
0
        /// <summary>
        /// Save the object.
        /// </summary>
        /// <param name="os">The stream to write to.</param>
        /// <param name="obj">The object to save.</param>
        public virtual void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var pop = (NEATPopulation) obj;
            xout.AddSection("NEAT-POPULATION");
            xout.AddSubSection("CONFIG");
            xout.WriteProperty(PersistConst.Snapshot, pop.Snapshot);
            xout.WriteProperty(NEATPopulation.PropertyOutputActivation,
                               pop.OutputActivationFunction);
            xout.WriteProperty(NEATPopulation.PropertyNEATActivation,
                               pop.NeatActivationFunction);
            xout.WriteProperty(PersistConst.InputCount, pop.InputCount);
            xout.WriteProperty(PersistConst.OutputCount, pop.OutputCount);
            xout.WriteProperty(PopulationConst.PropertyOldAgePenalty,
                               pop.OldAgePenalty);
            xout.WriteProperty(PopulationConst.PropertyOldAgeThreshold,
                               pop.OldAgeThreshold);
            xout.WriteProperty(PopulationConst.PropertyPopulationSize,
                               pop.PopulationSize);
            xout.WriteProperty(PopulationConst.PropertySurvivalRate,
                               pop.SurvivalRate);
            xout.WriteProperty(PopulationConst.PropertyYoungAgeThreshold,
                               pop.YoungBonusAgeThreshold);
            xout.WriteProperty(PopulationConst.PropertyYoungAgeBonus,
                               pop.YoungScoreBonus);
            xout.WriteProperty(PopulationConst.PropertyNextGenomeID, pop.GenomeIDGenerate.CurrentID);
            xout.WriteProperty(PopulationConst.PropertyNextInnovationID, pop.InnovationIDGenerate.CurrentID);
            xout.WriteProperty(PopulationConst.PropertyNextGeneID, pop.GeneIDGenerate.CurrentID);
            xout.WriteProperty(PopulationConst.PropertyNextSpeciesID, pop.SpeciesIDGenerate.CurrentID);
            xout.AddSubSection("INNOVATIONS");
            if (pop.Innovations != null)
            {
                foreach (IInnovation innovation  in  pop.Innovations.Innovations)
                {
                    var neatInnovation = (NEATInnovation) innovation;
                    xout.AddColumn(neatInnovation.InnovationID);
                    xout.AddColumn(InnovationTypeToString(neatInnovation.InnovationType));
                    xout.AddColumn(NeuronTypeToString(neatInnovation.NeuronType));
                    xout.AddColumn(neatInnovation.SplitX);
                    xout.AddColumn(neatInnovation.SplitY);
                    xout.AddColumn(neatInnovation.NeuronID);
                    xout.AddColumn(neatInnovation.FromNeuronID);
                    xout.AddColumn(neatInnovation.ToNeuronID);
                    xout.WriteLine();
                }
            }
            xout.AddSubSection("GENOMES");

            foreach (IGenome genome  in  pop.Genomes)
            {
                var neatGenome = (NEATGenome) genome;
                xout.AddColumn("g");
                xout.AddColumn(neatGenome.GenomeID);
                xout.AddColumn(neatGenome.SpeciesID);
                xout.AddColumn(neatGenome.AdjustedScore);
                xout.AddColumn(neatGenome.AmountToSpawn);
                xout.AddColumn(neatGenome.NetworkDepth);
                xout.AddColumn(neatGenome.Score);
                xout.WriteLine();

                foreach (IGene neuronGene  in  neatGenome.Neurons.Genes)
                {
                    var neatNeuronGene = (NEATNeuronGene) neuronGene;
                    xout.AddColumn("n");
                    xout.AddColumn(neatNeuronGene.Id);
                    xout.AddColumn(NeuronTypeToString(neatNeuronGene.NeuronType));
                    xout.AddColumn(neatNeuronGene.Enabled);
                    xout.AddColumn(neatNeuronGene.InnovationId);
                    xout.AddColumn(neatNeuronGene.ActivationResponse);
                    xout.AddColumn(neatNeuronGene.SplitX);
                    xout.AddColumn(neatNeuronGene.SplitY);
                    xout.WriteLine();
                }

                foreach (IGene linkGene  in  neatGenome.Links.Genes)
                {
                    var neatLinkGene = (NEATLinkGene) linkGene;
                    xout.AddColumn("l");
                    xout.AddColumn(neatLinkGene.Id);
                    xout.AddColumn(neatLinkGene.Enabled);
                    xout.AddColumn(neatLinkGene.Recurrent);
                    xout.AddColumn(neatLinkGene.FromNeuronID);
                    xout.AddColumn(neatLinkGene.ToNeuronID);
                    xout.AddColumn(neatLinkGene.Weight);
                    xout.AddColumn(neatLinkGene.InnovationId);
                    xout.WriteLine();
                }
            }
            xout.AddSubSection("SPECIES");

            foreach (ISpecies species  in  pop.Species)
            {
                xout.AddColumn(species.SpeciesID);
                xout.AddColumn(species.Age);
                xout.AddColumn(species.BestScore);
                xout.AddColumn(species.GensNoImprovement);
                xout.AddColumn(species.NumToSpawn);
                xout.AddColumn(species.SpawnsRequired);
                xout.AddColumn(species.Leader.GenomeID);
                xout.WriteLine();
            }
            xout.Flush();
        }
 /// <summary>
 /// Save the ML sections.
 /// </summary>
 ///
 /// <param name="xout">The output file.</param>
 private void SaveMachineLearning(EncogWriteHelper xout)
 {
     SaveSubSection(xout, "ML", "CONFIG");
     SaveSubSection(xout, "ML", "TRAIN");
 }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var output = new EncogWriteHelper(os);
            var pop = (NEATPopulation)obj;
            output.AddSection("NEAT-POPULATION");
            output.AddSubSection("CONFIG");
            output.WriteProperty(PersistConst.ActivationCycles, pop.ActivationCycles);

            if (pop.IsHyperNEAT)
            {
                output.WriteProperty(NEATPopulation.PropertyNEATActivation,TypeCppn);
            }
            else
            {
                IActivationFunction af = pop.ActivationFunctions.Contents[0].obj;
                output.WriteProperty(NEATPopulation.PropertyNEATActivation, af);
            }

            output.WriteProperty(PersistConst.InputCount, pop.InputCount);
            output.WriteProperty(PersistConst.OutputCount, pop.OutputCount);
            output.WriteProperty(NEATPopulation.PropertyCycles, pop.ActivationCycles);
            output.WriteProperty(NEATPopulation.PropertyPopulationSize, pop.PopulationSize);
            output.WriteProperty(NEATPopulation.PropertySurvivalRate, pop.SurvivalRate);
            output.AddSubSection("INNOVATIONS");
            if (pop.Innovations != null)
            {
                foreach (string key in pop.Innovations.Innovations.Keys)
                {
                    NEATInnovation innovation = pop.Innovations.Innovations[key];
                    output.AddColumn(key);
                    output.AddColumn(innovation.InnovationId);
                    output.AddColumn(innovation.NeuronId);
                    output.WriteLine();
                }
            }

            output.AddSubSection("SPECIES");

            // make sure the best species goes first
            ISpecies bestSpecies = pop.DetermineBestSpecies();
            if (bestSpecies != null)
            {
                SaveSpecies(output, bestSpecies);
            }

            // now write the other species, other than the best one
            foreach (ISpecies species in pop.Species)
            {
                if (species != bestSpecies)
                {
                    SaveSpecies(output, species);
                }
            }
            output.Flush();
        }
        /// <summary>
        /// Save segregate info.
        /// </summary>
        ///
        /// <param name="xout">The output file.</param>
        private void SaveSegregate(EncogWriteHelper xout)
        {
            SaveSubSection(xout, "SEGREGATE", "CONFIG");
            xout.AddSubSection("FILES");
            xout.AddColumn("file");
            xout.AddColumn("percent");
            xout.WriteLine();


            foreach (AnalystSegregateTarget target  in  _script.Segregate.SegregateTargets)
            {
                xout.AddColumn(target.File);
                xout.AddColumn(target.Percent);
                xout.WriteLine();
            }
        }
        private void SaveSpecies(EncogWriteHelper output, ISpecies species)
        {
            output.AddColumn("s");
            output.AddColumn(species.Age);
            output.AddColumn(species.BestScore);
            output.AddColumn(species.GensNoImprovement);
            output.WriteLine();

            foreach (IGenome genome in species.Members)
            {
                var neatGenome = (NEATGenome)genome;
                output.AddColumn("g");
                output.AddColumn(neatGenome.AdjustedScore);
                output.AddColumn(neatGenome.Score);
                output.AddColumn(neatGenome.BirthGeneration);
                output.WriteLine();

                foreach (NEATNeuronGene neatNeuronGene in neatGenome.NeuronsChromosome)
                {
                    output.AddColumn("n");
                    output.AddColumn(neatNeuronGene.Id);
                    output.AddColumn(neatNeuronGene.ActivationFunction);
                    output.AddColumn(NeuronTypeToString(neatNeuronGene.NeuronType));
                    output.AddColumn(neatNeuronGene.InnovationId);
                    output.WriteLine();
                }
                foreach (NEATLinkGene neatLinkGene in neatGenome.LinksChromosome)
                {
                    output.AddColumn("l");
                    output.AddColumn(neatLinkGene.Id);
                    output.AddColumn(neatLinkGene.Enabled);
                    output.AddColumn(neatLinkGene.FromNeuronId);
                    output.AddColumn(neatLinkGene.ToNeuronId);
                    output.AddColumn(neatLinkGene.Weight);
                    output.AddColumn(neatLinkGene.InnovationId);
                    output.WriteLine();
                }

            }
        }
        /// <summary>
        /// Save the tasks.
        /// </summary>
        ///
        /// <param name="xout">The output file.</param>
        private void SaveTasks(EncogWriteHelper xout)
        {
            xout.AddSection("TASKS");
            var list = _script.Tasks.Keys.ToList();

            list.Sort();

            foreach (String key  in  list)
            {
                AnalystTask task = _script.GetTask(key);
                xout.AddSubSection(task.Name);

                foreach (String line  in  task.Lines)
                {
                    xout.AddLine(line);
                }
            }
        }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var net = (BasicNetwork) obj;
            FlatNetwork flat = net.Structure.Flat;
            xout.AddSection("BASIC");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(net.Properties);
            xout.AddSubSection("NETWORK");

            xout.WriteProperty(BasicNetwork.TagBeginTraining,
                               flat.BeginTraining);
            xout.WriteProperty(BasicNetwork.TagConnectionLimit,
                               flat.ConnectionLimit);
            xout.WriteProperty(BasicNetwork.TagContextTargetOffset,
                               flat.ContextTargetOffset);
            xout.WriteProperty(BasicNetwork.TagContextTargetSize,
                               flat.ContextTargetSize);
            xout.WriteProperty(BasicNetwork.TagEndTraining, flat.EndTraining);
            xout.WriteProperty(BasicNetwork.TagHasContext, flat.HasContext);
            xout.WriteProperty(PersistConst.InputCount, flat.InputCount);
            xout.WriteProperty(BasicNetwork.TagLayerCounts, flat.LayerCounts);
            xout.WriteProperty(BasicNetwork.TagLayerFeedCounts,
                               flat.LayerFeedCounts);
            xout.WriteProperty(BasicNetwork.TagLayerContextCount,
                               flat.LayerContextCount);
            xout.WriteProperty(BasicNetwork.TagLayerIndex, flat.LayerIndex);
            xout.WriteProperty(PersistConst.Output, flat.LayerOutput);
            xout.WriteProperty(PersistConst.OutputCount, flat.OutputCount);
            xout.WriteProperty(BasicNetwork.TagWeightIndex, flat.WeightIndex);
            xout.WriteProperty(PersistConst.Weights, flat.Weights);
            xout.WriteProperty(BasicNetwork.TagBiasActivation,
                               flat.BiasActivation);
            xout.AddSubSection("ACTIVATION");

            foreach (IActivationFunction af  in  flat.ActivationFunctions)
            {
                xout.AddColumn(af.GetType().Name);
                for (int i = 0; i < af.Params.Length; i++)
                {
                    xout.AddColumn(af.Params[i]);
                }
                xout.WriteLine();
            }

            xout.Flush();
        }
        /// <summary>
        /// Save the config info.
        /// </summary>
        ///
        /// <param name="xout">THe output file.</param>
        private void SaveConfig(EncogWriteHelper xout)
        {
            SaveSubSection(xout, "SETUP", "CONFIG");
            xout.AddSubSection("FILENAMES");

            IList<String> list = _script.Properties.Filenames;


            foreach (var key  in  list)
            {
                String v = _script.Properties.GetFilename(key);
                var f = new FileInfo(v);
                xout.WriteProperty(key,
                                   f.DirectoryName.Equals(_script.BasePath, StringComparison.InvariantCultureIgnoreCase)
                                       ? f.Name
                                       : v);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        ///
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var pnn = (BasicPNN) obj;
            xout.AddSection("PNN");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(pnn.Properties);
            xout.AddSubSection("NETWORK");

            xout.WriteProperty(PersistConst.Error, pnn.Error);
            xout.WriteProperty(PersistConst.InputCount, pnn.InputCount);
            xout.WriteProperty(PersistConst.Kernel,
                               KernelToString(pnn.Kernel));
            xout.WriteProperty(PersistConst.OutputCount, pnn.OutputCount);
            xout.WriteProperty(PropertyOutputMode,
                               OutputModeToString(pnn.OutputMode));
            xout.WriteProperty(PersistConst.Sigma, pnn.Sigma);

            xout.AddSubSection("SAMPLES");

            if (pnn.Samples != null)
            {
                foreach (IMLDataPair pair in pnn.Samples)
                {
                    for (int i = 0; i < pair.Input.Count; i++)
                    {
                        xout.AddColumn(pair.Input[i]);
                    }

                    for (int i = 0; i < pair.Ideal.Count; i++)
                    {
                        xout.AddColumn(pair.Ideal[i]);
                    }
                    xout.WriteLine();
                }
            }
            xout.Flush();
        }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            EncogWriteHelper o = new EncogWriteHelper(os);
            BayesianNetwork b = (BayesianNetwork)obj;
            o.AddSection("BAYES-NETWORK");
            o.AddSubSection("BAYES-PARAM");
            String queryType = "";
            String queryStr = b.ClassificationStructure;

            if (b.Query != null)
            {
                queryType = b.Query.GetType().Name;
            }

            o.WriteProperty("queryType", queryType);
            o.WriteProperty("query", queryStr);
            o.WriteProperty("contents", b.Contents);
            o.AddSubSection("BAYES-PROPERTIES");
            o.AddProperties(b.Properties);

            o.AddSubSection("BAYES-TABLE");
            foreach (BayesianEvent e in b.Events)
            {
                foreach (TableLine line in e.Table.Lines)
                {
                    if (line == null)
                        continue;
                    StringBuilder str = new StringBuilder();
                    str.Append("P(");

                    str.Append(BayesianEvent.FormatEventName(e, line.Result));

                    if (e.Parents.Count > 0)
                    {
                        str.Append("|");
                    }

                    int index = 0;
                    bool first = true;
                    foreach (BayesianEvent parentEvent in e.Parents)
                    {
                        if (!first)
                        {
                            str.Append(",");
                        }
                        first = false;
                        int arg = line.Arguments[index++];
                        if (parentEvent.IsBoolean)
                        {
                            if (arg == 0)
                            {
                                str.Append("+");
                            }
                            else
                            {
                                str.Append("-");
                            }
                        }
                        str.Append(parentEvent.Label);
                        if (!parentEvent.IsBoolean)
                        {
                            str.Append("=");
                            if (arg >= parentEvent.Choices.Count)
                            {
                                throw new BayesianError("Argument value " + arg + " is out of range for event " + parentEvent.ToString());
                            }
                            str.Append(parentEvent.GetChoice(arg));
                        }
                    }
                    str.Append(")=");
                    str.Append(line.Probability);
                    str.Append("\n");
                    o.Write(str.ToString());
                }
            }

            o.Flush();
        }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var cpn = (CPNNetwork) obj;
            xout.AddSection("CPN");
            xout.AddSubSection("PARAMS");
            xout.AddProperties(cpn.Properties);
            xout.AddSubSection("NETWORK");

            xout.WriteProperty(PersistConst.InputCount, cpn.InputCount);
            xout.WriteProperty(PersistConst.Instar, cpn.InstarCount);
            xout.WriteProperty(PersistConst.OutputCount, cpn.OutputCount);
            xout.WriteProperty(PropertyInputToInstar,
                               cpn.WeightsInputToInstar);
            xout.WriteProperty(PropertyInstarToInput,
                               cpn.WeightsInstarToOutstar);
            xout.WriteProperty(PropertyWinnerCount, cpn.WinnerCount);

            xout.Flush();
        }
        /// <inheritdoc/>
        public void Save(Stream os, Object obj)
        {
            var xout = new EncogWriteHelper(os);
            var cont = (TrainingContinuation) obj;
            xout.AddSection("CONT");
            xout.AddSubSection("PARAMS");
            xout.WriteProperty("type", cont.TrainingType);

            foreach (String key  in  cont.Contents.Keys)
            {
                var list = (double[]) cont.Get(key);
                xout.WriteProperty(key, list);
            }
            xout.Flush();
        }
Beispiel #30
0
 public virtual void Save(Stream os, object obj)
 {
     EncogWriteHelper xout = new EncogWriteHelper(os);
     NEATNetwork network = (NEATNetwork) obj;
     xout.AddSection("NEAT");
     xout.AddSubSection("PARAMS");
     xout.AddProperties(network.Properties);
     xout.AddSubSection("NETWORK");
     if (8 != 0)
     {
     }
     xout.WriteProperty("inputCount", network.InputCount);
     xout.WriteProperty("outputCount", network.OutputCount);
     xout.WriteProperty("activationFunction", network.ActivationFunction);
     xout.WriteProperty("outAct", network.OutputActivationFunction);
     xout.WriteProperty("depth", network.NetworkDepth);
     Label_0087:
     xout.WriteProperty("snapshot", network.Snapshot);
     xout.AddSubSection("NEURONS");
     using (IEnumerator<NEATNeuron> enumerator = network.Neurons.GetEnumerator())
     {
         NEATNeuron current;
         goto Label_00E3;
     Label_00B2:
         if (8 == 0)
         {
             goto Label_00F6;
         }
         xout.AddColumn(current.ActivationResponse);
         xout.AddColumn(current.SplitX);
         xout.AddColumn(current.SplitY);
         xout.WriteLine();
     Label_00E3:
         if (!enumerator.MoveNext())
         {
             goto Label_0124;
         }
         current = enumerator.Current;
     Label_00F6:
         xout.AddColumn((int) current.NeuronID);
         xout.AddColumn(PersistNEATPopulation.NeuronTypeToString(current.NeuronType));
         goto Label_00B2;
     }
     Label_0124:
     xout.AddSubSection("LINKS");
     foreach (NEATNeuron neuron2 in network.Neurons)
     {
         foreach (NEATLink link in neuron2.OutputboundLinks)
         {
             WriteLink(xout, link);
         }
     }
     xout.Flush();
     if (-1 != 0)
     {
         return;
     }
     goto Label_0087;
 }