/// <summary> /// Load the SVM network. /// </summary> /// <param name="xmlin">Where to read it from.</param> /// <returns>The loaded object.</returns> public IEncogPersistedObject Load(ReadXML xmlin) { SVMNetwork result = null; int input = -1, output = -1; String name = xmlin.LastTag.Attributes[ EncogPersistedCollection.ATTRIBUTE_NAME]; String description = xmlin.LastTag.Attributes[ EncogPersistedCollection.ATTRIBUTE_DESCRIPTION]; while (xmlin.ReadToTag()) { if (xmlin.IsIt(SVMNetworkPersistor.TAG_INPUT, true)) { input = int.Parse(xmlin.ReadTextToTag()); } else if (xmlin.IsIt(SVMNetworkPersistor.TAG_OUTPUT, true)) { output = int.Parse(xmlin.ReadTextToTag()); } else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODELS, true)) { result = new SVMNetwork(input, output, false); HandleModels(xmlin, result); } else if (xmlin.IsIt(EncogPersistedCollection.TYPE_SVM, false)) { break; } } result.Name = name; result.Description = description; return result; }
/// <summary> /// Load the models. /// </summary> /// <param name="xmlin">Where to read the models from.</param> /// <param name="network">Where the models are read into.</param> private void HandleModels(ReadXML xmlin, SVMNetwork network) { int index = 0; while (xmlin.ReadToTag()) { if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODEL, true)) { svm_parameter param = new svm_parameter(); svm_model model = new svm_model(); model.param = param; network.Models[index] = model; HandleModel(xmlin, network.Models[index]); index++; } else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODELS, false)) { break; } } }
/// <summary> /// Construct a trainer for an SVM network. /// </summary> /// <param name="network">The network to train.</param> /// <param name="training">The training data for this network.</param> public SVMTrain(BasicNetwork network, INeuralDataSet training) { this.network = (SVMNetwork)network; this.Training = training; this.isSetup = false; this.trainingDone = false; this.Fold = 5; this.ConstBegin = DEFAULT_CONST_BEGIN; this.ConstStep = DEFAULT_CONST_END; this.ConstEnd = DEFAULT_CONST_STEP; this.GammaBegin = DEFAULT_GAMMA_BEGIN; this.GammaEnd = DEFAULT_GAMMA_END; this.GammaStep = DEFAULT_GAMMA_STEP; this.problem = new svm_problem[this.network.OutputCount]; for (int i = 0; i < this.network.OutputCount; i++) { this.problem[i] = EncodeSVMProblem.Encode(training, i); } }