Commit ac2f7a58 authored by balanche's avatar balanche

Merge branch 'progressbar' into ProgressThread

Merge local to remote
parents e283223e cdf1f2c4
...@@ -4,6 +4,7 @@ import java.awt.Color; ...@@ -4,6 +4,7 @@ import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Observable; import java.util.Observable;
import java.util.Vector; import java.util.Vector;
...@@ -19,6 +20,8 @@ import jcl.jcld.RmiServer; ...@@ -19,6 +20,8 @@ import jcl.jcld.RmiServer;
import jcl.jcld.database.SSHParameters; import jcl.jcld.database.SSHParameters;
import jcl.learning.LearningMethod; import jcl.learning.LearningMethod;
import jcl.learning.methods.ClassifierUtils; import jcl.learning.methods.ClassifierUtils;
import jcl.utils.ProgressMonitor;
import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException; import jcl.utils.exceptions.MethodNotImplementedException;
...@@ -32,10 +35,12 @@ import jcl.utils.exceptions.MethodNotImplementedException; ...@@ -32,10 +35,12 @@ import jcl.utils.exceptions.MethodNotImplementedException;
* </p> * </p>
* *
* @author WEMMERT Cedric * @author WEMMERT Cedric
*
* Implementation progressable avec liste de sous-processus progressable à suivre par Jean-Noël Balanche
*/ */
public abstract class Classification extends Observable implements public abstract class Classification extends Observable implements
Serializable, Cloneable { Progressable, Serializable, Cloneable {
/** */ /** */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -49,7 +54,7 @@ public abstract class Classification extends Observable implements ...@@ -49,7 +54,7 @@ public abstract class Classification extends Observable implements
/** paramtre de la connection ssh si besoin */ /** paramtre de la connection ssh si besoin */
public SSHParameters sshParameters = null; public SSHParameters sshParameters = null;
/** panel ou il faut afficher la non disponibiliter du server rmi */ /** panel ou il faut afficher la non disponibilite du server rmi */
transient public JPanel container_; transient public JPanel container_;
/** titre de la classid pour le tabedpane en hybridclassification */ /** titre de la classid pour le tabedpane en hybridclassification */
...@@ -68,6 +73,23 @@ public abstract class Classification extends Observable implements ...@@ -68,6 +73,23 @@ public abstract class Classification extends Observable implements
/** Le nom de la classification */ /** Le nom de la classification */
private String name = ""; private String name = "";
/**
* Parametre de progression pour l'affichage eventuel d'une barre de
* progression
*/
protected int progress = 0;
/** Valeur maximale de la progression */
protected int progressM = 100;
/** Name of the current step of learning */
protected String statusName = "Loading";
/**
* The list of all the progressable to monitor
*/
protected ArrayList<Progressable> progressableList = new ArrayList<Progressable>();
/** /**
* <p> * <p>
...@@ -768,4 +790,112 @@ public abstract class Classification extends Observable implements ...@@ -768,4 +790,112 @@ public abstract class Classification extends Observable implements
*/ */
public abstract Classification ImportResult(String model, int classifIndex) throws MethodNotImplementedException, JCLFormatException; public abstract Classification ImportResult(String model, int classifIndex) throws MethodNotImplementedException, JCLFormatException;
/**
* <p>
* Fin de la progression.
* </p>
*/
@Override
public void endProgress() {
this.progress = this.progressM;
}
/**
* <p>
* Incrementation du niveau de progression.
* </p>
*/
@Override
public void incProgress() {
this.progress++;
}
/**
* <p>
* Remise e zero du niveau de progression.
* </p>
*/
@Override
public void resetProgress() {
this.progress = 0;
}
@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 ... ";
boolean allEnded = true; //boolean for the stop condition
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()+1) + " : " + this.progressableList.get(i).getStatus();
allEnded = false;
}
}
}
}
if(allEnded) {//return the usual value (this.status) when all progressables are done (to monitor the final step which is displaying the result)
status = this.statusName;
}
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) {//return the usual value (this.progress) when all progressables are done (to monitor the final step which is displaying the result)
progress = this.progress;
//System.out.println("all progressable ended");
}
return progress;
}
/**
* Add a progressable to monitor
* @param p the progressable to add
*/
public void addProgressable(Progressable p) {
this.progressableList.add(p);
}
/**
* Get the list of all the progressables to monitor in this classification
* @return the progressable list
*/
public ArrayList<Progressable> getProgressableList(){
return this.progressableList;
}
} }
...@@ -1170,7 +1170,6 @@ public class ClusteringEvaluation { ...@@ -1170,7 +1170,6 @@ public class ClusteringEvaluation {
int CPindex = 2; int CPindex = 2;
ClusteringResult clusteringResult = classification.getClusteringResult(); ClusteringResult clusteringResult = classification.getClusteringResult();
Iterator<DataObject> iter = clusteringResult.getData().getWholeSourceDataObjects(); Iterator<DataObject> iter = clusteringResult.getData().getWholeSourceDataObjects();
// initialization for WG // initialization for WG
...@@ -1185,11 +1184,13 @@ public class ClusteringEvaluation { ...@@ -1185,11 +1184,13 @@ public class ClusteringEvaluation {
clustersSE[k] = 0; clustersSE[k] = 0;
} }
double step = 100./clusteringResult.getNbObjects();
double progress = classification.getProgress()+step;
for(int n = 0 ; iter.hasNext() ; n++) { for(int n = 0 ; iter.hasNext() ; n++) {
DataObject object = iter.next(); DataObject object = iter.next();
int currentCluster = clusteringResult.getClusterMap(false)[n]; int currentCluster = clusteringResult.getClusterMap(false)[n];
// compute for WG // compute for WG
double distMinWG = Double.MAX_VALUE; double distMinWG = Double.MAX_VALUE;
for (int i = 0; i < clusteringResult.getNbClusters(); i++) { for (int i = 0; i < clusteringResult.getNbClusters(); i++) {
...@@ -1212,6 +1213,11 @@ public class ClusteringEvaluation { ...@@ -1212,6 +1213,11 @@ public class ClusteringEvaluation {
// compute for Square Error // compute for Square Error
final double distanceSE = clusteringResult.getCluster(currentCluster).distance(currentCluster); final double distanceSE = clusteringResult.getCluster(currentCluster).distance(currentCluster);
qualities[SEindex] += (distanceSE * distanceSE); qualities[SEindex] += (distanceSE * distanceSE);
/*
* increments classification's progressable (for the "Displaying" step)
*/
progress+=step;
classification.setProgress((int)progress);
} }
......
...@@ -365,7 +365,7 @@ public abstract class LearningMethod implements Progressable, Cloneable, ...@@ -365,7 +365,7 @@ public abstract class LearningMethod implements Progressable, Cloneable,
*/ */
@Override @Override
public void setProgress(final int value) { public void setProgress(final int value) {
this.progressM = value; this.progress = value;
} }
@Override @Override
......
...@@ -7,6 +7,7 @@ import java.util.List; ...@@ -7,6 +7,7 @@ import java.util.List;
import jcl.Classification; import jcl.Classification;
import jcl.clustering.ClusteringResult; import jcl.clustering.ClusteringResult;
import jcl.data.Data; import jcl.data.Data;
import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException; import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights; import jcl.weights.ClassificationWeights;
...@@ -21,7 +22,7 @@ import jcl.weights.ClassificationWeights; ...@@ -21,7 +22,7 @@ import jcl.weights.ClassificationWeights;
* @author WEMMERT Cedric * @author WEMMERT Cedric
*/ */
public abstract class LearningResult extends Object implements Serializable { public abstract class LearningResult extends Object implements Progressable,Serializable {
/** */ /** */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -47,6 +48,19 @@ public abstract class LearningResult extends Object implements Serializable { ...@@ -47,6 +48,19 @@ public abstract class LearningResult extends Object implements Serializable {
/** allow to specify a specific set of colors to all clustering result generated by this model */ /** allow to specify a specific set of colors to all clustering result generated by this model */
protected List<Color> colors = null; protected List<Color> colors = null;
/**
* Parametre de progression pour l'affichage eventuel d'une barre de
* progression
*/
protected int progress = 0;
/** Valeur maximale de la progression */
protected int progressM = 100;
/** Name of the current step of learning */
private String statusName = "Classifying";
/** /**
* <p> * <p>
* Constructeur a partir d'un ensemble de parametres et de ponderations. * Constructeur a partir d'un ensemble de parametres et de ponderations.
...@@ -204,4 +218,72 @@ public abstract class LearningResult extends Object implements Serializable { ...@@ -204,4 +218,72 @@ public abstract class LearningResult extends Object implements Serializable {
* @return the LearningResult generated * @return the LearningResult generated
*/ */
protected abstract LearningResult ImportResult(String model) throws MethodNotImplementedException, JCLFormatException; protected abstract LearningResult ImportResult(String model) throws MethodNotImplementedException, JCLFormatException;
/**
* <p>
* Fin de la progression.
* </p>
*/
@Override
public void endProgress() {
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.
* </p>
*/
@Override
public void incProgress() {
this.progress++;
}
/**
* <p>
* Remise e zero du niveau de progression.
* </p>
*/
@Override
public void resetProgress() {
this.progress = 0;
}
/**
* <p>
* Modification du niveau de progression des calculs.
* </p>
*
* @param value
* la nouvelle valeur du compteur de progression
*/
@Override
public void setProgress(final int value) {
this.progress = value;
}
@Override
public void setStatus(String status)
{
statusName = status;
}
@Override
public String getStatus()
{
return statusName;
}
} }
...@@ -7,6 +7,7 @@ import java.io.IOException; ...@@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Vector; import java.util.Vector;
import javax.naming.Context; import javax.naming.Context;
...@@ -26,6 +27,7 @@ import jcl.learning.methods.ClassifierUtils; ...@@ -26,6 +27,7 @@ import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.monostrategy.ahc.LearningResultAHC; import jcl.learning.methods.monostrategy.ahc.LearningResultAHC;
import jcl.learning.methods.monostrategy.ahc.ParametersAHC; import jcl.learning.methods.monostrategy.ahc.ParametersAHC;
import jcl.learning.methods.monostrategy.kmeans.LearningResultKmeans; import jcl.learning.methods.monostrategy.kmeans.LearningResultKmeans;
import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException; import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights; import jcl.weights.ClassificationWeights;
...@@ -322,6 +324,12 @@ public class SingleClassification extends Classification { ...@@ -322,6 +324,12 @@ public class SingleClassification extends Classification {
@Override @Override
public void classify() { public void classify() {
/*
* Add all the processes to monitor in the list (they have to implement progressable)
*/
this.addProgressable(this.learningMethod);
this.addProgressable(null);// had null because this.learningResult is not defined yet
if (this.useRmi() && !this.isMaclaw()) { if (this.useRmi() && !this.isMaclaw()) {
if (this.sshParameters == null) { if (this.sshParameters == null) {
this.rmiClassify(); this.rmiClassify();
...@@ -330,16 +338,19 @@ public class SingleClassification extends Classification { ...@@ -330,16 +338,19 @@ public class SingleClassification extends Classification {
} }
} else { } else {
if (this.learningResult == null) { if (this.learningResult == null) {
// System.out.println("debut learn"); // System.out.println("debut learn "+new Date().toString());
this.learn(); this.learn();
// System.out.println("fin learn"); // System.out.println("fin learn "+new Date().toString());
} }
this.progressableList.set(1, this.learningResult);// now this.learningResult isn't null anymore so we can add him
// System.out.println("debut classify "+new Date().toString());
this.clusteringResult = this.learningResult this.clusteringResult = this.learningResult
.classify(this.classificationData, false); .classify(this.classificationData, false);
// System.out.println("fin classify "+new Date().toString());
this.clusteringResult.setMethode(this.learningMethod.getType()); this.clusteringResult.setMethode(this.learningMethod.getType());
/* /*
* si l'utilisateur souhaite une classification hierarchique, il * si l'utilisateur souhaite une classification hierarchique, il
* faut encore appliquer l'algorithme de classification hierarchique * faut encore appliquer l'algorithme de classification hierarchique
...@@ -459,7 +470,7 @@ public class SingleClassification extends Classification { ...@@ -459,7 +470,7 @@ public class SingleClassification extends Classification {
this.learningMethod.sshparameters = this.sshParameters; this.learningMethod.sshparameters = this.sshParameters;
this.learningMethod.container_ = this.container_; 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 this.learningResult = this.learningMethod
.learn(this.classificationData); .learn(this.classificationData);
} }
...@@ -610,4 +621,8 @@ public class SingleClassification extends Classification { ...@@ -610,4 +621,8 @@ public class SingleClassification extends Classification {
return result; return result;
} }
} }
...@@ -281,6 +281,7 @@ public class ClassifierKmeans extends LearningMethod { ...@@ -281,6 +281,7 @@ public class ClassifierKmeans extends LearningMethod {
@Override @Override
public LearningResult learn(Data data) { public LearningResult learn(Data data) {
this.progressM = this.getNbIters(); this.progressM = this.getNbIters();
LearningResultKmeans result = new LearningResultKmeans(data, (ParametersKmeans) this.parameters, this.samples); LearningResultKmeans result = new LearningResultKmeans(data, (ParametersKmeans) this.parameters, this.samples);
this.initViewers(result); this.initViewers(result);
......
...@@ -139,7 +139,6 @@ public class LearningResultKmeans extends LearningResult { ...@@ -139,7 +139,6 @@ public class LearningResultKmeans extends LearningResult {
@Override @Override
public ClusteringResult classify(Data data, boolean fromSample) { public ClusteringResult classify(Data data, boolean fromSample) {
for (int i = 0 ; i < this.seeds.size() ; i++) { for (int i = 0 ; i < this.seeds.size() ; i++) {
if (this.seeds.get(i) instanceof LightHardSeed) { if (this.seeds.get(i) instanceof LightHardSeed) {
((LightHardSeed) this.seeds.get(i)).setId(i); ((LightHardSeed) this.seeds.get(i)).setId(i);
...@@ -147,10 +146,9 @@ public class LearningResultKmeans extends LearningResult { ...@@ -147,10 +146,9 @@ public class LearningResultKmeans extends LearningResult {
} }
// long startT = System.nanoTime(); // long startT = System.nanoTime();
// System.out.println("start at "+startT); // System.out.println("start at "+startT);
int clusterMap[] = this.clusterAffectation(data,fromSample); int clusterMap[] = this.clusterAffectation(data,fromSample);// !!!
// long endT = System.nanoTime(); // long endT = System.nanoTime();
// System.out.println("endat "+ endT + " total of "+ (endT - startT)/1000000000l); // System.out.println("endat "+ endT + " total of "+ (endT - startT)/1000000000l);
ClusteringResult result = null; ClusteringResult result = null;
if (((ParametersKmeans) this.params).fuzzy) { if (((ParametersKmeans) this.params).fuzzy) {
...@@ -163,7 +161,6 @@ public class LearningResultKmeans extends LearningResult { ...@@ -163,7 +161,6 @@ public class LearningResultKmeans extends LearningResult {
result = ClusteringResult.gerenerateDefaultClusteringResult(this, clusterMap, null, this.weights, result = ClusteringResult.gerenerateDefaultClusteringResult(this, clusterMap, null, this.weights,
this.seeds.size(), null, data, this.qualityIndices, getColors()); this.seeds.size(), null, data, this.qualityIndices, getColors());
} }
return result; return result;
} }
...@@ -257,8 +254,11 @@ public class LearningResultKmeans extends LearningResult { ...@@ -257,8 +254,11 @@ public class LearningResultKmeans extends LearningResult {
} else { } else {
nbObjects = data.getWholeDataNbObjects(); nbObjects = data.getWholeDataNbObjects();
} }
int clusterMap[] = new int[nbObjects];
this.progressM=nbObjects;
this.resetProgress();
int clusterMap[] = new int[nbObjects];
int nbThreads = ((ParametersKmeans) this.params).nbThreads; int nbThreads = ((ParametersKmeans) this.params).nbThreads;
nbThreads = 1; nbThreads = 1;
if (((ParametersKmeans) this.params).fuzzy) { if (((ParametersKmeans) this.params).fuzzy) {
...@@ -899,6 +899,7 @@ public class LearningResultKmeans extends LearningResult { ...@@ -899,6 +899,7 @@ public class LearningResultKmeans extends LearningResult {
threadGlobalDistance += distMin; threadGlobalDistance += distMin;
//((HardSeed) seeds.get(clusterMap[i])).addObject(obj); //((HardSeed) seeds.get(clusterMap[i])).addObject(obj);
incProgress();
i++; i++;
} }
// writer.close(); // 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