Commit 075821b4 authored by lafabregue's avatar lafabregue

minor modifications

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