/// <inheritdoc/> public Object Read(Stream mask0) { var result = new TrainingContinuation(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("CONT") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); foreach (String key in paras.Keys) { if (key.Equals("type", StringComparison.InvariantCultureIgnoreCase)) { result.TrainingType = paras[key]; } else { double[] list = EncogFileSection .ParseDoubleArray(paras, key); result.Put(key, list); } } } } return result; }
/** * {@inheritDoc} */ public Object Read(Stream istream) { var result = new SOMNetwork(); var reader = new EncogReadHelper(istream); EncogFileSection section; while ((section = reader.ReadNextSection()) != null) { if (section.SectionName.Equals("SOM") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> p = section.ParseParams(); EngineArray.PutAll(p, result.Properties); } if (section.SectionName.Equals("SOM") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.Weights = EncogFileSection.ParseMatrix(p, PersistConst.Weights) ; } } return result; }
/// <summary> /// Read a an object. /// </summary> public Object Read(Stream mask0) { var result = new HopfieldNetwork(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("HOPFIELD") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("HOPFIELD") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.Weights = NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Weights])); result.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Output]))); result.NeuronCount = EncogFileSection.ParseInt(p, PersistConst.NeuronCount); } } return result; }
public object Read(Stream mask0) { EncogFileSection section; BAMNetwork network = new BAMNetwork(); EncogReadHelper helper = new EncogReadHelper(mask0); goto Label_002F; Label_000B: if (!section.SectionName.Equals("BAM")) { goto Label_002F; } Label_001D: if (section.SubSectionName.Equals("NETWORK")) { IDictionary<string, string> paras = section.ParseParams(); network.F1Count = EncogFileSection.ParseInt(paras, "f1Count"); network.F2Count = EncogFileSection.ParseInt(paras, "f2Count"); if (0 != 0) { goto Label_000B; } network.WeightsF1ToF2 = EncogFileSection.ParseMatrix(paras, "weightsF1F2"); if (0 != 0) { goto Label_00C2; } network.WeightsF2ToF1 = EncogFileSection.ParseMatrix(paras, "weightsF2F1"); } Label_002F: if ((section = helper.ReadNextSection()) != null) { if (!section.SectionName.Equals("BAM")) { goto Label_000B; } } else { return network; } Label_00AB: if (section.SubSectionName.Equals("PARAMS")) { EngineArray.PutAll<string, string>(section.ParseParams(), network.Properties); } else { goto Label_000B; } Label_00C2: if (0 != 0) { goto Label_00AB; } if (15 != 0) { goto Label_000B; } goto Label_001D; }
/// <inheritdoc/> public Object Read(Stream mask0) { var result = new BAMNetwork(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("BAM") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("BAM") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.F1Count = EncogFileSection.ParseInt(p, PersistConst.PropertyF1Count); result.F2Count = EncogFileSection.ParseInt(p, PersistConst.PropertyF2Count); result.WeightsF1ToF2 = EncogFileSection.ParseMatrix(p,PersistConst.PropertyWeightsF1F2); result.WeightsF2ToF1 = EncogFileSection.ParseMatrix(p,PersistConst.PropertyWeightsF2F1); } } return result; }
/// <inheritdoc/> public Object Read(Stream mask0) { var result = new ART1(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("ART1") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("ART1") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.A1 = EncogFileSection.ParseDouble(p, BasicART.PropertyA1); result.B1 = EncogFileSection.ParseDouble(p, BasicART.PropertyB1); result.C1 = EncogFileSection.ParseDouble(p, BasicART.PropertyC1); result.D1 = EncogFileSection.ParseDouble(p, BasicART.PropertyD1); result.F1Count = EncogFileSection.ParseInt(p, PersistConst.PropertyF1Count); result.F2Count = EncogFileSection.ParseInt(p, PersistConst.PropertyF2Count); result.NoWinner = EncogFileSection.ParseInt(p, BasicART.PropertyNoWinner); result.L = EncogFileSection .ParseDouble(p, BasicART.PropertyL); result.Vigilance = EncogFileSection.ParseDouble(p, BasicART.PropertyVigilance); result.WeightsF1ToF2 = EncogFileSection.ParseMatrix(p, PersistConst.PropertyWeightsF1F2); result.WeightsF2ToF1 = EncogFileSection.ParseMatrix(p, PersistConst.PropertyWeightsF2F1); } } return result; }
/// <inheritdoc/> public Object Read(Stream mask0) { IDictionary<String, String> networkParams = null; var ins0 = new EncogReadHelper(mask0); EncogFileSection section; int inputCount = 0; int instarCount = 0; int outputCount = 0; int winnerCount = 0; Matrix m1 = null; Matrix m2 = null; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("CPN") && section.SubSectionName.Equals("PARAMS")) { networkParams = section.ParseParams(); } if (section.SectionName.Equals("CPN") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> paras = section.ParseParams(); inputCount = EncogFileSection.ParseInt(paras, PersistConst.InputCount); instarCount = EncogFileSection.ParseInt(paras, PersistConst.Instar); outputCount = EncogFileSection.ParseInt(paras, PersistConst.OutputCount); winnerCount = EncogFileSection.ParseInt(paras, PropertyWinnerCount); m1 = EncogFileSection.ParseMatrix(paras, PropertyInputToInstar); m2 = EncogFileSection.ParseMatrix(paras, PropertyInstarToInput); } } var result = new CPNNetwork(inputCount, instarCount, outputCount, winnerCount); EngineArray.PutAll(networkParams, result.Properties); result.WeightsInputToInstar.Set(m1); result.WeightsInstarToOutstar.Set(m2); return result; }
public void Load(Stream stream) { EncogReadHelper helper = null; try { EncogFileSection section; helper = new EncogReadHelper(stream); while ((section = helper.ReadNextSection()) != null) { this.xf9edee23632d6876(section); } this._x594135906c55045c.Init(); } finally { if (helper != null) { helper.Close(); } } }
/// <inheritdoc/> public Object Read(Stream mask0) { var result = new BoltzmannMachine(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("BOLTZMANN") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("BOLTZMANN") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.Weights = NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Weights])); result.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Output]))); result.NeuronCount = EncogFileSection.ParseInt(p, PersistConst.NeuronCount); result.Threshold = NumberList.FromList(CSVFormat.EgFormat, (p[PersistConst.Thresholds])); result.AnnealCycles = EncogFileSection.ParseInt(p, BoltzmannMachine.ParamAnnealCycles); result.RunCycles = EncogFileSection.ParseInt(p, BoltzmannMachine.ParamRunCycles); result.Temperature = EncogFileSection.ParseDouble(p, PersistConst.Temperature); } } return result; }
public object Read(Stream mask0) { FlatNetwork network2; EncogReadHelper helper; EncogFileSection section; IDictionary<string, string> dictionary2; int num; int num2; BasicNetwork network = new BasicNetwork(); goto Label_03B8; Label_000B: if ((section = helper.ReadNextSection()) != null) { goto Label_036A; } network.Structure.Flat = network2; if ((((uint) num) - ((uint) num2)) <= uint.MaxValue) { if (8 != 0) { return network; } goto Label_03B8; } Label_003F: num = 0; network2.ActivationFunctions = new IActivationFunction[network2.LayerCounts.Length]; using (IEnumerator<string> enumerator = section.Lines.GetEnumerator()) { string str; IActivationFunction function; IList<string> list; Label_0064: if (enumerator.MoveNext()) { goto Label_00E2; } goto Label_000B; Label_0072: network2.ActivationFunctions[num++] = function; if (0 == 0) { goto Label_00D6; } Label_0087: num2 = 0; while (num2 < function.ParamNames.Length) { function.Params[num2] = CSVFormat.EgFormat.Parse(list[num2 + 1]); num2++; } if ((((uint) num) + ((uint) num2)) <= uint.MaxValue) { goto Label_0072; } Label_00D6: if (4 != 0) { goto Label_0064; } goto Label_000B; Label_00E2: str = enumerator.Current; list = EncogFileSection.SplitColumns(str); string name = "Encog.Engine.Network.Activation." + list[0]; try { function = (IActivationFunction) ReflectionUtil.LoadObject(name); goto Label_0087; } catch (TypeLoadException exception) { throw new PersistError(exception); } catch (TargetException exception2) { throw new PersistError(exception2); } catch (MemberAccessException exception3) { throw new PersistError(exception3); } } goto Label_000B; Label_0182: if (!section.SectionName.Equals("BASIC")) { goto Label_01A9; } Label_0194: if (section.SubSectionName.Equals("NETWORK")) { dictionary2 = section.ParseParams(); network2.BeginTraining = EncogFileSection.ParseInt(dictionary2, "beginTraining"); network2.ConnectionLimit = EncogFileSection.ParseDouble(dictionary2, "connectionLimit"); goto Label_032A; } Label_01A9: if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("ACTIVATION")) { goto Label_003F; } goto Label_000B; Label_032A: network2.ContextTargetOffset = EncogFileSection.ParseIntArray(dictionary2, "contextTargetOffset"); network2.ContextTargetSize = EncogFileSection.ParseIntArray(dictionary2, "contextTargetSize"); network2.EndTraining = EncogFileSection.ParseInt(dictionary2, "endTraining"); network2.HasContext = EncogFileSection.ParseBoolean(dictionary2, "hasContext"); network2.InputCount = EncogFileSection.ParseInt(dictionary2, "inputCount"); if ((((uint) num2) - ((uint) num2)) <= uint.MaxValue) { if ((((uint) num) + ((uint) num)) > uint.MaxValue) { return network; } network2.LayerCounts = EncogFileSection.ParseIntArray(dictionary2, "layerCounts"); do { network2.LayerFeedCounts = EncogFileSection.ParseIntArray(dictionary2, "layerFeedCounts"); network2.LayerContextCount = EncogFileSection.ParseIntArray(dictionary2, "layerContextCount"); network2.LayerIndex = EncogFileSection.ParseIntArray(dictionary2, "layerIndex"); network2.LayerOutput = EncogFileSection.ParseDoubleArray(dictionary2, "output"); } while ((((uint) num) + ((uint) num)) < 0); network2.LayerSums = new double[network2.LayerOutput.Length]; network2.OutputCount = EncogFileSection.ParseInt(dictionary2, "outputCount"); network2.WeightIndex = EncogFileSection.ParseIntArray(dictionary2, "weightIndex"); do { network2.Weights = EncogFileSection.ParseDoubleArray(dictionary2, "weights"); } while (0 != 0); network2.BiasActivation = EncogFileSection.ParseDoubleArray(dictionary2, "biasActivation"); goto Label_000B; } Label_036A: if (section.SectionName.Equals("BASIC")) { if (section.SubSectionName.Equals("PARAMS")) { EngineArray.PutAll<string, string>(section.ParseParams(), network.Properties); } goto Label_0182; } if (0 == 0) { goto Label_0182; } if ((((uint) num2) + ((uint) num2)) < 0) { goto Label_032A; } goto Label_0194; Label_03B8: network2 = new FlatNetwork(); helper = new EncogReadHelper(mask0); goto Label_000B; }
/// <summary> /// Read an object. /// </summary> public Object Read(Stream mask0) { var ins0 = new EncogReadHelper(mask0); EncogFileSection section; var samples = new BasicMLDataSet(); IDictionary<String, String> networkParams = null; PNNKernelType kernel = default(PNNKernelType) /* was: null */; PNNOutputMode outmodel = default(PNNOutputMode) /* was: null */; int inputCount = 0; int outputCount = 0; double error = 0; double[] sigma = null; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("PNN") && section.SubSectionName.Equals("PARAMS")) { networkParams = section.ParseParams(); } if (section.SectionName.Equals("PNN") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> paras = section.ParseParams(); inputCount = EncogFileSection.ParseInt(paras, PersistConst.InputCount); outputCount = EncogFileSection.ParseInt(paras, PersistConst.OutputCount); kernel = StringToKernel(paras[PersistConst.Kernel]); outmodel = StringToOutputMode(paras[PropertyOutputMode]); error = EncogFileSection .ParseDouble(paras, PersistConst.Error); sigma = section.ParseDoubleArray(paras, PersistConst.Sigma); } if (section.SectionName.Equals("PNN") && section.SubSectionName.Equals("SAMPLES")) { foreach (String line in section.Lines) { IList<String> cols = EncogFileSection .SplitColumns(line); int index = 0; var inputData = new BasicMLData(inputCount); for (int i = 0; i < inputCount; i++) { inputData[i] = CSVFormat.EgFormat.Parse(cols[index++]); } var idealData = new BasicMLData(inputCount); idealData[0] = CSVFormat.EgFormat.Parse(cols[index++]); IMLDataPair pair = new BasicMLDataPair(inputData, idealData); samples.Add(pair); } } } var result = new BasicPNN(kernel, outmodel, inputCount, outputCount); if (networkParams != null) { EngineArray.PutAll(networkParams, result.Properties); } result.Samples = samples; result.Error = error; if (sigma != null) { EngineArray.ArrayCopy(sigma, result.Sigma); } return result; }
/// <summary> /// Read an object. /// </summary> /// public Object Read(Stream mask0) { var result = new BasicNetwork(); var flat = new FlatNetwork(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); flat.BeginTraining = EncogFileSection.ParseInt(p, BasicNetwork.TagBeginTraining); flat.ConnectionLimit = EncogFileSection.ParseDouble(p, BasicNetwork.TagConnectionLimit); flat.ContextTargetOffset = EncogFileSection.ParseIntArray( p, BasicNetwork.TagContextTargetOffset); flat.ContextTargetSize = EncogFileSection.ParseIntArray( p, BasicNetwork.TagContextTargetSize); flat.EndTraining = EncogFileSection.ParseInt(p, BasicNetwork.TagEndTraining); flat.HasContext = EncogFileSection.ParseBoolean(p, BasicNetwork.TagHasContext); flat.InputCount = EncogFileSection.ParseInt(p, PersistConst.InputCount); flat.LayerCounts = EncogFileSection.ParseIntArray(p, BasicNetwork.TagLayerCounts); flat.LayerFeedCounts = EncogFileSection.ParseIntArray(p, BasicNetwork.TagLayerFeedCounts); flat.LayerContextCount = EncogFileSection.ParseIntArray( p, BasicNetwork.TagLayerContextCount); flat.LayerIndex = EncogFileSection.ParseIntArray(p, BasicNetwork.TagLayerIndex); flat.LayerOutput = section.ParseDoubleArray(p,PersistConst.Output); flat.LayerSums = new double[flat.LayerOutput.Length]; flat.OutputCount = EncogFileSection.ParseInt(p, PersistConst.OutputCount); flat.WeightIndex = EncogFileSection.ParseIntArray(p, BasicNetwork.TagWeightIndex); flat.Weights = section.ParseDoubleArray(p, PersistConst.Weights); flat.BiasActivation = section.ParseDoubleArray(p, BasicNetwork.TagBiasActivation); } else if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("ACTIVATION")) { int index = 0; flat.ActivationFunctions = new IActivationFunction[flat.LayerCounts.Length]; foreach (String line in section.Lines) { IActivationFunction af; IList<String> cols = EncogFileSection .SplitColumns(line); String name = ReflectionUtil.AfPath + cols[0]; try { af = (IActivationFunction) ReflectionUtil.LoadObject(name); } catch (TypeLoadException e) { throw new PersistError(e); } catch (TargetException e) { throw new PersistError(e); } catch (MemberAccessException e) { throw new PersistError(e); } for (int i = 0; i < af.ParamNames.Length; i++) { af.Params[i] = CSVFormat.EgFormat.Parse(cols[i + 1]); } flat.ActivationFunctions[index++] = af; } } } result.Structure.Flat = flat; return result; }
/// <inheritdoc/> public Object Read(Stream istream) { long nextInnovationId = 0; long nextGeneId = 0; var result = new NEATPopulation(); var innovationList = new NEATInnovationList {Population = result}; result.Innovations = innovationList; var reader = new EncogReadHelper(istream); EncogFileSection section; while ((section = reader.ReadNextSection()) != null) { if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("INNOVATIONS")) { foreach (String line in section.Lines) { IList<String> cols = EncogFileSection .SplitColumns(line); var innovation = new NEATInnovation(); var innovationId = int.Parse(cols[1]); innovation.InnovationId = innovationId; innovation.NeuronId = int.Parse(cols[2]); result.Innovations.Innovations[cols[0]] = innovation; nextInnovationId = Math.Max(nextInnovationId, innovationId + 1); } } else if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("SPECIES")) { NEATGenome lastGenome = null; BasicSpecies lastSpecies = null; foreach (String line in section.Lines) { IList<String> cols = EncogFileSection.SplitColumns(line); if (String.Compare(cols[0], "s", StringComparison.OrdinalIgnoreCase) == 0) { lastSpecies = new BasicSpecies { Population = result, Age = int.Parse(cols[1]), BestScore = CSVFormat.EgFormat.Parse(cols[2]), GensNoImprovement = int.Parse(cols[3]) }; result.Species.Add(lastSpecies); } else if (String.Compare(cols[0], "g", StringComparison.OrdinalIgnoreCase) == 0) { bool isLeader = lastGenome == null; lastGenome = new NEATGenome { InputCount = result.InputCount, OutputCount = result.OutputCount, Species = lastSpecies, AdjustedScore = CSVFormat.EgFormat.Parse(cols[1]), Score = CSVFormat.EgFormat.Parse(cols[2]), BirthGeneration = int.Parse(cols[3]) }; lastSpecies.Add(lastGenome); if (isLeader) { lastSpecies.Leader = lastGenome; } } else if (String.Compare(cols[0], "n", StringComparison.OrdinalIgnoreCase) == 0) { var neuronGene = new NEATNeuronGene(); int geneId = int.Parse(cols[1]); neuronGene.Id = geneId; IActivationFunction af = EncogFileSection.ParseActivationFunction(cols[2]); neuronGene.ActivationFunction = af; neuronGene.NeuronType = PersistNEATPopulation.StringToNeuronType(cols[3]); neuronGene.InnovationId = int.Parse(cols[4]); lastGenome.NeuronsChromosome.Add(neuronGene); nextGeneId = Math.Max(geneId + 1, nextGeneId); } else if (String.Compare(cols[0], "l", StringComparison.OrdinalIgnoreCase) == 0) { var linkGene = new NEATLinkGene { Id = int.Parse(cols[1]), Enabled = (int.Parse(cols[2]) > 0), FromNeuronId = int.Parse(cols[3]), ToNeuronId = int.Parse(cols[4]), Weight = CSVFormat.EgFormat.Parse(cols[5]), InnovationId = int.Parse(cols[6]) }; lastGenome.LinksChromosome.Add(linkGene); } } } else if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("CONFIG")) { IDictionary<string, string> prm = section.ParseParams(); string afStr = prm[NEATPopulation.PropertyNEATActivation]; if (String.Compare(afStr, TypeCppn, StringComparison.OrdinalIgnoreCase) == 0) { HyperNEATGenome.BuildCPPNActivationFunctions(result.ActivationFunctions); } else { result.NEATActivationFunction = EncogFileSection.ParseActivationFunction(prm, NEATPopulation.PropertyNEATActivation); } result.ActivationCycles = EncogFileSection.ParseInt(prm, PersistConst.ActivationCycles); result.InputCount = EncogFileSection.ParseInt(prm, PersistConst.InputCount); result.OutputCount = EncogFileSection.ParseInt(prm, PersistConst.OutputCount); result.PopulationSize = EncogFileSection.ParseInt(prm, NEATPopulation.PropertyPopulationSize); result.SurvivalRate = EncogFileSection.ParseDouble(prm, NEATPopulation.PropertySurvivalRate); result.ActivationCycles = EncogFileSection.ParseInt(prm, NEATPopulation.PropertyCycles); } } // set factories if (result.IsHyperNEAT) { result.GenomeFactory = new FactorHyperNEATGenome(); result.CODEC = new HyperNEATCODEC(); } else { result.GenomeFactory = new FactorNEATGenome(); result.CODEC = new NEATCODEC(); } // set the next ID's result.InnovationIDGenerate.CurrentID = nextInnovationId; result.GeneIdGenerate.CurrentID = nextGeneId; // find first genome, which should be the best genome if (result.Species.Count > 0) { ISpecies species = result.Species[0]; if (species.Members.Count > 0) { result.BestGenome = species.Members[0]; } } return result; }
public virtual object Read(Stream mask0) { IDictionary<ISpecies, int> dictionary2; IDictionary<int, IGenome> dictionary3; EncogFileSection section; IDictionary<string, string> dictionary4; int num; int num2; NEATPopulation population = new NEATPopulation(); NEATInnovationList list = new NEATInnovationList { Population = population }; population.Innovations = list; EncogReadHelper helper = new EncogReadHelper(mask0); IDictionary<int, ISpecies> dictionary = new Dictionary<int, ISpecies>(); goto Label_0BD6; Label_0023: if ((section = helper.ReadNextSection()) != null) { if (!section.SectionName.Equals("NEAT-POPULATION")) { goto Label_085C; } if (section.SubSectionName.Equals("INNOVATIONS")) { using (IEnumerator<string> enumerator = section.Lines.GetEnumerator()) { string str; IList<string> list2; NEATInnovation innovation; NEATInnovation innovation2; goto Label_0A6C; Label_0A43: innovation = innovation2; if ((((uint) num2) - ((uint) num)) <= uint.MaxValue) { } population.Innovations.Add(innovation); Label_0A6C: if (enumerator.MoveNext()) { goto Label_0B54; } goto Label_0AD7; Label_0A7A: innovation2.SplitY = CSVFormat.EgFormat.Parse(list2[4]); innovation2.NeuronID = int.Parse(list2[5]); innovation2.FromNeuronID = int.Parse(list2[6]); innovation2.ToNeuronID = int.Parse(list2[7]); goto Label_0A43; Label_0AD7: if ((((uint) num2) - ((uint) num)) >= 0) { goto Label_0023; } Label_0AEF: innovation2 = new NEATInnovation(); innovation2.InnovationID = int.Parse(list2[0]); innovation2.InnovationType = StringToInnovationType(list2[1]); innovation2.NeuronType = StringToNeuronType(list2[2]); innovation2.SplitX = CSVFormat.EgFormat.Parse(list2[3]); if (0 == 0) { goto Label_0A7A; } goto Label_0023; Label_0B54: str = enumerator.Current; do { list2 = EncogFileSection.SplitColumns(str); } while (0 != 0); goto Label_0AEF; } } if (((uint) num) <= uint.MaxValue) { goto Label_085C; } goto Label_030B; } using (IEnumerator<IGenome> enumerator4 = population.Genomes.GetEnumerator()) { IGenome genome3; NEATGenome genome4; ISpecies species3; Label_0040: if (enumerator4.MoveNext()) { goto Label_00D6; } goto Label_0102; Label_0051: genome4.OutputCount = population.OutputCount; if ((((uint) num) - ((uint) num2)) >= 0) { goto Label_0040; } Label_007D: if (dictionary.ContainsKey(num)) { goto Label_00BA; } Label_0087: genome4.InputCount = population.InputCount; goto Label_0051; Label_0096: num = (int) genome4.SpeciesID; if ((((uint) num2) + ((uint) num2)) <= uint.MaxValue) { } goto Label_007D; Label_00BA: species3 = dictionary[num]; species3.Members.Add(genome4); goto Label_0087; Label_00D6: genome3 = enumerator4.Current; genome4 = (NEATGenome) genome3; goto Label_0096; } Label_0102: using (IEnumerator<ISpecies> enumerator5 = dictionary2.Keys.GetEnumerator()) { ISpecies current; goto Label_011F; Label_0112: ((BasicSpecies) current).Population = population; Label_011F: if (enumerator5.MoveNext()) { current = enumerator5.Current; num2 = dictionary2[current]; do { IGenome genome5 = dictionary3[num2]; current.Leader = genome5; } while (-1 == 0); goto Label_0112; } return population; } Label_016E: population.YoungScoreBonus = EncogFileSection.ParseDouble(dictionary4, "youngAgeBonus"); population.GenomeIDGenerate.CurrentID = EncogFileSection.ParseInt(dictionary4, "nextGenomeID"); population.InnovationIDGenerate.CurrentID = EncogFileSection.ParseInt(dictionary4, "nextInnovationID"); population.GeneIDGenerate.CurrentID = EncogFileSection.ParseInt(dictionary4, "nextGeneID"); population.SpeciesIDGenerate.CurrentID = EncogFileSection.ParseInt(dictionary4, "nextSpeciesID"); goto Label_0023; Label_0201: population.SurvivalRate = EncogFileSection.ParseDouble(dictionary4, "survivalRate"); if (0 != 0) { goto Label_03AA; } goto Label_02E9; Label_0242: population.OldAgePenalty = EncogFileSection.ParseDouble(dictionary4, "oldAgePenalty"); population.OldAgeThreshold = EncogFileSection.ParseInt(dictionary4, "oldAgeThreshold"); Label_0266: population.PopulationSize = EncogFileSection.ParseInt(dictionary4, "populationSize"); if (((uint) num2) <= uint.MaxValue) { if ((((uint) num2) - ((uint) num2)) >= 0) { if ((((uint) num) + ((uint) num2)) > uint.MaxValue) { goto Label_0242; } goto Label_0201; } goto Label_02E9; } Label_028A: population.OutputActivationFunction = EncogFileSection.ParseActivationFunction(dictionary4, "outAct"); if ((((uint) num2) + ((uint) num2)) < 0) { goto Label_0BD6; } population.Snapshot = EncogFileSection.ParseBoolean(dictionary4, "snapshot"); population.InputCount = EncogFileSection.ParseInt(dictionary4, "inputCount"); population.OutputCount = EncogFileSection.ParseInt(dictionary4, "outputCount"); goto Label_0242; Label_02E9: if ((((uint) num2) - ((uint) num)) >= 0) { population.YoungBonusAgeThreshhold = EncogFileSection.ParseInt(dictionary4, "youngAgeThreshold"); } if (0xff != 0) { goto Label_016E; } Label_030B: population.NeatActivationFunction = EncogFileSection.ParseActivationFunction(dictionary4, "neatAct"); goto Label_028A; Label_03AA: if (!section.SectionName.Equals("NEAT-POPULATION") || !section.SubSectionName.Equals("CONFIG")) { goto Label_0023; } if ((((uint) num2) + ((uint) num2)) <= uint.MaxValue) { if ((((uint) num2) + ((uint) num2)) <= uint.MaxValue) { dictionary4 = section.ParseParams(); } goto Label_030B; } Label_0821: if (section.SectionName.Equals("NEAT-POPULATION")) { if (section.SubSectionName.Equals("GENOMES")) { NEATGenome genome = null; using (IEnumerator<string> enumerator3 = section.Lines.GetEnumerator()) { string str3; IList<string> list3; NEATGenome genome2; NEATNeuronGene gene; NEATNeuronGene gene2; NEATLinkGene gene3; goto Label_0402; Label_03DA: genome.Links.Add(gene3); goto Label_0402; Label_03EA: if (list3[0].Equals("l", StringComparison.InvariantCultureIgnoreCase)) { goto Label_04EA; } Label_0402: if (enumerator3.MoveNext()) { goto Label_0770; } if ((((uint) num2) | 0x80000000) != 0) { goto Label_0023; } Label_0429: gene3.Enabled = int.Parse(list3[2]) > 0; Label_0440: gene3.Recurrent = int.Parse(list3[3]) > 0; gene3.FromNeuronID = int.Parse(list3[4]); gene3.ToNeuronID = int.Parse(list3[5]); gene3.Weight = CSVFormat.EgFormat.Parse(list3[6]); gene3.InnovationId = int.Parse(list3[7]); goto Label_03DA; Label_04B4: if ((((uint) num) & 0) != 0) { goto Label_03DA; } gene3.Id = int.Parse(list3[1]); goto Label_0429; Label_04EA: gene3 = new NEATLinkGene(); goto Label_04B4; Label_04F6: gene2.SplitY = CSVFormat.EgFormat.Parse(list3[7]); Label_050F: gene = gene2; genome.Neurons.Add(gene); if ((((uint) num2) & 0) != 0) { goto Label_0782; } goto Label_0402; Label_053D: gene2.Enabled = int.Parse(list3[3]) > 0; gene2.InnovationId = int.Parse(list3[4]); if (0xff == 0) { goto Label_050F; } gene2.ActivationResponse = CSVFormat.EgFormat.Parse(list3[5]); gene2.SplitX = CSVFormat.EgFormat.Parse(list3[6]); goto Label_04F6; Label_05A7: gene2.Id = int.Parse(list3[1]); gene2.NeuronType = StringToNeuronType(list3[2]); goto Label_053D; Label_05DA: if (!list3[0].Equals("n", StringComparison.InvariantCultureIgnoreCase)) { goto Label_03EA; } if (3 == 0) { goto Label_0440; } gene2 = new NEATNeuronGene(); goto Label_07C8; Label_0608: population.Add(genome); dictionary3[(int) genome.GenomeID] = genome; if (((uint) num) >= 0) { goto Label_0402; } goto Label_06B0; Label_0638: genome.AmountToSpawn = CSVFormat.EgFormat.Parse(list3[4]); genome.NetworkDepth = int.Parse(list3[5]); if ((((uint) num2) | 0x80000000) == 0) { goto Label_07AD; } if (((uint) num2) < 0) { goto Label_0023; } genome.Score = CSVFormat.EgFormat.Parse(list3[6]); goto Label_06F8; Label_06B0: genome.GenomeID = int.Parse(list3[1]); genome.SpeciesID = int.Parse(list3[2]); genome.AdjustedScore = CSVFormat.EgFormat.Parse(list3[3]); goto Label_0638; Label_06F8: if (3 != 0) { goto Label_0608; } goto Label_0402; Label_0704: genome.Chromosomes.Add(genome.LinksChromosome); if ((((uint) num2) + ((uint) num2)) >= 0) { goto Label_06B0; } goto Label_0402; Label_0737: if (8 == 0) { goto Label_050F; } genome = genome2; genome.Chromosomes.Add(genome.NeuronsChromosome); if ((((uint) num) - ((uint) num2)) <= uint.MaxValue) { goto Label_0704; } Label_0770: str3 = enumerator3.Current; list3 = EncogFileSection.SplitColumns(str3); Label_0782: if (!list3[0].Equals("g", StringComparison.InvariantCultureIgnoreCase)) { goto Label_05DA; } genome2 = new NEATGenome { NeuronsChromosome = new Chromosome() }; Label_07AD: genome2.LinksChromosome = new Chromosome(); goto Label_0737; Label_07C8: if ((((uint) num2) - ((uint) num)) <= uint.MaxValue) { goto Label_05A7; } if (0 == 0) { goto Label_04EA; } goto Label_04B4; } } if ((((uint) num2) < 0) || ((((uint) num2) - ((uint) num2)) > uint.MaxValue)) { goto Label_030B; } } goto Label_03AA; Label_085C: if (section.SectionName.Equals("NEAT-POPULATION")) { if ((((uint) num) | 1) == 0) { goto Label_0266; } if (section.SubSectionName.Equals("SPECIES")) { if ((((uint) num) | 8) == 0) { goto Label_0201; } using (IEnumerator<string> enumerator2 = section.Lines.GetEnumerator()) { string str2; string[] strArray; BasicSpecies species; BasicSpecies species2; goto Label_0913; Label_08CB: species = species2; species.SpawnsRequired = CSVFormat.EgFormat.Parse(strArray[5]); dictionary2[species] = int.Parse(strArray[6]); population.Species.Add(species); dictionary[(int) species.SpeciesID] = species; Label_0913: if (enumerator2.MoveNext()) { goto Label_09D6; } goto Label_0023; Label_0924: if ((((uint) num2) & 0) != 0) { goto Label_0969; } if (2 == 0) { goto Label_0924; } goto Label_09BE; Label_0941: species2 = new BasicSpecies(); species2.SpeciesID = int.Parse(strArray[0]); species2.Age = int.Parse(strArray[1]); Label_0969: species2.BestScore = CSVFormat.EgFormat.Parse(strArray[2]); species2.GensNoImprovement = int.Parse(strArray[3]); species2.SpawnsRequired = CSVFormat.EgFormat.Parse(strArray[4]); if ((((uint) num) + ((uint) num2)) >= 0) { goto Label_0924; } Label_09BE: if ((((uint) num2) + ((uint) num)) <= uint.MaxValue) { goto Label_09FD; } Label_09D6: str2 = enumerator2.Current; strArray = str2.Split(new char[] { ',' }); goto Label_0941; Label_09FD: if ((((uint) num) - ((uint) num)) <= uint.MaxValue) { goto Label_08CB; } goto Label_0023; } } } goto Label_0821; Label_0BD6: dictionary2 = new Dictionary<ISpecies, int>(); dictionary3 = new Dictionary<int, IGenome>(); goto Label_0023; }
/// <inheritdoc/> public Object Read(Stream mask0) { var result = new SupportVectorMachine(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("SVM") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } if (section.SectionName.Equals("SVM") && section.SubSectionName.Equals("SVM-PARAM")) { IDictionary<String, String> p = section.ParseParams(); result.InputCount = EncogFileSection.ParseInt(p, PersistConst.InputCount); result.Params.C = EncogFileSection.ParseDouble(p, ParamC); result.Params.cache_size = EncogFileSection.ParseDouble( p, ParamCacheSize); result.Params.coef0 = EncogFileSection.ParseDouble(p, ParamCoef0); result.Params.degree = EncogFileSection.ParseDouble(p, ParamDegree); result.Params.eps = EncogFileSection.ParseDouble(p, ParamEps); result.Params.gamma = EncogFileSection.ParseDouble(p, ParamGamma); result.Params.kernel_type = EncogFileSection.ParseInt( p, ParamKernelType); result.Params.nr_weight = EncogFileSection.ParseInt( p, ParamNumWeight); result.Params.nu = EncogFileSection.ParseDouble(p, ParamNu); result.Params.p = EncogFileSection.ParseDouble(p, ParamP); result.Params.probability = EncogFileSection.ParseInt( p, ParamProbability); result.Params.shrinking = EncogFileSection.ParseInt( p, ParamShrinking); /*result.Params.statIterations = Encog.Persist.EncogFileSection.ParseInt( params_0, PersistSVM.PARAM_START_ITERATIONS);*/ result.Params.svm_type = EncogFileSection.ParseInt(p, ParamSVMType); result.Params.weight = section.ParseDoubleArray(p, ParamWeight); result.Params.weight_label = EncogFileSection .ParseIntArray(p, ParamWeightLabel); } else if (section.SectionName.Equals("SVM") && section.SubSectionName.Equals("SVM-MODEL")) { try { var rdr = new StringReader( section.LinesAsString); TextReader br = rdr; svm_model model = svm.svm_load_model(rdr); result.Model = model; br.Close(); rdr.Close(); } catch (IOException ex) { throw new PersistError(ex); } } } return result; }
public object Read(Stream mask0) { IDictionary<string, string> source = null; EncogFileSection section; IDictionary<string, string> dictionary2; EncogReadHelper helper = new EncogReadHelper(mask0); int theInputCount = 0; int theInstarCount = 0; int theOutstarCount = 0; int theWinnerCount = 0; Matrix other = null; Matrix matrix2 = null; goto Label_0097; Label_0075: if (3 == 0) { goto Label_00D0; } if ((((uint) theInstarCount) + ((uint) theOutstarCount)) > uint.MaxValue) { goto Label_019A; } Label_0097: if ((section = helper.ReadNextSection()) != null) { if (!section.SectionName.Equals("CPN")) { goto Label_00D0; } goto Label_019A; } CPNNetwork network = new CPNNetwork(theInputCount, theInstarCount, theOutstarCount, theWinnerCount); EngineArray.PutAll<string, string>(source, network.Properties); if ((((uint) theInputCount) & 0) != 0) { goto Label_0176; } network.WeightsInputToInstar.Set(other); network.WeightsInstarToOutstar.Set(matrix2); if (((uint) theInstarCount) <= uint.MaxValue) { return network; } goto Label_00E4; Label_00D0: if (!section.SectionName.Equals("CPN")) { goto Label_0097; } if (((uint) theInstarCount) >= 0) { if (section.SubSectionName.Equals("NETWORK")) { dictionary2 = section.ParseParams(); theInputCount = EncogFileSection.ParseInt(dictionary2, "inputCount"); goto Label_0176; } if (((uint) theInstarCount) >= 0) { goto Label_0097; } goto Label_0075; } return network; Label_00E4: theWinnerCount = EncogFileSection.ParseInt(dictionary2, "winnerCount"); other = EncogFileSection.ParseMatrix(dictionary2, "inputToInstar"); matrix2 = EncogFileSection.ParseMatrix(dictionary2, "instarToInput"); if (2 != 0) { goto Label_0075; } goto Label_00D0; Label_0176: theInstarCount = EncogFileSection.ParseInt(dictionary2, "instar"); if (((uint) theWinnerCount) >= 0) { theOutstarCount = EncogFileSection.ParseInt(dictionary2, "outputCount"); if ((((uint) theInputCount) + ((uint) theInstarCount)) < 0) { goto Label_019A; } } goto Label_00E4; Label_019A: if (section.SubSectionName.Equals("PARAMS")) { source = section.ParseParams(); } goto Label_00D0; }
public object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; SOMNetwork network = new SOMNetwork(); goto Label_00FC; Label_000B: if (section.SubSectionName.Equals("NETWORK")) { IDictionary<string, string> paras = section.ParseParams(); network.Weights = EncogFileSection.ParseMatrix(paras, "weights"); network.OutputCount = EncogFileSection.ParseInt(paras, "outputCount"); network.InputCount = EncogFileSection.ParseInt(paras, "inputCount"); if (0 != 0) { if (0 == 0) { goto Label_0055; } goto Label_0039; } } Label_001D: if ((section = helper.ReadNextSection()) != null) { if (!section.SectionName.Equals("SOM")) { goto Label_003E; } goto Label_00A0; } if (15 != 0) { return network; } goto Label_00FC; Label_0039: if (0 == 0) { goto Label_001D; } goto Label_000B; Label_003E: if (!section.SectionName.Equals("SOM")) { goto Label_0039; } if (1 != 0) { goto Label_000B; } return network; Label_0055: if (0 != 0) { if (0 != 0) { goto Label_001D; } } else { goto Label_003E; } Label_00A0: if (section.SubSectionName.Equals("PARAMS")) { EngineArray.PutAll<string, string>(section.ParseParams(), network.Properties); } goto Label_003E; Label_00FC: if (4 == 0) { goto Label_0055; } helper = new EncogReadHelper(mask0); goto Label_001D; }
public object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; IDictionary<string, string> dictionary; TrainingContinuation continuation = new TrainingContinuation(); if (3 != 0) { helper = new EncogReadHelper(mask0); goto Label_001E; } Label_0010: if ((-2 == 0) || (4 == 0)) { goto Label_005C; } Label_001E: if ((section = helper.ReadNextSection()) == null) { return continuation; } if (!section.SectionName.Equals("CONT")) { if (1 != 0) { if (0xff == 0) { return continuation; } goto Label_0010; } if (0 == 0) { goto Label_0077; } goto Label_001E; } Label_005C: if (section.SubSectionName.Equals("PARAMS")) { dictionary = section.ParseParams(); } else if ((0 == 0) && ((0 != 0) || (3 != 0))) { goto Label_001E; } Label_0077: using (IEnumerator<string> enumerator = dictionary.Keys.GetEnumerator()) { string current; double[] numArray; goto Label_0090; Label_0086: continuation.Put(current, numArray); Label_0090: if (enumerator.MoveNext()) { current = enumerator.Current; if (current.Equals("type", StringComparison.InvariantCultureIgnoreCase)) { continuation.TrainingType = dictionary[current]; goto Label_0090; } numArray = EncogFileSection.ParseDoubleArray(dictionary, current); if (0xff != 0) { } goto Label_0086; } } goto Label_001E; }
/// <inheritdoc/> public Object Read(Stream istream) { int states = 0; int[] items; double[] pi = null; Matrix transitionProbability = null; IDictionary<String, String> properties = null; IList<IStateDistribution> distributions = new List<IStateDistribution>(); EncogReadHelper reader = new EncogReadHelper(istream); EncogFileSection section; while ((section = reader.ReadNextSection()) != null) { if (section.SectionName.Equals("HMM") && section.SubSectionName.Equals("PARAMS")) { properties = section.ParseParams(); } if (section.SectionName.Equals("HMM") && section.SubSectionName.Equals("CONFIG")) { IDictionary<String, String> p = section.ParseParams(); states = EncogFileSection.ParseInt(p, HiddenMarkovModel.TAG_STATES); if (p.ContainsKey(HiddenMarkovModel.TAG_ITEMS)) { items = EncogFileSection.ParseIntArray(p, HiddenMarkovModel.TAG_ITEMS); } pi = section.ParseDoubleArray(p, HiddenMarkovModel.TAG_PI); transitionProbability = EncogFileSection.ParseMatrix(p, HiddenMarkovModel.TAG_TRANSITION); } else if (section.SectionName.Equals("HMM") && section.SubSectionName.StartsWith("DISTRIBUTION-")) { IDictionary<String, String> p = section.ParseParams(); String t = p[HiddenMarkovModel.TAG_DIST_TYPE]; if ("ContinousDistribution".Equals(t)) { double[] mean = section.ParseDoubleArray(p, HiddenMarkovModel.TAG_MEAN); Matrix cova = EncogFileSection.ParseMatrix(p, HiddenMarkovModel.TAG_COVARIANCE); ContinousDistribution dist = new ContinousDistribution(mean, cova.Data); distributions.Add(dist); } else if ("DiscreteDistribution".Equals(t)) { Matrix prob = EncogFileSection.ParseMatrix(p, HiddenMarkovModel.TAG_PROBABILITIES); DiscreteDistribution dist = new DiscreteDistribution(prob.Data); distributions.Add(dist); } } } HiddenMarkovModel result = new HiddenMarkovModel(states); EngineArray.PutAll(properties, result.Properties); result.TransitionProbability = transitionProbability.Data; result.Pi = pi; int index = 0; foreach (IStateDistribution dist in distributions) { result.StateDistributions[index++] = dist; } return result; }
/// <summary> /// Load an Encog script. /// </summary> /// <param name="stream">The stream to load from.</param> public void Load(Stream stream) { EncogReadHelper reader = null; try { EncogFileSection section; reader = new EncogReadHelper(stream); while ((section = reader.ReadNextSection()) != null) { ProcessSubSection(section); } // init the script _script.Init(); } finally { if (reader != null) { reader.Close(); } } }
/// <summary> /// Read the object. /// </summary> /// <param name="mask0">The stream to read from.</param> /// <returns>The loaded object.</returns> public virtual Object Read(Stream mask0) { var result = new NEATNetwork(); var ins0 = new EncogReadHelper(mask0); EncogFileSection section; IDictionary<Int32, NEATNeuron> neuronMap = new Dictionary<Int32, NEATNeuron>(); while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("NEAT") && section.SubSectionName.Equals("PARAMS")) { IDictionary<String, String> paras = section.ParseParams(); foreach (String key in paras.Keys) { result.Properties.Add(key, paras[key]); } } if (section.SectionName.Equals("NEAT") && section.SubSectionName.Equals("NETWORK")) { IDictionary<String, String> p = section.ParseParams(); result.InputCount = EncogFileSection.ParseInt(p, PersistConst.InputCount); result.OutputCount = EncogFileSection.ParseInt(p, PersistConst.OutputCount); result.ActivationFunction = EncogFileSection .ParseActivationFunction(p, PersistConst.ActivationFunction); result.OutputActivationFunction = EncogFileSection .ParseActivationFunction(p, NEATPopulation.PropertyOutputActivation); result.NetworkDepth = EncogFileSection.ParseInt(p, PersistConst.Depth); result.Snapshot = EncogFileSection.ParseBoolean(p, PersistConst.Snapshot); } else if (section.SectionName.Equals("NEAT") && section.SubSectionName.Equals("NEURONS")) { foreach (String line in section.Lines) { IList<String> cols = EncogFileSection.SplitColumns(line); long neuronID = Int32.Parse(cols[0]); NEATNeuronType neuronType = PersistNEATPopulation .StringToNeuronType(cols[1]); double activationResponse = CSVFormat.EgFormat .Parse(cols[2]); double splitY = CSVFormat.EgFormat .Parse(cols[3]); double splitX = CSVFormat.EgFormat .Parse(cols[4]); var neatNeuron = new NEATNeuron(neuronType, neuronID, splitY, splitX, activationResponse); result.Neurons.Add(neatNeuron); neuronMap[((int) neuronID)] = (neatNeuron); } } else if (section.SectionName.Equals("NEAT") && section.SubSectionName.Equals("LINKS")) { foreach (String line in section.Lines) { IList<String> cols = EncogFileSection.SplitColumns(line); int fromID = Int32.Parse(cols[0]); int toID = Int32.Parse(cols[1]); bool recurrent = Int32.Parse(cols[2]) > 0; double weight = CSVFormat.EgFormat.Parse(cols[3]); NEATNeuron fromNeuron = (neuronMap[fromID]); NEATNeuron toNeuron = (neuronMap[toID]); var neatLink = new NEATLink(weight, fromNeuron, toNeuron, recurrent); fromNeuron.OutputboundLinks.Add(neatLink); toNeuron.InboundLinks.Add(neatLink); } } } return result; }
/// <inheritdoc /> public Object Read(Stream istream) { var context = new EncogProgramContext(); var result = new PrgPopulation(context, 0); var reader = new EncogReadHelper(istream); EncogFileSection section; int count = 0; ISpecies lastSpecies = null; while ((section = reader.ReadNextSection()) != null) { if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("PARAMS")) { IDictionary<string, string> prms = section.ParseParams(); EngineArray.PutAll(prms, result.Properties); } else if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("EPL-POPULATION")) { foreach (string line in section.Lines) { IList<String> cols = EncogFileSection.SplitColumns(line); if (String.Compare(cols[0], "s", StringComparison.OrdinalIgnoreCase) == 0) { lastSpecies = new BasicSpecies { Age = int.Parse(cols[1]), BestScore = CSVFormat.EgFormat.Parse(cols[2]), Population = result, GensNoImprovement = int.Parse(cols[3]) }; result.Species.Add(lastSpecies); } else if (cols[0].Equals("p")) { double score; double adjustedScore; if (String.Compare(cols[1], "nan", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(cols[2], "nan", StringComparison.OrdinalIgnoreCase) == 0) { score = Double.NaN; adjustedScore = Double.NaN; } else { score = CSVFormat.EgFormat.Parse(cols[1]); adjustedScore = CSVFormat.EgFormat.Parse(cols[2]); } String code = cols[3]; var prg = new EncogProgram(context); prg.CompileEPL(code); prg.Score = score; prg.Species = lastSpecies; prg.AdjustedScore = adjustedScore; if (lastSpecies == null) { throw new EncogError( "Have not defined a species yet"); } lastSpecies.Add(prg); count++; } } } else if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("EPL-OPCODES")) { foreach (String line in section.Lines) { IList<string> cols = EncogFileSection.SplitColumns(line); String name = cols[0]; int args = int.Parse(cols[1]); result.Context.Functions.AddExtension(name, args); } } else if (section.SectionName.Equals("BASIC") && section.SubSectionName.Equals("EPL-SYMBOLIC")) { bool first = true; foreach (string line in section.Lines) { if (!first) { IList<String> cols = EncogFileSection.SplitColumns(line); String name = cols[0]; String t = cols[1]; var vt = EPLValueType.Unknown; if (string.Compare(t, "f", true) == 0) { vt = EPLValueType.FloatingType; } else if (string.Compare(t, "b", true) == 0) { vt = EPLValueType.BooleanType; } else if (string.Compare(t, "i", true) == 0) { vt = EPLValueType.IntType; } else if (string.Compare(t, "s", true) == 0) { vt = EPLValueType.StringType; } else if (string.Compare(t, "e", true) == 0) { vt = EPLValueType.EnumType; } int enumType = int.Parse(cols[2]); int enumCount = int.Parse(cols[3]); var mapping = new VariableMapping( name, vt, enumType, enumCount); if (mapping.Name.Length > 0) { result.Context.DefineVariable(mapping); } else { result.Context.Result = mapping; } } else { first = false; } } } } result.PopulationSize = count; // set the best genome, should be the first genome in the first species if (result.Species.Count > 0) { ISpecies species = result.Species[0]; if (species.Members.Count > 0) { result.BestGenome = species.Members[0]; } // set the leaders foreach (ISpecies sp in result.Species) { if (sp.Members.Count > 0) { sp.Leader = sp.Members[0]; } } } return result; }
public object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; IDictionary<string, string> dictionary2; HopfieldNetwork network = new HopfieldNetwork(); goto Label_00F0; Label_000D: if (section.SectionName.Equals("HOPFIELD") || (0 != 0)) { goto Label_0031; } Label_0022: if ((section = helper.ReadNextSection()) != null) { if (section.SectionName.Equals("HOPFIELD")) { if (0 != 0) { goto Label_0031; } if (3 != 0) { if (0xff == 0) { goto Label_0022; } if (section.SubSectionName.Equals("PARAMS")) { IDictionary<string, string> source = section.ParseParams(); if (0 == 0) { EngineArray.PutAll<string, string>(source, network.Properties); } } } } goto Label_000D; } return network; Label_0031: if (section.SubSectionName.Equals("NETWORK")) { dictionary2 = section.ParseParams(); } else { goto Label_0022; } network.Weights = NumberList.FromList(CSVFormat.EgFormat, dictionary2["weights"]); if (0 == 0) { network.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, dictionary2["output"])); network.NeuronCount = EncogFileSection.ParseInt(dictionary2, "neurons"); goto Label_0022; } if (3 != 0) { goto Label_000D; } Label_00F0: helper = new EncogReadHelper(mask0); goto Label_0022; }
public virtual object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; IDictionary<int, NEATNeuron> dictionary; IDictionary<string, string> dictionary2; double num2; double num3; int num5; int num6; bool flag; double num7; NEATNetwork network = new NEATNetwork(); if ((((uint) flag) + ((uint) num3)) <= uint.MaxValue) { if ((((uint) num6) + ((uint) num6)) < 0) { goto Label_03FB; } if ((((uint) flag) + ((uint) num3)) <= uint.MaxValue) { helper = new EncogReadHelper(mask0); if ((((uint) flag) & 0) == 0) { dictionary = new Dictionary<int, NEATNeuron>(); goto Label_0023; } } goto Label_03AA; } goto Label_0035; Label_0023: if ((section = helper.ReadNextSection()) != null) { goto Label_045C; } return network; Label_0035: if (section.SectionName.Equals("NEAT")) { while (section.SubSectionName.Equals("LINKS")) { using (IEnumerator<string> enumerator3 = section.Lines.GetEnumerator()) { string str3; IList<string> list2; NEATNeuron neuron3; NEATLink link; goto Label_007D; Label_005B: if ((((uint) num6) & 0) != 0) { goto Label_00D5; } neuron3.InboundLinks.Add(link); Label_007D: if (enumerator3.MoveNext()) { goto Label_00FA; } if ((((uint) num2) + ((uint) num3)) >= 0) { goto Label_0023; } Label_009E: num7 = CSVFormat.EgFormat.Parse(list2[3]); NEATNeuron fromNeuron = dictionary[num5]; neuron3 = dictionary[num6]; link = new NEATLink(num7, fromNeuron, neuron3, flag); Label_00D5: fromNeuron.OutputboundLinks.Add(link); if (((uint) num3) >= 0) { goto Label_005B; } goto Label_0023; Label_00FA: str3 = enumerator3.Current; list2 = EncogFileSection.SplitColumns(str3); num5 = int.Parse(list2[0]); if (-2 != 0) { } num6 = int.Parse(list2[1]); flag = int.Parse(list2[2]) > 0; goto Label_009E; } } if (((uint) num7) >= 0) { } } goto Label_0023; Label_03AA: if (!section.SectionName.Equals("NEAT") || !section.SubSectionName.Equals("NETWORK")) { if (section.SectionName.Equals("NEAT") && section.SubSectionName.Equals("NEURONS")) { using (IEnumerator<string> enumerator2 = section.Lines.GetEnumerator()) { string str2; IList<string> list; long num; NEATNeuronType type; NEATNeuron neuron; Label_01BD: if (enumerator2.MoveNext()) { goto Label_0257; } goto Label_0023; Label_01CE: if ((((uint) num) + ((uint) num5)) > uint.MaxValue) { goto Label_02A0; } network.Neurons.Add(neuron); dictionary[(int) num] = neuron; goto Label_02D0; Label_0206: num3 = CSVFormat.EgFormat.Parse(list[3]); double num4 = CSVFormat.EgFormat.Parse(list[4]); neuron = new NEATNeuron(type, num, num3, num4, num2); if ((((uint) num7) - ((uint) num)) <= uint.MaxValue) { goto Label_02B9; } Label_0257: str2 = enumerator2.Current; do { list = EncogFileSection.SplitColumns(str2); num = int.Parse(list[0]); type = PersistNEATPopulation.StringToNeuronType(list[1]); } while ((((uint) num) + ((uint) num5)) < 0); Label_02A0: num2 = CSVFormat.EgFormat.Parse(list[2]); goto Label_0206; Label_02B9: if ((((uint) num3) & 0) == 0) { goto Label_01CE; } Label_02D0: if ((((uint) num6) - ((uint) num4)) >= 0) { goto Label_01BD; } goto Label_0023; } } goto Label_0035; } IDictionary<string, string> paras = section.ParseParams(); network.InputCount = EncogFileSection.ParseInt(paras, "inputCount"); network.OutputCount = EncogFileSection.ParseInt(paras, "outputCount"); network.ActivationFunction = EncogFileSection.ParseActivationFunction(paras, "activationFunction"); if (((uint) num7) <= uint.MaxValue) { network.OutputActivationFunction = EncogFileSection.ParseActivationFunction(paras, "outAct"); if (((uint) num3) >= 0) { network.NetworkDepth = EncogFileSection.ParseInt(paras, "depth"); network.Snapshot = EncogFileSection.ParseBoolean(paras, "snapshot"); goto Label_0023; } goto Label_0035; } Label_03F3: dictionary2 = section.ParseParams(); Label_03FB: foreach (string str in dictionary2.Keys) { network.Properties.Add(str, dictionary2[str]); } goto Label_03AA; if (((((uint) flag) + ((uint) num2)) <= uint.MaxValue) && (((uint) flag) >= 0)) { goto Label_03AA; } Label_045C: if (section.SectionName.Equals("NEAT") && section.SubSectionName.Equals("PARAMS")) { goto Label_03F3; } goto Label_03AA; }
public object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; ART1 art = new ART1(); goto Label_01A7; Label_0014: if (0 != 0) { goto Label_005C; } Label_0020: if ((section = helper.ReadNextSection()) != null) { if (section.SectionName.Equals("ART1") && (section.SubSectionName.Equals("PARAMS") || (0 != 0))) { EngineArray.PutAll<string, string>(section.ParseParams(), art.Properties); } goto Label_0048; } return art; Label_0041: if ((-2 != 0) && (15 != 0)) { if (0xff == 0) { goto Label_0014; } goto Label_0020; } Label_0048: if (!section.SectionName.Equals("ART1")) { goto Label_0014; } Label_005C: if (section.SubSectionName.Equals("NETWORK")) { IDictionary<string, string> dictionary2; Label_0166: dictionary2 = section.ParseParams(); if (0 == 0) { art.A1 = EncogFileSection.ParseDouble(dictionary2, "A1"); art.B1 = EncogFileSection.ParseDouble(dictionary2, "B1"); art.C1 = EncogFileSection.ParseDouble(dictionary2, "C1"); if (0 == 0) { art.D1 = EncogFileSection.ParseDouble(dictionary2, "D1"); art.F1Count = EncogFileSection.ParseInt(dictionary2, "f1Count"); if (4 != 0) { if (0 != 0) { goto Label_0041; } if (0 != 0) { goto Label_0166; } art.F2Count = EncogFileSection.ParseInt(dictionary2, "f2Count"); art.NoWinner = EncogFileSection.ParseInt(dictionary2, "noWinner"); } art.L = EncogFileSection.ParseDouble(dictionary2, "L"); art.Vigilance = EncogFileSection.ParseDouble(dictionary2, "VIGILANCE"); } art.WeightsF1ToF2 = EncogFileSection.ParseMatrix(dictionary2, "weightsF1F2"); art.WeightsF2ToF1 = EncogFileSection.ParseMatrix(dictionary2, "weightsF2F1"); goto Label_0041; } } else { goto Label_0020; } Label_01A7: helper = new EncogReadHelper(mask0); goto Label_0020; }
public object Read(Stream mask0) { EncogFileSection section; IDictionary<string, string> dictionary; IDictionary<string, string> dictionary2; int num; int num2; int num3; int num4; int num5; int num6; RBFNetwork network = new RBFNetwork(); FlatNetworkRBF flat = (FlatNetworkRBF) network.Flat; EncogReadHelper helper = new EncogReadHelper(mask0); Label_003B: if ((section = helper.ReadNextSection()) != null) { if (!section.SectionName.Equals("RBF-NETWORK")) { goto Label_0473; } goto Label_069F; } if ((((uint) num5) & 0) == 0) { goto Label_0236; } goto Label_0070; Label_005E: if (!section.SectionName.Equals("RBF-NETWORK")) { goto Label_003B; } Label_0070: if (section.SubSectionName.Equals("RBF")) { num3 = 0; num4 = flat.LayerCounts[1]; do { if (0 != 0) { if ((((uint) num6) - ((uint) num2)) < 0) { goto Label_0473; } goto Label_0416; } } while ((((uint) num3) - ((uint) num3)) > uint.MaxValue); num5 = flat.LayerCounts[2]; if ((((uint) num4) | 0xfffffffe) == 0) { goto Label_0473; } goto Label_0273; } if ((((uint) num) + ((uint) num)) > uint.MaxValue) { goto Label_02F4; } if ((((uint) num2) - ((uint) num5)) >= 0) { if (((((uint) num4) - ((uint) num3)) > uint.MaxValue) && ((((uint) num5) - ((uint) num5)) < 0)) { goto Label_005E; } goto Label_003B; } Label_0236: if ((((uint) num3) + ((uint) num4)) >= 0) { return network; } if (4 != 0) { goto Label_02F4; } if ((((uint) num) + ((uint) num5)) >= 0) { goto Label_005E; } Label_0273: flat.RBF = new IRadialBasisFunction[num4]; if (((uint) num2) >= 0) { if ((((uint) num5) | 0xfffffffe) == 0) { return network; } using (IEnumerator<string> enumerator2 = section.Lines.GetEnumerator()) { string str3; IRadialBasisFunction function2; IList<string> list2; goto Label_00EC; Label_00D6: if (num6 < num5) { goto Label_00FF; } Label_00DC: flat.RBF[num3++] = function2; Label_00EC: if (enumerator2.MoveNext()) { goto Label_01F2; } goto Label_003B; Label_00FA: num6 = 0; goto Label_00D6; Label_00FF: function2.Centers[num6] = CSVFormat.EgFormat.Parse(list2[num6 + 3]); Label_011E: num6++; if (0 == 0) { goto Label_00D6; } goto Label_003B; Label_012C: function2.Centers = new double[num5]; goto Label_00FA; Label_013F: if (0 != 0) { goto Label_011E; } list2 = EncogFileSection.SplitColumns(str3); string name = "Encog.MathUtil.RBF." + list2[0]; try { function2 = (IRadialBasisFunction) ReflectionUtil.LoadObject(name); } catch (TypeLoadException exception2) { throw new PersistError(exception2); } catch (TargetException exception3) { throw new PersistError(exception3); } catch (MemberAccessException exception4) { throw new PersistError(exception4); } function2.Width = CSVFormat.EgFormat.Parse(list2[1]); function2.Peak = CSVFormat.EgFormat.Parse(list2[2]); if ((((uint) num6) + ((uint) num)) >= 0) { goto Label_0200; } if ((((uint) num4) - ((uint) num3)) < 0) { goto Label_00DC; } Label_01F2: str3 = enumerator2.Current; goto Label_013F; Label_0200: if ((((uint) num4) | 3) != 0) { goto Label_012C; } goto Label_00FA; } } Label_02F4: using (IEnumerator<string> enumerator = section.Lines.GetEnumerator()) { string str; IActivationFunction function; IList<string> list; goto Label_0313; Label_0303: flat.ActivationFunctions[num++] = function; Label_0313: if (enumerator.MoveNext()) { goto Label_03A2; } if (0xff != 0) { goto Label_003B; } Label_032B: if (num2 < function.ParamNames.Length) { goto Label_0376; } goto Label_03AD; Label_033A: list = EncogFileSection.SplitColumns(str); string str2 = "Encog.Engine.Network.Activation." + list[0]; try { function = (IActivationFunction) ReflectionUtil.LoadObject(str2); } catch (Exception exception) { throw new PersistError(exception); } num2 = 0; goto Label_032B; Label_0376: function.Params[num2] = CSVFormat.EgFormat.Parse(list[num2 + 1]); num2++; goto Label_032B; Label_03A2: str = enumerator.Current; goto Label_033A; Label_03AD: if ((((uint) num2) | uint.MaxValue) != 0) { goto Label_0303; } goto Label_003B; } goto Label_005E; Label_0416: if (!section.SectionName.Equals("RBF-NETWORK") || !section.SubSectionName.Equals("ACTIVATION")) { goto Label_005E; } if ((((uint) num2) | 4) == 0) { goto Label_069F; } num = 0; Label_045E: flat.ActivationFunctions = new IActivationFunction[flat.LayerCounts.Length]; goto Label_02F4; Label_0473: if (section.SectionName.Equals("RBF-NETWORK")) { goto Label_05FF; } goto Label_0416; Label_05EB: flat.InputCount = EncogFileSection.ParseInt(dictionary2, "inputCount"); flat.LayerCounts = EncogFileSection.ParseIntArray(dictionary2, "layerCounts"); if ((((uint) num) + ((uint) num3)) <= uint.MaxValue) { goto Label_06F4; } goto Label_06B4; Label_05FF: if (!section.SubSectionName.Equals("NETWORK")) { goto Label_0416; } dictionary2 = section.ParseParams(); flat.BeginTraining = EncogFileSection.ParseInt(dictionary2, "beginTraining"); flat.ConnectionLimit = EncogFileSection.ParseDouble(dictionary2, "connectionLimit"); flat.ContextTargetOffset = EncogFileSection.ParseIntArray(dictionary2, "contextTargetOffset"); flat.ContextTargetSize = EncogFileSection.ParseIntArray(dictionary2, "contextTargetSize"); flat.EndTraining = EncogFileSection.ParseInt(dictionary2, "endTraining"); flat.HasContext = EncogFileSection.ParseBoolean(dictionary2, "hasContext"); goto Label_05EB; Label_069F: if (section.SubSectionName.Equals("PARAMS")) { dictionary = section.ParseParams(); } else if (0 == 0) { goto Label_06D9; } Label_06B4: EngineArray.PutAll<string, string>(dictionary, network.Properties); if ((((uint) num5) - ((uint) num5)) >= 0) { goto Label_0473; } Label_06D9: if ((((uint) num) - ((uint) num3)) >= 0) { if (0 == 0) { goto Label_0473; } goto Label_05FF; } Label_06F4: if (-2147483648 != 0) { flat.LayerFeedCounts = EncogFileSection.ParseIntArray(dictionary2, "layerFeedCounts"); if (((uint) num3) < 0) { goto Label_05EB; } flat.LayerContextCount = EncogFileSection.ParseIntArray(dictionary2, "layerContextCount"); flat.LayerIndex = EncogFileSection.ParseIntArray(dictionary2, "layerIndex"); if (0 == 0) { flat.LayerOutput = EncogFileSection.ParseDoubleArray(dictionary2, "output"); flat.LayerSums = new double[flat.LayerOutput.Length]; flat.OutputCount = EncogFileSection.ParseInt(dictionary2, "outputCount"); } flat.WeightIndex = EncogFileSection.ParseIntArray(dictionary2, "weightIndex"); if ((((uint) num3) > uint.MaxValue) || ((((uint) num2) - ((uint) num2)) < 0)) { goto Label_045E; } flat.Weights = EncogFileSection.ParseDoubleArray(dictionary2, "weights"); flat.BiasActivation = EncogFileSection.ParseDoubleArray(dictionary2, "biasActivation"); goto Label_003B; } return network; }
/// <inheritdoc/> public Object Read(Stream istream) { BayesianNetwork result = new BayesianNetwork(); EncogReadHelper input = new EncogReadHelper(istream); EncogFileSection section; String queryType = ""; String queryStr = ""; String contentsStr = ""; while ((section = input.ReadNextSection()) != null) { if (section.SectionName.Equals("BAYES-NETWORK") && section.SubSectionName.Equals("BAYES-PARAM")) { IDictionary<String, String> p = section.ParseParams(); queryType = p["queryType"]; queryStr = p["query"]; contentsStr = p["contents"]; } if (section.SectionName.Equals("BAYES-NETWORK") && section.SubSectionName.Equals("BAYES-TABLE")) { result.Contents = contentsStr; // first, define relationships (1st pass) foreach (String line in section.Lines) { result.DefineRelationship(line); } result.FinalizeStructure(); // now define the probabilities (2nd pass) foreach (String line in section.Lines) { result.DefineProbability(line); } } if (section.SectionName.Equals("BAYES-NETWORK") && section.SubSectionName.Equals("BAYES-PROPERTIES")) { IDictionary<String, String> paras = section.ParseParams(); EngineArray.PutAll(paras, result.Properties); } } // define query, if it exists if (queryType.Length > 0) { IBayesianQuery query = null; if (queryType.Equals("EnumerationQuery")) { query = new EnumerationQuery(result); } else { query = new SamplingQuery(result); } if (query != null && queryStr.Length > 0) { result.Query = query; result.DefineClassificationStructure(queryStr); } } return result; }
/// <summary> /// Read the object. /// </summary> /// <param name="mask0">The stream to read the object from.</param> /// <returns>The object that was loaded.</returns> public virtual Object Read(Stream mask0) { var result = new NEATPopulation(); var innovationList = new NEATInnovationList {Population = result}; result.Innovations = innovationList; var ins0 = new EncogReadHelper(mask0); IDictionary<Int32, ISpecies> speciesMap = new Dictionary<Int32, ISpecies>(); IDictionary<ISpecies, Int32> leaderMap = new Dictionary<ISpecies, Int32>(); IDictionary<Int32, IGenome> genomeMap = new Dictionary<Int32, IGenome>(); EncogFileSection section; while ((section = ins0.ReadNextSection()) != null) { if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("INNOVATIONS")) { foreach (String line in section.Lines) { IList<String> cols = EncogFileSection.SplitColumns(line); var innovation = new NEATInnovation { InnovationID = Int32.Parse(cols[0]), InnovationType = StringToInnovationType(cols[1]), NeuronType = StringToNeuronType(cols[2]), SplitX = CSVFormat.EgFormat.Parse(cols[3]), SplitY = CSVFormat.EgFormat.Parse(cols[4]), NeuronID = Int32.Parse(cols[5]), FromNeuronID = Int32.Parse(cols[6]), ToNeuronID = Int32.Parse(cols[7]) }; result.Innovations.Add(innovation); } } else if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("SPECIES")) { foreach (String line in section.Lines) { String[] cols = line.Split(','); var species = new BasicSpecies { SpeciesID = Int32.Parse(cols[0]), Age = Int32.Parse(cols[1]), BestScore = CSVFormat.EgFormat.Parse(cols[2]), GensNoImprovement = Int32.Parse(cols[3]), SpawnsRequired = CSVFormat.EgFormat .Parse(cols[4]) }; species.SpawnsRequired = CSVFormat.EgFormat .Parse(cols[5]); leaderMap[(species)] = (Int32.Parse(cols[6])); result.Species.Add(species); speciesMap[((int) species.SpeciesID)] = (species); } } else if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("GENOMES")) { NEATGenome lastGenome = null; foreach (String line in section.Lines) { IList<String> cols = EncogFileSection.SplitColumns(line); if (cols[0].Equals("g", StringComparison.InvariantCultureIgnoreCase)) { lastGenome = new NEATGenome { NeuronsChromosome = new Chromosome(), LinksChromosome = new Chromosome() }; lastGenome.Chromosomes.Add(lastGenome.NeuronsChromosome); lastGenome.Chromosomes.Add(lastGenome.LinksChromosome); lastGenome.GenomeID = Int32.Parse(cols[1]); lastGenome.SpeciesID = Int32.Parse(cols[2]); lastGenome.AdjustedScore = CSVFormat.EgFormat .Parse(cols[3]); lastGenome.AmountToSpawn = CSVFormat.EgFormat .Parse(cols[4]); lastGenome.NetworkDepth = Int32.Parse(cols[5]); lastGenome.Score = CSVFormat.EgFormat.Parse(cols[6]); result.Add(lastGenome); genomeMap[(int) lastGenome.GenomeID] = lastGenome; } else if (cols[0].Equals("n", StringComparison.InvariantCultureIgnoreCase)) { var neuronGene = new NEATNeuronGene { Id = Int32.Parse(cols[1]), NeuronType = StringToNeuronType(cols[2]), Enabled = Int32.Parse(cols[3]) > 0, InnovationId = Int32.Parse(cols[4]), ActivationResponse = CSVFormat.EgFormat .Parse(cols[5]), SplitX = CSVFormat.EgFormat.Parse(cols[6]), SplitY = CSVFormat.EgFormat.Parse(cols[7]) }; lastGenome.Neurons.Add(neuronGene); } else if (cols[0].Equals("l", StringComparison.InvariantCultureIgnoreCase)) { var linkGene = new NEATLinkGene(); linkGene.Id = Int32.Parse(cols[1]); linkGene.Enabled = Int32.Parse(cols[2]) > 0; linkGene.Recurrent = Int32.Parse(cols[3]) > 0; linkGene.FromNeuronID = Int32.Parse(cols[4]); linkGene.ToNeuronID = Int32.Parse(cols[5]); linkGene.Weight = CSVFormat.EgFormat.Parse(cols[6]); linkGene.InnovationId = Int32.Parse(cols[7]); lastGenome.Links.Add(linkGene); } } } else if (section.SectionName.Equals("NEAT-POPULATION") && section.SubSectionName.Equals("CONFIG")) { IDictionary<String, String> paras = section.ParseParams(); result.NeatActivationFunction = EncogFileSection .ParseActivationFunction(paras, NEATPopulation.PropertyNEATActivation); result.OutputActivationFunction = EncogFileSection .ParseActivationFunction(paras, NEATPopulation.PropertyOutputActivation); result.Snapshot = EncogFileSection.ParseBoolean(paras, PersistConst.Snapshot); result.InputCount = EncogFileSection.ParseInt(paras, PersistConst.InputCount); result.OutputCount = EncogFileSection.ParseInt(paras, PersistConst.OutputCount); result.OldAgePenalty = EncogFileSection.ParseDouble(paras, PopulationConst.PropertyOldAgePenalty); result.OldAgeThreshold = EncogFileSection.ParseInt(paras, PopulationConst.PropertyOldAgeThreshold); result.PopulationSize = EncogFileSection.ParseInt(paras, PopulationConst.PropertyPopulationSize); result.SurvivalRate = EncogFileSection.ParseDouble(paras, PopulationConst.PropertySurvivalRate); result.YoungBonusAgeThreshhold = EncogFileSection.ParseInt( paras, PopulationConst.PropertyYoungAgeThreshold); result.YoungScoreBonus = EncogFileSection.ParseDouble(paras, PopulationConst.PropertyYoungAgeBonus); result.GenomeIDGenerate.CurrentID = EncogFileSection.ParseInt(paras, PopulationConst. PropertyNextGenomeID); result.InnovationIDGenerate.CurrentID = EncogFileSection.ParseInt(paras, PopulationConst. PropertyNextInnovationID); result.GeneIDGenerate.CurrentID = EncogFileSection.ParseInt(paras, PopulationConst. PropertyNextGeneID); result.SpeciesIDGenerate.CurrentID = EncogFileSection.ParseInt(paras, PopulationConst. PropertyNextSpeciesID); } } // now link everything up // first put all the genomes into correct species foreach (IGenome genome in result.Genomes) { var neatGenome = (NEATGenome) genome; var speciesId = (int) neatGenome.SpeciesID; if( speciesMap.ContainsKey(speciesId)) { ISpecies s = speciesMap[speciesId]; s.Members.Add(neatGenome); } neatGenome.InputCount = result.InputCount; neatGenome.OutputCount = result.OutputCount; } // set the species leader links foreach (ISpecies species in leaderMap.Keys) { int leaderID = leaderMap[species]; IGenome leader = genomeMap[leaderID]; species.Leader = leader; ((BasicSpecies) species).Population = result; } return result; }
public object Read(Stream mask0) { EncogFileSection section; IDictionary<string, string> dictionary2; BoltzmannMachine machine = new BoltzmannMachine(); EncogReadHelper helper = new EncogReadHelper(mask0); Label_0034: if ((section = helper.ReadNextSection()) != null) { goto Label_012B; } return machine; Label_00A3: machine.Threshold = NumberList.FromList(CSVFormat.EgFormat, dictionary2["thresholds"]); machine.AnnealCycles = EncogFileSection.ParseInt(dictionary2, "annealCycles"); machine.RunCycles = EncogFileSection.ParseInt(dictionary2, "runCycles"); if (0 == 0) { machine.Temperature = EncogFileSection.ParseDouble(dictionary2, "temperature"); goto Label_0034; } goto Label_0142; Label_00C4: if (section.SectionName.Equals("BOLTZMANN") && section.SubSectionName.Equals("NETWORK")) { dictionary2 = section.ParseParams(); machine.Weights = NumberList.FromList(CSVFormat.EgFormat, dictionary2["weights"]); } else { goto Label_0034; } machine.SetCurrentState(NumberList.FromList(CSVFormat.EgFormat, dictionary2["output"])); machine.NeuronCount = EncogFileSection.ParseInt(dictionary2, "neurons"); goto Label_00A3; Label_012B: if (!section.SectionName.Equals("BOLTZMANN")) { goto Label_00C4; } Label_0142: if (section.SubSectionName.Equals("PARAMS")) { EngineArray.PutAll<string, string>(section.ParseParams(), machine.Properties); if (0 == 0) { goto Label_00C4; } goto Label_012B; } if (0 != 0) { goto Label_0142; } if (2 == 0) { if (-1 == 0) { goto Label_00A3; } if (8 != 0) { goto Label_012B; } goto Label_0142; } goto Label_00C4; }
public object Read(Stream mask0) { EncogReadHelper helper; EncogFileSection section; IDictionary<string, string> dictionary2; SupportVectorMachine machine = new SupportVectorMachine(); goto Label_0306; Label_000B: if (section.SubSectionName.Equals("SVM-MODEL")) { try { svm_model _model; StringReader fp = new StringReader(section.LinesAsString); TextReader reader2 = fp; if (0 == 0) { _model = svm.svm_load_model(fp); } machine.Model = _model; reader2.Close(); fp.Close(); } catch (IOException exception) { throw new PersistError(exception); } } Label_001D: if ((section = helper.ReadNextSection()) != null) { goto Label_028D; } return machine; Label_002F: if (!section.SectionName.Equals("SVM")) { goto Label_001D; } if (-2 == 0) { goto Label_023F; } if (3 != 0) { goto Label_000B; } return machine; Label_0237: dictionary2 = section.ParseParams(); Label_023F: machine.InputCount = EncogFileSection.ParseInt(dictionary2, "inputCount"); machine.Params.C = EncogFileSection.ParseDouble(dictionary2, "C"); machine.Params.cache_size = EncogFileSection.ParseDouble(dictionary2, "cacheSize"); if (0 == 0) { if (0 == 0) { while (true) { machine.Params.coef0 = EncogFileSection.ParseDouble(dictionary2, "coef0"); machine.Params.degree = EncogFileSection.ParseDouble(dictionary2, "degree"); machine.Params.eps = EncogFileSection.ParseDouble(dictionary2, "eps"); machine.Params.gamma = EncogFileSection.ParseDouble(dictionary2, "gamma"); machine.Params.kernel_type = EncogFileSection.ParseInt(dictionary2, "kernelType"); machine.Params.nr_weight = EncogFileSection.ParseInt(dictionary2, "nrWeight"); machine.Params.nu = EncogFileSection.ParseDouble(dictionary2, "nu"); machine.Params.p = EncogFileSection.ParseDouble(dictionary2, "p"); if (0 == 0) { machine.Params.probability = EncogFileSection.ParseInt(dictionary2, "probability"); if (-2147483648 == 0) { goto Label_001D; } machine.Params.shrinking = EncogFileSection.ParseInt(dictionary2, "shrinking"); machine.Params.svm_type = EncogFileSection.ParseInt(dictionary2, "svmType"); machine.Params.weight = EncogFileSection.ParseDoubleArray(dictionary2, "weight"); machine.Params.weight_label = EncogFileSection.ParseIntArray(dictionary2, "weightLabel"); if (0xff != 0) { goto Label_001D; } goto Label_002F; } } } goto Label_000B; } if (0 == 0) { goto Label_0306; } Label_028D: if (section.SectionName.Equals("SVM") && section.SubSectionName.Equals("PARAMS")) { IDictionary<string, string> source = section.ParseParams(); if (0x7fffffff == 0) { goto Label_0237; } EngineArray.PutAll<string, string>(source, machine.Properties); } if (section.SectionName.Equals("SVM") && section.SubSectionName.Equals("SVM-PARAM")) { if (8 != 0) { if (3 == 0) { goto Label_001D; } goto Label_0237; } } else { goto Label_002F; } Label_0306: helper = new EncogReadHelper(mask0); goto Label_001D; }