This is a network that is backed by one or more Support Vector Machines (SVM). It is designed to function very similarly to an Encog neural network, and is largely interchangeable with an Encog neural network. The support vector machine supports several types. Regression is used when you want the network to predict a value, given the input. Function approximation is a good example of regression. Classification is used when you want the SVM to group the input data into one or more classes. Support Vector Machines typically have a single output. Neural networks can have multiple output neurons. To get around this issue, this class will create multiple SVM's if there is more than one output specified. Because a SVM is trained quite differently from a neural network, none of the neural network training classes will work. This class must be trained using SVMTrain.
Inheritance: BasicNetwork
        /// <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;
                }
            }

        }
示例#3
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);
            }
        }