Commit 1c2b4f88 authored by balanche's avatar balanche

Modification de l'algorithme K-means : celui ci utilise maintenant un Model...

Modification de l'algorithme K-means : celui ci utilise maintenant un Model pour définir les distances à utiliser. Still WIP
parent b2b142b3
......@@ -17,7 +17,14 @@ import javax.xml.parsers.SAXParserFactory;
import jcl.Classification;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.Model;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeSequence;
import jcl.data.distance.Distance;
import jcl.data.distance.DistanceParameter;
import jcl.data.distance.EmptyDistanceParameter;
import jcl.data.distance.sequential.DistanceDTW;
import jcl.data.distance.sequential.ParameterDTW;
import jcl.io.arff.ClassificationParametersIO;
import jcl.jcld.RmiServer;
import jcl.learning.LearningParameters;
......@@ -1000,7 +1007,24 @@ public class ClassifierPanel extends JPanel {
case ClassifierUtils.KMEANS: {
int nbClusters = Integer.valueOf(((JTextField) comp[1]).getText()).intValue();
int nbIters = Integer.valueOf(((JTextField) comp[3]).getText()).intValue();
params = new ParametersKmeans(nbClusters, nbIters, weights);
int nbThreads = 2;
//~ It is now necessary to parametrize the Kmeans algorithm
//~ 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++) {
int i = 0;
for (Distance d : data.getModel().getDistances()) {
if(d instanceof DistanceDTW) {
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)
}
else
distanceParameters[th][i] = EmptyDistanceParameter.getInstance();//no parameter for a numerical euclidean distance
i++;
}
}
params = new ParametersKmeans(nbClusters, nbIters, nbThreads, weights, distanceParameters);
break;
}
case ClassifierUtils.FCM: {
......@@ -1107,6 +1131,7 @@ public class ClassifierPanel extends JPanel {
else {
if (this.useNaiveDist) {
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
data.setModel(Model.generateNaiveModel(data.getOneDataObject()));
}
else {
AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.DTW_BARYCENTRE);
......
......@@ -15,6 +15,7 @@ import javax.swing.JScrollPane;
import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup;
import jcl.data.Model;
import jcl.data.mask.Mask;
import jcl.data.sampling.Sampler;
import mustic.gui.ImageDesktopFrame;
......@@ -143,11 +144,14 @@ public class DataConstructPanel extends JPanel implements ToUpdateObject {
if (containsAtLeastOne) {
((ImageSampler) sample).setMaskSequence(maskSequence);
}
}
}
if (filesPaths.size() > 1) {
data = new ImageData(sample, filesPaths);
data = new ImageData(sample, filesPaths, null);
data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
} else {
data = new ImageData(sample, filesPaths.get(0));
data = new ImageData(sample, filesPaths.get(0), null);
data.setModel(Model.generateDefaultModel(data.getOneDataObject()));
}
MainFrame.getInstance().createDataSession(data);
......
......@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Vector;
import jcl.data.DataObject;
import jcl.data.Model;
import jcl.data.SimpleData;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.data.attribute.AttributeNumerical;
......@@ -236,8 +237,10 @@ public class ImageData extends SimpleData implements Serializable {
* the path of the image
* @param mask
* a mask to apply to the sampler
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, RawImage path, Mask mask) {
public ImageData(Sampler sampler, RawImage path, Mask mask, Model model) {
if (MainFrame.DEBUG_MODE) {
System.out.println(">> ImageData(Sampler,String) <<");
}
......@@ -289,6 +292,8 @@ 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);
}
......@@ -302,15 +307,16 @@ public class ImageData extends SimpleData implements Serializable {
* The sample to extract data from
* @param path
* the path of the image
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, RawImage path) {
this(sampler, path, null);
public ImageData(Sampler sampler, RawImage path, Model model) {
this(sampler, path, null,model);
}
/**
* <p>
* Construcor from an already built set of DataObject of a sampler,
* Constructor from an already built set of DataObject of a sampler,
* paths are only used to gather the image informations
* </p>
*
......@@ -320,8 +326,10 @@ public class ImageData extends SimpleData implements Serializable {
* paths of the images
* @param mask
* a mask to apply to the sampler
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask) {
public ImageData(Sampler sampler, Vector<RawImage> images, Mask mask, Model model) {
for(RawImage s : images) {
this.rawImages.add(s);
......@@ -381,12 +389,14 @@ public class ImageData extends SimpleData implements Serializable {
System.out.println("___________________Total elapsed time in execution of loading image is :"
+ ((endTime - startTime)));
}
setModel(model);
}
/**
* <p>
* Construcor from an already built set of DataObject of a sampler,
* Constructor from an already built set of DataObject of a sampler,
* paths are only used to gather the image informations
* </p>
*
......@@ -394,11 +404,11 @@ public class ImageData extends SimpleData implements Serializable {
* the sample to extract data from
* @param path
* paths of the images
* @param mask
* a mask to apply to the sampler
* @param model
* the model to use with the data
*/
public ImageData(Sampler sampler, Vector<RawImage> images) {
this(sampler, images, null);
public ImageData(Sampler sampler, Vector<RawImage> images, Model model) {
this(sampler, images, null, model);
}
......
......@@ -960,12 +960,6 @@ public class ImageSampler extends Sampler {
return selectedIndexes;
}
@Override
public DataObject getDataObject(int index) {
updateRAMAvailable(false);
return getDataObject(index);
}
/**
* Return the mask list used to generate the data
* It does not affect the whole data functions.
......
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