Commit b230db4b authored by lafabregue's avatar lafabregue

change test files

parent 274045dd
...@@ -7,6 +7,7 @@ import java.util.Vector; ...@@ -7,6 +7,7 @@ import java.util.Vector;
import jcl.Classification; import jcl.Classification;
import jcl.clustering.constraints.Constraint; import jcl.clustering.constraints.Constraint;
import jcl.learning.methods.ClassifierUtils; import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.LearningAgent; import jcl.learning.methods.multistrategy.samarah.LearningAgent;
import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.JCLFormatException;
import multiCube.tools.util.exceptions.MethodNotImplementedException; import multiCube.tools.util.exceptions.MethodNotImplementedException;
...@@ -18,7 +19,7 @@ import multiCube.tools.util.exceptions.MethodNotImplementedException; ...@@ -18,7 +19,7 @@ import multiCube.tools.util.exceptions.MethodNotImplementedException;
* @author WEMMERT Cedric * @author WEMMERT Cedric
*/ */
public class HybridClassification extends jcl.learning.methods.multistrategy.samarah.HybridClassification { public class HybridClassificationConstrained extends jcl.learning.methods.multistrategy.samarah.HybridClassification {
/** */ /** */
...@@ -29,7 +30,7 @@ public class HybridClassification extends jcl.learning.methods.multistrategy.sam ...@@ -29,7 +30,7 @@ public class HybridClassification extends jcl.learning.methods.multistrategy.sam
* Constructeur vide. * Constructeur vide.
* </p> * </p>
*/ */
public HybridClassification() { public HybridClassificationConstrained() {
super(); super();
} }
...@@ -38,14 +39,14 @@ public class HybridClassification extends jcl.learning.methods.multistrategy.sam ...@@ -38,14 +39,14 @@ public class HybridClassification extends jcl.learning.methods.multistrategy.sam
* *
* @param hybridClassif * @param hybridClassif
*/ */
protected HybridClassification(final HybridClassification hybridClassif) { protected HybridClassificationConstrained(final HybridClassificationConstrained hybridClassif) {
super(hybridClassif); super(hybridClassif);
} }
@Override @Override
public Classification ImportResult(String model, int classifIndex) public Classification ImportResult(String model, int classifIndex)
throws MethodNotImplementedException, JCLFormatException { throws MethodNotImplementedException, JCLFormatException {
HybridClassification classification = new HybridClassification(); HybridClassificationConstrained classification = new HybridClassificationConstrained();
return exportHybridClassification(model, classification); return exportHybridClassification(model, classification);
} }
...@@ -261,6 +262,6 @@ public class HybridClassification extends jcl.learning.methods.multistrategy.sam ...@@ -261,6 +262,6 @@ public class HybridClassification extends jcl.learning.methods.multistrategy.sam
@Override @Override
public Object clone() { public Object clone() {
return new HybridClassification(this); return new HybridClassificationConstrained(this);
} }
} }
package jcl.learning.methods.multistrategy.samarahConstrained;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Vector;
import jcl.Classification;
import jcl.clustering.constraints.Constraint;
import jcl.learning.methods.ClassifierUtils;
import jcl.learning.methods.multistrategy.samarah.HybridClassification;
import jcl.learning.methods.multistrategy.samarah.LearningAgent;
import jcl.utils.exceptions.JCLFormatException;
import multiCube.tools.util.exceptions.MethodNotImplementedException;
/**
* <p>
* Classe implantant le concept de classification hybride.
* </p>
* @author WEMMERT Cedric
*/
public class HybridClassificationConstrained2 extends jcl.learning.methods.multistrategy.samarah.HybridClassification {
/** */
private static final long serialVersionUID = -4587580305809652597L;
/**
* <p>
* Constructeur vide.
* </p>
*/
public HybridClassificationConstrained2() {
super();
}
/**
* Copy constructor
*
* @param hybridClassif
*/
protected HybridClassificationConstrained2(final HybridClassificationConstrained2 hybridClassif) {
super(hybridClassif);
}
@Override
public Classification ImportResult(String model, int classifIndex)
throws MethodNotImplementedException, JCLFormatException {
HybridClassificationConstrained2 classification = new HybridClassificationConstrained2();
return exportHybridClassification(model, classification);
}
@Override
public void newIteration(Vector<Constraint> constraints) {
// vrai si phase descendante de gamma
boolean lost = true;
// nombre de tours constant mais pas en phase descendante
int const_tours = 0;
// nombre de tours constant en phase descendante
int const_bad = 0;
// nombre de tours en phase desendante
this.bad_tours = 0;
// gamma à tour - 1
double gammaOld = 0.0;
this.constraintsUsed = constraints;
this.pourcent();
// condition d'arret
this.stop = false;
for (LearningAgent a : this.agents) {
a.getClassification().setClusteringResult(a.getClassification()
.getLearningResult().classify(a.getData(), false));
}
this.eval(constraints);
this.evalMax = this.eval;
this.clusteringResultInitial = this.unification(false);
this.setChanged();
this.notifyObservers(HybridClassification.START);
// evaluation de la solution courante
this.bad_tours = 0;
const_bad = 0;
const_tours = 0;
this.setClusteringResult(this.unification(true));
int lastCstIndex = 0;
double cstPerAgent = Math.ceil((double) constraints.size()/ (double) this.agents.size());
final Vector<LearningAgent> clone = new Vector<LearningAgent>();
for (LearningAgent a : this.agents) {
LearningAgent c = (LearningAgent) a.clone();
c.getClassification().setClusteringResult(c.getClassification()
.getLearningResult().classify(c.getData(), true));
// we dispatch constraints through all agents
Vector<Constraint> tmpSet = new Vector<Constraint>();
for (int i = 0 ; i < cstPerAgent ; i++) {
if (lastCstIndex < constraints.size() && i < 3) {
tmpSet.add(constraints.get(lastCstIndex));
}
lastCstIndex++;
}
try {
c.injectConstraints(constraints);
} catch (MethodNotImplementedException e) {
e.printStackTrace();
}
clone.add((LearningAgent) c.clone());
}
this.agents = clone;
this.agentsMax = clone;
this.eval(constraints);
this.evalMax = this.eval;
this.gammaMax = this.eval.GAMMA;
this.setChanged();
this.notifyObservers(HybridClassification.VIEW_AGENTS);
this.conflictsLeft = -1;
//<< start test
try {
PrintWriter writer = new PrintWriter("log/log_samarah"+this.getName()+".log");
writer.print("");
writer.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//>> end test
// lancement du calcul
while (!this.stop) {
this.tours++;
this.eval(constraints);
this.setChanged();
this.notifyObservers(HybridClassification.VIEW_TOUR);
// Amelioration de la solution
if (this.eval.GAMMA > this.gammaMax) {
this.setChanged();
this.notifyObservers(HybridClassification.BEST_SOLUTION);
this.gammaMax = this.eval.GAMMA;
this.evalMax = this.eval;
// On memorise la liste des meilleurs resultats par clonage des
// agents courants
this.agentsMax = (Vector<LearningAgent>) (this.agents.clone());
this.bad_tours = 0;
const_bad = 0;
const_tours = 0;
this.setTrend(1);
lost = false;
this.best = true;
this.unification(true);
}
// Pas de modifications
else if (this.eval.GAMMA == gammaOld && !lost) {
const_tours++;
this.setChanged();
this.notifyObservers(HybridClassification.CONSTANT_SOLUTION);
this.setTrend(0);
this.best = false;
const_bad = 0;
}
// Perte de qualite
else {
this.bad_tours++;
this.setChanged();
this.notifyObservers(HybridClassification.BAD_SOLUTION);
this.setTrend(-1);
// Perte de qualite trop importante retour à la solution
// optimale
if ((this.bad_tours > this.config.maxBadTours) || (this.eval.GAMMA < this.config.degradationMax * this.gammaMax)) {
this.bad_tours = 0;
// On construit une liste d'agents courant par clonage de
// la liste des meilleurs resultats actuels
this.agents = (Vector<LearningAgent>) (this.agentsMax.clone());
this.eval = this.evalMax;
lost = false;
this.setChanged();
this.notifyObservers(HybridClassification.RETURN_BEST_SOLUTION);
const_tours++;
}
else if (this.eval.GAMMA == gammaOld) {
lost = true;
const_bad++;
}
else {
lost = true;
const_bad = 0;
}
this.best = false;
}
// on a trouve une meilleure solution, calcul de l'unification
if ((this.best == true)) {
this.setClusteringResult(this.unification(true));
}
// perte de qualite
if (lost) {
// On cree les conflits en tenant compte du nombre de tours
// ou le resultat unifiant s'est degrade
this.createConflicts(const_bad);
}
else {
this.createConflicts(const_tours);
}
this.conflictsLeft = this.getNbConflictsLeft();
if (this.conflicts.size() != 0) {
this.conflictsResolution(this.tours, constraints);
}
else {
this.stop = true;
}
gammaOld = this.eval.GAMMA;
}
for (LearningAgent a : this.agents) {
a.getClassification().setClusteringResult(a.getClassification()
.getLearningResult().classify(a.getData(), false));
}
this.setChanged();
this.setClusteringResult(this.unification(false));
/*
* On supprime les petites classes si config.typeSolution > 0 et pourcentage > 0)
*/
// if ((this.config.typeSolution > 0) && (this.config.pourcentage > 0))
// {
// this.clusteringResultBrut = this.clusteringResult;
// this.clusteringResult = this.supPetitesClasses(this.getData(),
// this.clusteringResultBrut.getClusterMap(),
// this.config.pourcentage, this.clusteringResultBrut
// .getNbClusters(), this.config.typeSolution);
// if (this.clusteringResult == null) {
// this.clusteringResult = this.clusteringResultBrut;
// this.clusteringResultBrut = null;
// }
// }
this.notifyObservers(HybridClassification.END);
}
@Override
public int getType() {
return ClassifierUtils.SAMARAH_CONSTRAINED;
}
@Override
public Object clone() {
return new HybridClassificationConstrained2(this);
}
}
...@@ -147,7 +147,7 @@ public class JCLModelExchange { ...@@ -147,7 +147,7 @@ public class JCLModelExchange {
case(ClassifierUtils.SAMARAH) : case(ClassifierUtils.SAMARAH) :
result = new HybridClassification().ImportResult(body, classifIndex); result = new HybridClassification().ImportResult(body, classifIndex);
case(ClassifierUtils.SAMARAH_CONSTRAINED) : case(ClassifierUtils.SAMARAH_CONSTRAINED) :
result = new jcl.learning.methods.multistrategy.samarahConstrained.HybridClassification() result = new jcl.learning.methods.multistrategy.samarahConstrained.HybridClassificationConstrained()
.ImportResult(body, classifIndex); .ImportResult(body, classifIndex);
} }
} }
......
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