/// <summary> /// Create a SVM 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( "SVM Train training cannot be used on a method of type: " + method.GetType().FullName); } double defaultGamma = 1.0d / ((SupportVectorMachine)method).InputCount; double defaultC = 1.0d; IDictionary <String, String> args = ArchitectureParse.ParseParams(argsStr); var holder = new ParamsHolder(args); double gamma = holder.GetDouble(MLTrainFactory.PropertyGamma, false, defaultGamma); double c = holder.GetDouble(MLTrainFactory.PropertyC, false, defaultC); var result = new SVMTrain((SupportVectorMachine)method, training); result.Gamma = gamma; result.C = c; return(result); }
/// <summary> /// Create an annealing 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 BasicNetwork)) { throw new TrainingError( "Invalid method type, requires BasicNetwork"); } ICalculateScore score = new TrainingSetScore(training); IDictionary <String, String> args = ArchitectureParse.ParseParams(argsStr); var holder = new ParamsHolder(args); double startTemp = holder.GetDouble( MLTrainFactory.PropertyTemperatureStart, false, 10); double stopTemp = holder.GetDouble( MLTrainFactory.PropertyTemperatureStop, false, 2); int cycles = holder.GetInt(MLTrainFactory.Cycles, false, 100); IMLTrain train = new NeuralSimulatedAnnealing( (BasicNetwork)method, score, startTemp, stopTemp, cycles); return(train); }
/// <summary> /// Create an annealing 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 BasicNetwork)) { throw new TrainingError( "Invalid method type, requires BasicNetwork"); } ICalculateScore score = new TrainingSetScore(training); IDictionary <String, String> args = ArchitectureParse.ParseParams(argsStr); var holder = new ParamsHolder(args); int populationSize = holder.GetInt( MLTrainFactory.PropertyPopulationSize, false, 5000); double mutation = holder.GetDouble( MLTrainFactory.PropertyMutation, false, 0.1d); double mate = holder.GetDouble(MLTrainFactory.PropertyMate, false, 0.25d); IMLTrain train = new NeuralGeneticAlgorithm((BasicNetwork)method, new RangeRandomizer(-1, 1), score, populationSize, mutation, mate); return(train); }
/// <summary> /// Create a backpropagation 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) { IDictionary <String, String> args = ArchitectureParse.ParseParams(argsStr); var holder = new ParamsHolder(args); double learningRate = holder.GetDouble( MLTrainFactory.PropertyLearningRate, false, 0.7d); double momentum = holder.GetDouble( MLTrainFactory.PropertyLearningMomentum, false, 0.3d); return(new Backpropagation((BasicNetwork)method, training, learningRate, momentum)); }
/// <summary> /// Create a RPROP 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 IContainsFlat)) { throw new EncogError( "RPROP 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 initialUpdate = holder.GetDouble( MLTrainFactory.PropertyInitialUpdate, false, RPROPConst.DefaultInitialUpdate); double maxStep = holder.GetDouble( MLTrainFactory.PropertyMaxStep, false, RPROPConst.DefaultMaxStep); return(new ResilientPropagation((IContainsFlat)method, training, initialUpdate, maxStep)); }
/// <summary> /// Create a SVM 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( "SVM Train training cannot be used on a method of type: " + method.GetType().FullName); } IDictionary <String, String> args = ArchitectureParse.ParseParams(argsStr); new ParamsHolder(args); var holder = new ParamsHolder(args); double gammaStart = holder.GetDouble( PropertyGamma1, false, SVMSearchTrain.DefaultGammaBegin); double cStart = holder.GetDouble(PropertyC1, false, SVMSearchTrain.DefaultConstBegin); double gammaStop = holder.GetDouble( PropertyGamma2, false, SVMSearchTrain.DefaultGammaEnd); double cStop = holder.GetDouble(PropertyC2, false, SVMSearchTrain.DefaultConstEnd); double gammaStep = holder.GetDouble( PropertyGammaStep, false, SVMSearchTrain.DefaultGammaStep); double cStep = holder.GetDouble(PropertyCStep, false, SVMSearchTrain.DefaultConstStep); var result = new SVMSearchTrain((SupportVectorMachine)method, training) { GammaBegin = gammaStart, GammaEnd = gammaStop, GammaStep = gammaStep, ConstBegin = cStart, ConstEnd = cStop, ConstStep = cStep }; return(result); }
/// <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); }