/// <summary> /// /// </summary> /// <param name="obj"></param> /// <param name="xmlOut"></param> public void Save(IEncogPersistedObject obj, WriteXML xmlOut) { PersistorUtil.BeginEncogObject(EncogPersistedCollection.TYPE_TRAINING, xmlOut, obj, true); INeuralDataSet set = (INeuralDataSet)obj; StringBuilder builder = new StringBuilder(); foreach (INeuralDataPair pair in set) { xmlOut.BeginTag(BasicNeuralDataSetPersistor.TAG_ITEM); NumberList.ToList(CSVFormat.EG_FORMAT, builder, pair.Input.Data); xmlOut.AddProperty(BasicNeuralDataSetPersistor.TAG_INPUT, builder .ToString()); if (pair.Ideal != null) { NumberList.ToList(CSVFormat.EG_FORMAT, builder, pair.Ideal.Data); xmlOut.AddProperty(BasicNeuralDataSetPersistor.TAG_IDEAL, builder .ToString()); } xmlOut.EndTag(); } xmlOut.EndTag(); }
/// <summary> /// Save the specified Encog object to an XML writer. /// </summary> /// <param name="obj">The object to save.</param> /// <param name="xmlOut">The XML writer to save to.</param> public void Save(IEncogPersistedObject obj, WriteXML xmlOut) { PersistorUtil.BeginEncogObject( EncogPersistedCollection.TYPE_BASIC_LAYER, xmlOut, obj, false); BasicLayer layer = (BasicLayer)obj; xmlOut.AddProperty(BasicLayerPersistor.PROPERTY_NEURONS, layer .NeuronCount); xmlOut.AddProperty(BasicLayerPersistor.PROPERTY_X, layer.X); xmlOut.AddProperty(BasicLayerPersistor.PROPERTY_Y, layer.Y); if (layer.HasBias) { StringBuilder result = new StringBuilder(); NumberList.ToList(CSVFormat.EG_FORMAT, result, layer.BiasWeights); xmlOut.AddProperty(BasicLayerPersistor.PROPERTY_THRESHOLD, result .ToString()); } xmlOut.AddProperty(BasicLayerPersistor.PROPERTY_BIAS_ACTIVATION, layer.BiasActivation); if (layer.ActivationFunction != null) { SaveActivationFunction(layer.ActivationFunction, xmlOut); } xmlOut.EndTag(); }
private void SaveRBF(WriteXML xmlout, RadialBasisFunctionLayer layer) { xmlout.BeginTag(RadialBasisFunctionLayerPersistor.PROPERTY_RBF); foreach (IRadialBasisFunction rbf in layer.RadialBasisFunction) { xmlout.BeginTag(rbf.GetType().Name); xmlout.AddProperty(PROPERTY_CENTERS, rbf.Centers, rbf.Centers.Length); xmlout.AddProperty(PROPERTY_PEAK, rbf.Peak); xmlout.AddProperty(PROPERTY_WIDTH, rbf.Width); xmlout.EndTag(); } xmlout.EndTag(); }
/// <summary> /// Save a RBF layer. /// </summary> /// <param name="obj">The object to save.</param> /// <param name="xmlout">XML stream to write to.</param> public void Save(IEncogPersistedObject obj, WriteXML xmlout) { PersistorUtil.BeginEncogObject( EncogPersistedCollection.TYPE_RADIAL_BASIS_LAYER, xmlout, obj, false); RadialBasisFunctionLayer layer = (RadialBasisFunctionLayer)obj; xmlout.AddProperty(BasicLayerPersistor.PROPERTY_NEURONS, layer.NeuronCount); xmlout.AddProperty(BasicLayerPersistor.PROPERTY_X, layer.X); xmlout.AddProperty(BasicLayerPersistor.PROPERTY_Y, layer.Y); SaveRBF(xmlout, layer); xmlout.EndTag(); }
/// <summary> /// Save a SVMNetwork. /// </summary> /// <param name="obj">The object to save.</param> /// <param name="xmlout">Where to save it to.</param> public void Save(IEncogPersistedObject obj, WriteXML xmlout) { PersistorUtil.BeginEncogObject(EncogPersistedCollection.TYPE_SVM, xmlout, obj, true); SVMNetwork net = (SVMNetwork)obj; xmlout.AddProperty(SVMNetworkPersistor.TAG_INPUT, net.InputCount); xmlout.AddProperty(SVMNetworkPersistor.TAG_OUTPUT, net.OutputCount); xmlout.BeginTag(SVMNetworkPersistor.TAG_MODELS); for (int i = 0; i < net.Models.Length; i++) { SaveModel(xmlout, net.Models[i]); } xmlout.EndTag(); xmlout.EndTag(); }
/// <summary> /// Save a model. /// </summary> /// <param name="xmlout">Where to save a model to.</param> /// <param name="model">The model to save to.</param> public static void SaveModel(WriteXML xmlout, svm_model model) { if (model != null) { xmlout.BeginTag(SVMNetworkPersistor.TAG_MODEL); svm_parameter param = model.param; xmlout.AddProperty(SVMNetworkPersistor.TAG_TYPE_SVM, svm_type_table[param.svm_type]); xmlout.AddProperty(SVMNetworkPersistor.TAG_TYPE_KERNEL, kernel_type_table[param.kernel_type]); if (param.kernel_type == svm_parameter.POLY) { xmlout.AddProperty(SVMNetworkPersistor.TAG_DEGREE, param.degree); } if (param.kernel_type == svm_parameter.POLY || param.kernel_type == svm_parameter.RBF || param.kernel_type == svm_parameter.SIGMOID) { xmlout.AddProperty(SVMNetworkPersistor.TAG_GAMMA, param.gamma); } if (param.kernel_type == svm_parameter.POLY || param.kernel_type == svm_parameter.SIGMOID) { xmlout.AddProperty(SVMNetworkPersistor.TAG_COEF0, param.coef0); } int nr_class = model.nr_class; int l = model.l; xmlout.AddProperty(SVMNetworkPersistor.TAG_NUMCLASS, nr_class); xmlout.AddProperty(SVMNetworkPersistor.TAG_TOTALSV, l); xmlout.AddProperty(SVMNetworkPersistor.TAG_RHO, model.rho, nr_class * (nr_class - 1) / 2); xmlout.AddProperty(SVMNetworkPersistor.TAG_LABEL, model.label, nr_class); xmlout.AddProperty(SVMNetworkPersistor.TAG_PROB_A, model.probA, nr_class * (nr_class - 1) / 2); xmlout.AddProperty(SVMNetworkPersistor.TAG_PROB_B, model.probB, nr_class * (nr_class - 1) / 2); xmlout.AddProperty(SVMNetworkPersistor.TAG_NSV, model.nSV, nr_class); xmlout.BeginTag(SVMNetworkPersistor.TAG_DATA); double[][] sv_coef = model.sv_coef; svm_node[][] SV = model.SV; StringBuilder line = new StringBuilder(); for (int i = 0; i < l; i++) { line.Length = 0; for (int j = 0; j < nr_class - 1; j++) { line.Append(sv_coef[j][i] + " "); } svm_node[] p = SV[i]; //if (param.kernel_type == svm_parameter.PRECOMPUTED) //{ // line.Append("0:" + (int) (p[0].value)); //} //else for (int j = 0; j < p.Length; j++) { line.Append(p[j].index + ":" + p[j].value_Renamed + " "); } xmlout.AddProperty(SVMNetworkPersistor.TAG_ROW, line.ToString()); } xmlout.EndTag(); xmlout.EndTag(); } }