Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit 226b3694 authored by lafabregue's avatar lafabregue
Browse files

small interface modifications and fixes

parent 5784c615
Pipeline #1829 failed with stages
in 41 seconds
This diff is collapsed.
......@@ -4,6 +4,7 @@ import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.Arrays;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
......@@ -27,6 +28,8 @@ import jcl.learning.*;
import jcl.learning.methods.monostrategy.SingleClassification;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.SamarahEval;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.io.JCLModelExchange;
import jsl.Segmentation;
......@@ -1141,6 +1144,26 @@ public class ImageResultPanel extends ResultPanel implements TreeSelectionListen
Packager.zipFile(out, name + "/"+outputPath, outputfile);
outputfile.delete();
/** this is some stats for samarah used for a test, this might be deleted */
//<<
if (classification instanceof HybridClassification) {
FileWriter fw3 = null;
try {
fw3 = new FileWriter("_concordence.log", true);
} catch (IOException e) {
e.printStackTrace();
}
BufferedWriter bw3 = new BufferedWriter(fw3);
PrintWriter out3 = new PrintWriter(bw3);
SamarahEval eval = new SamarahEval(((HybridClassification) classification), null,
((HybridClassification) classification).getConstraintsUsed());
eval.calGamma(((HybridClassification) classification).getAgents(),
((HybridClassification) classification).getConfig(), null);
out3.println(Arrays.deepToString(eval.omega));
}
//>>
/** Save the model file */
try {
String modelPath = "model.jclm";
......
......@@ -13,11 +13,12 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import jcl.evaluation.clustering.ClusteringEvaluation;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
......@@ -44,10 +45,15 @@ public class HybridClassificationSubParametersPanel extends JPanel {
private JCheckBox jCheckBoxNbClasses = new JCheckBox();
// private JCheckBox jCheckBoxUnifiSimple = new JCheckBox("No refinement");
private JSlider jSliderConstraints = new JSlider();
private JSlider jSliderDegradation = new JSlider();
private JSlider jSliderPePi = new JSlider();
private JSlider jSliderPqPs = new JSlider();
private JSpinner jSpinnerConstraints1 = null;
private JSpinner jSpinnerConstraints2 = null;
private JSpinner jSpinnerDegradation1 = null;
private JSpinner jSpinnerDegradation2 = null;
private JSpinner jSpinnerPePi1 = null;
private JSpinner jSpinnerPePi2 = null;
private JSpinner jSpinnerPqPs1 = null;
private JSpinner jSpinnerPqPs2 = null;
private JSpinner jSpinnerClassRatio = null;
private JSpinner jSpinnerConflict = new JSpinner();
......@@ -65,7 +71,11 @@ public class HybridClassificationSubParametersPanel extends JPanel {
private JButton resetButton;
private JCheckBox unificationbCheckBox;
/** Juste une unification sans raffinement */
/** Allow to not end up in a loop with jSpinners */
private boolean updateInProgress = false;
/** Just a unification without refinement */
// private boolean unification_simple = false;
/** classifictaion used to initialized parameters */
......@@ -117,26 +127,110 @@ public class HybridClassificationSubParametersPanel extends JPanel {
jTextFieldNInf.setPreferredSize(inputDimension);
jTextFieldNInf.setHorizontalAlignment(SwingConstants.CENTER);
jSliderPqPs.setPaintTicks(true);
jSliderPqPs.setMinorTickSpacing(25);
jSliderPqPs.setPreferredSize(new Dimension(160, 20));
jSliderPqPs.setValue(50);
jSliderPePi.setPaintTicks(true);
jSliderPePi.setMinorTickSpacing(25);
jSliderPePi.setPreferredSize(new Dimension(160, 20));
jSliderPePi.setValue(66);
jSliderConstraints.setPaintTicks(true);
jSliderConstraints.setMinorTickSpacing(25);
jSliderConstraints.setPreferredSize(new Dimension(160, 20));
jSliderConstraints.setValue(0);
jSliderDegradation.setMinorTickSpacing(25);
jSliderDegradation.setPaintTicks(true);
jSliderDegradation.setValue(90);
jSliderDegradation.setPreferredSize(new Dimension(160, 20));
jSpinnerPqPs1 = new JSpinner(new SpinnerNumberModel(0.5, 0.0, 1.0, 0.05));
jSpinnerPqPs1.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerPqPs1);
jSpinnerPqPs1.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerPqPs2.setValue(1 - ((double) jSpinnerPqPs1.getValue()));
updateInProgress = false;
}
}
});
jSpinnerPqPs2 = new JSpinner(new SpinnerNumberModel(0.5, 0.0, 1.0, 0.05));
jSpinnerPqPs2.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerPqPs2);
jSpinnerPqPs2.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerPqPs1.setValue(1 - ((double) jSpinnerPqPs2.getValue()));
updateInProgress = false;
}
}
});
jSpinnerPePi1 = new JSpinner(new SpinnerNumberModel(0.65, 0.0, 1.0, 0.05));
jSpinnerPePi1.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerPePi1);
jSpinnerPePi1.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerPePi2.setValue(1 - ((double) jSpinnerPePi1.getValue()));
updateInProgress = false;
}
}
});
jSpinnerPePi2 = new JSpinner(new SpinnerNumberModel(0.35, 0.0, 1.0, 0.05));
jSpinnerPePi2.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerPePi2);
jSpinnerPePi2.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerPePi1.setValue(1 - ((double) jSpinnerPePi2.getValue()));
updateInProgress = false;
}
}
});
jSpinnerConstraints1 = new JSpinner(new SpinnerNumberModel(0, 0.0, 1.0, 0.05));
jSpinnerConstraints1.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerConstraints1);
jSpinnerConstraints1.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerConstraints2.setValue(1 - ((double) jSpinnerConstraints1.getValue()));
updateInProgress = false;
}
}
});
jSpinnerConstraints2 = new JSpinner(new SpinnerNumberModel(1.0, 0.0, 1.0, 0.05));
jSpinnerConstraints2.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerConstraints1);
jSpinnerConstraints2.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerConstraints1.setValue(1 - ((double) jSpinnerConstraints2.getValue()));
updateInProgress = false;
}
}
});
jSpinnerDegradation1 = new JSpinner(new SpinnerNumberModel(0.9, 0.0, 1.0, 0.1));
jSpinnerDegradation1.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerDegradation1);
jSpinnerDegradation1.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerDegradation2.setValue(1 - ((double) jSpinnerDegradation1.getValue()));
updateInProgress = false;
}
}
});
jSpinnerDegradation2 = new JSpinner(new SpinnerNumberModel(0.1, 0.0, 1.0, 0.1));
jSpinnerDegradation2.setPreferredSize(inputDimension);
centerSpinnerText(jSpinnerDegradation2);
jSpinnerDegradation2.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!updateInProgress) {
updateInProgress = true;
jSpinnerDegradation1.setValue(1 - ((double) jSpinnerDegradation2.getValue()));
updateInProgress = false;
}
}
});
// Precisions Panels
jSpinnerSolutionType = new JSpinner(new SpinnerNumberModel(3, 0, 3, 1));
......@@ -174,25 +268,29 @@ public class HybridClassificationSubParametersPanel extends JPanel {
JPanel internQualityPanel = new JPanel();
internQualityPanel.add(new JLabel(" K-Intern : "));
internQualityPanel.add(new JLabel("Quality "));
internQualityPanel.add(jSliderPqPs);
internQualityPanel.add(jSpinnerPqPs1);
internQualityPanel.add(jSpinnerPqPs2);
internQualityPanel.add(new JLabel(" Similarity"));
JPanel gammaQualityPanel = new JPanel();
gammaQualityPanel.add(new JLabel("K-Int/Ext : "));
gammaQualityPanel.add(new JLabel("K-Extern "));
gammaQualityPanel.add(jSliderPePi);
gammaQualityPanel.add(jSpinnerPePi1);
gammaQualityPanel.add(jSpinnerPePi2);
gammaQualityPanel.add(new JLabel(" K-Intern"));
JPanel constraintsQualityPanel = new JPanel();
constraintsQualityPanel.add(new JLabel("Gamma : "));
constraintsQualityPanel.add(new JLabel("Constraints "));
constraintsQualityPanel.add(jSliderConstraints);
constraintsQualityPanel.add(jSpinnerConstraints1);
constraintsQualityPanel.add(jSpinnerConstraints2);
constraintsQualityPanel.add(new JLabel(" K-Int/Ext"));
JPanel degrapdationPanel = new JPanel();
degrapdationPanel.add(new JLabel("Degradation :"));
degrapdationPanel.add(new JLabel("None"));
degrapdationPanel.add(jSliderDegradation);
degrapdationPanel.add(jSpinnerDegradation1);
degrapdationPanel.add(jSpinnerDegradation2);
degrapdationPanel.add(new JLabel(" Full "));
JPanel qualityPanel = new JPanel();
......@@ -281,14 +379,18 @@ public class HybridClassificationSubParametersPanel extends JPanel {
jSpinnerPcr.setValue(samarah.config.pcr);
// parametre qualite/similitude
jSliderPqPs.setValue((int) (samarah.config.importanceQualite * 100.0));
jSliderConstraints.setValue((int) (samarah.config.importance_constraints * 100.0));
jSliderPePi.setValue((int) (100.0 * samarah.config.importance_Kexterne /(1-samarah.config.importance_constraints)));
jSpinnerPqPs1.setValue(samarah.config.importanceQualite);
jSpinnerPqPs1.setValue(1-samarah.config.importanceQualite);
jSpinnerConstraints1.setValue(samarah.config.importance_constraints);
jSpinnerConstraints2.setValue(1 - samarah.config.importance_constraints);
jSpinnerPePi1.setValue(samarah.config.importance_Kexterne /(1-samarah.config.importance_constraints));
jSpinnerPePi1.setValue(1 - samarah.config.importance_Kexterne /(1-samarah.config.importance_constraints));
jSpinnerSolutionType.setValue(samarah.config.typeSolution);
jSpinnerClassRatio.setValue(samarah.config.pourcentage);
criterionComboBox.setSelectedIndex(samarah.config.critereAUtiliser);
jSliderDegradation.setValue((int) (samarah.config.degradationMax * 100));
jSpinnerDegradation1.setValue(samarah.config.degradationMax);
jSpinnerDegradation2.setValue(samarah.config.degradationMax);
if (samarah.config.unification == SamarahConfig.WITH_UNCLASSIFIED_UNIFICATION) {
unificationbCheckBox.setSelected(true);
} else {
......@@ -300,10 +402,14 @@ public class HybridClassificationSubParametersPanel extends JPanel {
jSpinnerClassRatio.setValue(0.01);
jSpinnerPcr.setValue(0.2);
jSliderPqPs.setValue(50);
jSliderPePi.setValue(66);
jSliderConstraints.setValue(0);
jSliderDegradation.setValue(90);
jSpinnerPqPs1.setValue(0.5);
jSpinnerPqPs2.setValue(0.5);
jSpinnerPePi1.setValue(0.66);
jSpinnerPePi2.setValue(0.34);
jSpinnerConstraints1.setValue(0.0);
jSpinnerConstraints2.setValue(1.0);
jSpinnerDegradation1.setValue(0.9);
jSpinnerDegradation2.setValue(0.1);
jTextFieldNInf.setEnabled(false);
jTextFieldNSup.setEnabled(false);
jCheckBoxNbClasses.setSelected(false);
......@@ -396,16 +502,16 @@ public class HybridClassificationSubParametersPanel extends JPanel {
double pcr = (double) jSpinnerPcr.getValue();
// parametre qualite/similitude
double pq = jSliderPqPs.getValue() / 100.0;
double pq = (double) jSpinnerPqPs1.getValue();
double ps = 1.0 - pq;
double constraintsWgt = jSliderConstraints.getValue();
double kExtern = jSliderPePi.getValue() * ((100-constraintsWgt)/100);
double kIntern = (100 - jSliderPePi.getValue()) * ((100-constraintsWgt)/100);
double constraintsWgt = (double) jSpinnerConstraints1.getValue();
double kExtern = ((double) jSpinnerPePi1.getValue()) * (1-constraintsWgt);
double kIntern = (1 - ((double) jSpinnerPePi1.getValue())) * (1-constraintsWgt);
int solutionType = (int) jSpinnerSolutionType.getValue();
double classRatio = (double) jSpinnerClassRatio.getValue();
int criterion = criterionComboBox.getSelectedIndex();
double degradation = ((double) jSliderDegradation.getValue()) / 100;
double degradation = (double) jSpinnerDegradation1.getValue();
int unificationType;
if (unificationbCheckBox.isSelected())
unificationType = SamarahConfig.WITH_UNCLASSIFIED_UNIFICATION;
......
......@@ -138,7 +138,9 @@ public class DataOGRExchange {
feature.SetField("band_"+i, attr.getValue()); //$NON-NLS-1$
} else if (attr instanceof AttributeMultiDimSequence) {
for (int j = 0 ; j < ((AttributeMultiDimSequence) attr).getSequence().length ; j++) {
feature.SetField("band_"+i+"im_"+j, ((AttributeMultiDimSequence) attr).getSequence()[i][j]); //$NON-NLS-1$ //$NON-NLS-2$
for (int k = 0 ; k < ((AttributeMultiDimSequence) attr).getSequence()[j].length ; k++) {
feature.SetField("band_"+i+"im_"+j, ((AttributeMultiDimSequence) attr).getSequence()[j][k]); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
......
......@@ -10,6 +10,7 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
......@@ -32,6 +33,7 @@ import jcl.io.results.CSVResultWriter;
import jcl.learning.methods.monostrategy.kmeans.ParametersKmeans;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.SamarahConfig;
import jcl.learning.methods.multistrategy.samarah.SamarahEval;
import jcl.learning.methods.multistrategy.samarahConstrained.HybridClassificationConstrained2;
import jcl.utils.RandomizeTools;
import jcl.weights.GlobalWeights;
......@@ -41,17 +43,17 @@ import mustic.utils.io.CSVUtils;
public class TestA2CNESIterativeSelectedCst {
public static void main(String[] args) {
HybridClassificationConstrained2 classification = new HybridClassificationConstrained2(null, null);
final HybridClassificationConstrained2 classification = new HybridClassificationConstrained2(null, null);
// HybridClassificationConstrained2 classification = new HybridClassificationConstrained2();
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_iter/";
final int nInf = 54;
final int nSup = 68;
final int[] ag_seeds = {52, 64, 71};
final int nb_iter = 15;
final String datasetName = "FacesUCR";
final String datasetPath = "FacesUCR";
final String dataPath = System.getProperty("user.home")+"/A2CNES/";
final String resultPath = System.getProperty("user.home")+"/A2CNES/results_iter/";
final int nInf = 12;
final int nSup = 17;
final int[] ag_seeds = {16, 20, 24};
final int nb_iter = 15;
File directory = new File("log");
if (!directory.exists()){
......@@ -104,7 +106,7 @@ public class TestA2CNESIterativeSelectedCst {
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(
Paths.get(dataPath+datasetName+"/test/"), "*0.1_*")) {
Iterator<Path> iter = dirStream.iterator();
final String rand = Integer.toString((int) (Math.random()*1000));
final String rand = Integer.toString((int) (Math.random()*100000));
while(iter.hasNext()) {
final Vector<Constraint> constraintsCL = new Vector<Constraint>();
final Vector<Constraint> constraintsML = new Vector<Constraint>();
......@@ -174,7 +176,7 @@ public class TestA2CNESIterativeSelectedCst {
e.printStackTrace();
}
final int subsetSize = (int) Math.ceil(constraintsCL.size() * 0.1);
final int subsetSize = (int) Math.ceil(constraintsCL.size() * 0.05);
System.out.println("subset size : "+ subsetSize);
for(int i = 0 ; i < 1; i++) {
......@@ -191,7 +193,7 @@ public class TestA2CNESIterativeSelectedCst {
}
final String path_to_add = resultPath + datasetName + "/";
classif.setName(ImageHelper.stripExtension(filename)+"-"+i+
classif.setName(rand+"-"+ImageHelper.stripExtension(filename)+"-"+i+
".clustering");
classif.setData(currentData);
......@@ -211,7 +213,7 @@ public class TestA2CNESIterativeSelectedCst {
FileWriter fw = null;
try {
fw = new FileWriter("log/"+rand+"log_cst"+classif.getName()+".log", true);
fw = new FileWriter("log/"+"log_cst"+classif.getName()+".log", true);
} catch (IOException e) {
e.printStackTrace();
}
......@@ -220,13 +222,27 @@ public class TestA2CNESIterativeSelectedCst {
FileWriter fw2 = null;
try {
fw2 = new FileWriter("log/"+rand+"sat_cst"+classif.getName()+".log", true);
fw2 = new FileWriter("log/"+"sat_cst"+classif.getName()+".log", true);
} catch (IOException e) {
e.printStackTrace();
}
BufferedWriter bw2 = new BufferedWriter(fw2);
PrintWriter out2 = new PrintWriter(bw2);
FileWriter fw3 = null;
try {
fw3 = new FileWriter("log/"+"_concordence"+classif.getName()+".log", true);
} catch (IOException e) {
e.printStackTrace();
}
BufferedWriter bw3 = new BufferedWriter(fw3);
PrintWriter out3 = new PrintWriter(bw3);
SamarahEval eval = new SamarahEval(classif, null, classif.getConstraintsUsed());
eval.calGamma(classif.getAgents(), classif.getConfig(), null);
out3.println(Arrays.deepToString(eval.omega));
System.out.println("omega : "+Arrays.deepToString(eval.omega));
for (int i = 0 ; i < 5 ; i++) {
int[] clustMap = classif.getClusteringResult().getClusterMap();
int[] satisifiedMapCL = new int[constraintsCL.size()];
......@@ -250,6 +266,7 @@ public class TestA2CNESIterativeSelectedCst {
Mask satisfactionMaskML = new IntArrayMask(satisifiedMapML, 1, true);
Vector<Constraint> subset = extractConstraintsRandom(constraintsML, subsetSize, satisfactionMaskML);
subset.addAll(subsetCL);
out3.println("------- new iter : "+ (i+1) + " --------");
out.println("------- new iter : "+ (i+1) + " --------");
for (Constraint c : subset) {
if (c instanceof MustLinkConstraint) {
......@@ -277,6 +294,7 @@ public class TestA2CNESIterativeSelectedCst {
}
classif.setAdvancedParameters(degradation, classRatio, solutionType, kIntern,
kExtern, unificationType, criterion, 95);
classif.setName(classif.getName()+"_"+(i+1));
classif.newIteration(subset);
int countSat = 0;
for(Constraint c : subset) {
......@@ -285,9 +303,13 @@ public class TestA2CNESIterativeSelectedCst {
}
}
out2.write(subset.size()+";"+countSat+"\n");
SamarahEval eval_iter = new SamarahEval(classif, null, classif.getConstraintsUsed());
eval_iter.calGamma(classif.getAgents(), classif.getConfig(), null);
out3.println(Arrays.deepToString(eval_iter.omega));
try {
new CSVResultWriter(classif, path_to_add + classif.getName()+"_"+(i+1)).write();
new CSVResultWriter(classif, path_to_add + classif.getName()).write();
} catch (IOException e) {
e.printStackTrace();
}
......@@ -300,6 +322,9 @@ public class TestA2CNESIterativeSelectedCst {
out2.close();
bw2.close();
fw2.close();
out3.close();
bw3.close();
fw3.close();
} catch (IOException e) {
e.printStackTrace();
}
......
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