Mercurial > hg > jslab
view src/samer/mds/DistanceTask.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line source
package samer.mds; // import samer.core.*; import samer.maths.*; import samer.tools.*; /** Transfer distances directly from a distance matrix to an MDS object's distance vector. */ public class DistanceTask extends AnonymousTask { int N; double [] d; // linear array of distances double [][] _D; // matrix of source data /** 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 DistanceTask(MDSBase mds, Matrix D) { N = D.getRowDimension(); d=new double[N*(N - 1)/2]; _D=D.getArray(); mds.clearLinks(d); for (int k=0, i=0; i<N; i++) for (int j=i+1; j<N; 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 [] Drow=_D[i]; for (int j=i+1; j<N; j++) d[k++]=Drow[j]; } } }