/// <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(); }
/// <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(); }
/// <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 { #if !SILVERLIGHT 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(); #endif } catch (IOException ex) { throw new PersistError(ex); } } xout.Flush(); }
/** * {@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(); }
/// <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(); }
/// <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> /// /// </summary> /// public void Save(Stream os, Object obj) { var xout = new EncogWriteHelper(os); var bam = (BAMNetwork)obj; xout.AddSection("BAM"); xout.AddSubSection("PARAMS"); xout.AddProperties(bam.Properties); xout.AddSubSection("NETWORK"); xout.WriteProperty(PersistConst.PropertyF1Count, bam.F1Count); xout.WriteProperty(PersistConst.PropertyF2Count, bam.F2Count); xout.WriteProperty(PersistConst.PropertyWeightsF1F2, bam.WeightsF1ToF2); xout.WriteProperty(PersistConst.PropertyWeightsF2F1, bam.WeightsF2ToF1); xout.Flush(); }
/// <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(); }
/// <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 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) { EncogWriteHelper writer = new EncogWriteHelper(os); HiddenMarkovModel net = (HiddenMarkovModel)obj; writer.AddSection("HMM"); writer.AddSubSection("PARAMS"); writer.AddProperties(net.Properties); writer.AddSubSection("CONFIG"); writer.WriteProperty(HiddenMarkovModel.TAG_STATES, net.StateCount); if (net.Items != null) { writer.WriteProperty(HiddenMarkovModel.TAG_ITEMS, net.Items); } writer.WriteProperty(HiddenMarkovModel.TAG_PI, net.Pi); writer.WriteProperty(HiddenMarkovModel.TAG_TRANSITION, new Matrix(net.TransitionProbability)); for (int i = 0; i < net.StateCount; i++) { writer.AddSubSection("DISTRIBUTION-" + i); IStateDistribution sd = net.StateDistributions[i]; writer.WriteProperty(HiddenMarkovModel.TAG_DIST_TYPE, sd.GetType().Name); if (sd is ContinousDistribution) { ContinousDistribution cDist = (ContinousDistribution)sd; writer.WriteProperty(HiddenMarkovModel.TAG_MEAN, cDist.Mean); writer.WriteProperty(HiddenMarkovModel.TAG_COVARIANCE, cDist.Covariance); } else if (sd is DiscreteDistribution) { DiscreteDistribution dDist = (DiscreteDistribution)sd; writer.WriteProperty(HiddenMarkovModel.TAG_PROBABILITIES, new Matrix(dDist.Probabilities)); } } writer.Flush(); }
/// <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 ostream, Object obj) { var writer = new EncogWriteHelper(ostream); var pop = (PrgPopulation)obj; writer.AddSection("BASIC"); writer.AddSubSection("PARAMS"); writer.AddProperties(pop.Properties); writer.AddSubSection("EPL-OPCODES"); foreach (IProgramExtensionTemplate temp in pop.Context .Functions.OpCodes) { writer.AddColumn(temp.Name); writer.AddColumn(temp.ChildNodeCount); writer.WriteLine(); } writer.AddSubSection("EPL-SYMBOLIC"); writer.AddColumn("name"); writer.AddColumn("type"); writer.AddColumn("enum"); writer.AddColumn("enum_type"); writer.AddColumn("enum_count"); writer.WriteLine(); // write the first line, the result writer.AddColumn(""); writer.AddColumn(GetType(pop.Context.Result)); writer.AddColumn(pop.Context.Result.EnumType); writer.AddColumn(pop.Context.Result.EnumValueCount); writer.WriteLine(); // write the next lines, the variables foreach (VariableMapping mapping in pop.Context.DefinedVariables) { writer.AddColumn(mapping.Name); writer.AddColumn(GetType(mapping)); writer.AddColumn(mapping.EnumType); writer.AddColumn(mapping.EnumValueCount); writer.WriteLine(); } writer.AddSubSection("EPL-POPULATION"); foreach (ISpecies species in pop.Species) { if (species.Members.Count > 0) { writer.AddColumn("s"); writer.AddColumn(species.Age); writer.AddColumn(species.BestScore); writer.AddColumn(species.GensNoImprovement); writer.WriteLine(); foreach (IGenome genome in species.Members) { var prg = (EncogProgram)genome; writer.AddColumn("p"); if (Double.IsInfinity(prg.Score) || Double.IsNaN(prg.Score)) { writer.AddColumn("NaN"); writer.AddColumn("NaN"); } else { writer.AddColumn(prg.Score); writer.AddColumn(prg.AdjustedScore); } writer.AddColumn(prg.GenerateEPL()); writer.WriteLine(); } } } writer.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(); }