Class Solver

  • Direct Known Subclasses:
    NuSolver

    public class Solver
    extends java.lang.Object
    SMO solver for support vector machines, derived from libSVM.

    An SMO algorithm in Fan et al., JMLR 6(2005), p. 1889--1918

    Solves:
    \[\min 0.5(\alpha^T Q \alpha) + p^T \alpha\]
    \[y^T \alpha = \delta\] \[y_i = \pm 1\] \[0 ≤ alpha_i ≤ Cp \text{for} y_i = 1\] \[0 ≤ alpha_i ≤ Cn \text{for} y_i = -1\]
    Given:
    Q, p, y, Cp, Cn, and an initial feasible point \(\alpha\)
    l is the size of vectors and matrices
    eps is the stopping tolerance
    solution will be put in \(\alpha\), objective value will be put in obj

    Since:
    0.8.0
    Author:
    Erich Schubert
    • Field Detail

      • LOG

        private static final Logging LOG
      • active_size

        int active_size
      • y

        byte[] y
      • G

        double[] G
      • alpha_status

        byte[] alpha_status
      • alpha

        double[] alpha
      • eps

        double eps
      • Cp

        double Cp
      • Cn

        double Cn
      • p

        double[] p
      • active_set

        int[] active_set
      • G_bar

        double[] G_bar
      • Q_i

        float[] Q_i
      • Q_j

        float[] Q_j
      • l

        int l
      • unshrink

        boolean unshrink
    • Constructor Detail

      • Solver

        public Solver()
    • Method Detail

      • get_C

        double get_C​(int i)
      • update_alpha_status

        void update_alpha_status​(int i)
      • is_upper_bound

        boolean is_upper_bound​(int i)
      • is_lower_bound

        boolean is_lower_bound​(int i)
      • is_free

        boolean is_free​(int i)
      • swap_index

        void swap_index​(int i,
                        int j)
      • reconstruct_gradient

        void reconstruct_gradient()
      • solve

        public Solver.SolutionInfo solve​(int l,
                                         QMatrix Q,
                                         double[] p_,
                                         byte[] y_,
                                         double[] alpha_,
                                         double Cp,
                                         double Cn,
                                         double eps,
                                         boolean shrinking)
      • initializeAlpha

        protected void initializeAlpha()
        Initialize the alpha values.
      • initializeActiveSet

        protected void initializeActiveSet()
        Initialize the active set.
      • update_G

        private void update_G​(int i,
                              int j,
                              double old_alpha_i,
                              double old_alpha_j)
      • update_G_bar

        private void update_G_bar​(double C_i,
                                  float[] Q_i)
      • initializeGradient

        public void initializeGradient()
      • calculate_obj

        protected double calculate_obj()
      • nonzero

        protected static double nonzero​(double d)
      • select_working_set

        boolean select_working_set​(int[] working_set)
      • maxViolating

        protected double maxViolating​(int[] working_set)
      • minViolating

        protected double minViolating​(int[] working_set,
                                      double Gi)
      • do_shrinking

        void do_shrinking()
      • be_shrunk

        private boolean be_shrunk​(int i,
                                  double Gmax1,
                                  double Gmax2)
      • calculate_rho

        double calculate_rho()