org.apache.mahout.cf.taste.impl.recommender.knn
Class ConjugateGradientOptimizer
java.lang.Object
org.apache.mahout.cf.taste.impl.recommender.knn.ConjugateGradientOptimizer
- All Implemented Interfaces:
- Optimizer
public final class ConjugateGradientOptimizer
- extends Object
- implements Optimizer
Method Summary |
double[] |
optimize(double[][] matrix,
double[] b)
Conjugate gradient optimization. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConjugateGradientOptimizer
public ConjugateGradientOptimizer()
optimize
public double[] optimize(double[][] matrix,
double[] b)
Conjugate gradient optimization. Matlab code:
function [x] = conjgrad(A,b,x0)
x = x0;
r = b - A*x0;
w = -r;
for i = 1:size(A);
z = A*w;
a = (r'*w)/(w'*z);
x = x + a*w;
r = r - a*z;
if( norm(r) < 1e-10 )
break;
end
B = (r'*z)/(w'*z);
w = -r + B*w;
end
end
- Specified by:
optimize
in interface Optimizer
- Parameters:
matrix
- matrix nxn positionsb
- vector b, n positions
- Returns:
- vector of n weights
Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.