Commit d3c6c659 authored by lafabregue's avatar lafabregue

minor modifications

parent 27189188
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) {
}
}
......@@ -391,7 +391,7 @@ public class HybridClassificationSubParametersPanel extends JPanel {
jSpinnerClassRatio.setValue(samarah.config.pourcentage);
criterionComboBox.setSelectedIndex(samarah.config.critereAUtiliser);
jSpinnerDegradation1.setValue(samarah.config.degradationMax);
jSpinnerDegradation2.setValue(samarah.config.degradationMax);
jSpinnerDegradation2.setValue(1-samarah.config.degradationMax);
if (samarah.config.unification == SamarahConfig.WITH_UNCLASSIFIED_UNIFICATION) {
unificationbCheckBox.setSelected(true);
} else {
......
......@@ -291,7 +291,7 @@ public class DataPanel extends JPanel implements ChangeListener {
this.statsTable = new JTable();
this.statsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.statsTable.setFocusable(false);
updateStatsTable(0);
//updateStatsTable(0);
JScrollPane stastScrollPane = new JScrollPane(this.statsTable);
stastScrollPane.setPreferredSize(new Dimension(200, 100));
......
......@@ -41,16 +41,15 @@ public class TestA2CNES {
public static void main(String[] args) {
HybridClassification classification = new HybridClassification(null, null);
final String datasetName = "Frogs_MFCCs";
final String datasetPath = "Frogs_MFCCs";
final String dataPath = System.getProperty("user.home")+"/A2CNES/";
final String resultPath = System.getProperty("user.home")+"/A2CNES/results/";
final int nInf = 54;
final int nSup = 68;
final int[] ag_seeds = {52, 64, 71};
final int nb_iter = 15;
double constraintsWgt = 80;
final String datasetName = "foret";
final String datasetPath = "foret";
final String dataPath = System.getProperty("user.home")+"/A2CNES/";
final String resultPath = System.getProperty("user.home")+"/A2CNES/results/";
final int nInf = 22;
final int nSup = 25;
final int[] ag_seeds = {20,25,30};
final int nb_iter = 25;
double constraintsWgt = 90;
File directory = new File("log");
if (!directory.exists()){
......@@ -86,7 +85,7 @@ public class TestA2CNES {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
DistanceModel distanceModel = DistanceModel.generateNaiveModel(dataTest.getOneDataObject(),
DistanceModel distanceModel = DistanceModel.generateDefaultModel(dataTest.getOneDataObject(),
new GlobalWeights(dataTest.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, dataTest);
......@@ -243,7 +242,7 @@ public class TestA2CNES {
if (mask != null) {
maskLine = maskReader.readNext();
}
extractObjectFromLine(result, line, 1, maskLine);
extractObjectFromLine(result, line, 3, maskLine);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
......@@ -252,7 +251,7 @@ public class TestA2CNES {
data = new SimpleData(result, null, null);
DistanceModel distanceModel = DistanceModel.generateNaiveModel(data.getOneDataObject(),
DistanceModel distanceModel = DistanceModel.generateDefaultModel(data.getOneDataObject(),
new GlobalWeights(data.getOneDataObject()));
DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, data);
......
......@@ -89,7 +89,7 @@ public class TestA2CNESIterative {
classification.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, constraintsWgt);
final DistanceModel distanceModel = DistanceModel.generateNaiveModel(dataTest.getOneDataObject(),
final DistanceModel distanceModel = DistanceModel.generateDefaultModel(dataTest.getOneDataObject(),
new GlobalWeights(dataTest.getOneDataObject()));
final DistanceParameter[][] distanceParameters = DistanceModel.generateDefaultDistanceParameters(
3, distanceModel, dataTest);
......@@ -288,9 +288,16 @@ public class TestA2CNESIterative {
);
}
}
final double constraintsWgt = 0;
final double valueKExtern = 60;
final double kExtern = valueKExtern * ((100-constraintsWgt)/100);
final double kIntern = (100 - valueKExtern) * ((100-constraintsWgt)/100);
classif.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, 95);
classif.newIteration(subset);
kExtern, unificationType, criterion, constraintsWgt);
//classif.newIteration(subset);
classif.newIteration(new Vector<Constraint>());
FileWriter fw2 = null;
try {
fw2 = new FileWriter("log/"+rand+"sat_cst"+classif.getName()+".log", true);
......
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