Full code:
http://theparticle.com/applets/ml/least_squares_nonlinear/pMatrix.java
/**
* non-negative matrix factorization
*
* w.mult(h) = this
* w is weights matrix.
* h is feature matrix.
*
* k = size of factor matrices.
* n is NUMBER OF ITERATIONS.
* e is ERROR (once we're below that, we can return)
*
* returns w,h.
*/
public pMatrix[] nmf(int k,int n,double e){
pMatrix w = urandom(rows,k,1,n);
pMatrix h = urandom(k,cols,1,n);
for(int i=0;i