|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjml.optimization.BoundConstrainedPLBFGS
public class BoundConstrainedPLBFGS
A Java implementation for the projected limited-memory BFGS algorithm with bound constraints. It is a general algorithm interface, only gradient and objective function value are needed to compute outside the class.
A simple example:
W = repmat(zeros(nFea, 1), new int[]{1, K});
A = X.transpose().multiply(W);
V = sigmoid(A);
G = X.multiply(V.subtract(Y)).scalarMultiply(1.0 / nSample);
fval = -sum(sum(times(Y, log(plus(V, eps))))).getEntry(0, 0) / nSample;
boolean flags[] = null;
while (true) {
  flags = LBFGS.run(G, fval, epsilon, W);
  if (flags[0])
    break;
  A = X.transpose().multiply(W);
  V = sigmoid(A);
  fval = -sum(sum(times(Y, log(plus(V, eps))))).getEntry(0, 0) / nSample;
  if (flags[1])
    G = rdivide(X.multiply(V.subtract(Y)), nSample);
}
Field Summary | |
---|---|
private static double |
alpha
|
private static double |
beta
|
private static boolean |
converge
If the algorithm converges or not. |
private static double |
fval
The last objective function value. |
private static org.apache.commons.math.linear.RealMatrix |
G
Current gradient. |
private static org.apache.commons.math.linear.RealMatrix |
G_pre
Last gradient. |
private static boolean |
gradientRequired
If gradient is required for the next step. |
private static double |
H
|
private static java.util.ArrayList<java.lang.Double> |
J
An array holding the sequence of objective function values. |
private static int |
k
Iteration counter. |
private static int |
m
|
private static org.apache.commons.math.linear.RealMatrix |
p
Decreasing step. |
private static org.apache.commons.math.linear.RealMatrix |
PG
Current projected gradient. |
private static double |
rou_k
|
private static java.util.LinkedList<java.lang.Double> |
rou_ks
|
private static org.apache.commons.math.linear.RealMatrix |
s_k
|
private static java.util.LinkedList<org.apache.commons.math.linear.RealMatrix> |
s_ks
|
private static int |
state
State for the automata machine. |
private static double |
t
Step length for backtracking line search. |
private static double |
tol
Tolerance of convergence. |
private static org.apache.commons.math.linear.RealMatrix |
X
Current matrix variable that we want to optimize. |
private static org.apache.commons.math.linear.RealMatrix |
X_pre
Last matrix variable that we want to optimize. |
private static org.apache.commons.math.linear.RealMatrix |
y_k
|
private static java.util.LinkedList<org.apache.commons.math.linear.RealMatrix> |
y_ks
|
Constructor Summary | |
---|---|
BoundConstrainedPLBFGS()
|
Method Summary | |
---|---|
private static org.apache.commons.math.linear.RealMatrix |
project(org.apache.commons.math.linear.RealMatrix A,
double l,
double u)
Projection on a box region [l, u]. |
private static org.apache.commons.math.linear.RealMatrix |
project(org.apache.commons.math.linear.RealMatrix A,
org.apache.commons.math.linear.RealMatrix L,
org.apache.commons.math.linear.RealMatrix U)
Projection on a box region [L_{ij}, U_{ij}] for each element. |
static boolean[] |
run(org.apache.commons.math.linear.RealMatrix Grad_t,
double fval_t,
double l,
double u,
double epsilon,
org.apache.commons.math.linear.RealMatrix X_t)
Main entry for the LBFGS algorithm with bound constraints. |
static boolean[] |
run(org.apache.commons.math.linear.RealMatrix Grad_t,
double fval_t,
org.apache.commons.math.linear.RealMatrix L,
org.apache.commons.math.linear.RealMatrix U,
double epsilon,
org.apache.commons.math.linear.RealMatrix X_t)
Main entry for the LBFGS algorithm with bound constraints. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static org.apache.commons.math.linear.RealMatrix G
private static org.apache.commons.math.linear.RealMatrix PG
private static org.apache.commons.math.linear.RealMatrix G_pre
private static org.apache.commons.math.linear.RealMatrix X
private static org.apache.commons.math.linear.RealMatrix X_pre
private static org.apache.commons.math.linear.RealMatrix p
private static double fval
private static boolean gradientRequired
private static boolean converge
private static int state
private static double t
private static int k
private static double alpha
private static double beta
private static int m
private static double H
private static org.apache.commons.math.linear.RealMatrix s_k
private static org.apache.commons.math.linear.RealMatrix y_k
private static double rou_k
private static java.util.LinkedList<org.apache.commons.math.linear.RealMatrix> s_ks
private static java.util.LinkedList<org.apache.commons.math.linear.RealMatrix> y_ks
private static java.util.LinkedList<java.lang.Double> rou_ks
private static double tol
private static java.util.ArrayList<java.lang.Double> J
Constructor Detail |
---|
public BoundConstrainedPLBFGS()
Method Detail |
---|
public static boolean[] run(org.apache.commons.math.linear.RealMatrix Grad_t, double fval_t, double l, double u, double epsilon, org.apache.commons.math.linear.RealMatrix X_t)
Grad_t
- gradient at original X_tfval_t
- objective function value on original X_tl
- lower boundu
- upper boundepsilon
- convergence precisionX_t
- current matrix variable to be optimized, will be
updated in place to a better solution point with
lower objective function value.
boolean
array of two elements: {converge, gradientRequired}public static boolean[] run(org.apache.commons.math.linear.RealMatrix Grad_t, double fval_t, org.apache.commons.math.linear.RealMatrix L, org.apache.commons.math.linear.RealMatrix U, double epsilon, org.apache.commons.math.linear.RealMatrix X_t)
Grad_t
- gradient at original X_tfval_t
- objective function value on original X_tL
- lower bound matrixU
- upper bound matrixepsilon
- convergence precisionX_t
- current matrix variable to be optimized, will be
updated in place to a better solution point with
lower objective function value.
boolean
array of two elements: {converge, gradientRequired}private static org.apache.commons.math.linear.RealMatrix project(org.apache.commons.math.linear.RealMatrix A, double l, double u)
A
- a matrix to be projectedl
- lower boundu
- upper bound
private static org.apache.commons.math.linear.RealMatrix project(org.apache.commons.math.linear.RealMatrix A, org.apache.commons.math.linear.RealMatrix L, org.apache.commons.math.linear.RealMatrix U)
A
- a matrix to be projectedL
- lower bound matrixU
- upper bound matrix
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |