Commit 5adc0c52 authored by lafabregue's avatar lafabregue

Full switch on DistanceModel usage

parent e1663488
......@@ -17,6 +17,7 @@ public abstract class Attribute implements Serializable {
public static final String INTERVAL_ATTRIBUTE = "INTERVAL ATTRIBUTE";
public static final String NULERICAL_ATTRIBUTE = "NUMERICAL ATTRIBUTE";
public static final String SEQUENCE_ATTRIBUTE = "SEQUENCE ATTRIBUTE";
public static final String MULTIDIM_SEQUENCE_ATTRIBUTE = "MULTIDIM SEQUENCE ATTRIBUTE";
public static final String STRUCTURED_ATTRIBUTE = "STRUCTURED ATTRIBUTE";
public static final String SYMBOLIC_ATTRIBUTE = "SYMBOLIC ATTRIBUTE";
public static final String SYMBOLIC_HISTOGRAMS_ATTRIBUTE = "SYMBOLIC HISTOGRAMS ATTRIBUTE";
......
......@@ -340,7 +340,7 @@ public class AttributeDCMDSequence extends Attribute {
@Override
public String getTypeAttribute() {
return Attribute.SEQUENCE_ATTRIBUTE;
return Attribute.MULTIDIM_SEQUENCE_ATTRIBUTE;
}
protected static int ArgMin3(final double a, final double b, final double c) {
......
package jcl.data.attribute;
import static jcl.data.distance.Tools.*;
import java.util.Arrays;
import jcl.data.distance.sequential.DistanceDTWHardConstrainedMD;
import jcl.data.distance.sequential.DistanceDTWMD;
import jcl.data.distance.sequential.ParameterDTWConstrained;
import jcl.data.distance.sequential.ParameterDTW;
import jcl.data.sequence.DoubleTabArrayList;
/**
* Cette classe permet d'instancier un attribut de type séquence de t-uplets
......@@ -31,10 +24,6 @@ public class AttributeHardConstrainedMultiDimSequence extends Attribute {
public final static int NB_ITERATIONS = 15;
private final static int RIEN = -1;
private final static int DIAGONALE = 0;
private final static int GAUCHE = 1;
private final static int HAUT = 2;
// contient une sequence de tuples.
double[][] sequence;
......@@ -161,7 +150,7 @@ public class AttributeHardConstrainedMultiDimSequence extends Attribute {
@Override
public String getTypeAttribute() {
return Attribute.SEQUENCE_ATTRIBUTE;
return Attribute.MULTIDIM_SEQUENCE_ATTRIBUTE;
}
public static final int ArgMin3(final double a, final double b, final double c) {
......
......@@ -16,8 +16,8 @@ import java.util.TreeMap;
import java.util.TreeSet;
import jcl.data.concepts.Concept;
import jcl.data.distance.DistanceSymbolicHistogram;
import jcl.data.distance.ParameterSymbolicHistogramDistance;
import jcl.data.distance.unitary.DistanceSymbolicHistogram;
import jcl.data.distance.unitary.ParameterSymbolicHistogramDistance;
import jcl.utils.Couple;
import org.jfree.chart.ChartFactory;
......
......@@ -93,7 +93,7 @@ public class AttributeMDMRHSequence extends Attribute {
@Override
public String getTypeAttribute() {
return Attribute.SEQUENCE_ATTRIBUTE;
return Attribute.MULTIDIM_SEQUENCE_ATTRIBUTE;
}
public static double Min3(final double a, final double b, final double c) {
......
......@@ -140,7 +140,7 @@ public class AttributeMDMRSequence extends Attribute {
@Override
public String getTypeAttribute() {
return Attribute.SEQUENCE_ATTRIBUTE;
return Attribute.MULTIDIM_SEQUENCE_ATTRIBUTE;
}
public static double Min3(final double a, final double b, final double c) {
......
......@@ -151,14 +151,9 @@ public class AttributeMultiDimSequence extends Attribute {
}
@Override
public String getTypeAttribute() {
return Attribute.SEQUENCE_ATTRIBUTE;
return Attribute.MULTIDIM_SEQUENCE_ATTRIBUTE;
}
public static int ArgMin3(final double a, final double b, final double c) {
......
......@@ -2,8 +2,8 @@ package jcl.data.attribute;
import java.util.StringTokenizer;
import jcl.data.distance.CategorialDistance;
import jcl.data.distance.EmptyDistanceParameter;
import jcl.data.distance.unitary.CategorialDistance;
/**
* <p>
......
package jcl.data.distance;
import jcl.data.attribute.Attribute;
import jcl.weights.Weights;
/**
* Generic Distance interface.
......@@ -8,7 +9,11 @@ import jcl.data.attribute.Attribute;
* @param <A> Attribute
* @param <P> Parameter
*/
public interface Distance<A extends Attribute, P extends DistanceParameter> {
public abstract class Distance<A extends Attribute, P extends DistanceParameter> {
public abstract double compute(A a1, A a2, P p);
public double compute(A a1, A a2, P p, Weights w) {
return compute(a1, a2, p);
}
}
......@@ -15,15 +15,17 @@ import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.attribute.AttributeSequence;
import jcl.data.distance.average.Average;
import jcl.data.distance.average.AverageEuclidean;
import jcl.data.distance.average.AverageParameter;
import jcl.data.distance.average.EmptyAverageParameter;
import jcl.data.distance.average.ParameterDBAMean;
import jcl.data.distance.average.sequential.AverageMDDBAMean;
import jcl.data.distance.average.sequential.AverageMDeuclideanMean;
import jcl.data.distance.average.sequential.ParameterDBAMean;
import jcl.data.distance.average.unitary.AverageEuclidean;
import jcl.data.distance.sequential.DistanceDTW;
import jcl.data.distance.sequential.DistanceDTWMD;
import jcl.data.distance.sequential.DistanceEuclideanMD;
import jcl.data.distance.sequential.ParameterDTW;
import jcl.data.distance.unitary.NumericalEuclideanDistance;
import jcl.weights.ClassificationWeights;
/**
......@@ -109,7 +111,7 @@ public class DistanceModel {
for (int i = 0; i < dWeights.length; i++) {
dWeights[i]=weights.getWeights(0).getWeight(i);//?
}
MetaDistance metaDistance = new MetaDistanceWeightedSquaredEuclidean(dWeights); //defines the way the two scores are combined, by default it is euclidean
MetaDistance metaDistance = new MetaDistanceWeightedSquaredEuclidean(weights); //defines the way the two scores are combined, by default it is euclidean
DistanceModel model = new DistanceModel(distances, metaDistance, averages);
return model;
}
......@@ -124,18 +126,22 @@ public class DistanceModel {
Average[] averages = new Average[dataObject.getNbAttributes()];
for (int i=0; i<distances.length;i++) {
distances[i]=NumericalEuclideanDistance.getInstance();// uses euclidian distance for every attribute
if (dataObject.getAttribute(i) instanceof AttributeMultiDimSequence)
// uses euclidian distance for every attribute
if (dataObject.getAttribute(i) instanceof AttributeMultiDimSequence) {
distances[i] = DistanceEuclideanMD.getInstance();// uses DTWMD distances for sequential attributes ...
averages[i]=AverageMDeuclideanMean.getInstance();// uses MultiDim euclidean mean for sequential attributes ...
else
averages[i] = AverageEuclidean.getInstance();// and classic euclidean mean for numerical attributes
}
else {
distances[i]=NumericalEuclideanDistance.getInstance();//... and euclidean distances for numerical attributes
averages[i] = AverageEuclidean.getInstance();// ... and classic euclidean mean for numerical attributes
}
}
double[] dWeights = new double[weights.getNbAttributes()];
for (int i = 0; i < dWeights.length; i++) {
dWeights[i]=weights.getWeights(0).getWeight(i);//?
}
MetaDistance metaDistance = new MetaDistanceWeightedSquaredEuclidean(dWeights); // defines the way the two scores are combined, by default it is Euclidian
MetaDistance metaDistance = new MetaDistanceWeightedSquaredEuclidean(weights); // defines the way the two scores are combined, by default it is Euclidian
DistanceModel model = new DistanceModel(distances, metaDistance, averages);
return model;
}
......
......@@ -17,7 +17,8 @@ public class MetaDistanceSquaredEuclidean implements MetaDistance {
@Override
public double compute(DataObject o1, DataObject o2, Distance<Attribute,DistanceParameter>[] distances,DistanceParameter[] params) {
public double compute(DataObject o1, DataObject o2, Distance<Attribute,DistanceParameter>[] distances,
DistanceParameter[] params) {
double res = 0.0;
for(int i=0;i<o1.getNbAttributes();i++){
......
......@@ -2,16 +2,17 @@ package jcl.data.distance;
import jcl.data.DataObject;
import jcl.data.attribute.Attribute;
import jcl.weights.ClassificationWeights;
public class MetaDistanceWeightedSquaredEuclidean implements MetaDistance {
public double[] weights;
public ClassificationWeights weights;
/**
* Meta distance using weights
* @param weights double tab giving the weights of the attributes
*/
public MetaDistanceWeightedSquaredEuclidean(double[] weights) {
public MetaDistanceWeightedSquaredEuclidean(ClassificationWeights weights) {
this.weights = weights;
}
......@@ -20,7 +21,8 @@ public class MetaDistanceWeightedSquaredEuclidean implements MetaDistance {
double res = 0.0;
for (int i = 0; i < o1.getNbAttributes(); i++) {
double tmp = weights[i] * distances[i].compute(o1.getAttribute(i), o2.getAttribute(i), params[i]);
double tmp = weights.getGlobalWeights().getWeight(i) * distances[i]
.compute(o1.getAttribute(i), o2.getAttribute(i), params[i], weights.getGlobalSubWeights()[i]);
res += tmp * tmp;
}
return res;
......
......@@ -6,12 +6,15 @@ import java.util.ArrayList;
import java.util.Arrays;
import jcl.data.attribute.AttributeDCMDSequence;
import jcl.weights.Weights;
public class Tools {
public final static double Min3(final double a, final double b, final double c) {
return (a < b) ? ((a < c) ? a : c) : (b < c) ? b : c;
}
public final static double distanceTo(double[] a, double[] b) {
double res = 0.0, tmp;
for (int i = 0; i < a.length; i++) {
......@@ -21,6 +24,15 @@ public class Tools {
return res;
}
public final static double distanceTo(double[] a, double[] b, Weights weights) {
double res = 0.0, tmp;
for (int i = 0; i < a.length; i++) {
tmp = (a[i] - b[i]);
res += weights.getWeight(i) * tmp * tmp;
}
return res;
}
public static double distanceTo(double a, double b) {
return (a - b) * (a - b);
}
......
......@@ -5,7 +5,6 @@ import static jcl.data.distance.Tools.distanceTo;
import jcl.data.attribute.Attribute;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.average.Average;
import jcl.data.distance.average.ParameterDBAMean;
import jcl.data.sequence.DoubleTabArrayList;
/**
......
package jcl.data.distance.average;
package jcl.data.distance.average.sequential;
import jcl.data.distance.average.AverageParameter;
/**
* Parameters used by DBA mean
......
package jcl.data.distance.average;
package jcl.data.distance.average.unitary;
import jcl.data.attribute.Attribute;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.distance.average.Average;
import jcl.data.distance.average.EmptyAverageParameter;
/**
* Class implementing the averaging method to use for numerical attributes
* @author Jean-Noël Balanche
......
......@@ -7,11 +7,12 @@ import jcl.data.attribute.AttributeSequence;
import jcl.data.distance.Distance;
public class DistanceDTW implements Distance<AttributeSequence,ParameterDTW> {
public class DistanceDTW extends Distance<AttributeSequence,ParameterDTW> {
private static DistanceDTW instance = new DistanceDTW();
private DistanceDTW(){}
public static DistanceDTW getInstance(){
return instance;
}
......
......@@ -5,8 +5,9 @@ import static jcl.data.distance.Tools.Min3;
import static jcl.data.distance.Tools.distanceTo;
import jcl.data.attribute.AttributeDCMDSequence;
import jcl.data.distance.Distance;
import jcl.weights.Weights;
public class DistanceDTWConstrainedByDate implements Distance<AttributeDCMDSequence, ParameterDTWConstrained> {
public class DistanceDTWConstrainedByDate extends Distance<AttributeDCMDSequence, ParameterDTWConstrained> {
private static DistanceDTWConstrainedByDate instance = new DistanceDTWConstrainedByDate();
......@@ -67,5 +68,60 @@ public class DistanceDTWConstrainedByDate implements Distance<AttributeDCMDSeque
return matriceW[tailleS - 1][tailleT - 1];
}
@Override
public double compute(AttributeDCMDSequence S, AttributeDCMDSequence T, ParameterDTWConstrained p, Weights weights) {
if (weights == null) {
return compute(S, T, p);
}
final int tailleS = S.getNbTuples();
final int tailleT = T.getNbTuples();
int i, j;
double[][] matriceW = p.weightMatrix;
int dateDifference = p.constraint;
if (tailleS > matriceW.length || tailleT > matriceW[0].length || tailleS == 0 || tailleT == 0) {
System.err.println("attention seq max dépassée!! ou taille=0");
return Double.NaN;
}
// Remplissage première colonne et première ligne de la matrice
if (abs(S.dates[0] - T.dates[0]) < dateDifference) {
matriceW[0][0] = distanceTo(S.sequence[0], T.sequence[0], weights);
} else {
matriceW[0][0] = Integer.MAX_VALUE;
}
for (i = 1; i < tailleS; i++) {
if (abs(S.dates[i] - T.dates[0]) < dateDifference) {
matriceW[i][0] = matriceW[i - 1][0] + distanceTo(S.sequence[i], T.sequence[0], weights);
} else {
matriceW[i][0] = Integer.MAX_VALUE;
}
}
for (j = 1; j < tailleT; j++) {
if (abs(S.dates[0] - T.dates[j]) < dateDifference) {
matriceW[0][j] = matriceW[0][j - 1] + distanceTo(T.sequence[j], S.sequence[0], weights);
} else {
matriceW[0][j] = Integer.MAX_VALUE;
}
}
// Calcul de la matrice
for (i = 1; i < tailleS; i++) {
for (j = 1; j < tailleT; j++) {
if (abs(S.dates[i] - T.dates[j]) < dateDifference) {
matriceW[i][j] = Min3(matriceW[i - 1][j - 1], matriceW[i][j - 1], matriceW[i - 1][j])
+ distanceTo(S.sequence[i], T.sequence[j], weights);
} else {
matriceW[i][j] = Integer.MAX_VALUE;
}
}
}
return matriceW[tailleS - 1][tailleT - 1];
}
}
......@@ -4,8 +4,9 @@ import static jcl.data.distance.Tools.Min3;
import static jcl.data.distance.Tools.distanceTo;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
import jcl.weights.Weights;
public class DistanceDTWHardConstrainedMD implements Distance<AttributeMultiDimSequence, ParameterDTWConstrained> {
public class DistanceDTWHardConstrainedMD extends Distance<AttributeMultiDimSequence, ParameterDTWConstrained> {
private static DistanceDTWHardConstrainedMD instance = new DistanceDTWHardConstrainedMD();
......@@ -58,6 +59,50 @@ public class DistanceDTWHardConstrainedMD implements Distance<AttributeMultiDimS
return matriceW[tailleS - 1][tailleT - 1];
}
@Override
public double compute(AttributeMultiDimSequence S, AttributeMultiDimSequence T, ParameterDTWConstrained p, Weights weights) {
int deplacement = p.constraint;
final int tailleS = S.getNbTuples();
final int tailleT = T.getNbTuples();
int i, j;
double[][] matriceW = p.weightMatrix;
int[][] jIndexes = p.jIndexes;
if (tailleS > matriceW.length || tailleT > matriceW[0].length || tailleS == 0 || tailleT == 0) {
System.err.println("attention seq max dépassée!! ou taille=0");
return Double.NaN;
}
bresenhamConstraint(0, 0, tailleT - 1, tailleS - 1, deplacement, matriceW, jIndexes);
// Remplissage première colonne et première ligne de la matrice
matriceW[0][0] = distanceTo(S.sequence[0], T.sequence[0], weights);
i = 1;
while (jIndexes[i][0] == 0) { //tant que jMin de la ligne i est egal a 0
matriceW[i][0] = matriceW[i - 1][0] + distanceTo(S.sequence[i], T.sequence[0], weights);
jIndexes[i][0] = 1;
i++;
}
for (j = 1; j < jIndexes[0][1]; j++) { //pour j de 1 a jMax
matriceW[0][j] = matriceW[0][j - 1] + distanceTo(T.sequence[j], S.sequence[0], weights);
}
// Calcul de la matrice
for (i = 1; i < tailleS; i++) {
for (j = jIndexes[i][0]; j < jIndexes[i][1]; j++) { //pour j de jMin a jMax
matriceW[i][j] = Min3(matriceW[i - 1][j - 1], matriceW[i][j - 1], matriceW[i - 1][j])
+ distanceTo(S.sequence[i], T.sequence[j], weights);
}
}
return matriceW[tailleS - 1][tailleT - 1];
}
private static final void bresenhamConstraint(int x1, int y1, int x2, int y2, int deplacement, double[][] matriceW, int[][] jIndexes) {
if (((double) (y2 - y1)) / ((double) x2 - x1) <= 1.0) { //si la pente est <1 i.e., la matrice est plus large que haute
......
package jcl.data.distance.sequential;
import static jcl.data.distance.Tools.Min3;
import static jcl.data.distance.Tools.distanceTo;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
import static jcl.data.distance.Tools.distanceTo;
import static jcl.data.distance.Tools.Min3;
import jcl.weights.Weights;
public class DistanceDTWMD implements Distance<AttributeMultiDimSequence,ParameterDTW> {
public class DistanceDTWMD extends Distance<AttributeMultiDimSequence,ParameterDTW> {
private static DistanceDTWMD instance = new DistanceDTWMD();
private DistanceDTWMD(){}
public static DistanceDTWMD getInstance(){
return instance;
}
......@@ -51,4 +51,45 @@ public class DistanceDTWMD implements Distance<AttributeMultiDimSequence,Paramet
return matriceW[tailleS - 1][tailleT - 1];
}
@Override
public double compute(AttributeMultiDimSequence S, AttributeMultiDimSequence T, ParameterDTW p, Weights weights) {
if (weights == null) {
return compute(S, T, p);
}
if (S == null || T == null) {
return 0;
}
final int tailleS = S.getNbTuples();
final int tailleT = T.getNbTuples();
int i, j;
double[][] matriceW = p.weightMatrix;
if (tailleS > matriceW.length || tailleT > matriceW[0].length || tailleS == 0 || tailleT == 0) {
System.err.println("attention seq max dépassée!! ou taille=0");
return Double.NaN;
}
// Remplissage première colonne et première ligne de la matrice
matriceW[0][0] = distanceTo(S.sequence[0], T.sequence[0], weights);
for (i = 1; i < tailleS; i++) {
matriceW[i][0] = matriceW[i - 1][0] + distanceTo(S.sequence[i], T.sequence[0], weights);
}
for (j = 1; j < tailleT; j++) {
matriceW[0][j] = matriceW[0][j - 1] + distanceTo(T.sequence[j], S.sequence[0], weights);
}
// Calcul de la matrice
for (i = 1; i < tailleS; i++) {
for (j = 1; j < tailleT; j++) {
matriceW[i][j] = Min3(matriceW[i - 1][j - 1], matriceW[i][j - 1], matriceW[i - 1][j])
+ distanceTo(S.sequence[i], T.sequence[j], weights);
}
}
// res = Math.sqrt( AttributeMultiDimSequence.matriceW[thread][tailleS - 1][tailleT - 1] ) ;
return matriceW[tailleS - 1][tailleT - 1];
}
}
......@@ -6,8 +6,9 @@ import jcl.data.attribute.AttributeMDMRHSequence;
import jcl.data.attribute.AttributeMDMRSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.Tools;
import jcl.weights.Weights;
public class DistanceDTWMDMRAverageLink implements Distance<AttributeMDMRSequence,ParameterDTW> {
public class DistanceDTWMDMRAverageLink extends Distance<AttributeMDMRSequence,ParameterDTW> {
private static DistanceDTWMDMRAverageLink instance = new DistanceDTWMDMRAverageLink();
......@@ -46,6 +47,42 @@ public class DistanceDTWMDMRAverageLink implements Distance<AttributeMDMRSequenc
}
return matriceW[tailleS - 1][tailleT - 1];
}
@Override
public double compute(AttributeMDMRSequence S, AttributeMDMRSequence T, ParameterDTW p, Weights weights) {
if (weights == null) {
return compute(S, T, p);
}
final int tailleS = S.getNbTuples();
final int tailleT = T.getNbTuples();
int i, j;
double[][] matriceW = p.weightMatrix;
if (tailleS > matriceW.length || tailleT > matriceW.length || tailleS == 0 || tailleT == 0) {
System.err.println("attention seq max dépassée!! ou taille=0");
return Double.NaN;
}
// Remplissage première colonne et première ligne de la matrice
matriceW[0][0] = distanceTo(S.sequence[0], T.sequence[0], weights);
for (i = 1; i < tailleS; i++) {
matriceW[i][0] = matriceW[i - 1][0] + distanceTo(S.sequence[i], T.sequence[0], weights);
}
for (j = 1; j < tailleT; j++) {
matriceW[0][j] = matriceW[0][j - 1] + distanceTo(T.sequence[j], S.sequence[0], weights);
}
// Calcul de la matrice
for (i = 1; i < tailleS; i++) {
for (j = 1; j < tailleT; j++) {
matriceW[i][j] = Tools.Min3(matriceW[i - 1][j - 1], matriceW[i][j - 1], matriceW[i - 1][j])
+ distanceTo(S.sequence[i], T.sequence[j], weights);
}
}
return matriceW[tailleS - 1][tailleT - 1];
}
public double compute(AttributeMDMRHSequence S, AttributeMDMRHSequence T, ParameterDTW p) {
......@@ -96,6 +133,24 @@ public class DistanceDTWMDMRAverageLink implements Distance<AttributeMDMRSequenc
return distance;
}
private static final double distanceTo(double[][] s1, double[][] s2, Weights weights) {
double distance = 0.0;
double currentDistance, tmp;
for (double[] p1 : s1) {
for (double[] p2 : s2) {
currentDistance = 0.0;
for (int d = 0; d < p1.length; d++) {
tmp = (p1[d] - p2[d]);
currentDistance += weights.getWeight(d) * tmp * tmp;
}
distance+=sqrt(currentDistance);
}
}
distance = distance /(s1.length+s2.length);
return distance;
}
}
......@@ -5,8 +5,9 @@ import jcl.data.attribute.AttributeMDMRHSequence;
import jcl.data.attribute.AttributeMDMRSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.Tools;
import jcl.weights.Weights;
public class DistanceDTWMDMRSingleLink implements Distance<AttributeMDMRSequence,ParameterDTW> {
public class DistanceDTWMDMRSingleLink extends Distance<AttributeMDMRSequence,ParameterDTW> {
private static DistanceDTWMDMRSingleLink instance = new DistanceDTWMDMRSingleLink();
......@@ -45,6 +46,42 @@ public class DistanceDTWMDMRSingleLink implements Distance<AttributeMDMRSequence
}
return matriceW[tailleS - 1][tailleT - 1];
}
@Override
public double compute(AttributeMDMRSequence S, AttributeMDMRSequence T, ParameterDTW p, Weights weights) {
if (weights == null) {
return compute(S, T, p);
}
final int tailleS = S.getNbTuples();
final int tailleT = T.getNbTuples();
int i, j;
double[][] matriceW = p.weightMatrix;
if (tailleS > matriceW.length || tailleT > matriceW.length || tailleS == 0 || tailleT == 0) {
System.err.println("attention seq max dépassée!! ou taille=0");
return Double.NaN;
}
// Remplissage première colonne et première ligne de la matrice
matriceW[0][0] = distanceTo(S.sequence[0], T.sequence[0], weights);
for (i = 1; i < tailleS; i++) {
matriceW[i][0] = matriceW[i - 1][0] + distanceTo(S.sequence[i], T.sequence[0], weights);
}
for (j = 1; j < tailleT; j++) {
matriceW[0][j] = matriceW[0][j - 1] + distanceTo(T.sequence[j], S.sequence[0], weights);
}
// Calcul de la matrice
for (i = 1; i < tailleS; i++) {
for (j = 1; j < tailleT; j++) {
matriceW[i][j] = Tools.Min3(matriceW[i - 1][j - 1], matriceW[i][j - 1], matriceW[i - 1][j])
+ distanceTo(S.sequence[i], T.sequence[j], weights);
}
}
return matriceW[tailleS - 1][tailleT - 1];
}
public double compute(AttributeMDMRHSequence S, AttributeMDMRHSequence T, ParameterDTW p) {
final int tailleS = S.getNbTuples();
......@@ -75,7 +112,7 @@ public class DistanceDTWMDMRSingleLink implements Distance<AttributeMDMRSequence
}
return matriceW[tailleS - 1][tailleT - 1];
}
public static final double distanceTo(double[][] s1, double[][] s2) {
double minDistance = Double.MAX_VALUE;
double currentDistance, tmp;
......@@ -93,6 +130,23 @@ public class DistanceDTWMDMRSingleLink implements Distance<AttributeMDMRSequence
return minDistance;
}
public static final double distanceTo(double[][] s1, double[][] s2, Weights weights) {
double minDistance = Double.MAX_VALUE;
double currentDistance, tmp;
for (double[] p1 : s1) {
for (double[] p2 : s2) {
currentDistance = 0.0;
for (int d = 0; d < p1.length; d++) {
tmp = (p1[d] - p2[d]);
currentDistance += weights.getWeight(d) * tmp * tmp;
}
minDistance = (currentDistance < minDistance) ? currentDistance : minDistance;
}
}
return minDistance;
}