示例#1
0
        /// <summary>
        ///   Runs the learning algorithm.
        /// </summary>
        ///
        protected override void InnerRun()
        {
            int samples    = Inputs.Length;
            int parameters = Inputs[0].Length + 1;

            this.z  = new double[samples];
            this.I  = new int[samples];
            this.wa = new double[samples];

            this.g         = new double[parameters];
            this.h         = new double[parameters];
            this.biasIndex = parameters - 1;

            tron = new TrustRegionNewtonMethod(parameters)
            {
                Function      = objective,
                Gradient      = gradient,
                Hessian       = hessian,
                Tolerance     = tolerance,
                MaxIterations = maxIterations
            };

            for (int i = 0; i < tron.Solution.Length; i++)
            {
                tron.Solution[i] = 0;
            }

            tron.Minimize();

            double[] w = tron.Solution;
            Model.SupportVectors = new[] { w.First(Model.NumberOfInputs) };
            Model.Weights        = new[] { 1.0 };
            Model.Threshold      = w[biasIndex];
        }
        /// <summary>
        ///   Runs the learning algorithm.
        /// </summary>
        ///
        protected override void InnerRun()
        {
            int samples    = Inputs.Length;
            int parameters = Model.NumberOfInputs + 1;

            this.z         = new double[samples];
            this.D         = new double[samples];
            this.g         = new double[parameters];
            this.Hs        = new double[parameters];
            this.biasIndex = parameters - 1;

            tron = new TrustRegionNewtonMethod(parameters)
            {
                Function      = objective,
                Gradient      = gradient,
                Hessian       = hessian,
                Tolerance     = tolerance,
                MaxIterations = maxIterations,
                Token         = Token
            };

            for (int i = 0; i < tron.Solution.Length; i++)
            {
                tron.Solution[i] = 0;
            }

            tron.Minimize();

            double[] weights = tron.Solution;

            Model.Weights         = new double[] { 1.0 };
            Model.SupportVectors  = new[] { weights.First(weights.Length - 1) };
            Model.Threshold       = weights[biasIndex];
            Model.IsProbabilistic = true;
        }
示例#3
0
        /// <summary>
        ///   Runs the learning algorithm.
        /// </summary>
        ///
        protected override void InnerRun()
        {
            int samples    = Inputs.Length;
            int parameters = Kernel.GetLength(Inputs) + 1;

            this.z  = new double[samples];
            this.I  = new int[samples];
            this.wa = new double[samples];

            this.g         = new double[parameters];
            this.h         = new double[parameters];
            this.biasIndex = parameters - 1;

            tron = new TrustRegionNewtonMethod(parameters)
            {
                Function      = objective,
                Gradient      = gradient,
                Hessian       = hessian,
                Tolerance     = tolerance,
                MaxIterations = maxIterations,
                Token         = Token
            };

            for (int i = 0; i < tron.Solution.Length; i++)
            {
                tron.Solution[i] = 0;
            }

            tron.Minimize();

            // Get the solution found by TRON
            double[] weightsWithBias = tron.Solution;

            // Separate the weights and the bias coefficient
            double[] weights = weightsWithBias.Get(0, -1);
            double   bias    = weightsWithBias[biasIndex];

            Debug.Assert(weights.Length == parameters - 1);

            // Create the machine
            Model.NumberOfInputs = weights.Length;
            Model.SupportVectors = new[] { Kernel.CreateVector(weights) };
            Model.Weights        = new[] { 1.0 };
            Model.Threshold      = bias;
        }
        /// <summary>
        ///   Constructs a new Newton method algorithm for L2-regularized
        ///   logistic regression (probabilistic linear SVMs) primal problems.
        /// </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 ProbabilisticNewtonMethod(SupportVectorMachine machine, double[][] inputs, int[] outputs)
            : base(machine, inputs, outputs)
        {
            if (!IsLinear)
            {
                throw new ArgumentException("Only linear machines are supported.", "machine");
            }

            int samples    = inputs.Length;
            int parameters = machine.Inputs + 1;

            this.C         = new double[samples];
            this.z         = new double[samples];
            this.D         = new double[samples];
            this.g         = new double[parameters];
            this.Hs        = new double[parameters];
            this.biasIndex = machine.Inputs;

            tron           = new TrustRegionNewtonMethod(parameters);
            this.Tolerance = 0.01;
        }
示例#5
0
        /// <summary>
        ///   Constructs a new Newton method algorithm for L2-regularized
        ///   support vector regression (SVR-SVMs) primal problems.
        /// </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 value for each input point.</param>
        ///
        public LinearRegressionNewtonMethod(SupportVectorMachine machine, double[][] inputs, double[] outputs)
            : base(machine, inputs, outputs)
        {
            if (!IsLinear)
            {
                throw new ArgumentException("Only linear machines are supported.", "machine");
            }

            int samples    = inputs.Length;
            int parameters = machine.Inputs + 1;

            this.z  = new double[samples];
            this.I  = new int[samples];
            this.wa = new double[samples];

            this.g         = new double[parameters];
            this.h         = new double[parameters];
            this.biasIndex = machine.Inputs;

            tron = new TrustRegionNewtonMethod(parameters);
        }