Commit 440ce305 authored by balanche's avatar balanche

[Classe Model renommé en DistanceModel] Correction d'un bug de classification,...

[Classe Model renommé en DistanceModel] Correction d'un bug de classification, Déplacement du DistanceModel de Data vers Parameters, Correction d'un bug avec les attributs séquentiels
parent 1c2b4f88
...@@ -17,13 +17,14 @@ import javax.xml.parsers.SAXParserFactory; ...@@ -17,13 +17,14 @@ import javax.xml.parsers.SAXParserFactory;
import jcl.Classification; import jcl.Classification;
import jcl.data.Data; import jcl.data.Data;
import jcl.data.DataObject; import jcl.data.DataObject;
import jcl.data.Model; import jcl.data.DistanceModel;
import jcl.data.attribute.AttributeMultiDimSequence; import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeSequence; import jcl.data.attribute.AttributeSequence;
import jcl.data.distance.Distance; import jcl.data.distance.Distance;
import jcl.data.distance.DistanceParameter; import jcl.data.distance.DistanceParameter;
import jcl.data.distance.EmptyDistanceParameter; import jcl.data.distance.EmptyDistanceParameter;
import jcl.data.distance.sequential.DistanceDTW; import jcl.data.distance.sequential.DistanceDTW;
import jcl.data.distance.sequential.DistanceDTWMD;
import jcl.data.distance.sequential.ParameterDTW; import jcl.data.distance.sequential.ParameterDTW;
import jcl.io.arff.ClassificationParametersIO; import jcl.io.arff.ClassificationParametersIO;
import jcl.jcld.RmiServer; import jcl.jcld.RmiServer;
...@@ -936,6 +937,18 @@ public class ClassifierPanel extends JPanel { ...@@ -936,6 +937,18 @@ public class ClassifierPanel extends JPanel {
Component[] comp = this.paramsPanel.getComponents(); Component[] comp = this.paramsPanel.getComponents();
ClassificationWeights weights = new GlobalWeights(data); ClassificationWeights weights = new GlobalWeights(data);
DistanceModel model = null;
/* generates model */
if (this.useNaiveDist) {
// AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
model = DistanceModel.generateNaiveModel(data.getOneDataObject());
}
else {
// AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE);
model = DistanceModel.generateDefaultModel(data.getOneDataObject());
}
if (this.attributeSelectionPanel != null) if (this.attributeSelectionPanel != null)
weights = this.attributeSelectionPanel.getWeights(); weights = this.attributeSelectionPanel.getWeights();
...@@ -1008,23 +1021,25 @@ public class ClassifierPanel extends JPanel { ...@@ -1008,23 +1021,25 @@ public class ClassifierPanel extends JPanel {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue(); int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue(); int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
int nbThreads = 2; int nbThreads = 2;
//~ It is now necessary to parametrize the Kmeans algorithm DistanceParameter[][] distanceParameters = new DistanceParameter[nbThreads][model.getDistances().length];
//~ The Kmeans algorithm requires a set of distance parameters for each thread
//~ => it corresponds to a distance parameter by attribute and by thread
DistanceParameter[][] distanceParameters = new DistanceParameter[nbThreads][data.getModel().getDistances().length];
for (int th = 0; th < nbThreads; th++) { for (int th = 0; th < nbThreads; th++) {
int i = 0; int i = 0;
for (Distance d : data.getModel().getDistances()) { for (Distance d : model.getDistances()) {
if(d instanceof DistanceDTW) { if(d instanceof DistanceDTWMD) {
AttributeMultiDimSequence seq = (AttributeMultiDimSequence) data.getOneDataObject().getAttribute(i);//need the corresponding attribute to get the sequence length AttributeMultiDimSequence seq = (AttributeMultiDimSequence) data.getOneDataObject().getAttribute(i);//need the corresponding attribute to get the sequence length
distanceParameters[th][i] = new ParameterDTW(new double[seq.getNbTuples()][seq.getNbTuples()]); //special attribute for DTW distances (requires a matrix to work in) distanceParameters[th][i] = new ParameterDTW(new double[seq.getNbTuples()][seq.getNbTuples()]); //special attribute for DTW distances (requires a matrix to work in)
} }
else if(d instanceof DistanceDTW) {
AttributeSequence seq = (AttributeSequence) data.getOneDataObject().getAttribute(i);//need the corresponding attribute to get the sequence length
distanceParameters[th][i] = new ParameterDTW(new double[seq.getNbTuples()][seq.getNbTuples()]); //special attribute for DTW distances (requires a matrix to work in)
}
else else
distanceParameters[th][i] = EmptyDistanceParameter.getInstance();//no parameter for a numerical euclidean distance distanceParameters[th][i] = EmptyDistanceParameter.getInstance();//no parameter for a numerical euclidean distance
i++; i++;
} }
} }
params = new ParametersKmeans(nbClusters, nbIters, nbThreads, weights, distanceParameters); params = new ParametersKmeans(nbClusters, nbIters, nbThreads, weights, distanceParameters);
params.setModel(model);
break; break;
} }
case ClassifierUtils.FCM: { case ClassifierUtils.FCM: {
...@@ -1129,13 +1144,14 @@ public class ClassifierPanel extends JPanel { ...@@ -1129,13 +1144,14 @@ public class ClassifierPanel extends JPanel {
if (params == null) if (params == null)
System.out.println(Messages.getString("ClassifierPanel.108")); //$NON-NLS-1$ System.out.println(Messages.getString("ClassifierPanel.108")); //$NON-NLS-1$
else { else {
if (this.useNaiveDist) { // if (this.useNaiveDist) {
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN); // AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
data.setModel(Model.generateNaiveModel(data.getOneDataObject())); // data.setModel(Model.generateNaiveModel(data.getOneDataObject()));
} // }
else { // else {
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE); // AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE);
} // data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
// }
AttributeMultiDimSequence.setSimplifyFrom(-1); AttributeMultiDimSequence.setSimplifyFrom(-1);
if (this.hClustering) if (this.hClustering)
params.setHClustering(true); params.setHClustering(true);
......
...@@ -15,7 +15,7 @@ import javax.swing.JScrollPane; ...@@ -15,7 +15,7 @@ import javax.swing.JScrollPane;
import com.l2fprod.common.swing.JTaskPane; import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup; import com.l2fprod.common.swing.JTaskPaneGroup;
import jcl.data.Model; import jcl.data.DistanceModel;
import jcl.data.mask.Mask; import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler; import jcl.data.sampling.Sampler;
import mustic.gui.ImageDesktopFrame; import mustic.gui.ImageDesktopFrame;
...@@ -148,10 +148,10 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject { ...@@ -148,10 +148,10 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject {
if (filesPaths.size() > 1) { if (filesPaths.size() > 1) {
data = new ImageData(sample, filesPaths, null); data = new ImageData(sample, filesPaths, null);
data.setModel(Model.generateDefaultModel(data.getOneDataObject())); // data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
} else { } else {
data = new ImageData(sample, filesPaths.get(0), null); data = new ImageData(sample, filesPaths.get(0), null);
data.setModel(Model.generateDefaultModel(data.getOneDataObject())); // data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
} }
MainFrame.getInstance().createDataSession(data); MainFrame.getInstance().createDataSession(data);
......
...@@ -5,7 +5,7 @@ import java.util.ArrayList; ...@@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import jcl.data.DataObject; import jcl.data.DataObject;
import jcl.data.Model; import jcl.data.DistanceModel;
import jcl.data.SimpleData; import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence; import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeNumerical; import jcl.data.attribute.AttributeNumerical;
...@@ -240,7 +240,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -240,7 +240,7 @@ public class ImageData extends SimpleData implements Serializable {
* @param model * @param model
* the model to use with the data * the model to use with the data
*/ */
public ImageData(Sampler sampler, RawImage path, Mask mask, Model model) { public ImageData(Sampler sampler, RawImage path, Mask mask, DistanceModel model) {
if (MainFrame.DEBUG_MODE) { if (MainFrame.DEBUG_MODE) {
System.out.println(">> ImageData(Sampler,String) <<"); System.out.println(">> ImageData(Sampler,String) <<");
} }
...@@ -310,7 +310,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -310,7 +310,7 @@ public class ImageData extends SimpleData implements Serializable {
* @param model * @param model
* the model to use with the data * the model to use with the data
*/ */
public ImageData(Sampler sampler, RawImage path, Model model) { public ImageData(Sampler sampler, RawImage path, DistanceModel model) {
this(sampler, path, null,model); this(sampler, path, null,model);
} }
...@@ -329,7 +329,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -329,7 +329,7 @@ public class ImageData extends SimpleData implements Serializable {
* @param model * @param model
* the model to use with the data * the model to use with the data
*/ */
public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask, Model model) { public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask, DistanceModel model) {
for(RawImage s : images) { for(RawImage s : images) {
this.rawImages.add(s); this.rawImages.add(s);
...@@ -407,7 +407,7 @@ public class ImageData extends SimpleData implements Serializable { ...@@ -407,7 +407,7 @@ public class ImageData extends SimpleData implements Serializable {
* @param model * @param model
* the model to use with the data * the model to use with the data
*/ */
public ImageData(Sampler sampler, Vector<RawImage> images, Model model) { public ImageData(Sampler sampler, Vector<RawImage> images, DistanceModel model) {
this(sampler, images, null, model); this(sampler, images, null, model);
} }
......
...@@ -1013,8 +1013,8 @@ public class ImageSampler extends Sampler { ...@@ -1013,8 +1013,8 @@ public class ImageSampler extends Sampler {
this.cursorX = start % sampler.imageWidth; this.cursorX = start % sampler.imageWidth;
this.cursorY = start / sampler.imageWidth; this.cursorY = start / sampler.imageWidth;
if (end >= sampler.imageHeight * sampler.imageWidth -1) { if (end >= sampler.imageHeight * sampler.imageWidth -1) {
this.endY = sampler.imageHeight-1; this.endY = sampler.imageHeight;
this.endX = sampler.imageWidth-1; this.endX = sampler.imageWidth;
} else { } else {
this.endX = end % sampler.imageWidth; this.endX = end % sampler.imageWidth;
this.endY = end / sampler.imageWidth; this.endY = end / sampler.imageWidth;
...@@ -1086,8 +1086,8 @@ public class ImageSampler extends Sampler { ...@@ -1086,8 +1086,8 @@ public class ImageSampler extends Sampler {
this.cursorX = start % sampler.imageWidth; this.cursorX = start % sampler.imageWidth;
this.cursorY = start / sampler.imageWidth; this.cursorY = start / sampler.imageWidth;
if (end >= sampler.imageHeight * sampler.imageWidth -1) { if (end >= sampler.imageHeight * sampler.imageWidth -1) {
this.endY = sampler.imageHeight-1; this.endY = sampler.imageHeight;
this.endX = sampler.imageWidth-1; this.endX = sampler.imageWidth;
} else { } else {
this.endX = end % sampler.imageWidth; this.endX = end % sampler.imageWidth;
this.endY = end / sampler.imageWidth; this.endY = end / sampler.imageWidth;
...@@ -1177,8 +1177,8 @@ public class ImageSampler extends Sampler { ...@@ -1177,8 +1177,8 @@ public class ImageSampler extends Sampler {
this.cursorX = start % sampler.imageWidth; this.cursorX = start % sampler.imageWidth;
this.cursorY = start / sampler.imageWidth; this.cursorY = start / sampler.imageWidth;
if (end >= sampler.imageHeight * sampler.imageWidth -1) { if (end >= sampler.imageHeight * sampler.imageWidth -1) {
this.endY = sampler.imageHeight-1; this.endY = sampler.imageHeight;
this.endX = sampler.imageWidth-1; this.endX = sampler.imageWidth;
} else { } else {
this.endX = end % sampler.imageWidth; this.endX = end % sampler.imageWidth;
this.endY = end / sampler.imageWidth; this.endY = end / sampler.imageWidth;
......
...@@ -7,7 +7,7 @@ import java.util.Vector; ...@@ -7,7 +7,7 @@ import java.util.Vector;
import jcl.data.Data; import jcl.data.Data;
import jcl.data.DataObject; import jcl.data.DataObject;
import jcl.data.Model; import jcl.data.DistanceModel;
import jcl.data.SimpleData; import jcl.data.SimpleData;
import jcl.data.attribute.AttributeNumerical; import jcl.data.attribute.AttributeNumerical;
import jcl.data.distance.Distance; import jcl.data.distance.Distance;
...@@ -81,7 +81,7 @@ public class RegionDataBuilder { ...@@ -81,7 +81,7 @@ public class RegionDataBuilder {
distances[i] = NumericalEuclideanDistance.getInstance(); // first attribute compared with an euclidean distance between numericals 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) MetaDistance metaDistance = MetaDistanceEuclidean.getInstance(); // defines the way the two scores are combined (possibility to weight)
Model model = new Model(distances, metaDistance); DistanceModel model = new DistanceModel(distances, metaDistance);
this.data = new SimpleData(allObjects, model); this.data = new SimpleData(allObjects, model);
this.data.setAttributesNames(names); this.data.setAttributesNames(names);
this.data.setComments("% Donnees de regions"); this.data.setComments("% Donnees de regions");
......
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