Commit 2324f382 authored by lafabregue's avatar lafabregue

fix merge with new constrained samarah

parents 33a0b68d bd1cc665
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -23,6 +23,9 @@ 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.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.gui.dialog.SequenceDialog;
......@@ -138,7 +141,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());
......@@ -212,16 +215,23 @@ public class ArffToDataDialog extends JInternalFrame implements ToUpdateObject {
// test if we have one or multiples images
if (sequenceFiles.size() > 1) {
data = new ImageData(new ImportedImageSampler(sequenceFilesPath,
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles);
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles, null, null);
} else {
data = new ImageData(new ImportedImageSampler(sequenceFilesPath.get(0),
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles.get(0));
(List<DataObject>) result[1], (List<Integer>) result[0]), sequenceFiles.get(0),
null, null);
}
} else {
// if no images is associated we create a SimpleData
data = new SimpleData((List<DataObject>) result[1]);
data = new SimpleData((List<DataObject>) result[1], null, null);
}
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
data.getOneDataObject(), new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
if (this.textData.getText().length() == 0) {
this.textData.setText(DataArffExchange.getRelationName(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.distance.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
......
......@@ -24,6 +24,9 @@ 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.weights.GlobalWeights;
import multiCube.tools.image.ImageHelper;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
......@@ -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(
......
package mustic.gui.dialog.csv;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
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;
<<<<<<< HEAD
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
=======
import multiCube.tools.image.ImageHelper;
>>>>>>> master
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.ToUpdateObject;
import mustic.utils.io.CSVUtils;
/**
* Dialog that allow the user to generate a Data from an arff file
*
* @author Baptiste LAFABREGUE
*
*/
public class CSVToDataDialog extends JInternalFrame implements ToUpdateObject {
private static final long serialVersionUID = 1L;
private JTextField textFile = new JTextField();
private JTextField textData = new JTextField();
private JTextField textSeparator = new JTextField();
public CSVToDataDialog() {
super();
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(3, 2));
JPanel pInpout = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.0")), BorderLayout.WEST); //$NON-NLS-1$
pInpout.add(this.textFile, BorderLayout.CENTER);
this.textFile.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
updateOutputName();
}
@Override
public void focusGained(FocusEvent e) {
}
});
JButton buttonBrowse = new JButton("..."); //$NON-NLS-1$
buttonBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
int returnVal = fileChooser
.showOpenDialog(CSVToDataDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
CSVToDataDialog.this.textFile.setText(fileChooser
.getSelectedFile().getPath());
updateOutputName();
if (!fileChooser.getSelectedFile().getPath()
.endsWith(".csv")) { //$NON-NLS-1$
JOptionPane.showMessageDialog(CSVToDataDialog.this,
Messages.getString("CSVToDataDialog.3"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
}
}
});
pInpout.add(buttonBrowse, BorderLayout.EAST);
panel.add(pInpout);
JPanel pSeparator = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.2")), BorderLayout.WEST); //$NON-NLS-1$
pSeparator.add(this.textSeparator, BorderLayout.CENTER);
panel.add(pSeparator);
this.textSeparator.setText(";");
JPanel pOutpout = new JPanel(new BorderLayout());
panel.add(new JLabel(Messages.getString("CSVToDataDialog.5")), BorderLayout.WEST); //$NON-NLS-1$
pOutpout.add(this.textData, BorderLayout.CENTER);
panel.add(pOutpout);
this.textFile.setPreferredSize(new Dimension(200, 30));
JPanel panelButton = new JPanel();
JButton buttonOk = new JButton(Messages.getString("CSVToDataDialog.7")); //$NON-NLS-1$
panelButton.add(buttonOk);
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonOk_actionPerformed();
}
});
mainPanel.add(panel, BorderLayout.NORTH);
mainPanel.add(panelButton, BorderLayout.SOUTH);
this.setContentPane(mainPanel);
this.setTitle(Messages.getString("CSVToDataDialog.8")); //$NON-NLS-1$
this.setSize(300, 180);
this.setResizable(true);
this.setMaximizable(true);
this.setIconifiable(true);
this.setClosable(true);
this.setVisible(true);
this.requestFocus();
}
private void updateOutputName() {
if (this.textData.getText() != null && this.textData.getText() != "") { //$NON-NLS-1$
// we don't update if there is already a value
return;
}
if (this.textFile.getText() != null && this.textFile.getText() != "") { //$NON-NLS-1$
this.textData.setText(ImageHelper.extractFileName(
ImageHelper.stripExtension(this.textData.getText())));
}
}
protected void buttonOk_actionPerformed() {
try {
List<DataObject> result = new ArrayList<DataObject>();
Data data = null;
CSVUtils reader = null;
try {
File file = new File(this.textFile.getText());
reader = new CSVUtils(file, this.textSeparator.getText().charAt(0));
List<String> line;
while((line = reader.readNext()) != null) {
extractObjectFromLine(result, line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
result = null;
}
if(result != null) {
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(
ImageHelper.stripExtension(this.textData.getText())));
}
data.setDataName(this.textData.getText());
MainFrame.getInstance().createDataSession(data);
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.151") + this.textData.getText() //$NON-NLS-1$
+ " " + Messages.getString("CSVToDataDialog.152"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.16"), //$NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.41"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
this.dispose();
} catch (Exception e) {
JOptionPane.showMessageDialog(this,
Messages.getString("CSVToDataDialog.41"), //$NON-NLS-1$
Messages.getString("CSVToDataDialog.4"), //$NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
e.printStackTrace();
}
}
/**
* Construct a DataObject from a set of Strings and add it to a List
* @param list
* the list to add the DataObject to
* @param line
* the line to interpret
*/
private void extractObjectFromLine(List<DataObject> list, List<String> line) {
DataObject obj = new DataObject(1);
double[][] seq = new double[line.size()][];
for (int i = 0 ; i < line.size() ; i++) {
seq[i] = new double[1];
seq[i][0] = Double.parseDouble(line.get(i));
}
obj.setAttribute(0, new AttributeMultiDimSequence(seq));
list.add(obj);
}
@Override
public void update(String s) {
}
}
......@@ -21,6 +21,9 @@ import javax.swing.text.PlainDocument;
import jcl.data.Data;
import jcl.data.DataObject;
import jcl.data.SimpleData;
import jcl.data.distance.DistanceModel;
import jcl.data.distance.DistanceParameter;
import jcl.weights.GlobalWeights;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.utils.documentFilter.BasicIntDocumentFilter;
......@@ -158,7 +161,13 @@ public class OGRToDataDialog extends JInternalFrame implements ToUpdateObject {
if(result != null) {
data = new SimpleData(result);
data = new SimpleData(result, null, null);
DistanceModel distanceModel = DistanceModel.generateDefaultModel(
data.getOneDataObject(), new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel
.generateDefaultDistanceParameters(1, distanceModel, data);
data.setDistanceModel(distanceModel, distanceParameters);
data.setDataName(this.textData.getText());
MainFrame.getInstance().createDataSession(data);
......
package mustic.gui.panels;
import java.io.File;
import java.util.Vector;
import javax.swing.JOptionPane;
import jcl.data.attribute.AttributeMultiDimSequence;
import jcl.learning.LearningParameters;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
import jcl.learning.methods.monostrategy.cobweb.ParametersCobweb;
import jcl.learning.methods.monostrategy.cure.ParametersCure;
import jcl.learning.methods.monostrategy.em.ParametersEM;
import jcl.learning.methods.monostrategy.gng.ParametersGNG;
import jcl.learning.methods.monostrategy.kmeans.ParametersKmeans;
import jcl.learning.methods.monostrategy.perceptron.ParametersPerceptron;
import jcl.learning.methods.monostrategy.random.ParametersRandom;
import jcl.learning.methods.monostrategy.som.ParametersSOM;
import jcl.weights.*;
import mustic.gui.DesktopFrame;
import mustic.gui.MainFrame;
import mustic.gui.panels.classifier.components.HybridClassificationPanel;
import mustic.io.*;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class HybridParametersHandler extends DefaultHandler {
private static final int AHC = 13;
private static final int COBWEB = 1;
private static final int CURE = 12;
private static final int EM = 4;
private static final int FUZZI_C_MEAN = 6;
private static final int FUZZY_GW_C_MEANS = 8;
private static final int FUZZY_LW_C_MEANS = 10;
private static final int GNG = 11;
private static final int GW_K_MEAN = 7;
private static final int K_MEANS = 0;
private static final int LW_K_MEANS = 9;
private static final int PERCEPTRON = 3;
private static final int RANDOM = 5;
private static final int SOM = 2;
private StringBuffer buffer;
private HybridClassificationPanel hybridPanel;
private boolean isHClustering;
private boolean isPanel;
private boolean isSimplifySequence;
private boolean isUseNaiveDist;
// private String data = null;
private Vector<String> listData = new Vector<String>();
private Vector<Double> listParam = new Vector<Double>();
private LearningParameters param = null;
private int type;
private Weights weight;
// simple constructeur
public HybridParametersHandler(HybridClassificationPanel hc, boolean isPanel) {
super();
this.hybridPanel = hc;
this.isPanel = isPanel;
}
// détection de caractères
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
String lecture = new String(ch, start, length);
if (buffer != null)
buffer.append(lecture);
}
// fin du parsing
@Override
public void endDocument() throws SAXException {
System.out.println("Agents ouverts");
}
// détection fin de balise
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("ListAgents")) {}
else if (qName.equals("agent")) {
ClassificationWeights weights = new GlobalWeights(this.weight);
DesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop().getAllDesktopFrames();
int nbSessions = desktopFrames.length;
ImageData data = null;
for (int i = 0; i < nbSessions; i++) {
if (this.listData.get(0).equals(desktopFrames[i].getImageSession().getRawImage().getPath())) {
data = desktopFrames[i].getImageSession().getImageData();
break;
}
}
if (data == null && this.isPanel) {
File f = new File(this.listData.get(0));
if (!f.exists()) {
JOptionPane.showMessageDialog(this.hybridPanel, this.listData.get(0) + "not found", "Warning", JOptionPane.WARNING_MESSAGE);
MainFrame.getInstance().openNewFile();
MainFrame.getInstance().getCurrentSession().associatedFrame.toBack();
data = MainFrame.getInstance().getCurrentSession().getImageData();
}
else {
try {
System.out.println("\n ouverture de " + f);
MainFrame.getInstance().createSession(MainFrame.getInstance().open(f), null);
if (MainFrame.getInstance().getCurrentSession().getRawImage().getNbBands() > 1) {
MainFrame.getInstance().getCurrentSession().getBirdViewPanel().setR(0);
MainFrame.getInstance().getCurrentSession().getBirdViewPanel().setG(1);
MainFrame.getInstance().getCurrentSession().getBirdViewPanel().setB(2);
MainFrame.getInstance().getCurrentSession().getBirdViewPanel().syncImage(MainFrame.getInstance().getCurrentSession());
PictureTool.setR(MainFrame.getInstance().getCurrentSession().getRawImage().getBirdview(), 0);
PictureTool.setG(MainFrame.getInstance().getCurrentSession().getRawImage().getBirdview(), 1);
PictureTool.setB(MainFrame.getInstance().getCurrentSession().getRawImage().getBirdview(), 2);
MainFrame.getInstance().getCurrentSession().getBirdViewPanel().refresh();
MainFrame.getInstance().getCurrentSession().associatedFrame.toBack();
data = MainFrame.getInstance().getCurrentSession().getImageData();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
else {
File f = new File(this.listData.get(0));
try {
data = new ImageData(MainFrame.getInstance().open(f));
} catch (Exception e) {
e.printStackTrace();
}
}
boolean open = false;
if (this.listData.size() > 1) {
RawImage images[] = new RawImage[this.listData.size()];
for (int im = 0; im < this.listData.size(); im++) {
for (int i = 0; i < nbSessions; i++) {
if (this.listData.get(im).equals(desktopFrames[i].getImageSession().getRawImage().getPath())) {
images[im] = desktopFrames[i].getImageSession().getRawImage();
open = true;
break;
}
if (!open) {
File f = new File(this.listData.get(im));
try {
images[im] = MainFrame.getInstance().open(f);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
ImageMultiDimSequenceData sequenceData = new ImageMultiDimSequenceData(images);
data.setSequence(sequenceData);
Vector<String> filesName = new Vector<String>();
filesName.add("sequence");
data.setDataFilesName(filesName); //$NON-NLS-1$
} else {
Vector<String> filesName = new Vector<String>();
filesName.add(this.listData.get(0));
}
switch (this.type) {
case K_MEANS:
this.param = new ParametersKmeans(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), weights);
break;
case COBWEB:
this.param = new ParametersCobweb(this.listParam.get(0), this.listParam.get(1), this.listParam.get(2).intValue(), this.listParam
.get(3).intValue(), this.listParam.get(4).intValue(), weights);
break;
case SOM:
this.param = new ParametersSOM(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(2)
.intValue(), this.listParam.get(3), weights);
break;
case PERCEPTRON:
this.param = new ParametersPerceptron(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(2),
this.listParam.get(3), weights);
break;
case EM:
this.param = new ParametersEM(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), weights);
break;
case RANDOM:
this.param = new ParametersRandom(this.listParam.get(0).intValue(), weights);
break;
case FUZZI_C_MEAN:
this.param = new ParametersKmeans(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(4),
weights);
break;
case GW_K_MEAN:
this.param = new ParametersKmeans(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(2),
ParametersKmeans.GLOBAL_FEATURE_WEIGHTING, weights);
break;
case FUZZY_GW_C_MEANS:
this.param = new ParametersKmeans(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(4),
this.listParam.get(2), ParametersKmeans.GLOBAL_FEATURE_WEIGHTING, weights);
break;
case LW_K_MEANS:
this.param = new ParametersKmeans(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(2),
ParametersKmeans.LOCAL_FEATURE_WEIGHTING, weights);
break;
case FUZZY_LW_C_MEANS:
this.param = new ParametersKmeans(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(4),
this.listParam.get(2), ParametersKmeans.LOCAL_FEATURE_WEIGHTING, weights);
break;
case GNG:
this.param = new ParametersGNG(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(2)
.intValue(), this.listParam.get(3).intValue(), weights);
break;
case CURE:
this.param = new ParametersCure(this.listParam.get(0).intValue(), this.listParam.get(1).intValue(), this.listParam.get(2),
weights);
break;
case AHC: