Commit 79997ae5 authored by lafabregue's avatar lafabregue

changed samarah unification method

parent 32bb3000
......@@ -153,11 +153,17 @@ public class DistanceModel {
for (Distance d : model.getDistances()) {
if(d instanceof DistanceDTWMD) {
AttributeMultiDimSequence seq = (AttributeMultiDimSequence) data.getOneDataObject().getAttribute(i);//need the corresponding attribute to get the sequence length
distanceParameters[th][i] = new ParameterDTW(new double[seq.getNbTuples()][seq.getNbTuples()]); //special attribute for DTW distances (requires a matrix to work in)
int size = seq.getNbTuples();
if (size < 50)
size = 50;
distanceParameters[th][i] = new ParameterDTW(new double[size][size]); //special attribute for DTW distances (requires a matrix to work in)
}
else if(d instanceof DistanceDTW) {
AttributeSequence seq = (AttributeSequence) data.getOneDataObject().getAttribute(i);//need the corresponding attribute to get the sequence length
distanceParameters[th][i] = new ParameterDTW(new double[seq.getNbTuples()][seq.getNbTuples()]); //special attribute for DTW distances (requires a matrix to work in)
int size = seq.getNbTuples();
if (size < 50)
size = 50;
distanceParameters[th][i] = new ParameterDTW(new double[size][size]); //special attribute for DTW distances (requires a matrix to work in)
}
else {
distanceParameters[th][i] = EmptyDistanceParameter.getInstance();//no parameter for a numerical euclidean distance
......@@ -174,11 +180,17 @@ public class DistanceModel {
for (Distance d : model.getDistances()) {
if(d instanceof DistanceDTWMD) {
AttributeMultiDimSequence seq = (AttributeMultiDimSequence) data.getOneDataObject().getAttribute(j);//need the corresponding attribute to get the sequence length
averageParameters[j] = new ParameterDBAMean(seq.getNbTuples(), 15);
int size = seq.getNbTuples();
if (size < 50)
size = 50;
averageParameters[j] = new ParameterDBAMean(size, 15);
}
else if(d instanceof DistanceDTW) {
AttributeSequence seq = (AttributeSequence) data.getOneDataObject().getAttribute(j);//need the corresponding attribute to get the sequence length
averageParameters[j] = new ParameterDBAMean(seq.getNbTuples(), 15);
int size = seq.getNbTuples();
if (size < 50)
size = 50;
averageParameters[j] = new ParameterDBAMean(size, 15);
}
else {
averageParameters[j] = EmptyAverageParameter.getInstance();
......
......@@ -56,8 +56,8 @@ public class AverageMDDBAMean implements Average<AttributeMultiDimSequence,Param
* L'idée de cette méthode est de calculer la moyenne d'un ensemble de séquences, comme la mise-à-jour de l'ancienne moyenne, en calculant le
* barycentre des points ayant été associé à chaque point de cette dernière.
*
* @param oldCenter ancien centre du cluster
* @param attributesTab séquences associées au cluster
* @param oldCenter ancien centre du cluster
* @param p paramètres utilisés pour le calcul
* @return le nouveau centre, comme l'approximation des séquences
*/
......
......@@ -223,6 +223,10 @@ public class HybridClassification extends Classification implements Runnable, It
@Override
public void classify() {
File directory = new File("log");
if (! directory.exists() && directory.isDirectory()){
directory.mkdir();
}
if (this.useRmi()) {
this.learnRMI();
}
......@@ -1228,7 +1232,7 @@ public class HybridClassification extends Classification implements Runnable, It
* @return the unification result
*/
public ClusteringResult unification(boolean onSample) {
return unification(this.data, onSample);
return unification_relative(this.data, onSample);
}
/**
......@@ -1388,6 +1392,165 @@ public class HybridClassification extends Classification implements Runnable, It
return tmp;
}
/**
* <p>
* Method to unify the result from classification agents
* </p>
*
* @param data
* the data to unify over
* @param onSample
* run the unification on the sample if true, on the whole data otherwise
* @return the unification result
*/
public ClusteringResult unification_relative(Data data, boolean onSample) {
LearningAgent a;
int[] stat;
int[] ff;
int[] ag;
int[] cl;
double[][] vote;
int[][] clustermaps;
// nombre d'agents au total
final int nbre_agents = this.agents.size();
// nombre d'objets classifies : on prend le plus gros
int nb_obj = 0;
if (onSample) {
nb_obj = data.getNbObjects();
} else {
nb_obj = data.getWholeDataNbObjects();
}
// Initialisation des parametres et de la matrice
stat = new int[nb_obj];
ff = new int[nb_obj];
ag = new int[nb_obj];
cl = new int[nb_obj];
for (int p = 0; p < nb_obj; p++) {
stat[p] = 0;
ff[p] = 0;
ag[p] = -1;
cl[p] = -1;
}
vote = new double[nbre_agents][];
for (int i = 0; i < nbre_agents; i++) {
a = this.getAgent(i);
vote[i] = new double[a.getNbClusters()];
}
// compute the cluster map for each agent
clustermaps = new int[nbre_agents][];
for (int i = 0; i < nbre_agents; i++) {
a = this.getAgent(i);
if (a.getData() == this.data) {
clustermaps[i] = a.getClassification().getClusteringResult()
.getClusterMap(onSample);
} else {
clustermaps[i] = a.getClassification().getLearningResult()
.classify(data, onSample).getClusterMap(onSample);
}
}
// Calcul de la matrice de vote sur les objets
for (int p = 0; p < nb_obj; p++) {
for (int i = 0; i < nbre_agents; i++) {
a = this.getAgent(i);
for (int j = 0; j < a.getNbClusters(); j++) {
vote[i][j] = 0;
}
}
for (int i = 0; i < nbre_agents; i++) {
a = this.getAgent(i);
final int k = clustermaps[i][p];
if (k >= 0) {
vote[i][k] += 1;
}
for (int j = 0; j < nbre_agents; j++) {
if ((j != i) && (k >= 0)) {
final int km = this.evalMax.alpha[i][j].maxColumn(k);
a = this.getAgent(j);
final int kj = clustermaps[j][p];
// we weight the impact of the vote
vote[j][km] += this.evalMax.alpha[i][j].column(k)[km];
if (kj == km) {
stat[p] += 1;
}
}
}
}
double max = vote[0][0];
for (int i = 0; i < nbre_agents; i++) {
a = this.getAgent(i);
for (int j = 0; j < a.getNbClusters(); j++) {
if (vote[i][j] > max) {
max = vote[i][j];
ag[p] = i;
cl[p] = j;
}
}
}
}
final int[] agree = new int[12];
for (int i = 0; i < stat.length; i++) {
agree[(int) ((float) stat[i] / (float) nbre_agents + 0.5)]++;
}
final Vector<Integer> values = new Vector<Integer>();
for (int p = 0; p < nb_obj; p++) {
int classe = -1;
stat[p] = (int) ((float) stat[p] / (float) nbre_agents + 0.5);
if ((this.config.unification == SamarahConfig.WITH_UNCLASSIFIED_UNIFICATION && stat[p] >= ((nbre_agents - 1) / 2))
|| this.config.unification == SamarahConfig.WITHOUT_UNCLASSIFIED_UNIFICATION) {
classe = ag[p] + (cl[p] + 1) * nbre_agents;
}
final Integer val = new Integer(classe);
if (!values.contains(val)) {
values.add(val);
}
ff[p] = values.indexOf(val);
}
final int nbClasses = values.size();
double resoMin = 0;
int agentMin = 0;
try {
resoMin = (this.agents.get(0)).getData().getResolution();
for (int x = 0; x < this.agents.size(); x++) {
if ((this.agents.get(0)).getData().getResolution() < resoMin) {
resoMin = (this.agents.get(0)).getData().getResolution();
agentMin = x;
}
}
} catch (final ClassCastException ex) {
agentMin = 0;
}
this.overall_stat = ff;
if (this.first_stat == null) {
this.first_stat = stat;
}
//final Data biggestData = (this.agents.get(agentMin)).getData();
final ClusteringResult tmp = ClusteringResult.gerenerateDefaultClusteringResult(null, ff,
new GlobalWeights(data.getOneDataObject()), nbClasses, data,
HybridClassification.QUALITY_INDICES, importedColors);
importedColors = null;
return tmp;
}
/**
* <p>
* Methode gardant uniquement les pires conflits.
......
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