public GetString ( String name, bool required, String defaultValue ) : String | ||
name | String | The name of the string. |
required | bool | True if this value is required. |
defaultValue | String | The default value. |
Résultat | String |
/// <summary> /// Create a NEAT population. /// </summary> /// <param name="architecture">The architecture string to use.</param> /// <param name="input">The input count.</param> /// <param name="output">The output count.</param> /// <returns>The population.</returns> public IMLMethod Create(String architecture, int input, int output) { if (input <= 0) { throw new EncogError("Must have at least one input for NEAT."); } if (output <= 0) { throw new EncogError("Must have at least one output for NEAT."); } IDictionary<String, String> args = ArchitectureParse.ParseParams(architecture); ParamsHolder holder = new ParamsHolder(args); int populationSize = holder.GetInt( MLMethodFactory.PropertyPopulationSize, false, 1000); int cycles = holder.GetInt( MLMethodFactory.PropertyCycles, false, NEATPopulation.DefaultCycles); IActivationFunction af = this.factory.Create( holder.GetString(MLMethodFactory.PropertyAF, false, MLActivationFactory.AF_SSIGMOID)); NEATPopulation pop = new NEATPopulation(input, output, populationSize); pop.Reset(); pop.ActivationCycles = cycles; pop.NEATActivationFunction = af; return pop; }
/** * Create a K2 trainer. * * @param method * The method to use. * @param training * The training data to use. * @param argsStr * The arguments to use. * @return The newly created trainer. */ public IMLTrain Create(IMLMethod method, IMLDataSet training, String argsStr) { IDictionary<String, String> args = ArchitectureParse.ParseParams(argsStr); ParamsHolder holder = new ParamsHolder(args); int maxParents = holder.GetInt( MLTrainFactory.PropertyMaxParents, false, 1); String searchStr = holder.GetString("SEARCH", false, "k2"); String estimatorStr = holder.GetString("ESTIMATOR", false, "simple"); String initStr = holder.GetString("INIT", false, "naive"); IBayesSearch search; IBayesEstimator estimator; BayesianInit init; if( string.Compare(searchStr,"k2",true)==0) { search = new SearchK2(); } else if( string.Compare(searchStr,"none",true)==0) { search = new SearchNone(); } else { throw new BayesianError("Invalid search type: " + searchStr); } if( string.Compare(estimatorStr,"simple",true)==0) { estimator = new SimpleEstimator(); } else if( string.Compare(estimatorStr, "none",true)==0) { estimator = new EstimatorNone(); } else { throw new BayesianError("Invalid estimator type: " + estimatorStr); } if( string.Compare(initStr, "simple") ==0) { init = BayesianInit.InitEmpty; } else if( string.Compare(initStr, "naive") ==0) { init = BayesianInit.InitNaiveBayes; } else if( string.Compare(initStr, "none") ==0) { init = BayesianInit.InitNoChange; } else { throw new BayesianError("Invalid init type: " + initStr); } return new TrainBayesian((BayesianNetwork) method, training, maxParents, init, search, estimator); }
/// <summary> /// Create a feed forward network. /// </summary> /// <param name="architecture">The architecture string to use.</param> /// <param name="input">The input count.</param> /// <param name="output">The output count.</param> /// <returns>The feedforward network.</returns> public IMLMethod Create(String architecture, int input, int output) { if (input <= 0) { throw new EncogError("Must have at least one input for EPL."); } if (output <= 0) { throw new EncogError("Must have at least one output for EPL."); } IDictionary<String, String> args = ArchitectureParse.ParseParams(architecture); var holder = new ParamsHolder(args); int populationSize = holder.GetInt( MLMethodFactory.PropertyPopulationSize, false, 1000); String variables = holder.GetString("vars", false, "x"); String funct = holder.GetString("funct", false, null); var context = new EncogProgramContext(); string[] tok = variables.Split(','); foreach (string v in tok) { context.DefineVariable(v); } if (String.Compare("numeric", funct, StringComparison.OrdinalIgnoreCase) == 0) { StandardExtensions.CreateNumericOperators(context); } var pop = new PrgPopulation(context, populationSize); if (context.Functions.Count > 0) { (new RampedHalfAndHalf(context, 2, 6)).Generate(new EncogRandom(), pop); } return pop; }
/// <summary> /// Create a LMA trainer. /// </summary> /// /// <param name="method">The method to use.</param> /// <param name="training">The training data to use.</param> /// <param name="argsStr">The arguments to use.</param> /// <returns>The newly created trainer.</returns> public IMLTrain Create(IMLMethod method, IMLDataSet training, String argsStr) { if (!(method is SupportVectorMachine)) { throw new EncogError( "Neighborhood training cannot be used on a method of type: " + method.GetType().FullName); } IDictionary<String, String> args = ArchitectureParse.ParseParams(argsStr); var holder = new ParamsHolder(args); double learningRate = holder.GetDouble( MLTrainFactory.PropertyLearningRate, false, 0.7d); String neighborhoodStr = holder.GetString( MLTrainFactory.PropertyNeighborhood, false, "rbf"); String rbfTypeStr = holder.GetString( MLTrainFactory.PropertyRBFType, false, "gaussian"); RBFEnum t; if (rbfTypeStr.Equals("Gaussian", StringComparison.InvariantCultureIgnoreCase)) { t = RBFEnum.Gaussian; } else if (rbfTypeStr.Equals("Multiquadric", StringComparison.InvariantCultureIgnoreCase)) { t = RBFEnum.Multiquadric; } else if (rbfTypeStr.Equals("InverseMultiquadric", StringComparison.InvariantCultureIgnoreCase)) { t = RBFEnum.InverseMultiquadric; } else if (rbfTypeStr.Equals("MexicanHat", StringComparison.InvariantCultureIgnoreCase)) { t = RBFEnum.MexicanHat; } else { t = RBFEnum.Gaussian; } INeighborhoodFunction nf = null; if (neighborhoodStr.Equals("bubble", StringComparison.InvariantCultureIgnoreCase)) { nf = new NeighborhoodBubble(1); } else if (neighborhoodStr.Equals("rbf", StringComparison.InvariantCultureIgnoreCase)) { String str = holder.GetString( MLTrainFactory.PropertyDimensions, true, null); int[] size = NumberList.FromListInt(CSVFormat.EgFormat, str); nf = new NeighborhoodRBF(size, t); } else if (neighborhoodStr.Equals("rbf1d", StringComparison.InvariantCultureIgnoreCase)) { nf = new NeighborhoodRBF1D(t); } if (neighborhoodStr.Equals("single", StringComparison.InvariantCultureIgnoreCase)) { nf = new NeighborhoodSingle(); } var result = new BasicTrainSOM((SOMNetwork) method, learningRate, training, nf); if (args.ContainsKey(MLTrainFactory.PropertyIterations)) { int plannedIterations = holder.GetInt( MLTrainFactory.PropertyIterations, false, 1000); double startRate = holder.GetDouble( MLTrainFactory.PropertyStartLearningRate, false, 0.05d); double endRate = holder.GetDouble( MLTrainFactory.PropertyEndLearningRate, false, 0.05d); double startRadius = holder.GetDouble( MLTrainFactory.PropertyStartRadius, false, 10); double endRadius = holder.GetDouble( MLTrainFactory.PropertyEndRadius, false, 1); result.SetAutoDecay(plannedIterations, startRate, endRate, startRadius, endRadius); } return result; }
/// <summary> /// Create a PNN network. /// </summary> /// /// <param name="architecture">THe architecture string to use.</param> /// <param name="input">The input count.</param> /// <param name="output">The output count.</param> /// <returns>The RBF network.</returns> public IMLMethod Create(String architecture, int input, int output) { IList<String> layers = ArchitectureParse.ParseLayers(architecture); if (layers.Count != MaxLayers) { throw new EncogError( "PNN Networks must have exactly three elements, " + "separated by ->."); } ArchitectureLayer inputLayer = ArchitectureParse.ParseLayer( layers[0], input); ArchitectureLayer pnnLayer = ArchitectureParse.ParseLayer( layers[1], -1); ArchitectureLayer outputLayer = ArchitectureParse.ParseLayer( layers[2], output); int inputCount = inputLayer.Count; int outputCount = outputLayer.Count; PNNKernelType kernel; PNNOutputMode outmodel; if (pnnLayer.Name.Equals("c", StringComparison.InvariantCultureIgnoreCase)) { outmodel = PNNOutputMode.Classification; } else if (pnnLayer.Name.Equals("r", StringComparison.InvariantCultureIgnoreCase)) { outmodel = PNNOutputMode.Regression; } else if (pnnLayer.Name.Equals("u", StringComparison.InvariantCultureIgnoreCase)) { outmodel = PNNOutputMode.Unsupervised; } else { throw new NeuralNetworkError("Unknown model: " + pnnLayer.Name); } var holder = new ParamsHolder(pnnLayer.Params); String kernelStr = holder.GetString("KERNEL", false, "gaussian"); if (kernelStr.Equals("gaussian", StringComparison.InvariantCultureIgnoreCase)) { kernel = PNNKernelType.Gaussian; } else if (kernelStr.Equals("reciprocal", StringComparison.InvariantCultureIgnoreCase)) { kernel = PNNKernelType.Reciprocal; } else { throw new NeuralNetworkError("Unknown kernel: " + kernelStr); } var result = new BasicPNN(kernel, outmodel, inputCount, outputCount); return result; }
public IMLMethod Create(string architecture, int input, int output) { ArchitectureLayer layer3; int count; int num2; PNNKernelType reciprocal; PNNOutputMode classification; ParamsHolder holder; string str; IList<string> list = ArchitectureParse.ParseLayers(architecture); if (list.Count != 3) { throw new EncogError("PNN Networks must have exactly three elements, separated by ->."); } ArchitectureLayer layer = ArchitectureParse.ParseLayer(list[0], input); ArchitectureLayer layer2 = ArchitectureParse.ParseLayer(list[1], -1); goto Label_015F; Label_000C: if (str.Equals("reciprocal", StringComparison.InvariantCultureIgnoreCase)) { reciprocal = PNNKernelType.Reciprocal; } else { throw new NeuralNetworkError("Unknown kernel: " + str); } Label_0032: return new BasicPNN(reciprocal, classification, count, num2); Label_0089: throw new NeuralNetworkError("Unknown model: " + layer2.Name); Label_009F: holder = new ParamsHolder(layer2.Params); str = holder.GetString("KERNEL", false, "gaussian"); if ((((uint) num2) & 0) == 0) { if (str.Equals("gaussian", StringComparison.InvariantCultureIgnoreCase)) { reciprocal = PNNKernelType.Gaussian; if ((((uint) num2) - ((uint) input)) > uint.MaxValue) { goto Label_0089; } goto Label_0032; } goto Label_000C; } Label_015F: layer3 = ArchitectureParse.ParseLayer(list[2], output); count = layer.Count; num2 = layer3.Count; if ((((uint) input) & 0) != 0) { goto Label_0089; } if (!layer2.Name.Equals("c", StringComparison.InvariantCultureIgnoreCase)) { if (layer2.Name.Equals("r", StringComparison.InvariantCultureIgnoreCase)) { classification = PNNOutputMode.Regression; if ((((uint) output) + ((uint) num2)) < 0) { goto Label_000C; } goto Label_009F; } if (layer2.Name.Equals("u", StringComparison.InvariantCultureIgnoreCase)) { classification = PNNOutputMode.Unsupervised; goto Label_009F; } goto Label_0089; } classification = PNNOutputMode.Classification; goto Label_009F; }
public IMLTrain Create(IMLMethod method, IMLDataSet training, string argsStr) { IDictionary<string, string> dictionary; ParamsHolder holder; double num; string str; string str2; RBFEnum mexicanHat; INeighborhoodFunction function; string str3; int[] numArray; BasicTrainSOM nsom; int num2; double num3; double num4; double num6; if (method is SupportVectorMachine) { dictionary = ArchitectureParse.ParseParams(argsStr); holder = new ParamsHolder(dictionary); num = holder.GetDouble("LR", false, 0.7); str = holder.GetString("NEIGHBORHOOD", false, "rbf"); if (2 != 0) { goto Label_03DF; } goto Label_039F; } goto Label_03F4; Label_0083: num4 = holder.GetDouble("END_LR", false, 0.05); double startRadius = holder.GetDouble("START_RADIUS", false, 10.0); if ((((uint) num4) + ((uint) num4)) > uint.MaxValue) { return nsom; } if ((((uint) num3) + ((uint) num2)) <= uint.MaxValue) { num6 = holder.GetDouble("END_RADIUS", false, 1.0); nsom.SetAutoDecay(num2, num3, num4, startRadius, num6); return nsom; } Label_00E4: if (4 == 0) { if ((((uint) num3) + ((uint) num2)) > uint.MaxValue) { goto Label_0292; } goto Label_02F8; } Label_00EE: nsom = new BasicTrainSOM((SOMNetwork) method, num, training, function); do { if (dictionary.ContainsKey("ITERATIONS")) { do { num2 = holder.GetInt("ITERATIONS", false, 0x3e8); num3 = holder.GetDouble("START_LR", false, 0.05); } while ((((uint) num3) | 15) == 0); goto Label_0083; } } while ((((uint) num6) | 0xff) == 0); if (0 == 0) { if ((((uint) num3) + ((uint) num3)) >= 0) { return nsom; } goto Label_03F4; } if ((((uint) num2) - ((uint) startRadius)) <= uint.MaxValue) { goto Label_00E4; } goto Label_0083; Label_0184: if (!str.Equals("single", StringComparison.InvariantCultureIgnoreCase)) { goto Label_00EE; } function = new NeighborhoodSingle(); if ((((uint) num6) - ((uint) num3)) >= 0) { if ((((uint) num) - ((uint) startRadius)) >= 0) { goto Label_00E4; } goto Label_0324; } if ((((uint) num2) & 0) == 0) { goto Label_0233; } Label_01E2: while (!str.Equals("rbf1d", StringComparison.InvariantCultureIgnoreCase)) { if (0 == 0) { if ((((uint) num3) - ((uint) num6)) >= 0) { goto Label_0184; } goto Label_0233; } } function = new NeighborhoodRBF1D(mexicanHat); if ((((uint) num2) + ((uint) num)) >= 0) { if (((uint) num6) < 0) { goto Label_01E2; } goto Label_0184; } if (((uint) num2) < 0) { goto Label_03DF; } goto Label_01E2; Label_0233: function = new NeighborhoodRBF(numArray, mexicanHat); goto Label_0184; Label_0243: if (!str.Equals("rbf", StringComparison.InvariantCultureIgnoreCase)) { if ((((uint) num2) & 0) != 0) { goto Label_03DF; } goto Label_01E2; } Label_0292: str3 = holder.GetString("DIM", true, null); if ((((uint) num3) + ((uint) num)) > uint.MaxValue) { goto Label_0292; } numArray = NumberList.FromListInt(CSVFormat.EgFormat, str3); if ((((uint) num6) & 0) == 0) { goto Label_0233; } goto Label_0243; Label_02F8: if (str.Equals("bubble", StringComparison.InvariantCultureIgnoreCase)) { function = new NeighborhoodBubble(1); goto Label_0184; } if ((((uint) num3) & 0) == 0) { goto Label_0243; } goto Label_0292; Label_0324: function = null; goto Label_02F8; Label_0362: mexicanHat = RBFEnum.Multiquadric; goto Label_0324; Label_039F: mexicanHat = RBFEnum.Gaussian; goto Label_0324; Label_03DF: str2 = holder.GetString("RBF_TYPE", false, "gaussian"); if (str2.Equals("Gaussian", StringComparison.InvariantCultureIgnoreCase)) { goto Label_039F; } if (((uint) startRadius) <= uint.MaxValue) { if (str2.Equals("Multiquadric", StringComparison.InvariantCultureIgnoreCase)) { goto Label_0362; } if (!str2.Equals("InverseMultiquadric", StringComparison.InvariantCultureIgnoreCase) || ((((uint) num2) + ((uint) num2)) < 0)) { if (str2.Equals("MexicanHat", StringComparison.InvariantCultureIgnoreCase)) { mexicanHat = RBFEnum.MexicanHat; } else { mexicanHat = RBFEnum.Gaussian; } goto Label_0324; } } else if (((uint) num3) <= uint.MaxValue) { goto Label_0362; } if ((((uint) num3) - ((uint) num3)) <= uint.MaxValue) { mexicanHat = RBFEnum.InverseMultiquadric; goto Label_0324; } goto Label_00E4; Label_03F4: throw new EncogError("Neighborhood training cannot be used on a method of type: " + method.GetType().FullName); }