org.apache.mahout.cf.taste.impl.recommender.knn
Class ConjugateGradientOptimizer

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.recommender.knn.ConjugateGradientOptimizer
All Implemented Interfaces:
Optimizer

public final class ConjugateGradientOptimizer
extends Object
implements Optimizer


Constructor Summary
ConjugateGradientOptimizer()
           
 
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
 

Constructor Detail

ConjugateGradientOptimizer

public ConjugateGradientOptimizer()
Method Detail

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 positions
b - vector b, n positions
Returns:
vector of n weights


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.