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