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