Commit 3b7e6baf authored by balanche's avatar balanche

Partial migration to DistanceModel utilisation

parent 7482508b
......@@ -26,11 +26,14 @@ import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceParameter;
import jcl.learning.LearningMethod;
import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import jsl.Segmentation;
import mustic.gui.dialog.*;
import mustic.gui.dialog.arff.ArffLoadDialog;
......@@ -2989,7 +2992,13 @@ public class MainFrame extends JFrame {
result = ClusteringResult.gerenerateDefaultClusteringResult(clusters);
result.setClusterMap(clusterMap);
result.setWeights(weights);
Classification classif = new SingleClassification(name, new SimpleData(dataObjects), method, result);
Classification classif = new SingleClassification(name,
new SimpleData(dataObjects, null, null), method, result);
DistanceModel model = DistanceModel.generateDefaultModel(dataObjects.get(0),
new GlobalWeights(dataObjects.get(0)));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,
model, classif.getData());
classif.getData().setDistanceModel(model, parameters);
// fichierImage = new File(fileName);
if (MainFrame.DEBUG_MODE)
......@@ -3065,7 +3074,12 @@ public class MainFrame extends JFrame {
}
else {
Data data = new SimpleData(dataObjects);
Data data = new SimpleData(dataObjects, null, null);
DistanceModel distModel = DistanceModel.generateDefaultModel(dataObjects.get(0),
new GlobalWeights(dataObjects.get(0)));
DistanceParameter[][] distParameters = DistanceModel
.generateDefaultDistanceParameters(1, model, data);
data.setDistanceModel(distModel, distParameters);
data.setDataName(file.getName());
MainFrame.getInstance().createDataSession(data);
......@@ -3086,7 +3100,8 @@ public class MainFrame extends JFrame {
// classif.setClusteringResult(result);
ci.addResult(classif, name);
// System.out.println("Resultat ajoute a la classif");
ImageResultPanel irp = (ImageResultPanel) ci.tabbedPane.getTabAt(ci.tabbedPane.getTabCount() - 1).getContentComponent();
ImageResultPanel irp = (ImageResultPanel) ci.tabbedPane
.getTabAt(ci.tabbedPane.getTabCount() - 1).getContentComponent();
if (MainFrame.DEBUG_MODE)
System.out.println(qualities);
irp.setQualityPanel(new QualityPanel(classif, qualities));
......
......@@ -138,7 +138,7 @@ public class ArffToDataDialog extends JInternalFrame implements ToUpdateObject {
}
}
@SuppressWarnings({ "unchecked", "deprecation" })
@SuppressWarnings({ "unchecked" })
protected void buttonOk_actionPerformed() {
try {
Object[] result = DataArffExchange.arffToData(this.textFile.getText());
......
......@@ -56,6 +56,9 @@ import jcl.clustering.constraints.LabelConstraint;
import jcl.clustering.constraints.MustLinkConstraint;
import jcl.clustering.constraints.NbClusterConstraint;
import jcl.data.Data;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.utils.image.ImageAddOn;
import mustic.utils.image.ImageDisplayer;
import mustic.utils.tools.ProgressPropertyChangeListener;
......@@ -161,11 +164,15 @@ public class ConstraintsSelectionFrame extends JFrame implements ImageAddOn {
this.imageDisplayer = imgDisplayer;
this.constraintsContainer = constraintsContainer;
if (data != null) {
// case of Data provided
minDistance = data.getEstimatedMinDistance();
maxDistance = data.getEstimatedMaxDistance();
DistanceModel model = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, data);
minDistance = data.getEstimatedMinDistance(model, parameters[0]);
maxDistance = data.getEstimatedMaxDistance(model, parameters[0]);
this.data = data;
} else {
// otherwise we base our estimation on the image
......
......@@ -22,8 +22,11 @@ import javax.swing.JTextField;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.ToUpdateObject;
......@@ -140,7 +143,6 @@ public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
}
}
@SuppressWarnings({"deprecation"})
protected void buttonOk_actionPerformed() {
try {
List<DataObject> result = new ArrayList<DataObject>();
......@@ -160,7 +162,11 @@ public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
}
if(result != null) {
data = new SimpleData(result);
data = new SimpleData(result, null, null);
DistanceModel model = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, data);
data.setDistanceModel(model, parameters);
if (this.textData.getText().length() == 0) {
this.textData.setText(ImageHelper.extractFileName(
......
......@@ -4,8 +4,6 @@ import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
......@@ -949,10 +947,11 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
*/
public void hClustering_actionPerformed(boolean newResult) {
try {
LearningParameters learningParameters = new ParametersAHC(null);
LearningParameters learningParameters = new ParametersAHC(imgData.getDistanceModel(),
imgData.getDistanceParameters());
LearningMethod learningMethod = learningParameters.getLearningMethodInstance();
@SuppressWarnings("deprecation")
Data classificationData = new SimpleData(this.result.getClusterCenters());
Data classificationData = new SimpleData(this.result.getClusterCenters(),
imgData.getDistanceModel(), imgData.getDistanceParameters());
LearningResult learningResult = learningMethod.learn(classificationData);
this.result.hierarchy = ((LearningResultAHC) learningResult).getHierarchy();
Classification classif = new SingleClassification("", classificationData, learningMethod, this.result);
......
......@@ -10,6 +10,7 @@ import javax.swing.*;
import javax.swing.border.TitledBorder;
import jcl.data.Data;
import jcl.data.DistanceModel;
import jcl.data.attribute.Attribute;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.distance.Distance;
......@@ -17,6 +18,7 @@ import jcl.data.distance.DistanceParameter;
import jcl.data.distance.sequential.DistanceEuclidean;
import jcl.learning.LearningParameters;
import jcl.learning.methods.multistrategy.samarah.*;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.classifier.AgentDialog;
import mustic.gui.panels.classifier.*;
......@@ -78,7 +80,7 @@ public class HybridClassificationPanel extends JPanel implements AgentListManage
this.title = this.title + "." + HybridClassificationPanel.nbSamarah;
HybridClassificationPanel.nbSamarah++;
// this.samarah = new HybridClassification("TEST", data, null);
this.samarah = new HybridClassification();
this.samarah = new HybridClassification(null, null);
if (MainFrame.DEBUG_MODE)
System.out.println(" in HybridClassificationParametersPanel() ");
this.samarah.config.printInfo();
......@@ -102,7 +104,11 @@ public class HybridClassificationPanel extends JPanel implements AgentListManage
jbInit();
HybridClassificationPanel.nbSamarah++;
// this.samarah = new HybridClassification("TEST", data, null);
this.samarah = new HybridClassification();
DistanceModel model = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, data);
this.samarah = new HybridClassification(model, parameters);
}
@Override
......@@ -155,16 +161,17 @@ public class HybridClassificationPanel extends JPanel implements AgentListManage
else {
file += "\t\t<isSimplifySequence>true</isSimplifySequence>\n";
}
for (Distance<Attribute, DistanceParameter> d : agent.getParams().getModel().getDistances()) {
if(!(d instanceof DistanceEuclidean))
}
if (AttributeMultiDimSequence.getMode() == AttributeMultiDimSequence.EUCLIDIEN && agent.getParams().getModel()) {
file += "\t\t<isUseNaiveDist>true</isUseNaiveDist>\n";
}
else {
file += "\t\t<isUseNaiveDist>false</isUseNaiveDist>\n";
}
//TODO try to match with the new distanceModel
// for (Distance<Attribute, DistanceParameter> d : agent.getParams().getModel().getDistances()) {
// if(!(d instanceof DistanceEuclidean))
//
// }
// if (AttributeMultiDimSequence.getMode() == AttributeMultiDimSequence.EUCLIDIEN && agent.getParams().getModel()) {
// file += "\t\t<isUseNaiveDist>true</isUseNaiveDist>\n";
// }
// else {
// file += "\t\t<isUseNaiveDist>false</isUseNaiveDist>\n";
// }
if (agent.getParams().weights != null) {
file += "\t\t<weight>";
double weights[] = agent.getParams().weights.getGlobalWeights().getWeights();
......
......@@ -16,8 +16,10 @@ import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
import jcl.weights.GlobalWeights;
import mustic.gui.ImageDesktopFrame;
import mustic.gui.ImageSession;
import mustic.gui.MainFrame;
......@@ -147,12 +149,16 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject {
}
if (filesPaths.size() > 1) {
data = new ImageData(sample, filesPaths, null);
// data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
data = new ImageData(sample, filesPaths, null, null, null);
} else {
data = new ImageData(sample, filesPaths.get(0), null);
// data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
data = new ImageData(sample, filesPaths.get(0), null, null);
}
DistanceModel distModel = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distParameters = DistanceModel
.generateDefaultDistanceParameters(1, distModel, data);
data.setDistanceModel(distModel, distParameters);
MainFrame.getInstance().createDataSession(data);
DataConstructFrame.getInstance().updateDataConstructPanel();
......
......@@ -7,8 +7,8 @@ import java.util.Vector;
import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.distance.DistanceParameter;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
import jcl.utils.exceptions.MethodNotImplementedException;
......@@ -59,7 +59,8 @@ public class ImageData extends SimpleData implements Serializable {
* @param image the image to convert
*/
@Deprecated
public ImageData(RawImage image) {
public ImageData(RawImage image, DistanceModel model, DistanceParameter[][] parameters) {
super(model, parameters);
if (MainFrame.DEBUG_MODE) {
System.out.println(">> ImageData(RawImage) <<");
}
......@@ -168,7 +169,8 @@ public class ImageData extends SimpleData implements Serializable {
* @param percent le pourcentage de pixels a choisir parmi l'image
*/
@Deprecated
public ImageData(RawImage image, double percent) {
public ImageData(RawImage image, double percent, DistanceModel model, DistanceParameter[][] parameters) {
super(model, parameters);
if (MainFrame.DEBUG_MODE)
System.out.println(">> ImageData(RawImage, double) <<");
......@@ -240,7 +242,9 @@ public class ImageData extends SimpleData implements Serializable {
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, RawImage path, Mask mask, DistanceModel model) {
public ImageData(Sampler sampler, RawImage path, Mask mask,
DistanceModel model, DistanceParameter[][] parameters) {
super(model, parameters);
if (MainFrame.DEBUG_MODE) {
System.out.println(">> ImageData(Sampler,String) <<");
}
......@@ -292,9 +296,6 @@ public class ImageData extends SimpleData implements Serializable {
long endTime = System.currentTimeMillis();
System.out.println("___________________Total elapsed time in execution of loading image is :" + ((endTime - startTime)));
}
setModel(model);
}
/**
......@@ -310,8 +311,8 @@ public class ImageData extends SimpleData implements Serializable {
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, RawImage path, DistanceModel model) {
this(sampler, path, null,model);
public ImageData(Sampler sampler, RawImage path, DistanceModel model, DistanceParameter[][] parameters) {
this(sampler, path, null, model, parameters);
}
/**
......@@ -329,8 +330,9 @@ public class ImageData extends SimpleData implements Serializable {
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask, DistanceModel model) {
public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask,
DistanceModel model, DistanceParameter[][] parameters) {
super(model, parameters);
for(RawImage s : images) {
this.rawImages.add(s);
}
......@@ -389,9 +391,6 @@ public class ImageData extends SimpleData implements Serializable {
System.out.println("___________________Total elapsed time in execution of loading image is :"
+ ((endTime - startTime)));
}
setModel(model);
}
/**
......@@ -407,8 +406,9 @@ public class ImageData extends SimpleData implements Serializable {
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, Vector<RawImage> images, DistanceModel model) {
this(sampler, images, null, model);
public ImageData(Sampler sampler, Vector<RawImage> images,
DistanceModel model, DistanceParameter[][] parameters) {
this(sampler, images, null, model, parameters);
}
......
......@@ -146,7 +146,8 @@ public class FilterDataDialog extends JDialog {
private void jButtonOK_actionPerformed() {
setVisible(false);
Filter filter = FilterUtils.createFilter(getParameters());
Filter filter = FilterUtils.createFilter(getParameters(),
data.getDistanceModel(), data.getDistanceParameters());
new FilterThread(filter, this.data, MainFrame.getProgressBar(), this)
.start();
}
......
......@@ -13,6 +13,8 @@ import javax.swing.tree.*;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.data.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.learning.IterativeClassification;
import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
......@@ -107,15 +109,20 @@ public class ClassConfigPanel extends JPanel implements TreeSelectionListener, A
* Constructeur par defaut.
* </p>
* @param classification les classes e afficher
* @param model
* the model used to compute the distance
* @param parameters
* the list of parameters used by the distance model
* @param resultPanel le panel de resultat e rafraichir en cas de modification. peut etre null
*/
public ClassConfigPanel(Classification classification, ResultPanel resultPanel) {
public ClassConfigPanel(Classification classification, ResultPanel resultPanel,
DistanceModel model, DistanceParameter[] parameters) {
super();
this.classification_ = classification;
this.resultPanel_ = resultPanel;
this.setLayout(new BorderLayout());
this.treeScrollPane = new JScrollPane();
this.treeScrollPane.setViewportView(getClusterTree());
this.treeScrollPane.setViewportView(getClusterTree(model, parameters));
this.treeScrollPane.setBorder(BorderFactory.createTitledBorder("Clusters"));
JPanel panel = null;
......@@ -911,12 +918,17 @@ public class ClassConfigPanel extends JPanel implements TreeSelectionListener, A
* <p>
* This method initializes clusterTree.
* </p>
*
* @param model
* the model used to compute the distance
* @param parameters
* the list of parameters used by the distance model
* @return le tree configure
*/
private JTree getClusterTree() {
private JTree getClusterTree(DistanceModel model, DistanceParameter[] parameters) {
ClusteringResult result = this.classification_.getClusteringResult();
this.clusterTree = new JTree(result.getRoot());
this.clusterTree = new JTree(result.getRoot(model, parameters));
this.clusterTree.setRootVisible(true);
this.clusterTree.setSelectionRow(0);
this.clusterTree.addTreeSelectionListener(this);
......
This diff is collapsed.
......@@ -109,7 +109,7 @@ public class HybridClassificationParametersPanel extends JPanel {
this.jSliderPcr.setValue(20);
// this.samarah = new HybridClassification("TEST", data, null);
this.data = null;
this.samarah = new HybridClassification();
this.samarah = new HybridClassification(null, null);
System.out.println(" in HybridClassificationParametersPanel() ");
this.samarah.config.printInfo();
}
......@@ -128,7 +128,7 @@ public class HybridClassificationParametersPanel extends JPanel {
this.jSliderPcr.setValue(20);
// this.samarah = new HybridClassification("TEST", data, null);
this.data = data;
this.samarah = new HybridClassification();
this.samarah = new HybridClassification(data.getDistanceModel(), data.getDistanceParameters());
}
/**
......
......@@ -51,7 +51,8 @@ public class QualityPanel extends JPanel implements Serializable {
this.qualities = qualities;
} else {
this.qualities = ClusteringEvaluation
.getAllQualities(classification);
.getAllQualities(classification, classification.getData().getDistanceModel(),
classification.getData().getDistanceParameters()[0]);
}
int nbIndices = this.qualities.length;
......
......@@ -194,7 +194,9 @@ public class ResultPanel extends JPanel {
/* On garde une trace de la classification */
this.classification = classification;
this.classPanel = new ClassConfigPanel(this.classification, this);
this.classPanel = new ClassConfigPanel(this.classification, this,
classification.getData().getDistanceModel(),
classification.getData().getDistanceParameters()[0]);
this.classFrame = frame;
setLayout(new BorderLayout());
panel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
......
......@@ -37,7 +37,7 @@ public class WriteDistancesPath {
//System.out.println("\t\t " + i + " ===> j = " + (i+1+j));
dataObject2 = dataObjectIter_j.next();
//distance = DistanceDTWMD.getInstance().compute(attMultiDimSequence1, attMultiDimSequence2, parameterDTW);
distance = dataObject1.distance(dataObject2);
distance = dataObject1.distance(dataObject2, data.getDistanceModel(), data.getDistanceParameters()[0]);
line += (distance);
if (dataObjectIter_j.hasNext())
line += ",";
......
......@@ -10,10 +10,8 @@ import jcl.data.DataObject;
import jcl.data.DistanceModel;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeNumerical;
import jcl.data.distance.Distance;
import jcl.data.distance.MetaDistance;
import jcl.data.distance.MetaDistanceEuclidean;
import jcl.data.distance.NumericalEuclideanDistance;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import jsl.Segmentation;
import jsl.io.Descripteur;
import jsl.io.ObjetImage;
......@@ -58,7 +56,7 @@ public class RegionDataBuilder {
int index = 0;
for (ObjetImage io : s.getResultat().getObjectsImage()) {
List listDescr = io.getListe_objetsDescripteur();
List<Descripteur> listDescr = io.getListe_objetsDescripteur();
current = new DataObject(listDescr.size());
int in = 0;
......@@ -76,19 +74,18 @@ public class RegionDataBuilder {
index++;
}
Distance[] distances = new Distance[listDesc.size()]; // a distance is set for every attribute
for (int i = 0; i < listDesc.size(); i++) {
distances[i] = NumericalEuclideanDistance.getInstance(); // first attribute compared with an euclidean distance between numericals
}
MetaDistance metaDistance = MetaDistanceEuclidean.getInstance(); // defines the way the two scores are combined (possibility to weight)
DistanceModel model = new DistanceModel(distances, metaDistance);
this.data = new SimpleData(allObjects, model);
this.data = new SimpleData(allObjects, null, null);
this.data.setAttributesNames(names);
this.data.setComments("% Donnees de regions");
this.data.setDataName("Regions");
Vector<String> filesName = new Vector<String>();
filesName.add("not assigned");
this.data.setDataFilesName(filesName);
DistanceModel model = DistanceModel.generateDefaultModel(this.data.getOneDataObject(),
new GlobalWeights(this.data.getOneDataObject()));
DistanceParameter[][] parameters = DistanceModel.generateDefaultDistanceParameters(1,model, this.data);
this.data.setDistanceModel(model, parameters);
}
public Data getData() {
......
......@@ -88,7 +88,7 @@ public class TestA2CNES {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
ClassificationWeights weights = new GlobalWeights(dataTrain);
ClassificationWeights weights = new GlobalWeights(dataTrain.getOneDataObject());
final Vector<Thread> threadList = new Vector<Thread>();
final Vector<Classification> classifList = new Vector<Classification>();
......
......@@ -80,7 +80,7 @@ public class TestA2CNESIterative {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
ClassificationWeights weights = new GlobalWeights(dataTest);
ClassificationWeights weights = new GlobalWeights(dataTest.getOneDataObject());
final Vector<Thread> threadList = new Vector<Thread>();
final Vector<Classification> classifList = new Vector<Classification>();
......
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