Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        /// <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;
                }
            }
        }
Exemplo n.º 4
0
        /// <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);
            }
        }