Example #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="BaseSupportVectorLearning"/> class.
        /// </summary>
        ///
        /// <param name="machine">The machine to be learned.</param>
        /// <param name="inputs">The input data.</param>
        /// <param name="outputs">The corresponding output data.</param>
        ///
        protected BaseSupportVectorLearning(SupportVectorMachine machine, double[][] inputs, int[] outputs)
        {
            // Initial argument checking
            SupportVectorLearningHelper.CheckArgs(machine, inputs, outputs);

            // Machine
            this.machine = machine;

            // Kernel (if applicable)
            KernelSupportVectorMachine ksvm = machine as KernelSupportVectorMachine;

            if (ksvm == null)
            {
                isLinear = true;
                Linear linear = new Linear(0);
                kernel = linear;
            }
            else
            {
                Linear linear = ksvm.Kernel as Linear;
                isLinear = linear != null;
                kernel   = ksvm.Kernel;
            }

            // Learning data
            this.inputs  = inputs;
            this.outputs = outputs;
        }
Example #2
0
        /// <summary>
        ///   Constructs a new Least Squares SVM (LS-SVM) learning algorithm.
        /// </summary>
        ///
        /// <param name="machine">A support vector machine.</param>
        /// <param name="inputs">The input data points as row vectors.</param>
        /// <param name="outputs">The output label for each input point. Values must be either -1 or +1.</param>
        ///
        public LeastSquaresLearning(SupportVectorMachine machine, double[][] inputs, int[] outputs)
        {
            SupportVectorLearningHelper.CheckArgs(machine, inputs, outputs);

            // Set the machine
            this.machine = machine;

            // Grab the machine kernel
            KernelSupportVectorMachine ksvm = machine as KernelSupportVectorMachine;

            this.kernel = (ksvm == null) ? new Linear() : ksvm.Kernel;

            // Kernel cache
            this.cacheSize = inputs.Length;

            // Get learning data
            this.inputs  = inputs;
            this.outputs = outputs;

            this.ones = Matrix.Vector(outputs.Length, 1);
        }