Commit 19755bdb authored by lafabregue's avatar lafabregue

fix compatibilty of cobweb and perceptron classifiers

parent 540054ed
...@@ -44,7 +44,9 @@ public class LightCluster extends Cluster { ...@@ -44,7 +44,9 @@ public class LightCluster extends Cluster {
this.id = id; this.id = id;
this.clusterCenter = center; this.clusterCenter = center;
this.cardinal = card; this.cardinal = card;
this.weights = new Weights(center.getNbAttributes()); if (center != null) {
this.weights = new Weights(center.getNbAttributes());
}
} }
/** /**
......
...@@ -544,7 +544,7 @@ public class SimpleData extends Data { ...@@ -544,7 +544,7 @@ public class SimpleData extends Data {
@Override @Override
public DataObject mean() { public DataObject mean() {
if (this.currentView == null) { if (this.currentView == null || this.currentView.size() == 0) {
return null; return null;
} }
......
...@@ -10,6 +10,8 @@ import jcl.data.Data; ...@@ -10,6 +10,8 @@ import jcl.data.Data;
import jcl.utils.Progressable; import jcl.utils.Progressable;
import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.JCLFormatException;
import jcl.weights.ClassificationWeights; import jcl.weights.ClassificationWeights;
import jcl.weights.GlobalWeights;
import jcl.weights.Weights;
import multiCube.tools.util.exceptions.MethodNotImplementedException; import multiCube.tools.util.exceptions.MethodNotImplementedException;
/** /**
...@@ -76,6 +78,8 @@ public abstract class LearningResult extends Object implements Progressable,Seri ...@@ -76,6 +78,8 @@ public abstract class LearningResult extends Object implements Progressable,Seri
this.params = params; this.params = params;
if (weights != null) { if (weights != null) {
this.weights = (ClassificationWeights) weights.clone(); this.weights = (ClassificationWeights) weights.clone();
} else if (data != null) {
this.weights = new GlobalWeights(data.getOneDataObject());
} }
this.setQualityIndices(); this.setQualityIndices();
this.data = data; this.data = data;
......
...@@ -11,6 +11,7 @@ import jcl.data.DataObject; ...@@ -11,6 +11,7 @@ import jcl.data.DataObject;
import jcl.learning.LearningMethod; import jcl.learning.LearningMethod;
import jcl.learning.LearningResult; import jcl.learning.LearningResult;
import jcl.learning.methods.ClassifierUtils; import jcl.learning.methods.ClassifierUtils;
import jcl.weights.Weights;
import multiCube.tools.util.exceptions.MethodNotImplementedException; import multiCube.tools.util.exceptions.MethodNotImplementedException;
/** /**
...@@ -108,9 +109,13 @@ public class ClassifierCobweb extends LearningMethod implements Cloneable, ...@@ -108,9 +109,13 @@ public class ClassifierCobweb extends LearningMethod implements Cloneable,
} }
int nbpasses = this.getNombre_de_passe(); int nbpasses = this.getNombre_de_passe();
Weights weights = new Weights(data.getOneDataObject().getNbAttributes());
if (this.parameters.weights != null) {
weights = this.parameters.weights.getWeights(0);
}
// Creation de la hierarchie des concepts // Creation de la hierarchie des concepts
Concept racine = new Concept(data.getOneDataObject(), this.getMapi(), Concept racine = new Concept(data.getOneDataObject(), this.getMapi(),
this.parameters.weights.getWeights(0), aacuite, true, this); weights, aacuite, true, this);
racine.id = this.idGenere(); racine.id = this.idGenere();
/** Premiere passe */ /** Premiere passe */
...@@ -179,7 +184,7 @@ public class ClassifierCobweb extends LearningMethod implements Cloneable, ...@@ -179,7 +184,7 @@ public class ClassifierCobweb extends LearningMethod implements Cloneable,
} }
// Re-creation de la hierarchie des concepts // Re-creation de la hierarchie des concepts
racine = new Concept(data.getOneDataObject(), this.getMapi(), racine = new Concept(data.getOneDataObject(), this.getMapi(),
this.parameters.weights.getWeights(0), aacuite, true, this); weights, aacuite, true, this);
this.id = 0; this.id = 0;
racine.id = this.idGenere(); racine.id = this.idGenere();
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
......
...@@ -75,7 +75,7 @@ public class ClassifierPerceptron extends LearningMethod { ...@@ -75,7 +75,7 @@ public class ClassifierPerceptron extends LearningMethod {
this.incProgress(); this.incProgress();
final LearningResultPerceptron result = new LearningResultPerceptron( final LearningResultPerceptron result = new LearningResultPerceptron(
(ParametersPerceptron) this.parameters); (ParametersPerceptron) this.parameters, data);
this.initViewers(result); this.initViewers(result);
for (int i = 0; i < data.getOneDataObject().getNbAttributes(); i++) { for (int i = 0; i < data.getOneDataObject().getNbAttributes(); i++) {
......
...@@ -97,10 +97,12 @@ public class LearningResultPerceptron extends LearningResult { ...@@ -97,10 +97,12 @@ public class LearningResultPerceptron extends LearningResult {
* </p> * </p>
* *
* @param params * @param params
* les parametres de la methode * the method parameters
* @param data
* the data to classify
*/ */
LearningResultPerceptron(final ParametersPerceptron params) { LearningResultPerceptron(final ParametersPerceptron params, Data data) {
super(params, params.weights, null); super(params, params.weights, data);
this.neuralNetwork = new NeuralNet(this.weights.getNbAttributes(), this.neuralNetwork = new NeuralNet(this.weights.getNbAttributes(),
params.nbClusters, params.initStep, params.stepMod); params.nbClusters, params.initStep, params.stepMod);
} }
...@@ -114,7 +116,7 @@ public class LearningResultPerceptron extends LearningResult { ...@@ -114,7 +116,7 @@ public class LearningResultPerceptron extends LearningResult {
} else { } else {
mapSize = data.getWholeDataNbObjects(); mapSize = data.getWholeDataNbObjects();
} }
final int clusterMap[] = new int[data.getNbObjects()]; final int clusterMap[] = new int[mapSize];
final int nbClusters = this.neuralNetwork.getNbOutputs(); final int nbClusters = this.neuralNetwork.getNbOutputs();
final double membershipDegree[][] = new double[nbClusters][mapSize]; final double membershipDegree[][] = new double[nbClusters][mapSize];
final double[][] inputData = LearningResultPerceptron.getData(data, fromSample); final double[][] inputData = LearningResultPerceptron.getData(data, fromSample);
......
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