Commit 226b3694 authored by lafabregue's avatar lafabregue

small interface modifications and fixes

parent 5784c615
Pipeline #1829 failed with stages
in 41 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -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";
......
......@@ -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