Mercurial > hg > jslab
diff src/samer/mds/CorrelationTask.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/mds/CorrelationTask.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,40 @@ +package samer.mds; + +// import samer.core.*; +import samer.maths.*; +import samer.tools.*; + +/** + Transfer correlation matrix to MDS distances. Assumes 1s + down the main diagonal and a symmetric matrix. + */ +public class CorrelationTask extends AnonymousTask +{ + int N; + double [] d; // linear array of distances + double [][] _R; // matrix of correlation coefficients + + /** link each object to all the others using distances in matrix, returns a task + that can be used to refresh distances from original matrix */ + public CorrelationTask(MDSBase mds, Matrix R) { + N = R.getRowDimension(); + + d=new double[N*(N - 1)/2]; + _R=R.getArray(); + + mds.clearLinks(d); + for (int k=0, i=0; i<N; i++) + for (int j=0; j<i; j++) mds.setLink(k++,i,j); + + run(); + } + + public Vec getDistances() { return new Vec.ForArray(d); } + public void run() { + for (int k=0, i=0; i<N; i++) { + double [] Ri=_R[i]; + for (int j=0; j<i; j++) + d[k++]=Math.sqrt(-Math.log(Math.abs(Ri[j]))); + } + } +}