Commit 3749b1ec authored by lafabregue's avatar lafabregue

Merge branch 'ProgressThread' into 'master'

Progress thread

See merge request !2
parents e283223e 304004c5
......@@ -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.Progressable;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException;
......@@ -32,10 +34,12 @@ import jcl.utils.exceptions.MethodNotImplementedException;
* </p>
*
* @author WEMMERT Cedric
*
* Implementation progressable avec liste de sous-processus progressable à suivre par Jean-Noël Balanche
*/
public abstract class Classification extends Observable implements
Serializable, Cloneable {
Progressable, Serializable, Cloneable {
/** */
private static final long serialVersionUID = 1L;
......@@ -49,7 +53,7 @@ public abstract class Classification extends Observable implements
/** paramtre de la connection ssh si besoin */
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_;
/** titre de la classid pour le tabedpane en hybridclassification */
......@@ -68,7 +72,24 @@ public abstract class Classification extends Observable implements
/** Le nom de la classification */
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>
* Methode utilisee pour le debuggage. Affiche le contenu de la memoire.
......@@ -767,5 +788,113 @@ public abstract class Classification extends Observable implements
* @return the Classification generated
*/
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 {
int CPindex = 2;
ClusteringResult clusteringResult = classification.getClusteringResult();
Iterator<DataObject> iter = clusteringResult.getData().getWholeSourceDataObjects();
// initialization for WG
......@@ -1184,11 +1183,13 @@ public class ClusteringEvaluation {
for (int k = 0; k < clusteringResult.getNbClusters(); k++) {
clustersSE[k] = 0;
}
double step = 100./clusteringResult.getNbObjects();
double progress = classification.getProgress()+step;
for(int n = 0 ; iter.hasNext() ; n++) {
DataObject object = iter.next();
int currentCluster = clusteringResult.getClusterMap(false)[n];
int currentCluster = clusteringResult.getClusterMap(false)[n];
// compute for WG
double distMinWG = Double.MAX_VALUE;
......@@ -1212,7 +1213,12 @@ public class ClusteringEvaluation {
// compute for Square Error
final double distanceSE = clusteringResult.getCluster(currentCluster).distance(currentCluster);
qualities[SEindex] += (distanceSE * distanceSE);
/*
* increments classification's progressable (for the "Displaying" step)
*/
progress+=step;
classification.setProgress((int)progress);
}
// merge result for WG
......
......@@ -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
......
......@@ -7,6 +7,7 @@ import java.util.List;
import jcl.Classification;
import jcl.clustering.ClusteringResult;
import jcl.data.Data;
import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException;
import jcl.utils.exceptions.MethodNotImplementedException;
import jcl.weights.ClassificationWeights;
......@@ -21,7 +22,7 @@ import jcl.weights.ClassificationWeights;
* @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;
......@@ -46,7 +47,20 @@ public abstract class LearningResult extends Object implements Serializable {
/** allow to specify a specific set of colors to all clustering result generated by this model */
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>
* Constructeur a partir d'un ensemble de parametres et de ponderations.
......@@ -204,4 +218,72 @@ public abstract class LearningResult extends Object implements Serializable {
* @return the LearningResult generated
*/
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;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.naming.Context;
......@@ -26,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;
......@@ -322,6 +324,12 @@ public class SingleClassification extends Classification {
@Override
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.sshParameters == null) {
this.rmiClassify();
......@@ -330,16 +338,15 @@ public class SingleClassification extends Classification {
}
} else {
if (this.learningResult == null) {
// System.out.println("debut learn");
this.learn();
// System.out.println("fin learn");
}
this.progressableList.set(1, this.learningResult);// now this.learningResult isn't null anymore so we can add him
this.clusteringResult = this.learningResult
.classify(this.classificationData, false);
this.clusteringResult.setMethode(this.learningMethod.getType());
/*
* si l'utilisateur souhaite une classification hierarchique, il
* faut encore appliquer l'algorithme de classification hierarchique
......@@ -459,7 +466,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);
}
......@@ -610,4 +617,8 @@ public class SingleClassification extends Classification {
return result;
}
}
......@@ -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) {
......@@ -347,7 +347,7 @@ public class LearningResultKmeans extends LearningResult {
this.weights, this.seeds);
}
tabThreads[nbThreads - 1].start();
for (int th = 0; th < nbThreads; th++) {
try {
tabThreads[th].join();
......@@ -899,6 +899,7 @@ public class LearningResultKmeans extends LearningResult {
threadGlobalDistance += distMin;
//((HardSeed) seeds.get(clusterMap[i])).addObject(obj);
incProgress();
i++;
}
// writer.close();
......
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