Commit 30427990 authored by balanche's avatar balanche

Progress bars de classification terminées

parent 8cfbc6cf
......@@ -4,6 +4,7 @@ import java.awt.Color;
import java.io.IOException;
import java.io.Serializable;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Observable;
import java.util.Vector;
......@@ -19,6 +20,7 @@ import jcl.jcld.RmiServer;
import jcl.jcld.database.SSHParameters;
import jcl.learning.LearningMethod;
import jcl.learning.methods.ClassifierUtils;
import jcl.utils.ProgressMonitor;
import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException;
......@@ -79,9 +81,12 @@ public abstract class Classification extends Observable implements
protected int progressM = 100;
/** Name of the current step of learning */
private String statusName = "Classifying";
protected String statusName = "Loading";
/**
* The list of all the progressable to monitor
*/
protected ArrayList<Progressable> progressableList = new ArrayList<Progressable>();
/**
......@@ -793,18 +798,6 @@ public abstract class Classification extends Observable implements
this.progress = this.progressM;
}
/**
* <p>
* Accesseur au niveau de progression des calculs.
* </p>
*
* @return le compteur de progression
*/
@Override
public int getProgress() {
return (int) (((double) this.progress / (double) this.progressM) * 100.0);
}
/**
* <p>
* Incrementation du niveau de progression.
......@@ -824,30 +817,14 @@ public abstract class Classification extends Observable implements
public void resetProgress() {
this.progress = 0;
}
/**
* <p>
* Modification du niveau de progression des calculs.
* </p>
*
* @param value
* la nouvelle valeur du compteur de progression
* Add a progressable to monitor
* @param p the progressable to add
*/
@Override
public void setProgress(final int value) {
this.progressM = value;
public void addProgressable(Progressable p) {
this.progressableList.add(p);
}
@Override
public void setStatus(String status)
{
statusName = status;
}
@Override
public String getStatus()
{
return statusName;
}
}
......@@ -365,7 +365,7 @@ public abstract class LearningMethod implements Progressable, Cloneable,
*/
@Override
public void setProgress(final int value) {
this.progressM = value;
this.progress = value;
}
@Override
......
......@@ -271,7 +271,7 @@ public abstract class LearningResult extends Object implements Progressable,Seri
*/
@Override
public void setProgress(final int value) {
this.progressM = value;
this.progress = value;
}
@Override
......
......@@ -27,6 +27,7 @@ import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
import jcl.learning.methods.monostrategy.kmeans.LearningResultKmeans;
import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
......@@ -323,6 +324,10 @@ public class SingleClassification extends Classification {
@Override
public void classify() {
/* Add all the process to monitor in the list (they have to implement progressable) */
this.addProgressable(this.learningMethod);
this.addProgressable(this.learningResult);
if (this.useRmi() && !this.isMaclaw()) {
if (this.sshParameters == null) {
this.rmiClassify();
......@@ -331,15 +336,18 @@ public class SingleClassification extends Classification {
}
} else {
if (this.learningResult == null) {
System.out.println("debut learn"+new Date().toString());
System.out.println("debut learn "+new Date().toString());
this.learn();
System.out.println("fin learn"+new Date().toString());
System.out.println("fin learn "+new Date().toString());
}
this.progressableList.set(1, this.learningResult);// ne se met pas à jour ??
//SEPARATION ICI ?
System.out.println("debut classify"+new Date().toString());
System.out.println("debut classify "+new Date().toString());
this.clusteringResult = this.learningResult
.classify(this.classificationData, false);
System.out.println("fin classify"+new Date().toString());
System.out.println("fin classify "+new Date().toString());
this.clusteringResult.setMethode(this.learningMethod.getType());
/*
......@@ -461,7 +469,7 @@ public class SingleClassification extends Classification {
this.learningMethod.sshparameters = this.sshParameters;
this.learningMethod.container_ = this.container_;
}
// System.out.println(this.learningMethod.getName()+" starts to learn");
System.out.println(this.learningMethod.getName()+" starts to learn");
this.learningResult = this.learningMethod
.learn(this.classificationData);
}
......@@ -612,4 +620,53 @@ public class SingleClassification extends Classification {
return result;
}
@Override
public void setProgress(final int value) {
this.progress = value;
}
@Override
public void setStatus(String status)
{
this.statusName = status;
}
@Override
public String getStatus()
{
String status = "Preparing ... ";
if(!this.progressableList.isEmpty()) {
for (int i = 0 ; i < this.progressableList.size(); i++) {
if (this.progressableList.get(i) != null) {
if (this.progressableList.get(i).getProgress() != 100)
status = "Step "+ (i+1) + "/" + this.progressableList.size() + " : " + this.progressableList.get(i).getStatus();
}
}
}
return status;
}
@Override
public int getProgress() {
int progress = 0;
boolean allEnded = true; //boolean for the stop condition
if(!this.progressableList.isEmpty()) {
for (Progressable p : this.progressableList) {
if(p!=null) {
if (p.getProgress() != 100) {
progress=p.getProgress();
allEnded=false;
}
}
}
}
if(allEnded) {//returns 100 to stop the ProgressThread if all progressables are at 100%
progress = 100;
System.out.println("allEnded");
}
return progress;
}
}
......@@ -281,6 +281,7 @@ public class ClassifierKmeans extends LearningMethod {
@Override
public LearningResult learn(Data data) {
this.progressM = this.getNbIters();
LearningResultKmeans result = new LearningResultKmeans(data, (ParametersKmeans) this.parameters, this.samples);
this.initViewers(result);
......
......@@ -139,7 +139,6 @@ public class LearningResultKmeans extends LearningResult {
@Override
public ClusteringResult classify(Data data, boolean fromSample) {
for (int i = 0 ; i < this.seeds.size() ; i++) {
if (this.seeds.get(i) instanceof LightHardSeed) {
((LightHardSeed) this.seeds.get(i)).setId(i);
......@@ -147,10 +146,9 @@ public class LearningResultKmeans extends LearningResult {
}
long startT = System.nanoTime();
System.out.println("start at "+startT);
int clusterMap[] = this.clusterAffectation(data,fromSample);
int clusterMap[] = this.clusterAffectation(data,fromSample);// !!!
long endT = System.nanoTime();
System.out.println("endat "+ endT + " total of "+ (endT - startT)/1000000000l);
ClusteringResult result = null;
if (((ParametersKmeans) this.params).fuzzy) {
......@@ -163,7 +161,6 @@ public class LearningResultKmeans extends LearningResult {
result = ClusteringResult.gerenerateDefaultClusteringResult(this, clusterMap, null, this.weights,
this.seeds.size(), null, data, this.qualityIndices, getColors());
}
return result;
}
......@@ -257,8 +254,11 @@ public class LearningResultKmeans extends LearningResult {
} else {
nbObjects = data.getWholeDataNbObjects();
}
int clusterMap[] = new int[nbObjects];
this.progressM=nbObjects;
this.resetProgress();
int clusterMap[] = new int[nbObjects];
int nbThreads = ((ParametersKmeans) this.params).nbThreads;
nbThreads = 1;
if (((ParametersKmeans) this.params).fuzzy) {
......@@ -899,6 +899,7 @@ public class LearningResultKmeans extends LearningResult {
threadGlobalDistance += distMin;
//((HardSeed) seeds.get(clusterMap[i])).addObject(obj);
incProgress();
i++;
}
// writer.close();
......
package jcl.utils;
/**
* ??
* @author Jean-Noël Balanche
*
*/
public interface ProgressMonitor {
/**
* ??
* @param id ??
*/
public void incProgress(int id);
/**
* <p>
* Methode de decrementation de l'indice de progression.
* </p>
*
*/
public void endMonitorProgress();
/**
* <p>
* Methode d'acces au pourcentage en cours de la progression.
* </p>
*
* @return le pourcentage (entre 0 et 100) de la progression
*/
public int getMonitorProgress();
/**
* <p>
* Methode d'incrementation de l'indice de progression.
* </p>
*/
public void incMonitorProgress();
/**
* <p>
* Methode de remise a zero de l'indice de progression.
* </p>
*/
public void resetMonitorProgress();
/**
* <p>
* Methode de modification du pourcentage de progression.
* </p>
*
* @param value
* la nouvelle valeur
*/
public void setMonitorProgress(int value);
/**
* <p>
* Methode de modification du status.
* </p>
*
* @param status
*/
public void setMonitorStatus(String status);
/**
* <p>
* Methode d'acces au status.
* </p>
*
* @param status
*/
public String getMonitorStatus();
}
\ No newline at end of file
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