Commit 075821b4 authored by lafabregue's avatar lafabregue

minor modifications

parent d3c6c659
...@@ -41,24 +41,22 @@ public class TestA2CNES { ...@@ -41,24 +41,22 @@ public class TestA2CNES {
public static void main(String[] args) { public static void main(String[] args) {
HybridClassification classification = new HybridClassification(null, null); HybridClassification classification = new HybridClassification(null, null);
final String datasetName = "foret"; final String datasetName = "NDVI_cuts";
final String datasetPath = "foret"; final String datasetPath = "NDVI_cuts";
final String dataPath = System.getProperty("user.home")+"/A2CNES/"; final String dataPath = System.getProperty("user.home")+"/A2CNES/";
final String resultPath = System.getProperty("user.home")+"/A2CNES/results/"; final String resultPath = System.getProperty("user.home")+"/A2CNES/results/";
final int nInf = 22; final int nInf = 10;
final int nSup = 25; final int nSup = 14;
final int[] ag_seeds = {20,25,30}; final int[] ag_seeds = {9,12,15};
final int nb_iter = 25; final int nb_iter = 25;
double constraintsWgt = 90; double constraintsWgt = 80;
Data dataTest = getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null, 1);
File directory = new File("log"); File directory = new File("log");
if (!directory.exists()){ if (!directory.exists()){
directory.mkdir(); directory.mkdir();
} }
Data dataTest = getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null);
final DateTime startTime = DateTime.now(); final DateTime startTime = DateTime.now();
...@@ -69,7 +67,7 @@ public class TestA2CNES { ...@@ -69,7 +67,7 @@ public class TestA2CNES {
double pcr = 0.2; double pcr = 0.2;
// parametre qualite/similitude // parametre qualite/similitude
double ps = 0.2; double ps = 0.3;
double pq = 1.0 - ps; double pq = 1.0 - ps;
double valueKExtern = 60; double valueKExtern = 60;
double kExtern = valueKExtern * ((100-constraintsWgt)/100); double kExtern = valueKExtern * ((100-constraintsWgt)/100);
...@@ -96,36 +94,37 @@ public class TestA2CNES { ...@@ -96,36 +94,37 @@ public class TestA2CNES {
final Vector<Thread> threadList = new Vector<Thread>(); final Vector<Thread> threadList = new Vector<Thread>();
// <<<< START FOR PARAM config // <<<< START FOR PARAM config
// for (int i = 0 ; i < 20 ; i++) { for (int i = 0 ; i < 10 ; i++) {
// final HybridClassification classif = (HybridClassification) classification.clone(); final HybridClassification classif = (HybridClassification) classification.clone();
// Data currentData = (Data) dataTest.clone(); Data currentData = (Data) dataTest.clone();
// final String path_to_add = resultPath + datasetName + "/"; final String path_to_add = resultPath + datasetName + "/";
// classif.setName(datasetName+"_unconstrained"+"-"+i+ classif.setName(datasetName+"_unconstrained"+"-"+i+
// ".clustering"); ".clustering");
// classif.setData(currentData); classif.setData(currentData);
//
// for (int a : ag_seeds) { for (int a : ag_seeds) {
// classif.addAgent(new ParametersKmeans(a, nb_iter, weights), currentData); classif.addAgent(new ParametersKmeans(a, nb_iter, distanceModel,
// } distanceParameters, averageParameters), currentData);
// }
//// >>>> REPLACE PARAM
// Thread t = new Thread() { // >>>> REPLACE PARAM
// @Override Thread t = new Thread() {
// public void run() { @Override
// classif.classify(); public void run() {
// System.out.println(classif.getName()); classif.classify();
// try { System.out.println(classif.getName());
// new CSVResultWriter(classif, path_to_add + classif.getName()).write(); try {
// } catch (IOException e) { new CSVResultWriter(classif, path_to_add + classif.getName()).write();
// e.printStackTrace(); } catch (IOException e) {
// } e.printStackTrace();
// } }
// }; }
// t.start(); };
// t.start();
// threadList.add(t);
// } threadList.add(t);
// <<<< CONSTRAINTS }
//// <<<< CONSTRAINTS
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream( try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(
Paths.get(dataPath+datasetName+"/test/"), "*.constraints")) { Paths.get(dataPath+datasetName+"/test/"), "*.constraints")) {
Iterator<Path> iter = dirStream.iterator(); Iterator<Path> iter = dirStream.iterator();
...@@ -220,7 +219,7 @@ public class TestA2CNES { ...@@ -220,7 +219,7 @@ public class TestA2CNES {
ClassificationFrame.getInstance().dispose(); ClassificationFrame.getInstance().dispose();
} }
public static Data getDataFromFile(String path, char separator, String name, String mask) { public static Data getDataFromFile(String path, char separator, String name, String mask, int nbFeatures) {
Data data = null; Data data = null;
// we create the two data session // we create the two data session
...@@ -242,7 +241,7 @@ public class TestA2CNES { ...@@ -242,7 +241,7 @@ public class TestA2CNES {
if (mask != null) { if (mask != null) {
maskLine = maskReader.readNext(); maskLine = maskReader.readNext();
} }
extractObjectFromLine(result, line, 3, maskLine); extractObjectFromLine(result, line, nbFeatures, maskLine);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -276,18 +275,24 @@ public class TestA2CNES { ...@@ -276,18 +275,24 @@ public class TestA2CNES {
*/ */
public static void extractObjectFromLine(List<DataObject> list, List<String> line, int featureNb, List<String> maskLine) { public static void extractObjectFromLine(List<DataObject> list, List<String> line, int featureNb, List<String> maskLine) {
DataObject obj = new DataObject(1); DataObject obj = new DataObject(1);
double[][] seq = new double[line.size()/featureNb][]; ArrayList<double[]> seq = new ArrayList<double[]>();
for (int i = 0 ; i < line.size()/featureNb ; i++) { for (int i = 0 ; i < line.size()/featureNb ; i++) {
if (maskLine != null) { if (maskLine != null) {
if(Integer.parseInt(maskLine.get(i)) == 0) if(Integer.parseInt(maskLine.get(i)) == 0)
continue; continue;
} }
seq[i] = new double[featureNb]; if (!line.get(i*featureNb).equalsIgnoreCase("NaN")) {
for (int j = 0 ; j < featureNb ; j++) { seq.add(new double[featureNb]);
seq[i][j] = Double.parseDouble(line.get(i*featureNb + j)); for (int j = 0 ; j < featureNb ; j++) {
seq.get(i)[j] = Double.parseDouble(line.get(i*featureNb + j));
}
} }
} }
obj.setAttribute(0, new AttributeMultiDimSequence(seq)); double[][] array = new double[seq.size()][featureNb];
for (int i = 0 ; i < seq.size() ; i++) {
array[i] = seq.get(i);
}
obj.setAttribute(0, new AttributeMultiDimSequence(array));
list.add(obj); list.add(obj);
} }
......
...@@ -50,6 +50,8 @@ public class TestA2CNESIterative { ...@@ -50,6 +50,8 @@ public class TestA2CNESIterative {
final int nSup = 17; final int nSup = 17;
final int[] ag_seeds = {16, 20, 24}; final int[] ag_seeds = {16, 20, 24};
final int nb_iter = 15; final int nb_iter = 15;
final Data dataTest = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data",
'\t', "test", null, 1);
File directory = new File("log"); File directory = new File("log");
if (!directory.exists()){ if (!directory.exists()){
...@@ -59,7 +61,6 @@ public class TestA2CNESIterative { ...@@ -59,7 +61,6 @@ public class TestA2CNESIterative {
// String testResultPath = System.getProperty("user.home")+"/A2CNES/Train_results/"; // String testResultPath = System.getProperty("user.home")+"/A2CNES/Train_results/";
// Data dataTrain = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/train/"+datasetName+".data", '\t', "train", null); // Data dataTrain = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/train/"+datasetName+".data", '\t', "train", null);
final Data dataTest = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null);
final DateTime startTime = DateTime.now(); final DateTime startTime = DateTime.now();
......
...@@ -54,6 +54,8 @@ public class TestA2CNESIterativeSelectedCst { ...@@ -54,6 +54,8 @@ public class TestA2CNESIterativeSelectedCst {
final int nSup = 17; final int nSup = 17;
final int[] ag_seeds = {16, 20, 24}; final int[] ag_seeds = {16, 20, 24};
final int nb_iter = 15; final int nb_iter = 15;
final Data dataTest = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data",
'\t', "test", null, 1);
File directory = new File("log"); File directory = new File("log");
if (!directory.exists()){ if (!directory.exists()){
...@@ -63,7 +65,6 @@ public class TestA2CNESIterativeSelectedCst { ...@@ -63,7 +65,6 @@ public class TestA2CNESIterativeSelectedCst {
// String testResultPath = System.getProperty("user.home")+"/A2CNES/Train_results/"; // String testResultPath = System.getProperty("user.home")+"/A2CNES/Train_results/";
// Data dataTrain = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/train/"+datasetName+".data", '\t', "train", null); // Data dataTrain = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/train/"+datasetName+".data", '\t', "train", null);
final Data dataTest = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/test/"+datasetName+".data", '\t', "test", null);
final DateTime startTime = DateTime.now(); final DateTime startTime = DateTime.now();
......
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