diff src/samer/mds/MDSBase.java @ 0:bf79fb79ee13

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