diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial')
7 files changed, 51 insertions, 56 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelClustering.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelClustering.java index af8fb1ea..3b5d0ec2 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelClustering.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelClustering.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.algorithm.clustering.trivial; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -144,7 +144,7 @@ public class ByLabelClustering extends AbstractAlgorithm<Clustering<Model>> impl HashMap<String, DBIDs> labelMap = multiple ? multipleAssignment(relation) : singleAssignment(relation); ModifiableDBIDs noiseids = DBIDUtil.newArray(); - Clustering<Model> result = new Clustering<Model>("By Label Clustering", "bylabel-clustering"); + Clustering<Model> result = new Clustering<>("By Label Clustering", "bylabel-clustering"); for(Entry<String, DBIDs> entry : labelMap.entrySet()) { DBIDs ids = entry.getValue(); if(ids.size() <= 1) { @@ -156,13 +156,13 @@ public class ByLabelClustering extends AbstractAlgorithm<Clustering<Model>> impl if(noisepattern != null && noisepattern.matcher(entry.getKey()).find()) { c.setNoise(true); } - result.addCluster(c); + result.addToplevelCluster(c); } // Collected noise IDs. if(noiseids.size() > 0) { Cluster<Model> c = new Cluster<Model>("Noise", noiseids, ClusterModel.CLUSTER); c.setNoise(true); - result.addCluster(c); + result.addToplevelCluster(c); } return result; } @@ -175,7 +175,7 @@ public class ByLabelClustering extends AbstractAlgorithm<Clustering<Model>> impl * @return a mapping of labels to ids */ private HashMap<String, DBIDs> singleAssignment(Relation<?> data) { - HashMap<String, DBIDs> labelMap = new HashMap<String, DBIDs>(); + HashMap<String, DBIDs> labelMap = new HashMap<>(); for(DBIDIter iditer = data.iterDBIDs(); iditer.valid(); iditer.advance()) { final Object val = data.get(iditer); @@ -193,7 +193,7 @@ public class ByLabelClustering extends AbstractAlgorithm<Clustering<Model>> impl * @return a mapping of labels to ids */ private HashMap<String, DBIDs> multipleAssignment(Relation<?> data) { - HashMap<String, DBIDs> labelMap = new HashMap<String, DBIDs>(); + HashMap<String, DBIDs> labelMap = new HashMap<>(); for(DBIDIter iditer = data.iterDBIDs(); iditer.valid(); iditer.advance()) { String[] labels = data.get(iditer).toString().split(" "); diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelHierarchicalClustering.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelHierarchicalClustering.java index dfb7d37f..33101221 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelHierarchicalClustering.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelHierarchicalClustering.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.algorithm.clustering.trivial; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -88,8 +88,7 @@ public class ByLabelHierarchicalClustering extends AbstractAlgorithm<Clustering< try { Relation<ClassLabel> relation = database.getRelation(TypeUtil.CLASSLABEL); return run(relation); - } - catch(NoSupportedDataTypeException e) { + } catch (NoSupportedDataTypeException e) { // Otherwise, try any labellike. return run(database.getRelation(getInputTypeRestriction()[0])); } @@ -101,12 +100,13 @@ public class ByLabelHierarchicalClustering extends AbstractAlgorithm<Clustering< * @param relation The data input to use */ public Clustering<Model> run(Relation<?> relation) { - HashMap<String, DBIDs> labelmap = new HashMap<String, DBIDs>(); + HashMap<String, DBIDs> labelmap = new HashMap<>(); ModifiableDBIDs noiseids = DBIDUtil.newArray(); + Clustering<Model> clustering = new Clustering<>("By Label Hierarchical Clustering", "bylabel-clustering"); - for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) { + for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) { final Object val = relation.get(iditer); - if(val == null) { + if (val == null) { noiseids.add(iditer); continue; } @@ -115,44 +115,41 @@ public class ByLabelHierarchicalClustering extends AbstractAlgorithm<Clustering< assign(labelmap, label, iditer); } - ArrayList<Cluster<Model>> clusters = new ArrayList<Cluster<Model>>(labelmap.size()); - for(Entry<String, DBIDs> entry : labelmap.entrySet()) { + ArrayList<Cluster<Model>> clusters = new ArrayList<>(labelmap.size()); + for (Entry<String, DBIDs> entry : labelmap.entrySet()) { DBIDs ids = entry.getValue(); - if(ids instanceof DBID) { + if (ids instanceof DBID) { noiseids.add((DBID) ids); continue; } - Cluster<Model> clus = new Cluster<Model>(entry.getKey(), ids, ClusterModel.CLUSTER, new ArrayList<Cluster<Model>>(), new ArrayList<Cluster<Model>>()); + Cluster<Model> clus = new Cluster<Model>(entry.getKey(), ids, ClusterModel.CLUSTER); clusters.add(clus); } - for(Cluster<Model> cur : clusters) { - for(Cluster<Model> oth : clusters) { - if(oth != cur) { - if(oth.getName().startsWith(cur.getName())) { - oth.getParents().add(cur); - cur.getChildren().add(oth); - // System.err.println(oth.getLabel() + " is a child of " + - // cur.getLabel()); + for (Cluster<Model> cur : clusters) { + boolean isrootcluster = true; + for (Cluster<Model> oth : clusters) { + if (oth != cur) { + if (oth.getName().startsWith(cur.getName())) { + clustering.addChildCluster(oth, cur); + if (LOG.isDebuggingFiner()) { + LOG.debugFiner(oth.getName() + " is a child of " + cur.getName()); + } + isrootcluster = false; } } } - } - ArrayList<Cluster<Model>> rootclusters = new ArrayList<Cluster<Model>>(); - for(Cluster<Model> cur : clusters) { - if(cur.getParents().size() == 0) { - rootclusters.add(cur); + if (isrootcluster) { + clustering.addToplevelCluster(cur); } } // Collected noise IDs. - if(noiseids.size() > 0) { + if (noiseids.size() > 0) { Cluster<Model> c = new Cluster<Model>("Noise", noiseids, ClusterModel.CLUSTER); c.setNoise(true); - rootclusters.add(c); + clustering.addToplevelCluster(c); } - assert (rootclusters.size() > 0) : "No clusters found by bylabel clustering. Empty database?"; - - return new Clustering<Model>("By Label Hierarchical Clustering", "bylabel-clustering", rootclusters); + return clustering; } /** @@ -163,21 +160,19 @@ public class ByLabelHierarchicalClustering extends AbstractAlgorithm<Clustering< * @param id the id of the object to be assigned */ private void assign(HashMap<String, DBIDs> labelMap, String label, DBIDRef id) { - if(labelMap.containsKey(label)) { + if (labelMap.containsKey(label)) { DBIDs exist = labelMap.get(label); - if(exist instanceof DBID) { + if (exist instanceof DBID) { ModifiableDBIDs n = DBIDUtil.newHashSet(); n.add((DBID) exist); n.add(id); labelMap.put(label, n); - } - else { + } else { assert (exist instanceof HashSetModifiableDBIDs); assert (exist.size() > 1); ((ModifiableDBIDs) exist).add(id); } - } - else { + } else { labelMap.put(label, DBIDUtil.deref(id)); } } @@ -191,4 +186,4 @@ public class ByLabelHierarchicalClustering extends AbstractAlgorithm<Clustering< protected Logging getLogger() { return LOG; } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelOrAllInOneClustering.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelOrAllInOneClustering.java index f082db9c..76b024a2 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelOrAllInOneClustering.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByLabelOrAllInOneClustering.java @@ -15,7 +15,7 @@ import de.lmu.ifi.dbs.elki.database.relation.Relation; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -66,9 +66,9 @@ public class ByLabelOrAllInOneClustering extends ByLabelClustering { // Ignore. } final DBIDs ids = database.getRelation(TypeUtil.ANY).getDBIDs(); - Clustering<Model> result = new Clustering<Model>("All-in-one trivial Clustering", "allinone-clustering"); + Clustering<Model> result = new Clustering<>("All-in-one trivial Clustering", "allinone-clustering"); Cluster<Model> c = new Cluster<Model>(ids, ClusterModel.CLUSTER); - result.addCluster(c); + result.addToplevelCluster(c); return result; } } diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByModelClustering.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByModelClustering.java index 2114ac16..73ad9880 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByModelClustering.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/ByModelClustering.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.algorithm.clustering.trivial; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -101,7 +101,7 @@ public class ByModelClustering extends AbstractAlgorithm<Clustering<Model>> impl */ public Clustering<Model> run(Relation<Model> relation) { // Build model mapping - HashMap<Model, ModifiableDBIDs> modelMap = new HashMap<Model, ModifiableDBIDs>(); + HashMap<Model, ModifiableDBIDs> modelMap = new HashMap<>(); for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) { Model model = relation.get(iditer); ModifiableDBIDs modelids = modelMap.get(model); @@ -112,16 +112,16 @@ public class ByModelClustering extends AbstractAlgorithm<Clustering<Model>> impl modelids.add(iditer); } - Clustering<Model> result = new Clustering<Model>("By Model Clustering", "bymodel-clustering"); + Clustering<Model> result = new Clustering<>("By Model Clustering", "bymodel-clustering"); for(Entry<Model, ModifiableDBIDs> entry : modelMap.entrySet()) { final Model model = entry.getKey(); final ModifiableDBIDs ids = entry.getValue(); final String name = (model instanceof GeneratorInterface) ? ((GeneratorInterface) model).getName() : model.toString(); - Cluster<Model> c = new Cluster<Model>(name, ids, model); + Cluster<Model> c = new Cluster<>(name, ids, model); if(noisepattern != null && noisepattern.matcher(name).find()) { c.setNoise(true); } - result.addCluster(c); + result.addToplevelCluster(c); } return result; } diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllInOne.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllInOne.java index eaa5d2b2..dae50c25 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllInOne.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllInOne.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.algorithm.clustering.trivial; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -63,9 +63,9 @@ public class TrivialAllInOne extends AbstractAlgorithm<Clustering<Model>> implem public Clustering<Model> run(Relation<?> relation) { final DBIDs ids = relation.getDBIDs(); - Clustering<Model> result = new Clustering<Model>("All-in-one trivial Clustering", "allinone-clustering"); + Clustering<Model> result = new Clustering<>("All-in-one trivial Clustering", "allinone-clustering"); Cluster<Model> c = new Cluster<Model>(ids, ClusterModel.CLUSTER); - result.addCluster(c); + result.addToplevelCluster(c); return result; } diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllNoise.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllNoise.java index dd0f94a5..ecc7dbec 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllNoise.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/TrivialAllNoise.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.algorithm.clustering.trivial; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -62,9 +62,9 @@ public class TrivialAllNoise extends AbstractAlgorithm<Clustering<Model>> implem public Clustering<Model> run(Relation<?> relation) { final DBIDs ids = relation.getDBIDs(); - Clustering<Model> result = new Clustering<Model>("All-in-noise trivial Clustering", "allinnoise-clustering"); + Clustering<Model> result = new Clustering<>("All-in-noise trivial Clustering", "allinnoise-clustering"); Cluster<Model> c = new Cluster<Model>(ids, true, ClusterModel.CLUSTER); - result.addCluster(c); + result.addToplevelCluster(c); return result; } diff --git a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/package-info.java b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/package-info.java index 5870a736..6b7b50f5 100644 --- a/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/algorithm/clustering/trivial/package-info.java @@ -7,7 +7,7 @@ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures -Copyright (C) 2012 +Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team |