Commit f960b309 authored by lafabregue's avatar lafabregue

test program modification

parent cab28086
...@@ -29,6 +29,9 @@ abstract public class Cluster implements Serializable { ...@@ -29,6 +29,9 @@ abstract public class Cluster implements Serializable {
/** The cluster's father node color*/ /** The cluster's father node color*/
protected Color couleur_pere = new Color(0); protected Color couleur_pere = new Color(0);
/** L'index qui correspond a la place du cluster dans result */
protected int id = -1;
/** /**
* Indicate if the cluster is freezed or not. If it is, we * Indicate if the cluster is freezed or not. If it is, we
...@@ -71,6 +74,7 @@ abstract public class Cluster implements Serializable { ...@@ -71,6 +74,7 @@ abstract public class Cluster implements Serializable {
this.clusterCenter = new DataObject(cluster.clusterCenter); this.clusterCenter = new DataObject(cluster.clusterCenter);
} }
this.weights = new Weights(cluster.weights); this.weights = new Weights(cluster.weights);
this.id = cluster.id;
} }
/** Renvoi le centroide du cluster et le calcul si il est vide */ /** Renvoi le centroide du cluster et le calcul si il est vide */
...@@ -135,6 +139,16 @@ abstract public class Cluster implements Serializable { ...@@ -135,6 +139,16 @@ abstract public class Cluster implements Serializable {
public DataObject getClusterCenter() { public DataObject getClusterCenter() {
return this.clusterCenter; return this.clusterCenter;
} }
/**
* <p>
* Return the id of the cluster in the ClusteringResult
* <p>
*
* @return the cluster id
*/
public int getId() {
return id;
}
/** /**
* <p> * <p>
......
...@@ -12,9 +12,6 @@ public class LightCluster extends Cluster { ...@@ -12,9 +12,6 @@ public class LightCluster extends Cluster {
/** */ /** */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** L'index qui correspond a la place du cluster dans result */
private int id = -1;
/** the cluster cardinality */ /** the cluster cardinality */
private int cardinal = -1; private int cardinal = -1;
...@@ -178,17 +175,6 @@ public class LightCluster extends Cluster { ...@@ -178,17 +175,6 @@ public class LightCluster extends Cluster {
return indexIterator; return indexIterator;
} }
/**
* <p>
* Return the id of the cluster in the ClusteringResult
* <p>
*
* @return the cluster id
*/
public int getId() {
return id;
}
/** /**
* <p> * <p>
* Set the id of the cluster in the ClusteringResult * Set the id of the cluster in the ClusteringResult
......
...@@ -123,6 +123,7 @@ public class SimpleCluster extends Cluster { ...@@ -123,6 +123,7 @@ public class SimpleCluster extends Cluster {
this.membershipProbabilityEM = proba; this.membershipProbabilityEM = proba;
this.locked = false; this.locked = false;
this.name = "Cluster " + (k + 1); this.name = "Cluster " + (k + 1);
this.id = k;
} }
/** /**
...@@ -203,6 +204,7 @@ public class SimpleCluster extends Cluster { ...@@ -203,6 +204,7 @@ public class SimpleCluster extends Cluster {
this.membershipProbabilityEM = proba; this.membershipProbabilityEM = proba;
this.locked = false; this.locked = false;
this.name = "Cluster " + (k + 1); this.name = "Cluster " + (k + 1);
this.id = k;
} }
/** /**
......
package jcl.clustering.constraints; package jcl.clustering.constraints;
import jcl.clustering.ClusteringResult; import jcl.clustering.ClusteringResult;
import jcl.data.DataObject;
import jcl.data.Model;
import jcl.data.distance.DistanceParameter;
/** /**
* Class that represent a generic constraint. * Class that represent a generic constraint.
...@@ -57,4 +60,95 @@ public abstract class Constraint { ...@@ -57,4 +60,95 @@ public abstract class Constraint {
return true; return true;
} }
/**
* Compute the marginal silhouette score of the i-th object from a Data.
* A value close to 1 indicates is similar to other object from his class,
* a value close to 0 indicates that the object is close to another class.
*
* @param index
* the object to evaluate index
* @param result
* the result to evaluate the object to
* @param metricToUse
* the metric to use for the evaluation
* @param parameters
* the parameters used by the metric if needed
* @return the marginal silhouette score
*/
public static double marginalSilhouetteScore(int index, ClusteringResult result, Model metricToUse,
DistanceParameter[] parameters) {
double msc = 0.0;
int closerCluster = -1;
double minDist = 0;
DataObject obj = result.getData().getDataObject(index);
if (result.getClusterCenter(0) != null) {
minDist = metricToUse.getMetaDistance().compute(obj, result.getClusterCenter(0),
metricToUse.getDistances(), parameters);
closerCluster = 0;
for (int i = 1 ; i < result.getNbClusters() ; i++) {
if (result.getClusterCenter(i) != null) {
double tmpDist = metricToUse.getMetaDistance().compute(result.getData().getDataObject(index),
result.getClusterCenter(i), metricToUse.getDistances(), parameters);
if (tmpDist < minDist) {
minDist = tmpDist;
closerCluster = i;
}
}
}
msc = computeAvgDissimilarity(obj, closerCluster, result, metricToUse, parameters);
} else {
msc = computeAvgDissimilarity(obj, 0, result, metricToUse, parameters);
for (int i = 1 ; i < result.getNbClusters() ; i++) {
if (result.getClusterCenter(i) != null) {
double tmpDist = computeAvgDissimilarity(obj, i, result, metricToUse, parameters);
if (tmpDist < msc) {
msc = tmpDist;
}
}
}
}
return msc;
}
/**
* Compute the average dissimilarity of a DataObject from the set of
* DataObject of a given cluster
*
* @param obj
* the object to evaluate
* @param clusterIndex
* the index of the cluster to compare
* @param result
* the result to evaluate the object to
* @param metricToUse
* the metric to use for the evaluation
* @param parameters
* the parameters used by the metric if needed
* @return the average dissimilarity
*/
private static double computeAvgDissimilarity(DataObject obj, int clusterIndex, ClusteringResult result,
Model metricToUse, DistanceParameter[] parameters) {
double total = 0;
int count = 0;
for (int i = 0 ; i < result.getClusterMap().length ; i++) {
if (result.getClusterMap()[i] == result.getCluster(clusterIndex).getId()) {
total += metricToUse.getMetaDistance().compute(obj, result.getData().getDataObject(i),
metricToUse.getDistances(), parameters);
count++;
}
}
total /= count;
return total;
}
} }
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