|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjml.optimization.NonlinearConjugateGradient
public class NonlinearConjugateGradient
A Java implementation for the nonlinear conjugate gradient method. 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 = NonlinearConjugateGradient.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 boolean |
converge
If the algorithm converges or not. |
private static int |
formula
Formula used to calculate beta. |
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 java.util.ArrayList<java.lang.Double> |
J
An array holding the sequence of objective function values. |
private static int |
k
Iteration counter. |
private static org.apache.commons.math.linear.RealMatrix |
p
Decreasing step. |
private static double |
rou
|
private static int |
state
State for the automata machine. |
private static double |
t
Step length for backtracking line search. |
private static org.apache.commons.math.linear.RealMatrix |
X
Current matrix variable that we want to optimize. |
private static double |
z
A temporary variable holding the inner product of the decreasing step p and the gradient G, it should be always non-positive. |
Constructor Summary | |
---|---|
NonlinearConjugateGradient()
|
Method Summary | |
---|---|
static boolean[] |
run(org.apache.commons.math.linear.RealMatrix Grad_t,
double fval_t,
double epsilon,
org.apache.commons.math.linear.RealMatrix X_t)
Main entry for the algorithm. |
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 G_pre
private static org.apache.commons.math.linear.RealMatrix X
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 double z
private static int k
private static double alpha
private static double rou
private static int formula
private static java.util.ArrayList<java.lang.Double> J
Constructor Detail |
---|
public NonlinearConjugateGradient()
Method Detail |
---|
public static boolean[] run(org.apache.commons.math.linear.RealMatrix Grad_t, double fval_t, double epsilon, org.apache.commons.math.linear.RealMatrix X_t)
Grad_t
- gradient at original X_t, required on the
first revocationfval_t
- objective function value on original X_tepsilon
- 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}
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |