Mercurial > hg > jslab
diff src/samer/mds/Minkowski.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/Minkowski.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,16 @@ +package samer.mds; +import samer.core.types.*; +import samer.maths.*; + +/** Minkowski metric */ + +public class Minkowski implements MDS.Metric { + VDouble exponent=new VDouble("exponent",1); + public Minkowski(double p) { exponent.set(p); } + public double d(double [] x, double [] y, double [] r) { + Mathx.sub(r,y,x); + double q=0, p=exponent.value; + for (int i=0; i<r.length; i++) q+=Math.pow(r[i],p); + return Math.pow(q,1/p); + } +}