Commit 5a0ee226 authored by lafabregue's avatar lafabregue

fix merge with new constrained samarah

parent 2324f382
......@@ -23,11 +23,13 @@ import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.average.AverageParameter;
import jcl.io.results.CSVResultWriter;
import jcl.learning.methods.monostrategy.kmeans.ParametersKmeans;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.SamarahConfig;
import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import multiCube.tools.image.ImageHelper;
import mustic.gui.ClassificationFrame;
......@@ -38,7 +40,7 @@ public class TestA2CNES {
public static void main(String[] args) {
HybridClassification classification = new HybridClassification();
HybridClassification classification = new HybridClassification(null, null);
final String datasetName = "Frogs_MFCCs";
final String datasetPath = "Frogs_MFCCs";
......@@ -57,8 +59,6 @@ public class TestA2CNES {
Data dataTest = getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null);
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
// AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE);
final DateTime startTime = DateTime.now();
......@@ -86,7 +86,13 @@ public class TestA2CNES {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
ClassificationWeights weights = new GlobalWeights(dataTest);
DistanceModel distanceModel = DistanceModel.generateNaiveModel(dataTest.getOneDataObject(),
new GlobalWeights(dataTest.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, dataTest);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(
distanceModel, dataTest);
final Vector<Thread> threadList = new Vector<Thread>();
......@@ -164,7 +170,8 @@ public class TestA2CNES {
currentData.updateAndSetConstraintsToSample(constraints);
for (int a : ag_seeds) {
classif.addAgent(new ParametersKmeans(a, nb_iter, weights), currentData);
classif.addAgent(new ParametersKmeans(a, nb_iter, distanceModel,
distanceParameters, averageParameters), currentData);
}
final String path_to_add = resultPath + datasetName + "/";
......@@ -243,7 +250,14 @@ public class TestA2CNES {
result = null;
}
data = new SimpleData(result);
data = new SimpleData(result, null, null);
DistanceModel distanceModel = DistanceModel.generateNaiveModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
data.setDataName(name);
MainFrame.getInstance().createDataSession(data);
......
......@@ -23,13 +23,9 @@ import jcl.clustering.constraints.CannotLinkConstraint;
import jcl.clustering.constraints.Constraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.data.Data;
import jcl.data.Model;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.MetaDistance;
import jcl.data.distance.MetaDistanceEuclidean;
import jcl.data.distance.sequential.ParameterDTW;
import jcl.data.distance.average.AverageParameter;
import jcl.data.mask.IntArrayMask;
import jcl.data.mask.Mask;
import jcl.io.results.CSVResultWriter;
......@@ -37,7 +33,6 @@ import jcl.learning.methods.monostrategy.kmeans.ParametersKmeans;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.SamarahConfig;
import jcl.utils.RandomizeTools;
import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import multiCube.tools.image.ImageHelper;
import mustic.gui.ClassificationFrame;
......@@ -45,7 +40,7 @@ import mustic.utils.io.CSVUtils;
public class TestA2CNESIterative {
public static void main(String[] args) {
HybridClassification classification = new HybridClassification();
HybridClassification classification = new HybridClassification(null, null);
final String datasetName = "FacesUCR";
final String datasetPath = "FacesUCR";
......@@ -67,9 +62,6 @@ public class TestA2CNESIterative {
final Data dataTest = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null);
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
// AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE);
final DateTime startTime = DateTime.now();
......@@ -97,7 +89,13 @@ public class TestA2CNESIterative {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
ClassificationWeights weights = new GlobalWeights(dataTest.getOneDataObject());
final DistanceModel distanceModel = DistanceModel.generateNaiveModel(dataTest.getOneDataObject(),
new GlobalWeights(dataTest.getOneDataObject()));
final DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, dataTest);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(
distanceModel, dataTest);
final Vector<Thread> threadList = new Vector<Thread>();
final Vector<Classification> classifList = new Vector<Classification>();
......@@ -211,7 +209,8 @@ public class TestA2CNESIterative {
for (int a : ag_seeds) {
classif.addAgent(new ParametersKmeans(a, nb_iter, weights), currentData);
classif.addAgent(new ParametersKmeans(a, nb_iter, distanceModel,
distanceParameters, averageParameters), currentData);
}
final String path_to_add = resultPath + datasetName + "/";
......@@ -243,15 +242,7 @@ public class TestA2CNESIterative {
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw);
Distance[] distances = new Distance[1]; // a distance is set for every attribute
distances[0] = jcl.data.distance.sequential.DistanceDTWMD.getInstance(); // second attribute (sequential) compared with the DTW distance
MetaDistance metaDistance = MetaDistanceEuclidean.getInstance(); // defines the way the two scores are combined (possibility to weight)
Model model = new Model(distances, metaDistance);
int seqLength = ((AttributeMultiDimSequence) dataTest.getOneDataObject().getAttribute(0)).sequence.length;
DistanceParameter[] distanceParameters = new DistanceParameter[1];
distanceParameters[0] = new ParameterDTW(new double[seqLength][seqLength]); //but yes for DTW (requires a matrix to work in)
for (int i = 0 ; i < 5 ; i++) {
int[] clustMap = classif.getClusteringResult().getClusterMap();
......@@ -279,10 +270,10 @@ public class TestA2CNESIterative {
out.println(c.toString()+";"+
Constraint.marginalSilhouetteScore(
ml.getFirstIndex(), classif.getClusteringResult(),
model, distanceParameters)+";"+
distanceModel , distanceParameters[0])+";"+
Constraint.marginalSilhouetteScore(
ml.getSecondIndex(), classif.getClusteringResult(),
model, distanceParameters)
distanceModel , distanceParameters[0])
);
} else {
......@@ -290,10 +281,10 @@ public class TestA2CNESIterative {
out.println(c.toString()+";"+
Constraint.marginalSilhouetteScore(
cl.getFirstIndex(), classif.getClusteringResult(),
model, distanceParameters)+";"+
distanceModel , distanceParameters[0])+";"+
Constraint.marginalSilhouetteScore(
cl.getSecondIndex(), classif.getClusteringResult(),
model, distanceParameters)
distanceModel , distanceParameters[0])
);
}
}
......
......@@ -23,23 +23,17 @@ import jcl.clustering.constraints.CannotLinkConstraint;
import jcl.clustering.constraints.Constraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.data.Data;
import jcl.data.Model;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.MetaDistance;
import jcl.data.distance.MetaDistanceEuclidean;
import jcl.data.distance.sequential.ParameterDTW;
import jcl.data.distance.average.AverageParameter;
import jcl.data.mask.IntArrayMask;
import jcl.data.mask.Mask;
import jcl.io.results.CSVResultWriter;
import jcl.learning.methods.monostrategy.kmeans.ParametersKmeans;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.SamarahConfig;
import jcl.learning.methods.multistrategy.samarahConstrained.HybridClassificationConstrained;
import jcl.learning.methods.multistrategy.samarahConstrained.HybridClassificationConstrained2;
import jcl.utils.RandomizeTools;
import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import multiCube.tools.image.ImageHelper;
import mustic.gui.ClassificationFrame;
......@@ -47,7 +41,7 @@ import mustic.utils.io.CSVUtils;
public class TestA2CNESIterativeSelectedCst {
public static void main(String[] args) {
HybridClassificationConstrained2 classification = new HybridClassificationConstrained2();
HybridClassificationConstrained2 classification = new HybridClassificationConstrained2(null, null);
// HybridClassificationConstrained2 classification = new HybridClassificationConstrained2();
final String datasetName = "Frogs_MFCCs";
......@@ -70,9 +64,6 @@ public class TestA2CNESIterativeSelectedCst {
final Data dataTest = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null);
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
// AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE);
final DateTime startTime = DateTime.now();
......@@ -100,7 +91,12 @@ public class TestA2CNESIterativeSelectedCst {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
ClassificationWeights weights = new GlobalWeights(dataTest);
final DistanceModel distanceModel = DistanceModel.generateNaiveModel(dataTest.getOneDataObject(),
new GlobalWeights(dataTest.getOneDataObject()));
final DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, dataTest);
AverageParameter[] averageParameters = DistanceModel.generateDefaultAverageParameters(
distanceModel, dataTest);
final Vector<Thread> threadList = new Vector<Thread>();
final Vector<Classification> classifList = new Vector<Classification>();
......@@ -128,7 +124,8 @@ public class TestA2CNESIterativeSelectedCst {
int index2 = Integer.parseInt(line.get(1))-1;
MustLinkConstraint ml = new MustLinkConstraint(index1, index2);
double mldist = dataTest.getDataObject(ml.getFirstIndex())
.distance(dataTest.getDataObject(ml.getSecondIndex()));
.distance(dataTest.getDataObject(ml.getSecondIndex()),
distanceModel, distanceParameters[0]);
boolean insert = false;
for(int i = 0 ; i < constraintsML.size() ; i++) {
if (mldist < distancesML.get(i)) {
......@@ -152,7 +149,8 @@ public class TestA2CNESIterativeSelectedCst {
int index2 = Integer.parseInt(line.get(1))-1;
CannotLinkConstraint cl = new CannotLinkConstraint(index1, index2);
double cldist = dataTest.getDataObject(cl.getFirstIndex())
.distance(dataTest.getDataObject(cl.getSecondIndex()));
.distance(dataTest.getDataObject(cl.getSecondIndex()),
distanceModel, distanceParameters[0]);
boolean insert = false;
for(int i = 0 ; i < constraintsCL.size() ; i++) {
if (cldist > distancesCL.get(i)) {
......@@ -188,7 +186,8 @@ public class TestA2CNESIterativeSelectedCst {
// currentData.updateAndSetConstraintsToSample(subset);
for (int a : ag_seeds) {
classif.addAgent(new ParametersKmeans(a, nb_iter, weights), currentData);
classif.addAgent(new ParametersKmeans(a, nb_iter, distanceModel,
distanceParameters, averageParameters), currentData);
}
final String path_to_add = resultPath + datasetName + "/";
......@@ -228,15 +227,6 @@ public class TestA2CNESIterativeSelectedCst {
BufferedWriter bw2 = new BufferedWriter(fw2);
PrintWriter out2 = new PrintWriter(bw2);
Distance[] distances = new Distance[1]; // a distance is set for every attribute
distances[0] = jcl.data.distance.sequential.DistanceDTWMD.getInstance(); // second attribute (sequential) compared with the DTW distance
MetaDistance metaDistance = MetaDistanceEuclidean.getInstance(); // defines the way the two scores are combined (possibility to weight)
Model model = new Model(distances, metaDistance);
int seqLength = ((AttributeMultiDimSequence) dataTest.getOneDataObject().getAttribute(0)).sequence.length;
DistanceParameter[] distanceParameters = new DistanceParameter[1];
distanceParameters[0] = new ParameterDTW(new double[seqLength][seqLength]); //but yes for DTW (requires a matrix to work in)
for (int i = 0 ; i < 5 ; i++) {
int[] clustMap = classif.getClusteringResult().getClusterMap();
int[] satisifiedMapCL = new int[constraintsCL.size()];
......@@ -267,10 +257,10 @@ public class TestA2CNESIterativeSelectedCst {
out.println(c.toString()+";"+
Constraint.marginalSilhouetteScore(
ml.getFirstIndex(), classif.getClusteringResult(),
model, distanceParameters)+";"+
distanceModel , distanceParameters[0])+";"+
Constraint.marginalSilhouetteScore(
ml.getSecondIndex(), classif.getClusteringResult(),
model, distanceParameters)
distanceModel , distanceParameters[0])
);
} else {
......@@ -278,10 +268,10 @@ public class TestA2CNESIterativeSelectedCst {
out.println(c.toString()+";"+
Constraint.marginalSilhouetteScore(
cl.getFirstIndex(), classif.getClusteringResult(),
model, distanceParameters)+";"+
distanceModel , distanceParameters[0])+";"+
Constraint.marginalSilhouetteScore(
cl.getSecondIndex(), classif.getClusteringResult(),
model, distanceParameters)
distanceModel , distanceParameters[0])
);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment