comparison src/samer/mds/CovarianceTask.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 package samer.mds;
2
3 // import samer.core.*;
4 import samer.maths.*;
5 import samer.tools.*;
6
7 /**
8 Transfer covariance matrix to MDS distances
9 Assumes that elements are not normalised to unit variance
10 */
11 public class CovarianceTask extends AnonymousTask
12 {
13 int N;
14 double [] d; // linear array of distances
15 double [][] _C; // matrix of covariances
16 double [] var; // array of variances
17
18 /** link each object to all the others using distances in matrix, returns a task
19 that can be used to refresh distances from original matrix */
20 public CovarianceTask(MDSBase mds, Matrix C) {
21 N = C.getRowDimension();
22
23 d=new double[N*(N - 1)/2];
24 var=new double[N];
25 _C=C.getArray();
26
27 mds.clearLinks(d);
28 for (int k=0, i=0; i<N; i++)
29 for (int j=0; j<i; j++) mds.setLink(k++,i,j);
30
31 run();
32 }
33
34 public Vec getDistances() { return new Vec.ForArray(d); }
35 public void run() {
36 for (int i=0; i<N; i++) var[i]=_C[i][i];
37 for (int k=0, i=0; i<N; i++) {
38 double [] Ci=_C[i];
39 double vari=var[i];
40 for (int j=0; j<i; j++)
41 d[k++]=Math.sqrt(0.5*Math.log(vari*var[j]/(Ci[j]*Ci[j])));
42 }
43 }
44 }