view src/samer/mds/CorrelationTask.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
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])));
		}
	}
}