samer@0: package samer.mds; samer@0: samer@0: import samer.core.*; samer@0: import samer.core.types.*; samer@0: import samer.maths.*; samer@0: import samer.tools.*; samer@0: samer@0: /** samer@0: MDS base class. Manages a NxE matrix of object positions, samer@0: an array of links (end point object indices and a distance per link), samer@0: a stress value and a learning rate, and a buffer which for samer@0: accumulating the "force" on each object. samer@0: samer@0: Client code or subclass must set up link array and implement samer@0: the actual adaptation algorithm. samer@0: */ samer@0: samer@0: public class MDSBase extends Viewable implements Task samer@0: { samer@0: int N, M, E; // points, links, dimensions samer@0: Matrix P; // object positions samer@0: VDouble S, rate; // stress, learning rate samer@0: double[] D; // input distances samer@0: short [] l1, l2; // arrays of link end points samer@0: double [][] F; // object 'forces' samer@0: double [] f; // force buffer samer@0: samer@0: public MDSBase(Matrix p) samer@0: { samer@0: super("mds"); samer@0: samer@0: P=p; samer@0: Shell.push(node); samer@0: N = p.getRowDimension(); samer@0: E = p.getColumnDimension(); samer@0: Shell.print("MDS: "+N+" objects"); samer@0: Shell.print("MDS: space is "+E+" dimensional"); samer@0: rate = new VDouble("rate",0.001); samer@0: S = new VDouble("stress"); samer@0: Shell.pop(); samer@0: F = new double[N][P.getColumnDimension()]; samer@0: f = new double[P.getColumnDimension()]; samer@0: M=0; samer@0: D = new double[M]; samer@0: } samer@0: samer@0: /** optimises only first E columns of P samer@0: E must be less than width of original P */ samer@0: public void setDimensionality(int e) { E=e; } samer@0: samer@0: /** link each object to all the others , returns distance array */ samer@0: public void clearLinks(double [] D) { samer@0: M=D.length; samer@0: Shell.print("MDS: creating "+M+" links."); samer@0: samer@0: l1 = new short[M]; samer@0: l2 = new short[M]; samer@0: this.D = D; samer@0: } samer@0: samer@0: /** the kth link joint objects i and j */ samer@0: public void setLink(int k, int i, int j) { l1[k]=(short)i; l2[k]=(short)j; } samer@0: public double [] getLinkArray() { return D; } samer@0: samer@0: public void dispose() { S.dispose(); rate.dispose(); } samer@0: public void starting() {} samer@0: public void stopping() {} samer@0: public void run() {} samer@0: }