annotate src/samer/mds/MDSBase.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 package samer.mds;
samer@0 2
samer@0 3 import samer.core.*;
samer@0 4 import samer.core.types.*;
samer@0 5 import samer.maths.*;
samer@0 6 import samer.tools.*;
samer@0 7
samer@0 8 /**
samer@0 9 MDS base class. Manages a NxE matrix of object positions,
samer@0 10 an array of links (end point object indices and a distance per link),
samer@0 11 a stress value and a learning rate, and a buffer which for
samer@0 12 accumulating the "force" on each object.
samer@0 13
samer@0 14 Client code or subclass must set up link array and implement
samer@0 15 the actual adaptation algorithm.
samer@0 16 */
samer@0 17
samer@0 18 public class MDSBase extends Viewable implements Task
samer@0 19 {
samer@0 20 int N, M, E; // points, links, dimensions
samer@0 21 Matrix P; // object positions
samer@0 22 VDouble S, rate; // stress, learning rate
samer@0 23 double[] D; // input distances
samer@0 24 short [] l1, l2; // arrays of link end points
samer@0 25 double [][] F; // object 'forces'
samer@0 26 double [] f; // force buffer
samer@0 27
samer@0 28 public MDSBase(Matrix p)
samer@0 29 {
samer@0 30 super("mds");
samer@0 31
samer@0 32 P=p;
samer@0 33 Shell.push(node);
samer@0 34 N = p.getRowDimension();
samer@0 35 E = p.getColumnDimension();
samer@0 36 Shell.print("MDS: "+N+" objects");
samer@0 37 Shell.print("MDS: space is "+E+" dimensional");
samer@0 38 rate = new VDouble("rate",0.001);
samer@0 39 S = new VDouble("stress");
samer@0 40 Shell.pop();
samer@0 41 F = new double[N][P.getColumnDimension()];
samer@0 42 f = new double[P.getColumnDimension()];
samer@0 43 M=0;
samer@0 44 D = new double[M];
samer@0 45 }
samer@0 46
samer@0 47 /** optimises only first E columns of P
samer@0 48 E must be less than width of original P */
samer@0 49 public void setDimensionality(int e) { E=e; }
samer@0 50
samer@0 51 /** link each object to all the others , returns distance array */
samer@0 52 public void clearLinks(double [] D) {
samer@0 53 M=D.length;
samer@0 54 Shell.print("MDS: creating "+M+" links.");
samer@0 55
samer@0 56 l1 = new short[M];
samer@0 57 l2 = new short[M];
samer@0 58 this.D = D;
samer@0 59 }
samer@0 60
samer@0 61 /** the kth link joint objects i and j */
samer@0 62 public void setLink(int k, int i, int j) { l1[k]=(short)i; l2[k]=(short)j; }
samer@0 63 public double [] getLinkArray() { return D; }
samer@0 64
samer@0 65 public void dispose() { S.dispose(); rate.dispose(); }
samer@0 66 public void starting() {}
samer@0 67 public void stopping() {}
samer@0 68 public void run() {}
samer@0 69 }