diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data')
86 files changed, 1245 insertions, 539 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/AbstractNumberVector.java b/src/de/lmu/ifi/dbs/elki/data/AbstractNumberVector.java index 95e81891..aec6a579 100644 --- a/src/de/lmu/ifi/dbs/elki/data/AbstractNumberVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/AbstractNumberVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/Arithmetic.java b/src/de/lmu/ifi/dbs/elki/data/Arithmetic.java index 534f7717..c9236539 100644 --- a/src/de/lmu/ifi/dbs/elki/data/Arithmetic.java +++ b/src/de/lmu/ifi/dbs/elki/data/Arithmetic.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/Bit.java b/src/de/lmu/ifi/dbs/elki/data/Bit.java index 7272e235..219ac2dd 100644 --- a/src/de/lmu/ifi/dbs/elki/data/Bit.java +++ b/src/de/lmu/ifi/dbs/elki/data/Bit.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/BitVector.java b/src/de/lmu/ifi/dbs/elki/data/BitVector.java index d662af66..750f6f5b 100644 --- a/src/de/lmu/ifi/dbs/elki/data/BitVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/BitVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/ClassLabel.java b/src/de/lmu/ifi/dbs/elki/data/ClassLabel.java index ce3b76a9..96df671d 100644 --- a/src/de/lmu/ifi/dbs/elki/data/ClassLabel.java +++ b/src/de/lmu/ifi/dbs/elki/data/ClassLabel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -26,7 +26,6 @@ package de.lmu.ifi.dbs.elki.data; import java.util.HashMap; import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; -import de.lmu.ifi.dbs.elki.utilities.InspectionUtilFrequentlyScanned; /** * A ClassLabel to identify a certain class of objects that is to discern from @@ -88,11 +87,11 @@ public abstract class ClassLabel implements Comparable<ClassLabel> { * @apiviz.has ClassLabel - - «creates» * @apiviz.stereotype factory */ - public abstract static class Factory<L extends ClassLabel> implements InspectionUtilFrequentlyScanned { + public abstract static class Factory<L extends ClassLabel> { /** * Set for reusing the same objects. */ - protected HashMap<String, L> existing = new HashMap<String, L>(); + protected HashMap<String, L> existing = new HashMap<>(); /** * Convert a string into a class label. diff --git a/src/de/lmu/ifi/dbs/elki/data/Cluster.java b/src/de/lmu/ifi/dbs/elki/data/Cluster.java index 95e9fb6a..00e1b693 100644 --- a/src/de/lmu/ifi/dbs/elki/data/Cluster.java +++ b/src/de/lmu/ifi/dbs/elki/data/Cluster.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -23,21 +23,12 @@ package de.lmu.ifi.dbs.elki.data; along with this program. If not, see <http://www.gnu.org/licenses/>. */ -import java.util.ArrayList; import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; import de.lmu.ifi.dbs.elki.data.model.Model; import de.lmu.ifi.dbs.elki.database.ids.DBIDs; import de.lmu.ifi.dbs.elki.result.textwriter.TextWriteable; import de.lmu.ifi.dbs.elki.result.textwriter.TextWriterStream; -import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.Hierarchical; -import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.Hierarchy; -import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.HierarchyReferenceLists; -import de.lmu.ifi.dbs.elki.utilities.iterator.EmptyIterator; /** * Generic cluster class, that may or not have hierarchical information. Note @@ -53,23 +44,13 @@ import de.lmu.ifi.dbs.elki.utilities.iterator.EmptyIterator; * @param <M> Model object type * * @author Erich Schubert - * + * * @apiviz.landmark * * @apiviz.composedOf DBIDs * @apiviz.composedOf Model - * @apiviz.has Hierarchy */ -// TODO: return unmodifiable collections? -// TODO: disallow clusters without a DBIDs? -// TODO: add Model interface and delegations consequently since we have the -// DBID group and hierarchy delegators? -public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextWriteable { - /** - * Object that the hierarchy management is delegated to. - */ - private Hierarchy<Cluster<M>> hierarchy = null; - +public class Cluster<M extends Model> implements TextWriteable { /** * Cluster name. */ @@ -97,44 +78,13 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param ids Object Group * @param noise Noise flag * @param model Model. May be null. - * @param hierarchy Hierarchy object. May be null. */ - public Cluster(String name, DBIDs ids, boolean noise, M model, Hierarchy<Cluster<M>> hierarchy) { + public Cluster(String name, DBIDs ids, boolean noise, M model) { super(); - // TODO: any way to check that this is a C? (see asC() method) this.name = name; this.ids = ids; this.noise = noise; this.model = model; - this.hierarchy = hierarchy; - } - - /** - * Constructor with hierarchy information. A new FullHierarchy object will be - * created to store the hierarchy information. - * - * @param name Cluster name. May be null. - * @param ids Object Group - * @param noise Noise flag - * @param model Model. May be null. - * @param children Children. Will NOT be copied. - * @param parents Parents. Will NOT be copied. - */ - public Cluster(String name, DBIDs ids, boolean noise, M model, List<Cluster<M>> children, List<Cluster<M>> parents) { - this(name, ids, noise, model, null); - this.setHierarchy(new HierarchyReferenceLists<Cluster<M>>(this, children, parents)); - } - - /** - * Constructor without hierarchy information. - * - * @param name Cluster name. May be null. - * @param ids Object group - * @param noise Noise flag - * @param model Model - */ - public Cluster(String name, DBIDs ids, boolean noise, M model) { - this(name, ids, noise, model, null); } /** @@ -145,7 +95,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param model Model */ public Cluster(String name, DBIDs ids, M model) { - this(name, ids, false, model, null); + this(name, ids, false, model); } /** @@ -156,7 +106,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param model Model */ public Cluster(DBIDs ids, boolean noise, M model) { - this(null, ids, noise, model, null); + this(null, ids, noise, model); } /** @@ -166,7 +116,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param model Model */ public Cluster(DBIDs ids, M model) { - this(null, ids, false, model, null); + this(null, ids, false, model); } /** @@ -177,7 +127,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param noise Noise flag */ public Cluster(String name, DBIDs ids, boolean noise) { - this(name, ids, noise, null, null); + this(name, ids, noise, null); } /** @@ -187,7 +137,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param ids Object group */ public Cluster(String name, DBIDs ids) { - this(name, ids, false, null, null); + this(name, ids, false, null); } /** @@ -197,7 +147,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param noise Noise flag */ public Cluster(DBIDs ids, boolean noise) { - this(null, ids, noise, null, null); + this(null, ids, noise, null); } /** @@ -206,125 +156,7 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * @param ids Object group */ public Cluster(DBIDs ids) { - this(null, ids, false, null, null); - } - - /** - * Constructor with hierarchy but noise flag defaulting to false. - * - * @param name Cluster name. May be null. - * @param ids Object group - * @param model Model. May be null. - * @param hierarchy Hierarchy object. May be null. - */ - public Cluster(String name, DBIDs ids, M model, Hierarchy<Cluster<M>> hierarchy) { - this(name, ids, false, model, hierarchy); - } - - /** - * Constructor with hierarchy information, but no noise flag. A new - * FullHierarchy object will be created to store the hierarchy information. - * - * @param name Cluster name. May be null. - * @param ids Object Group - * @param model Model. May be null. - * @param children Children. Will NOT be copied. - * @param parents Parents. Will NOT be copied. - */ - public Cluster(String name, DBIDs ids, M model, List<Cluster<M>> children, List<Cluster<M>> parents) { - this(name, ids, false, model, null); - this.setHierarchy(new HierarchyReferenceLists<Cluster<M>>(this, children, parents)); - } - - /** - * Test hierarchy - */ - @Override - public final boolean isHierarchical() { - if(hierarchy == null) { - return false; - } - return true; - } - - /** - * Delegate to hierarchy object - */ - @Override - public int numChildren() { - if(hierarchy == null) { - return 0; - } - return hierarchy.numChildren(this); - } - - /** - * Delegate to hierarchy object - */ - @Override - public List<Cluster<M>> getChildren() { - if(hierarchy == null) { - return new ArrayList<Cluster<M>>(0); - } - return hierarchy.getChildren(this); - } - - /** - * Delegate to hierarchy object - */ - @Override - public Iterator<Cluster<M>> iterDescendants() { - if(hierarchy == null) { - return EmptyIterator.STATIC(); - } - return hierarchy.iterDescendants(this); - } - - /** - * Collect descendants - * - * @return Set of descendants - */ - public Set<Cluster<M>> getDescendants() { - HashSet<Cluster<M>> set = new HashSet<Cluster<M>>(); - // add all - for(Iterator<Cluster<M>> iter = iterDescendants(); iter.hasNext();) { - set.add(iter.next()); - } - return set; - } - - /** - * Delegate to hierarchy object - */ - @Override - public int numParents() { - if(hierarchy == null) { - return 0; - } - return hierarchy.numParents(this); - } - - /** - * Delegate to hierarchy object - */ - @Override - public List<Cluster<M>> getParents() { - if(hierarchy == null) { - return new ArrayList<Cluster<M>>(0); - } - return hierarchy.getParents(this); - } - - /** - * Delegate to hierarchy object - */ - @Override - public Iterator<Cluster<M>> iterAncestors() { - if(hierarchy == null) { - return EmptyIterator.STATIC(); - } - return hierarchy.iterAncestors(this); + this(null, ids, false, null); } /** @@ -337,36 +169,17 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW } /** - * Get hierarchy object - * - * @return hierarchy object - */ - public Hierarchy<Cluster<M>> getHierarchy() { - return hierarchy; - } - - /** - * Set hierarchy object - * - * @param hierarchy new hierarchy object - */ - public void setHierarchy(Hierarchy<Cluster<M>> hierarchy) { - this.hierarchy = hierarchy; - } - - /** * Return either the assigned name or the suggested label * * @return a name for the cluster */ public String getNameAutomatic() { - if(name != null) { + if (name != null) { return name; } - if(isNoise()) { + if (isNoise()) { return "Noise"; - } - else { + } else { return "Cluster"; } } @@ -436,34 +249,25 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW public void writeToText(TextWriterStream out, String label) { String name = getNameAutomatic(); out.commentPrintLn(TextWriterStream.SER_MARKER + " " + Cluster.class.getName()); - if(name != null) { + if (name != null) { out.commentPrintLn("Name: " + name); } out.commentPrintLn("Noise flag: " + isNoise()); out.commentPrintLn("Size: " + ids.size()); // print hierarchy information. - if(isHierarchical()) { - out.commentPrint("Parents: "); - for(int i = 0; i < numParents(); i++) { - if(i > 0) { - out.commentPrint(", "); - } - out.commentPrint(getParents().get(i).getNameAutomatic()); - } - out.commentPrintLn(); - out.commentPrint("Children: "); - for(int i = 0; i < numChildren(); i++) { - if(i > 0) { - out.commentPrint(", "); - } - out.commentPrint(getChildren().get(i).getNameAutomatic()); - } - out.commentPrintLn(); - } + /* + * if (isHierarchical()) { out.commentPrint("Parents: "); for (int i = 0; i + * < numParents(); i++) { if (i > 0) { out.commentPrint(", "); } + * out.commentPrint(getParents().get(i).getNameAutomatic()); } + * out.commentPrintLn(); out.commentPrint("Children: "); for (int i = 0; i < + * numChildren(); i++) { if (i > 0) { out.commentPrint(", "); } + * out.commentPrint(getChildren().get(i).getNameAutomatic()); } + * out.commentPrintLn(); } + */ // also print model, if any and printable - if(getModel() != null) { + if (getModel() != null) { out.commentPrintLn("Model class: " + getModel().getClass().getName()); - if(getModel() instanceof TextWriteable) { + if (getModel() instanceof TextWriteable) { ((TextWriteable) getModel()).writeToText(out, label); } } @@ -491,31 +295,27 @@ public class Cluster<M extends Model> implements Hierarchical<Cluster<M>>, TextW * A partial comparator for Clusters, based on their name. Useful for sorting * clusters. Do NOT use in e.g. a TreeSet since it is * <em>inconsistent with equals</em>. - * - * @author Erich Schubert - * - * @apiviz.exclude */ - public static class PartialComparator implements Comparator<Cluster<?>> { + public static Comparator<Cluster<?>> BY_NAME_SORTER = new Comparator<Cluster<?>>() { @Override public int compare(Cluster<?> o1, Cluster<?> o2) { - if(o1 == o2) { + if (o1 == o2) { return 0; } // sort by label if possible - if(o1 != null && o1.name != null && o2 != null && o2.name != null) { + if (o1 != null && o1.name != null && o2 != null && o2.name != null) { int lblresult = o1.name.compareTo(o2.getName()); - if(lblresult != 0) { + if (lblresult != 0) { return lblresult; } } int hashresult = o1.hashCode() - o2.hashCode(); - if(hashresult != 0) { + if (hashresult != 0) { return hashresult; } return 0; } - } + }; /** {@inheritDoc} */ @Override diff --git a/src/de/lmu/ifi/dbs/elki/data/Clustering.java b/src/de/lmu/ifi/dbs/elki/data/Clustering.java index f4312c4c..ae70662e 100644 --- a/src/de/lmu/ifi/dbs/elki/data/Clustering.java +++ b/src/de/lmu/ifi/dbs/elki/data/Clustering.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -25,13 +25,15 @@ package de.lmu.ifi.dbs.elki.data; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; import de.lmu.ifi.dbs.elki.data.model.Model; import de.lmu.ifi.dbs.elki.result.BasicResult; +import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.HashMapHierarchy; +import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.Hierarchy; +import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.Hierarchy.Iter; +import de.lmu.ifi.dbs.elki.utilities.datastructures.hierarchy.ModifiableHierarchy; /** * Result class for clusterings. Can be used for both hierarchical and @@ -41,8 +43,9 @@ import de.lmu.ifi.dbs.elki.result.BasicResult; * instead they can be an arbitrary forest of directed graphs that COULD contain * cycles. * - * This class is NOT iterable for a simple reason: there is more than one method to do so. - * You need to specify whether you want to use getToplevelClusters() or getAllClusters(). + * This class is NOT iterable for a simple reason: there is more than one method + * to do so. You need to specify whether you want to use getToplevelClusters() + * or getAllClusters(). * * @author Erich Schubert * @@ -57,6 +60,11 @@ public class Clustering<M extends Model> extends BasicResult { private List<Cluster<M>> toplevelclusters; /** + * Cluster hierarchy. + */ + private ModifiableHierarchy<Cluster<M>> hierarchy; + + /** * Constructor with a list of top level clusters * * @param name The long name (for pretty printing) @@ -66,6 +74,7 @@ public class Clustering<M extends Model> extends BasicResult { public Clustering(String name, String shortname, List<Cluster<M>> toplevelclusters) { super(name, shortname); this.toplevelclusters = toplevelclusters; + this.hierarchy = new HashMapHierarchy<>(); } /** @@ -81,10 +90,21 @@ public class Clustering<M extends Model> extends BasicResult { /** * Add a cluster to the clustering. * - * @param n new cluster + * @param clus new cluster + */ + public void addToplevelCluster(Cluster<M> clus) { + toplevelclusters.add(clus); + hierarchy.add(clus); + } + + /** + * Add a cluster to the clustering. + * + * @param parent Parent cluster + * @param child Child cluster. */ - public void addCluster(Cluster<M> n) { - toplevelclusters.add(n); + public void addChildCluster(Cluster<M> parent, Cluster<M> child) { + hierarchy.add(parent, child); } /** @@ -97,24 +117,62 @@ public class Clustering<M extends Model> extends BasicResult { } /** + * Get the cluster hierarchy. + * + * @return Cluster hierarchy. + */ + public Hierarchy<Cluster<M>> getClusterHierarchy() { + return hierarchy; + } + + /** * Collect all clusters (recursively) into a List. * * @return List of all clusters. */ public List<Cluster<M>> getAllClusters() { - Set<Cluster<M>> clu = new HashSet<Cluster<M>>(); - for(Cluster<M> rc : toplevelclusters) { - if(!clu.contains(rc)) { - clu.add(rc); - for (Iterator<Cluster<M>> iter = rc.iterDescendants(); iter.hasNext(); ) { - clu.add(iter.next()); - } - } + ArrayList<Cluster<M>> res = new ArrayList<>(hierarchy.size()); + for (Hierarchy.Iter<Cluster<M>> iter = hierarchy.iterAll(); iter.valid(); iter.advance()) { + res.add(iter.get()); } - // Note: we canNOT use TreeSet above, because this comparator is only - // partial! - ArrayList<Cluster<M>> res = new ArrayList<Cluster<M>>(clu); - Collections.sort(res, new Cluster.PartialComparator()); + Collections.sort(res, Cluster.BY_NAME_SORTER); return res; } + + /** + * Iterate over the top level clusters. + * + * @return Iterator + */ + public Iter<Cluster<M>> iterToplevelClusters() { + return new Hierarchy.Iter<Cluster<M>>() { + Iterator<Cluster<M>> iter; + + Cluster<M> cur; + + { // Constructor. + iter = toplevelclusters.iterator(); + advance(); + } + + @Override + public boolean valid() { + return cur != null; + } + + @Override + public void advance() { + if (iter.hasNext()) { + cur = iter.next(); + } else { + cur = null; + } + } + + @Override + public Cluster<M> get() { + return cur; + } + }; + } } diff --git a/src/de/lmu/ifi/dbs/elki/data/DoubleVector.java b/src/de/lmu/ifi/dbs/elki/data/DoubleVector.java index dfc0a316..6c13c342 100644 --- a/src/de/lmu/ifi/dbs/elki/data/DoubleVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/DoubleVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -142,29 +142,17 @@ public class DoubleVector extends AbstractNumberVector<Double> { @Override @Deprecated public Double getValue(int dimension) { - try { - return values[dimension]; - } catch (IndexOutOfBoundsException e) { - throw new IllegalArgumentException("Dimension " + dimension + " out of range."); - } + return values[dimension]; } @Override public double doubleValue(int dimension) { - try { - return values[dimension]; - } catch (IndexOutOfBoundsException e) { - throw new IllegalArgumentException("Dimension " + dimension + " out of range."); - } + return values[dimension]; } @Override public long longValue(int dimension) { - try { - return (long) values[dimension]; - } catch (IndexOutOfBoundsException e) { - throw new IllegalArgumentException("Dimension " + dimension + " out of range."); - } + return (long) values[dimension]; } /** @@ -354,7 +342,6 @@ public class DoubleVector extends AbstractNumberVector<Double> { @Override public void toByteBuffer(ByteBuffer buffer, DoubleVector vec) throws IOException { - assert (vec.values.length < Short.MAX_VALUE) : "This serializer only supports a maximum dimensionality of " + Short.MAX_VALUE + "!"; assert (buffer.remaining() >= ByteArrayUtil.SIZE_DOUBLE * vec.values.length); ByteArrayUtil.writeUnsignedVarint(buffer, vec.values.length); for (int i = 0; i < vec.values.length; i++) { @@ -364,7 +351,6 @@ public class DoubleVector extends AbstractNumberVector<Double> { @Override public int getByteSize(DoubleVector vec) { - assert (vec.values.length < Short.MAX_VALUE) : "This serializer only supports a maximum dimensionality of " + Short.MAX_VALUE + "!"; return ByteArrayUtil.getUnsignedVarintSize(vec.values.length) + ByteArrayUtil.SIZE_DOUBLE * vec.values.length; } } diff --git a/src/de/lmu/ifi/dbs/elki/data/ExternalID.java b/src/de/lmu/ifi/dbs/elki/data/ExternalID.java index 1fc9873c..702b0431 100644 --- a/src/de/lmu/ifi/dbs/elki/data/ExternalID.java +++ b/src/de/lmu/ifi/dbs/elki/data/ExternalID.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/FeatureVector.java b/src/de/lmu/ifi/dbs/elki/data/FeatureVector.java index c3b255c6..f6f2f751 100644 --- a/src/de/lmu/ifi/dbs/elki/data/FeatureVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/FeatureVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -48,8 +48,8 @@ public interface FeatureVector<D> { /** * Returns the value in the specified dimension. * - * @param dimension the desired dimension, where 1 ≤ dimension ≤ - * <code>this.getDimensionality()</code> + * @param dimension the desired dimension, where 0 ≤ dimension ≤ + * <code>this.getDimensionality()-1</code> * @return the value in the specified dimension */ D getValue(int dimension); diff --git a/src/de/lmu/ifi/dbs/elki/data/FloatVector.java b/src/de/lmu/ifi/dbs/elki/data/FloatVector.java index 821c16c3..d750af01 100644 --- a/src/de/lmu/ifi/dbs/elki/data/FloatVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/FloatVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/HierarchicalClassLabel.java b/src/de/lmu/ifi/dbs/elki/data/HierarchicalClassLabel.java index 3db21bd8..7e84b2bf 100644 --- a/src/de/lmu/ifi/dbs/elki/data/HierarchicalClassLabel.java +++ b/src/de/lmu/ifi/dbs/elki/data/HierarchicalClassLabel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -49,7 +49,7 @@ public class HierarchicalClassLabel extends ClassLabel { /** * Type information. */ - public static final SimpleTypeInformation<HierarchicalClassLabel> TYPE = new SimpleTypeInformation<HierarchicalClassLabel>(HierarchicalClassLabel.class); + public static final SimpleTypeInformation<HierarchicalClassLabel> TYPE = new SimpleTypeInformation<>(HierarchicalClassLabel.class); /** * Holds the Pattern to separate different levels parsing input. diff --git a/src/de/lmu/ifi/dbs/elki/data/HyperBoundingBox.java b/src/de/lmu/ifi/dbs/elki/data/HyperBoundingBox.java index 299f329b..a1533b0c 100644 --- a/src/de/lmu/ifi/dbs/elki/data/HyperBoundingBox.java +++ b/src/de/lmu/ifi/dbs/elki/data/HyperBoundingBox.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -136,7 +136,7 @@ public class HyperBoundingBox implements SpatialComparable, Externalizable { */ @Override public String toString() { - return "[Min(" + FormatUtil.format(min, ",", FormatUtil.NF8) + "), Max(" + FormatUtil.format(max, ",", FormatUtil.NF8) + ")]"; + return "[Min(" + FormatUtil.format(min, ",", FormatUtil.NF) + "), Max(" + FormatUtil.format(max, ",", FormatUtil.NF) + ")]"; } /** diff --git a/src/de/lmu/ifi/dbs/elki/data/IntegerVector.java b/src/de/lmu/ifi/dbs/elki/data/IntegerVector.java index 595fcd94..a5f95650 100644 --- a/src/de/lmu/ifi/dbs/elki/data/IntegerVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/IntegerVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -98,7 +98,7 @@ public class IntegerVector extends AbstractNumberVector<Integer> { * Returns the value of the specified attribute. * * @param dimension the selected attribute. Attributes are counted starting - * with 1. + * with 0. * * @throws IllegalArgumentException if the specified dimension is out of range * of the possible attributes @@ -109,7 +109,7 @@ public class IntegerVector extends AbstractNumberVector<Integer> { @Deprecated public Integer getValue(int dimension) { try { - return Integer.valueOf(values[dimension - 1]); + return Integer.valueOf(values[dimension]); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException("Dimension " + dimension + " out of range."); } @@ -119,7 +119,7 @@ public class IntegerVector extends AbstractNumberVector<Integer> { * Returns the value of the specified attribute. * * @param dimension the selected attribute. Attributes are counted starting - * with 1. + * with 0. * * @throws IllegalArgumentException if the specified dimension is out of range * of the possible attributes @@ -129,7 +129,7 @@ public class IntegerVector extends AbstractNumberVector<Integer> { @Override public double doubleValue(int dimension) { try { - return values[dimension - 1]; + return values[dimension]; } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException("Dimension " + dimension + " out of range."); } @@ -139,7 +139,7 @@ public class IntegerVector extends AbstractNumberVector<Integer> { * Returns the value of the specified attribute as long. * * @param dimension the selected attribute. Attributes are counted starting - * with 1. + * with 0. * * @throws IllegalArgumentException if the specified dimension is out of range * of the possible attributes @@ -149,7 +149,7 @@ public class IntegerVector extends AbstractNumberVector<Integer> { @Override public long longValue(int dimension) { try { - return values[dimension - 1]; + return values[dimension]; } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException("Dimension " + dimension + " out of range."); } diff --git a/src/de/lmu/ifi/dbs/elki/data/Interval.java b/src/de/lmu/ifi/dbs/elki/data/Interval.java index 1b16fb88..978f9153 100644 --- a/src/de/lmu/ifi/dbs/elki/data/Interval.java +++ b/src/de/lmu/ifi/dbs/elki/data/Interval.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/LabelList.java b/src/de/lmu/ifi/dbs/elki/data/LabelList.java index 0301eff3..74685710 100644 --- a/src/de/lmu/ifi/dbs/elki/data/LabelList.java +++ b/src/de/lmu/ifi/dbs/elki/data/LabelList.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/ModifiableHyperBoundingBox.java b/src/de/lmu/ifi/dbs/elki/data/ModifiableHyperBoundingBox.java index 360fe5e9..3f1a3c8e 100644 --- a/src/de/lmu/ifi/dbs/elki/data/ModifiableHyperBoundingBox.java +++ b/src/de/lmu/ifi/dbs/elki/data/ModifiableHyperBoundingBox.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -82,7 +82,7 @@ public class ModifiableHyperBoundingBox extends HyperBoundingBox { * <code>dimension</code> */ public void setMax(int dimension, double value) { - max[dimension - 1] = value; + max[dimension] = value; } /** @@ -95,7 +95,7 @@ public class ModifiableHyperBoundingBox extends HyperBoundingBox { * <code>dimension</code> */ public void setMin(int dimension, double value) { - max[dimension - 1] = value; + max[dimension] = value; } /** diff --git a/src/de/lmu/ifi/dbs/elki/data/NumberVector.java b/src/de/lmu/ifi/dbs/elki/data/NumberVector.java index ac5e302a..4fbd36dd 100644 --- a/src/de/lmu/ifi/dbs/elki/data/NumberVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/NumberVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/OneDimensionalDoubleVector.java b/src/de/lmu/ifi/dbs/elki/data/OneDimensionalDoubleVector.java index 7198d820..3412c835 100644 --- a/src/de/lmu/ifi/dbs/elki/data/OneDimensionalDoubleVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/OneDimensionalDoubleVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/RationalNumber.java b/src/de/lmu/ifi/dbs/elki/data/RationalNumber.java index cf388481..6d9cbe8f 100644 --- a/src/de/lmu/ifi/dbs/elki/data/RationalNumber.java +++ b/src/de/lmu/ifi/dbs/elki/data/RationalNumber.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java b/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java index b0ee779c..8799370d 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java +++ b/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseDoubleVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseDoubleVector.java index 1b07d5e9..110f3084 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SparseDoubleVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/SparseDoubleVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -28,10 +28,13 @@ import gnu.trove.iterator.TIntDoubleIterator; import gnu.trove.map.TIntDoubleMap; import gnu.trove.map.hash.TIntDoubleHashMap; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.Arrays; import java.util.BitSet; import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; +import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil; import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayAdapter; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.NumberArrayAdapter; @@ -47,7 +50,6 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; * * @author Arthur Zimek */ -// TODO: implement ByteArraySerializer<SparseDoubleVector> public class SparseDoubleVector extends AbstractNumberVector<Double> implements SparseNumberVector<Double> { /** * Static instance. @@ -55,6 +57,11 @@ public class SparseDoubleVector extends AbstractNumberVector<Double> implements public static final SparseDoubleVector.Factory FACTORY = new SparseDoubleVector.Factory(); /** + * Serializer using varint encoding. + */ + public static final ByteBufferSerializer<SparseDoubleVector> VARIABLE_SERIALIZER = new VariableSerializer(); + + /** * Indexes of values. */ private final int[] indexes; @@ -165,7 +172,7 @@ public class SparseDoubleVector extends AbstractNumberVector<Double> implements for (int i = 0; i < values.length; i++) { double value = values[i]; if (value != 0.0f) { - this.indexes[pos] = i + 1; + this.indexes[pos] = i; this.values[pos] = value; pos++; } @@ -296,7 +303,7 @@ public class SparseDoubleVector extends AbstractNumberVector<Double> implements for (int i = 0; i < dim; i++) { values[i] = adapter.get(array, i); } - // TODO: inefficient + // TODO: improve efficiency return new SparseDoubleVector(values); } @@ -307,7 +314,7 @@ public class SparseDoubleVector extends AbstractNumberVector<Double> implements for (int i = 0; i < dim; i++) { values[i] = adapter.getDouble(array, i); } - // TODO: inefficient + // TODO: improve efficiency return new SparseDoubleVector(values); } @@ -318,10 +325,9 @@ public class SparseDoubleVector extends AbstractNumberVector<Double> implements @Override public ByteBufferSerializer<SparseDoubleVector> getDefaultSerializer() { - // FIXME: add a serializer - return null; + return VARIABLE_SERIALIZER; } - + @Override public Class<? super SparseDoubleVector> getRestrictionClass() { return SparseDoubleVector.class; @@ -355,4 +361,48 @@ public class SparseDoubleVector extends AbstractNumberVector<Double> implements * Empty map. */ public static final TIntDoubleMap EMPTYMAP = new TUnmodifiableIntDoubleMap(new TIntDoubleHashMap()); + + /** + * Serialization class using VarInt encodings. + * + * @author Erich Schubert + * + * @apiviz.uses SparseDoubleVector - - «serializes» + */ + public static class VariableSerializer implements ByteBufferSerializer<SparseDoubleVector> { + @Override + public SparseDoubleVector fromByteBuffer(ByteBuffer buffer) throws IOException { + final int dimensionality = ByteArrayUtil.readUnsignedVarint(buffer); + final int nonzero = ByteArrayUtil.readUnsignedVarint(buffer); + final int[] dims = new int[nonzero]; + final double[] values = new double[nonzero]; + for (int i = 0; i < nonzero; i++) { + dims[i] = ByteArrayUtil.readUnsignedVarint(buffer); + values[i] = buffer.getDouble(); + } + return new SparseDoubleVector(dims, values, dimensionality); + } + + @Override + public void toByteBuffer(ByteBuffer buffer, SparseDoubleVector vec) throws IOException { + ByteArrayUtil.writeUnsignedVarint(buffer, vec.dimensionality); + ByteArrayUtil.writeUnsignedVarint(buffer, vec.values.length); + for (int i = 0; i < vec.values.length; i++) { + ByteArrayUtil.writeUnsignedVarint(buffer, vec.indexes[i]); + buffer.putDouble(vec.values[i]); + } + } + + @Override + public int getByteSize(SparseDoubleVector vec) { + int sum = 0; + sum += ByteArrayUtil.getUnsignedVarintSize(vec.dimensionality); + sum += ByteArrayUtil.getUnsignedVarintSize(vec.values.length); + for (int d : vec.indexes) { + sum += ByteArrayUtil.getUnsignedVarintSize(d); + } + sum += vec.values.length * ByteArrayUtil.SIZE_DOUBLE; + return sum; + } + } } diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseFeatureVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseFeatureVector.java index 97ec8857..a430ad3c 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SparseFeatureVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/SparseFeatureVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java index de3e7293..ca337b4b 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -30,10 +30,13 @@ import gnu.trove.map.TIntDoubleMap; import gnu.trove.map.TIntFloatMap; import gnu.trove.map.hash.TIntFloatHashMap; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.Arrays; import java.util.BitSet; import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; +import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil; import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayAdapter; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.NumberArrayAdapter; @@ -49,7 +52,6 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; * * @author Arthur Zimek */ -// TODO: implement ByteArraySerializer<SparseFloatVector> public class SparseFloatVector extends AbstractNumberVector<Float> implements SparseNumberVector<Float> { /** * Static instance. @@ -57,6 +59,11 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp public static final SparseFloatVector.Factory FACTORY = new SparseFloatVector.Factory(); /** + * Serializer using varint encoding. + */ + public static final ByteBufferSerializer<SparseFloatVector> VARIABLE_SERIALIZER = new VariableSerializer(); + + /** * Indexes of values. */ private final int[] indexes; @@ -167,7 +174,7 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp for (int i = 0; i < values.length; i++) { float value = values[i]; if (value != 0.0f) { - this.indexes[pos] = i + 1; + this.indexes[pos] = i; this.values[pos] = value; pos++; } @@ -333,8 +340,7 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp @Override public ByteBufferSerializer<SparseFloatVector> getDefaultSerializer() { - // FIXME: add a serializer - return null; + return VARIABLE_SERIALIZER; } @Override @@ -370,4 +376,48 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp * Empty map. */ public static final TIntFloatMap EMPTYMAP = new TUnmodifiableIntFloatMap(new TIntFloatHashMap()); + + /** + * Serialization class using VarInt encodings. + * + * @author Erich Schubert + * + * @apiviz.uses SparseFloatVector - - «serializes» + */ + public static class VariableSerializer implements ByteBufferSerializer<SparseFloatVector> { + @Override + public SparseFloatVector fromByteBuffer(ByteBuffer buffer) throws IOException { + final int dimensionality = ByteArrayUtil.readUnsignedVarint(buffer); + final int nonzero = ByteArrayUtil.readUnsignedVarint(buffer); + final int[] dims = new int[nonzero]; + final float[] values = new float[nonzero]; + for (int i = 0; i < nonzero; i++) { + dims[i] = ByteArrayUtil.readUnsignedVarint(buffer); + values[i] = buffer.getFloat(); + } + return new SparseFloatVector(dims, values, dimensionality); + } + + @Override + public void toByteBuffer(ByteBuffer buffer, SparseFloatVector vec) throws IOException { + ByteArrayUtil.writeUnsignedVarint(buffer, vec.dimensionality); + ByteArrayUtil.writeUnsignedVarint(buffer, vec.values.length); + for (int i = 0; i < vec.values.length; i++) { + ByteArrayUtil.writeUnsignedVarint(buffer, vec.indexes[i]); + buffer.putFloat(vec.values[i]); + } + } + + @Override + public int getByteSize(SparseFloatVector vec) { + int sum = 0; + sum += ByteArrayUtil.getUnsignedVarintSize(vec.dimensionality); + sum += ByteArrayUtil.getUnsignedVarintSize(vec.values.length); + for (int d : vec.indexes) { + sum += ByteArrayUtil.getUnsignedVarintSize(d); + } + sum += vec.values.length * ByteArrayUtil.SIZE_FLOAT; + return sum; + } + } } diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseNumberVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseNumberVector.java index 6ac1cc66..26ab968a 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SparseNumberVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/SparseNumberVector.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/Subspace.java b/src/de/lmu/ifi/dbs/elki/data/Subspace.java index 8a6a2d14..a564d8b5 100644 --- a/src/de/lmu/ifi/dbs/elki/data/Subspace.java +++ b/src/de/lmu/ifi/dbs/elki/data/Subspace.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/VectorUtil.java b/src/de/lmu/ifi/dbs/elki/data/VectorUtil.java index ce8102fc..205dee17 100644 --- a/src/de/lmu/ifi/dbs/elki/data/VectorUtil.java +++ b/src/de/lmu/ifi/dbs/elki/data/VectorUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data; 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 @@ -38,6 +38,7 @@ import de.lmu.ifi.dbs.elki.database.relation.Relation; import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; import de.lmu.ifi.dbs.elki.math.DoubleMinMax; import de.lmu.ifi.dbs.elki.math.MathUtil; +import de.lmu.ifi.dbs.elki.math.linearalgebra.Matrix; import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; import de.lmu.ifi.dbs.elki.utilities.datastructures.QuickSelect; @@ -68,7 +69,7 @@ public final class VectorUtil { public static DoubleMinMax getRangeDouble(NumberVector<?> vec) { DoubleMinMax minmax = new DoubleMinMax(); - for(int i = 0; i < vec.getDimensionality(); i++) { + for (int i = 0; i < vec.getDimensionality(); i++) { minmax.put(vec.doubleValue(i)); } @@ -77,7 +78,7 @@ public final class VectorUtil { /** * Produce a new vector based on random numbers in [0:1]. - * + * * @param factory Vector factory * @param dim desired dimensionality * @param r Random generator @@ -113,9 +114,10 @@ public final class VectorUtil { BitSet both = (BitSet) b1.clone(); both.and(b2); + // TODO: add precomputed length to data type! // Length of first vector double l1 = 0.0; - for(int i = b1.nextSetBit(0); i >= 0; i = b1.nextSetBit(i + 1)) { + for (int i = b1.nextSetBit(0); i >= 0; i = b1.nextSetBit(i + 1)) { final double val = v1.doubleValue(i); l1 += val * val; } @@ -123,7 +125,7 @@ public final class VectorUtil { // Length of second vector double l2 = 0.0; - for(int i = b2.nextSetBit(0); i >= 0; i = b2.nextSetBit(i + 1)) { + for (int i = b2.nextSetBit(0); i >= 0; i = b2.nextSetBit(i + 1)) { final double val = v2.doubleValue(i); l2 += val * val; } @@ -131,10 +133,11 @@ public final class VectorUtil { // Cross product double cross = 0.0; - for(int i = both.nextSetBit(0); i >= 0; i = both.nextSetBit(i + 1)) { + for (int i = both.nextSetBit(0); i >= 0; i = both.nextSetBit(i + 1)) { cross += v1.doubleValue(i) * v2.doubleValue(i); } - return cross / (l1 * l2); + final double a = cross / (l1 * l2); + return (a > 1.0) ? 1.0 : a; } /** @@ -153,14 +156,15 @@ public final class VectorUtil { double[] oe = o.getArrayRef(); final int dim = v1.getDimensionality(); double s = 0, e1 = 0, e2 = 0; - for(int k = 0; k < dim; k++) { + for (int k = 0; k < dim; k++) { final double r1 = v1.doubleValue(k) - oe[k]; final double r2 = v2.doubleValue(k) - oe[k]; s += r1 * r2; e1 += r1 * r1; e2 += r2 * r2; } - return Math.sqrt((s / e1) * (s / e2)); + final double a = Math.sqrt((s / e1) * (s / e2)); + return (a > 1.0) ? 1.0 : a; } /** @@ -178,14 +182,15 @@ public final class VectorUtil { // We can just compute all three in parallel. final int dim = v1.getDimensionality(); double s = 0, e1 = 0, e2 = 0; - for(int k = 0; k < dim; k++) { + for (int k = 0; k < dim; k++) { final double r1 = v1.doubleValue(k) - o.doubleValue(k); final double r2 = v2.doubleValue(k) - o.doubleValue(k); s += r1 * r2; e1 += r1 * r1; e2 += r2 * r2; } - return Math.sqrt((s / e1) * (s / e2)); + final double a = Math.sqrt((s / e1) * (s / e2)); + return (a > 1.0) ? 1.0 : a; } /** @@ -198,7 +203,7 @@ public final class VectorUtil { * @return Angle */ public static double cosAngle(NumberVector<?> v1, NumberVector<?> v2) { - if(v1 instanceof SparseNumberVector<?> && v2 instanceof SparseNumberVector<?>) { + if (v1 instanceof SparseNumberVector<?> && v2 instanceof SparseNumberVector<?>) { return angleSparse((SparseNumberVector<?>) v1, (SparseNumberVector<?>) v2); } // Essentially, we want to compute this: @@ -208,22 +213,23 @@ public final class VectorUtil { final int d2 = v2.getDimensionality(); final int dim = Math.min(d1, d2); double s = 0, e1 = 0, e2 = 0; - for(int k = 0; k < dim; k++) { + for (int k = 0; k < dim; k++) { final double r1 = v1.doubleValue(k); final double r2 = v2.doubleValue(k); s += r1 * r2; e1 += r1 * r1; e2 += r2 * r2; } - for(int k = dim; k < d1; k++) { + for (int k = dim; k < d1; k++) { final double r1 = v1.doubleValue(k); e1 += r1 * r1; } - for(int k = dim; k < d2; k++) { + for (int k = dim; k < d2; k++) { final double r2 = v2.doubleValue(k); e2 += r2 * r2; } - return Math.min(Math.sqrt((s / e1) * (s / e2)), 1); + final double a = Math.sqrt((s / e1) * (s / e2)); + return (a > 1.0) ? 1.0 : a; } // TODO: add more precise but slower O(n^2) angle computation according to: @@ -238,7 +244,7 @@ public final class VectorUtil { * @return Angle */ public static double minCosAngle(SpatialComparable v1, SpatialComparable v2) { - if(v1 instanceof NumberVector<?> && v2 instanceof NumberVector<?>) { + if (v1 instanceof NumberVector<?> && v2 instanceof NumberVector<?>) { return cosAngle((NumberVector<?>) v1, (NumberVector<?>) v2); } // Essentially, we want to compute this: @@ -246,28 +252,27 @@ public final class VectorUtil { // We can just compute all three in parallel. final int dim = v1.getDimensionality(); double s1 = 0, s2 = 0, e1 = 0, e2 = 0; - for(int k = 0; k < dim; k++) { + for (int k = 0; k < dim; k++) { final double min1 = v1.getMin(k), max1 = v1.getMax(k); final double min2 = v2.getMin(k), max2 = v2.getMax(k); final double p1 = min1 * min2, p2 = min1 * max2; final double p3 = max1 * min2, p4 = max1 * max2; s1 += Math.max(Math.max(p1, p2), Math.max(p3, p4)); s2 += Math.min(Math.min(p1, p2), Math.min(p3, p4)); - if(max1 < 0) { + if (max1 < 0) { e1 += max1 * max1; - } - else if(min1 > 0) { + } else if (min1 > 0) { e1 += min1 * min1; } // else: 0 - if(max2 < 0) { + if (max2 < 0) { e2 += max2 * max2; - } - else if(min2 > 0) { + } else if (min2 > 0) { e2 += min2 * min2; } // else: 0 } final double s = Math.max(s1, Math.abs(s2)); - return Math.min(Math.sqrt((s / e1) * (s / e2)), 1.0); + final double a = Math.sqrt((s / e1) * (s / e2)); + return (a > 1.0) ? 1.0 : a; } /** @@ -282,7 +287,7 @@ public final class VectorUtil { public static double scalarProduct(NumberVector<?> d1, NumberVector<?> d2) { final int dim = d1.getDimensionality(); double result = 0.0; - for(int i = 0; i < dim; i++) { + for (int i = 0; i < dim; i++) { result += d1.doubleValue(i) * d2.doubleValue(i); } return result; @@ -308,10 +313,35 @@ public final class VectorUtil { } /** + * This is an ugly hack, but we don't want to have the {@link Matrix} class + * depend on {@link NumberVector}. Maybe a future version will no longer need + * this. + * + * @param mat Matrix + * @param v Vector + * @return {@code mat * v}, as double array. + */ + public static double[] fastTimes(Matrix mat, NumberVector<?> v) { + final double[][] elements = mat.getArrayRef(); + final int cdim = mat.getColumnDimensionality(); + final double[] X = new double[elements.length]; + // multiply it with each row from A + for (int i = 0; i < elements.length; i++) { + final double[] Arowi = elements[i]; + double s = 0; + for (int k = 0; k < cdim; k++) { + s += Arowi[k] * v.doubleValue(k); + } + X[i] = s; + } + return X; + } + + /** * Compare number vectors by a single dimension. * * @author Erich Schubert - * + * * @apiviz.exclude */ public static class SortDBIDsBySingleDimension implements Comparator<DBIDRef> { @@ -363,7 +393,7 @@ public final class VectorUtil { * Compare number vectors by a single dimension. * * @author Erich Schubert - * + * * @apiviz.exclude */ public static class SortVectorsBySingleDimension implements Comparator<NumberVector<?>> { @@ -421,7 +451,8 @@ public final class VectorUtil { values.put(d, v.doubleValue(d)); } } - // We can't avoid this cast, because Java doesn't know that V is a SparseNumberVector: + // We can't avoid this cast, because Java doesn't know that V is a + // SparseNumberVector: @SuppressWarnings("unchecked") V projectedVector = (V) sfactory.newNumberVector(values, selectedAttributes.cardinality()); return projectedVector; diff --git a/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java index cb6ca494..25181acd 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/AbstractComputeColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java b/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java index e45d27bd..1c3037d6 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/BlendComposite.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java index a13a4086..daa74726 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java index e9b428f1..96f3bf73 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeHSBColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java index 30fe21be..d6bf2e6c 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveHSBColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java index d28ed29b..5c40262e 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ComputeNaiveRGBColorHistogram.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java b/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java index 10722c36..06363625 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/ImageUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.images; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/images/package-info.java b/src/de/lmu/ifi/dbs/elki/data/images/package-info.java index 4a9d19ac..1a76913e 100644 --- a/src/de/lmu/ifi/dbs/elki/data/images/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/images/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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/BaseModel.java b/src/de/lmu/ifi/dbs/elki/data/model/BaseModel.java index 56d7cd3f..98fa0567 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/BaseModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/BaseModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/Bicluster.java b/src/de/lmu/ifi/dbs/elki/data/model/Bicluster.java index eb7755a7..27cdef74 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/Bicluster.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/Bicluster.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/BiclusterWithInverted.java b/src/de/lmu/ifi/dbs/elki/data/model/BiclusterWithInverted.java index 1f582fdd..12d4f18b 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/BiclusterWithInverted.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/BiclusterWithInverted.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/ClusterModel.java b/src/de/lmu/ifi/dbs/elki/data/model/ClusterModel.java index 5bd3123c..eacab5bc 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/ClusterModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/ClusterModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/CoreObjectsModel.java b/src/de/lmu/ifi/dbs/elki/data/model/CoreObjectsModel.java new file mode 100644 index 00000000..4a79d350 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/model/CoreObjectsModel.java @@ -0,0 +1,63 @@ +package de.lmu.ifi.dbs.elki.data.model; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.database.ids.DBIDs; + +/** + * Cluster model using "core" objects. Currently only used by the Generalized + * DBSCAN implementation when the {@code -gdbscan.core-model} flag is set. + * + * @author Erich Schubert + */ +public class CoreObjectsModel extends BaseModel { + /** + * Objects that are part of the cluster core. + */ + DBIDs core; + + /** + * Constructor. + * + * @param core Core objects + */ + public CoreObjectsModel(DBIDs core) { + super(); + this.core = core; + } + + /** + * Get the core object IDs. + * + * @return Core object IDs + */ + public DBIDs getCoreObjects() { + return core; + } + + @Override + public String toString() { + return "CoreModel"; + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/model/CorrelationAnalysisSolution.java b/src/de/lmu/ifi/dbs/elki/data/model/CorrelationAnalysisSolution.java index 4240cb83..364fc3dc 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/CorrelationAnalysisSolution.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/CorrelationAnalysisSolution.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/CorrelationModel.java b/src/de/lmu/ifi/dbs/elki/data/model/CorrelationModel.java index 1a111985..6cfa5137 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/CorrelationModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/CorrelationModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/DendrogramModel.java b/src/de/lmu/ifi/dbs/elki/data/model/DendrogramModel.java index 0ea1fe2b..ac1c53f0 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/DendrogramModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/DendrogramModel.java @@ -3,7 +3,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/DimensionModel.java b/src/de/lmu/ifi/dbs/elki/data/model/DimensionModel.java index 104ade9a..36b5653e 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/DimensionModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/DimensionModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/EMModel.java b/src/de/lmu/ifi/dbs/elki/data/model/EMModel.java index 3856b9b1..e83f4c72 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/EMModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/EMModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/KMeansModel.java b/src/de/lmu/ifi/dbs/elki/data/model/KMeansModel.java index da6e81f8..a1867695 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/KMeansModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/KMeansModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/LinearEquationModel.java b/src/de/lmu/ifi/dbs/elki/data/model/LinearEquationModel.java index 366c7717..cff9cc42 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/LinearEquationModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/LinearEquationModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/MeanModel.java b/src/de/lmu/ifi/dbs/elki/data/model/MeanModel.java index 15c3d571..84896d06 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/MeanModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/MeanModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/MedoidModel.java b/src/de/lmu/ifi/dbs/elki/data/model/MedoidModel.java index 5540b931..6df2356d 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/MedoidModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/MedoidModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/Model.java b/src/de/lmu/ifi/dbs/elki/data/model/Model.java index 627bc084..fb2d533f 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/Model.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/Model.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/OPTICSModel.java b/src/de/lmu/ifi/dbs/elki/data/model/OPTICSModel.java index 16a9619b..bf942ff5 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/OPTICSModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/OPTICSModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/SubspaceModel.java b/src/de/lmu/ifi/dbs/elki/data/model/SubspaceModel.java index 65607d8a..1cace130 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/SubspaceModel.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/SubspaceModel.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.model; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/model/package-info.java b/src/de/lmu/ifi/dbs/elki/data/model/package-info.java index c8f514ec..a7789826 100644 --- a/src/de/lmu/ifi/dbs/elki/data/model/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/model/package-info.java @@ -8,7 +8,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 diff --git a/src/de/lmu/ifi/dbs/elki/data/package-info.java b/src/de/lmu/ifi/dbs/elki/data/package-info.java index 8d1eb82f..73d500ea 100644 --- a/src/de/lmu/ifi/dbs/elki/data/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/package-info.java @@ -15,7 +15,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 diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/FeatureSelection.java b/src/de/lmu/ifi/dbs/elki/data/projection/FeatureSelection.java index bcb64800..f60f1145 100644 --- a/src/de/lmu/ifi/dbs/elki/data/projection/FeatureSelection.java +++ b/src/de/lmu/ifi/dbs/elki/data/projection/FeatureSelection.java @@ -1,9 +1,10 @@ package de.lmu.ifi.dbs.elki.data.projection; + /* 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 @@ -29,9 +30,16 @@ import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; import de.lmu.ifi.dbs.elki.data.type.TypeInformation; import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation; import de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation; +import de.lmu.ifi.dbs.elki.datasource.filter.transform.NumberVectorFeatureSelectionFilter; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayAdapter; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayLikeUtil; import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.SubsetArrayAdapter; +import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ListEachConstraint; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntListParameter; /** * Projection class for number vectors. @@ -61,30 +69,38 @@ public class FeatureSelection<V extends FeatureVector<F>, F> implements Projecti * Array adapter. */ protected ArrayAdapter<F, V> adapter; - + /** * Constructor. * * @param dims Dimensions - * @param factory Object factory */ - public FeatureSelection(int[] dims, FeatureVector.Factory<V, F> factory) { - this.adapter = new SubsetArrayAdapter<F, V>(getAdapter(factory), dims); - this.factory = factory; + public FeatureSelection(int[] dims) { + this.adapter = new SubsetArrayAdapter<>(getAdapter(factory), dims); this.dimensionality = dims.length; int mind = 0; - for(int dim : dims) { + for (int dim : dims) { mind = Math.max(mind, dim + 1); } this.mindim = mind; } + @SuppressWarnings("unchecked") + @Override + public void initialize(SimpleTypeInformation<V> in) { + final VectorFieldTypeInformation<V> vin = (VectorFieldTypeInformation<V>) in; + factory = (FeatureVector.Factory<V, F>) vin.getFactory(); + if (vin.getDimensionality() < mindim) { + throw new AbortException("Data does not have enough dimensions for this projection!"); + } + } + @Override public V project(V data) { return factory.newFeatureVector(data, adapter); } - + /** * Choose the best adapter for this. * @@ -95,7 +111,7 @@ public class FeatureSelection<V extends FeatureVector<F>, F> implements Projecti */ @SuppressWarnings("unchecked") private static <V extends FeatureVector<F>, F> ArrayAdapter<F, ? super V> getAdapter(Factory<V, F> factory) { - if(factory instanceof NumberVector.Factory) { + if (factory instanceof NumberVector.Factory) { return (ArrayAdapter<F, ? super V>) ArrayLikeUtil.NUMBERVECTORADAPTER; } return (ArrayAdapter<F, ? super V>) ArrayLikeUtil.FEATUREVECTORADAPTER; @@ -103,15 +119,43 @@ public class FeatureSelection<V extends FeatureVector<F>, F> implements Projecti @Override public SimpleTypeInformation<V> getOutputDataTypeInformation() { - @SuppressWarnings("unchecked") - final Class<V> cls = (Class<V>) factory.getClass(); - return new VectorFieldTypeInformation<V>(cls, dimensionality); + return new VectorFieldTypeInformation<>(factory, dimensionality); } @Override public TypeInformation getInputDataTypeInformation() { @SuppressWarnings("unchecked") - final Class<V> cls = (Class<V>) factory.getClass(); - return new VectorTypeInformation<V>(cls, mindim, Integer.MAX_VALUE); + final Class<V> cls = (Class<V>) factory.getRestrictionClass(); + return new VectorTypeInformation<>(cls, mindim, Integer.MAX_VALUE); + } + + /** + * Parameterization class. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer<V extends FeatureVector<F>, F> extends AbstractParameterizer { + /** + * Dimensions to select. + */ + int[] dims = null; + + @Override + protected void makeOptions(Parameterization config) { + super.makeOptions(config); + + IntListParameter selectedAttributesP = new IntListParameter(NumberVectorFeatureSelectionFilter.Parameterizer.SELECTED_ATTRIBUTES_ID); + selectedAttributesP.addConstraint(new ListEachConstraint<Integer>(new GreaterEqualConstraint(0))); + if (config.grab(selectedAttributesP)) { + dims = ArrayLikeUtil.toPrimitiveIntegerArray(selectedAttributesP.getValue()); + } + } + + @Override + protected FeatureSelection<V, F> makeInstance() { + return new FeatureSelection<>(dims); + } } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/LatLngToECEFProjection.java b/src/de/lmu/ifi/dbs/elki/data/projection/LatLngToECEFProjection.java new file mode 100644 index 00000000..ee7ba931 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/projection/LatLngToECEFProjection.java @@ -0,0 +1,113 @@ +package de.lmu.ifi.dbs.elki.data.projection; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +import de.lmu.ifi.dbs.elki.data.NumberVector; +import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; +import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation; +import de.lmu.ifi.dbs.elki.math.geodesy.EarthModel; +import de.lmu.ifi.dbs.elki.math.geodesy.SphericalVincentyEarthModel; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ObjectParameter; + +/** + * Project (Latitude, Longitude) vectors to (X, Y, Z), from spherical + * coordinates to ECEF (earth-centered earth-fixed). + * + * @author Erich Schubert + * + * @apiviz.composedOf EarthModel + * + * @param <V> Vector type + */ +public class LatLngToECEFProjection<V extends NumberVector<?>> implements Projection<V, V> { + /** + * Vector factory to use. + */ + private NumberVector.Factory<V, ?> factory; + + /** + * Earth model to use. + */ + private EarthModel model; + + /** + * Constructor. + * + * @param model Earth model to use. + */ + public LatLngToECEFProjection(EarthModel model) { + super(); + this.model = model; + } + + @Override + public void initialize(SimpleTypeInformation<V> in) { + final VectorFieldTypeInformation<V> vin = (VectorFieldTypeInformation<V>) in; + factory = (NumberVector.Factory<V, ?>) vin.getFactory(); + } + + @Override + public V project(V data) { + return factory.newNumberVector(model.latLngDegToECEF(data.doubleValue(0), data.doubleValue(1))); + } + + @Override + public SimpleTypeInformation<? super V> getInputDataTypeInformation() { + return new VectorFieldTypeInformation<>(NumberVector.class, 2, 2); + } + + @Override + public SimpleTypeInformation<V> getOutputDataTypeInformation() { + return new VectorFieldTypeInformation<>(factory, 3, 3, factory.getDefaultSerializer()); + } + + /** + * Parameterization class. + * + * @apiviz.exclude + * + * @author Erich Schubert + */ + public static class Parameterizer extends AbstractParameterizer { + /** + * Earth model to use. + */ + EarthModel model; + + @Override + protected void makeOptions(Parameterization config) { + super.makeOptions(config); + ObjectParameter<EarthModel> modelP = new ObjectParameter<>(EarthModel.MODEL_ID, EarthModel.class, SphericalVincentyEarthModel.class); + if (config.grab(modelP)) { + model = modelP.instantiateClass(config); + } + } + + @Override + protected LatLngToECEFProjection<NumberVector<?>> makeInstance() { + return new LatLngToECEFProjection<>(model); + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/LngLatToECEFProjection.java b/src/de/lmu/ifi/dbs/elki/data/projection/LngLatToECEFProjection.java new file mode 100644 index 00000000..d6769c9c --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/projection/LngLatToECEFProjection.java @@ -0,0 +1,113 @@ +package de.lmu.ifi.dbs.elki.data.projection; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +import de.lmu.ifi.dbs.elki.data.NumberVector; +import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; +import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation; +import de.lmu.ifi.dbs.elki.math.geodesy.EarthModel; +import de.lmu.ifi.dbs.elki.math.geodesy.SphericalVincentyEarthModel; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ObjectParameter; + +/** + * Project (Longitude, Latitude) vectors to (X, Y, Z), from spherical + * coordinates to ECEF (earth-centered earth-fixed). + * + * @author Erich Schubert + * + * @apiviz.composedOf EarthModel + * + * @param <V> Vector type + */ +public class LngLatToECEFProjection<V extends NumberVector<?>> implements Projection<V, V> { + /** + * Earth model to use + */ + EarthModel model; + + /** + * Vector factory to use. + */ + private NumberVector.Factory<V, ?> factory; + + /** + * Constructor. + * + * @param model Earth model to use. + */ + public LngLatToECEFProjection(EarthModel model) { + super(); + this.model = model; + } + + @Override + public void initialize(SimpleTypeInformation<V> in) { + final VectorFieldTypeInformation<V> vin = (VectorFieldTypeInformation<V>) in; + factory = (NumberVector.Factory<V, ?>) vin.getFactory(); + } + + @Override + public V project(V data) { + return factory.newNumberVector(model.latLngDegToECEF(data.doubleValue(1), data.doubleValue(0))); + } + + @Override + public SimpleTypeInformation<? super V> getInputDataTypeInformation() { + return new VectorFieldTypeInformation<>(NumberVector.class, 2, 2); + } + + @Override + public SimpleTypeInformation<V> getOutputDataTypeInformation() { + return new VectorFieldTypeInformation<>(factory, 3, 3, factory.getDefaultSerializer()); + } + + /** + * Parameterization class. + * + * @apiviz.exclude + * + * @author Erich Schubert + */ + public static class Parameterizer extends AbstractParameterizer { + /** + * Earth model to use. + */ + EarthModel model; + + @Override + protected void makeOptions(Parameterization config) { + super.makeOptions(config); + ObjectParameter<EarthModel> modelP = new ObjectParameter<>(EarthModel.MODEL_ID, EarthModel.class, SphericalVincentyEarthModel.class); + if (config.grab(modelP)) { + model = modelP.instantiateClass(config); + } + } + + @Override + protected LngLatToECEFProjection<NumberVector<?>> makeInstance() { + return new LngLatToECEFProjection<>(model); + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/NumericalFeatureSelection.java b/src/de/lmu/ifi/dbs/elki/data/projection/NumericalFeatureSelection.java index 9154839f..ea03888b 100644 --- a/src/de/lmu/ifi/dbs/elki/data/projection/NumericalFeatureSelection.java +++ b/src/de/lmu/ifi/dbs/elki/data/projection/NumericalFeatureSelection.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.projection; 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 @@ -30,10 +30,19 @@ import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; import de.lmu.ifi.dbs.elki.data.type.TypeInformation; import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation; import de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation; +import de.lmu.ifi.dbs.elki.datasource.filter.transform.NumberVectorFeatureSelectionFilter; +import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ListEachConstraint; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntListParameter; /** * Projection class for number vectors. * + * FIXME: Use int[] instead of a BitSet, to allow reordering? + * * @author Erich Schubert * * @param <V> Vector type @@ -63,25 +72,32 @@ public class NumericalFeatureSelection<V extends NumberVector<?>> implements Pro * Constructor. * * @param bits Dimensions - * @param factory Object factory */ - public NumericalFeatureSelection(BitSet bits, NumberVector.Factory<V, ?> factory) { + public NumericalFeatureSelection(BitSet bits) { super(); this.bits = bits; - this.factory = factory; this.dimensionality = bits.cardinality(); int mind = 0; - for(int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i + 1)) { + for (int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i + 1)) { mind = Math.max(mind, i + 1); } this.mindim = mind; } @Override + public void initialize(SimpleTypeInformation<V> in) { + final VectorFieldTypeInformation<V> vin = (VectorFieldTypeInformation<V>) in; + factory = (NumberVector.Factory<V, ?>) vin.getFactory(); + if (vin.getDimensionality() < mindim) { + throw new AbortException("Data does not have enough dimensions for this projection!"); + } + } + + @Override public V project(V data) { double[] dbl = new double[dimensionality]; - for(int i = bits.nextSetBit(0), j = 0; i >= 0; i = bits.nextSetBit(i + 1), j++) { + for (int i = bits.nextSetBit(0), j = 0; i >= 0; i = bits.nextSetBit(i + 1), j++) { dbl[j] = data.doubleValue(i); } return factory.newNumberVector(dbl); @@ -89,15 +105,44 @@ public class NumericalFeatureSelection<V extends NumberVector<?>> implements Pro @Override public SimpleTypeInformation<V> getOutputDataTypeInformation() { - @SuppressWarnings("unchecked") - final Class<V> cls = (Class<V>) factory.getRestrictionClass(); - return new VectorFieldTypeInformation<V>(cls, dimensionality); + return new VectorFieldTypeInformation<>(factory, dimensionality); } @Override public TypeInformation getInputDataTypeInformation() { - @SuppressWarnings("unchecked") - final Class<V> cls = (Class<V>) factory.getRestrictionClass(); - return new VectorTypeInformation<V>(cls, mindim, Integer.MAX_VALUE); + return new VectorTypeInformation<>(NumberVector.class, mindim, Integer.MAX_VALUE); + } + + /** + * Parameterization class. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer<V extends NumberVector<?>> extends AbstractParameterizer { + /** + * Dimensions to select. + */ + BitSet dims = new BitSet(); + + @Override + protected void makeOptions(Parameterization config) { + super.makeOptions(config); + + IntListParameter selectedAttributesP = new IntListParameter(NumberVectorFeatureSelectionFilter.Parameterizer.SELECTED_ATTRIBUTES_ID); + selectedAttributesP.addConstraint(new ListEachConstraint<Integer>(new GreaterEqualConstraint(0))); + if (config.grab(selectedAttributesP)) { + dims.clear(); + for (int in : selectedAttributesP.getValue()) { + dims.set(in); + } + } + } + + @Override + protected NumericalFeatureSelection<V> makeInstance() { + return new NumericalFeatureSelection<>(dims); + } } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/Projection.java b/src/de/lmu/ifi/dbs/elki/data/projection/Projection.java index c9cd98d2..b1e458e4 100644 --- a/src/de/lmu/ifi/dbs/elki/data/projection/Projection.java +++ b/src/de/lmu/ifi/dbs/elki/data/projection/Projection.java @@ -1,13 +1,10 @@ package de.lmu.ifi.dbs.elki.data.projection; -import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; -import de.lmu.ifi.dbs.elki.data.type.TypeInformation; - /* 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 @@ -26,15 +23,26 @@ import de.lmu.ifi.dbs.elki.data.type.TypeInformation; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; +import de.lmu.ifi.dbs.elki.data.type.TypeInformation; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameterizable; + /** * Projection interface. * * @author Erich Schubert - * + * * @param <IN> Input data type * @param <OUT> Output data type */ -public interface Projection<IN, OUT> { +public interface Projection<IN, OUT> extends Parameterizable { + /** + * Initialize + * + * @param in Data type to use for projecting. + */ + public void initialize(SimpleTypeInformation<IN> in); + /** * Project a single instance. * @@ -42,13 +50,6 @@ public interface Projection<IN, OUT> { * @return Projected data */ public OUT project(IN data); - - /** - * Output type restriction - * - * @return Output type - */ - public SimpleTypeInformation<OUT> getOutputDataTypeInformation(); /** * Input type information. @@ -56,4 +57,11 @@ public interface Projection<IN, OUT> { * @return Type restriction */ public TypeInformation getInputDataTypeInformation(); + + /** + * Output type restriction + * + * @return Output type + */ + public SimpleTypeInformation<OUT> getOutputDataTypeInformation(); } diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/RandomProjection.java b/src/de/lmu/ifi/dbs/elki/data/projection/RandomProjection.java new file mode 100644 index 00000000..74edd3e1 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/projection/RandomProjection.java @@ -0,0 +1,166 @@ +package de.lmu.ifi.dbs.elki.data.projection; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +import de.lmu.ifi.dbs.elki.data.NumberVector; +import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; +import de.lmu.ifi.dbs.elki.data.type.TypeInformation; +import de.lmu.ifi.dbs.elki.data.type.TypeUtil; +import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation; +import de.lmu.ifi.dbs.elki.logging.Logging; +import de.lmu.ifi.dbs.elki.math.linearalgebra.randomprojections.AchlioptasRandomProjectionFamily; +import de.lmu.ifi.dbs.elki.math.linearalgebra.randomprojections.RandomProjectionFamily; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntParameter; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ObjectParameter; + +/** + * Randomized projections of the data. + * + * This class allows projecting the data with different types of random + * projections, in particular database friendly projections (as suggested by + * Achlioptas, see {@link AchlioptasRandomProjectionFamily}), but also as + * suggested for locality sensitive hashing (LSH). + * + * @author Erich Schubert + * + * @param <V> Vector type + */ +public class RandomProjection<V extends NumberVector<?>> implements Projection<V, V> { + /** + * Class logger. + */ + private static final Logging LOG = Logging.getLogger(RandomProjection.class); + + /** + * Vector factory. + */ + private NumberVector.Factory<V, ?> factory = null; + + /** + * Output dimensionality. + */ + private int dimensionality; + + /** + * Projection matrix. + */ + private RandomProjectionFamily.Projection projection = null; + + /** + * Random projection family + */ + private RandomProjectionFamily family; + + /** + * Constructor. + * + * @param dimensionality Desired dimensionality + * @param family Random projection family + */ + public RandomProjection(int dimensionality, RandomProjectionFamily family) { + super(); + this.dimensionality = dimensionality; + this.family = family; + } + + @Override + public void initialize(SimpleTypeInformation<V> in) { + final VectorFieldTypeInformation<V> vin = (VectorFieldTypeInformation<V>) in; + factory = (NumberVector.Factory<V, ?>) vin.getFactory(); + int inputdim = vin.getDimensionality(); + + projection = family.generateProjection(inputdim, dimensionality); + if (LOG.isDebugging()) { + LOG.debug(projection.toString()); + } + } + + @Override + public V project(V data) { + return factory.newNumberVector(projection.project(data)); + } + + @Override + public TypeInformation getInputDataTypeInformation() { + return TypeUtil.NUMBER_VECTOR_FIELD; + } + + @Override + public SimpleTypeInformation<V> getOutputDataTypeInformation() { + return new VectorFieldTypeInformation<>(factory, dimensionality); + } + + /** + * Parameterization class. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + /** + * Parameter for the projection family. + */ + public static final OptionID FAMILY_ID = new OptionID("randomproj.family", "Projection family to use."); + + /** + * Parameter for the desired output dimensionality. + */ + public static final OptionID DIMENSIONALITY_ID = new OptionID("randomproj.dimensionality", "Amount of dimensions to project to."); + + /** + * Output dimensionality. + */ + private int dimensionality; + + /** + * Random generator. + */ + private RandomProjectionFamily family; + + @Override + protected void makeOptions(Parameterization config) { + super.makeOptions(config); + ObjectParameter<RandomProjectionFamily> familyP = new ObjectParameter<>(FAMILY_ID, RandomProjectionFamily.class); + familyP.setDefaultValue(AchlioptasRandomProjectionFamily.class); + if (config.grab(familyP)) { + family = familyP.instantiateClass(config); + } + + IntParameter dimP = new IntParameter(DIMENSIONALITY_ID); + dimP.addConstraint(new GreaterEqualConstraint(1)); + if (config.grab(dimP)) { + dimensionality = dimP.intValue(); + } + } + + @Override + protected RandomProjection<NumberVector<?>> makeInstance() { + return new RandomProjection<>(dimensionality, family); + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/projection/package-info.java b/src/de/lmu/ifi/dbs/elki/data/projection/package-info.java index d39c51ba..2fe8b010 100644 --- a/src/de/lmu/ifi/dbs/elki/data/projection/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/projection/package-info.java @@ -5,7 +5,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 diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/Polygon.java b/src/de/lmu/ifi/dbs/elki/data/spatial/Polygon.java index 3bb771c1..eef19e82 100644 --- a/src/de/lmu/ifi/dbs/elki/data/spatial/Polygon.java +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/Polygon.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.spatial; 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 @@ -25,12 +25,9 @@ package de.lmu.ifi.dbs.elki.data.spatial; import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; -import de.lmu.ifi.dbs.elki.utilities.iterator.ReverseListIterator; -import de.lmu.ifi.dbs.elki.utilities.iterator.UnmodifiableIterator; -import de.lmu.ifi.dbs.elki.utilities.iterator.UnmodifiableListIterator; +import de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.ArrayListIter; /** * Class representing a simple polygon. While you can obviously store non-simple @@ -41,7 +38,7 @@ import de.lmu.ifi.dbs.elki.utilities.iterator.UnmodifiableListIterator; * * @apiviz.composedOf Vector */ -public class Polygon implements Iterable<Vector>, SpatialComparable { +public class Polygon implements SpatialComparable { /** * The actual points */ @@ -66,15 +63,15 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { super(); this.points = points; // Compute the bounds. - if(points.size() > 0) { + if (points.size() > 0) { final Iterator<Vector> iter = points.iterator(); final Vector first = iter.next(); final int dim = first.getDimensionality(); min = first.getArrayCopy(); max = first.getArrayCopy(); - while(iter.hasNext()) { + while (iter.hasNext()) { Vector next = iter.next(); - for(int i = 0; i < dim; i++) { + for (int i = 0; i < dim; i++) { final double cur = next.get(i); min[i] = Math.min(min[i], cur); max[i] = Math.max(max[i], cur); @@ -90,27 +87,13 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { this.max = new double[] { maxx, maxy }; } - @Override - public Iterator<Vector> iterator() { - return new UnmodifiableIterator<Vector>(points.iterator()); - } - /** - * Get a list iterator. + * Get an iterator to the vector contents. * - * @return List iterator. + * @return Iterator */ - public ListIterator<Vector> listIterator() { - return new UnmodifiableListIterator<Vector>(points.listIterator()); - } - - /** - * Return an iterator that iterates the list backwards. - * - * @return Reversed iterator - */ - public ListIterator<Vector> descendingIterator() { - return new UnmodifiableListIterator<Vector>(new ReverseListIterator<Vector>(points)); + public ArrayListIter<Vector> iter() { + return new ArrayListIter<>(points); } /** @@ -120,15 +103,15 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { */ public void appendToBuffer(StringBuilder buf) { Iterator<Vector> iter = points.iterator(); - while(iter.hasNext()) { + while (iter.hasNext()) { double[] data = iter.next().getArrayRef(); - for(int i = 0; i < data.length; i++) { - if(i > 0) { + for (int i = 0; i < data.length; i++) { + if (i > 0) { buf.append(","); } buf.append(data[i]); } - if(iter.hasNext()) { + if (iter.hasNext()) { buf.append(" "); } } @@ -181,7 +164,7 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { * @return -1, 0, 1 for counterclockwise, undefined and clockwise. */ public int testClockwise() { - if(points.size() < 3) { + if (points.size() < 3) { return 0; } final int size = points.size(); @@ -189,7 +172,7 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { int c = 0; // TODO: faster when using an iterator? - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { // Three consecutive points final int j = (i + 1) % size; final int k = (i + 2) % size; @@ -198,20 +181,17 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { final double dyji = points.get(j).get(1) - points.get(i).get(1); final double dxkj = points.get(k).get(0) - points.get(j).get(0); final double z = (dxji * dykj) - (dyji * dxkj); - if(z < 0) { + if (z < 0) { c--; - } - else if(z > 0) { + } else if (z > 0) { c++; } } - if(c > 0) { + if (c > 0) { return -1; - } - else if(c < 0) { + } else if (c < 0) { return +1; - } - else { + } else { return 0; } } @@ -238,13 +218,13 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { public boolean intersects2DIncomplete(Polygon other) { assert (this.getDimensionality() == 2); assert (other.getDimensionality() == 2); - for(Vector v : this.points) { - if(other.containsPoint2D(v)) { + for (Vector v : this.points) { + if (other.containsPoint2D(v)) { return true; } } - for(Vector v : other.points) { - if(this.containsPoint2D(v)) { + for (Vector v : other.points) { + if (this.containsPoint2D(v)) { return true; } } @@ -269,14 +249,14 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { Iterator<Vector> it = points.iterator(); Vector pre = points.get(points.size() - 1); - while(it.hasNext()) { + while (it.hasNext()) { final Vector cur = it.next(); final double curx = cur.get(0); final double cury = cur.get(1); final double prex = pre.get(0); final double prey = pre.get(1); - if(((cury > testy) != (prey > testy))) { - if((testx < (prex - curx) * (testy - cury) / (prey - cury) + curx)) { + if (((cury > testy) != (prey > testy))) { + if ((testx < (prex - curx) * (testy - cury) / (prey - cury) + curx)) { c = !c; } } @@ -284,4 +264,4 @@ public class Polygon implements Iterable<Vector>, SpatialComparable { } return c; } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/PolygonsObject.java b/src/de/lmu/ifi/dbs/elki/data/spatial/PolygonsObject.java index f329c948..dbda87bd 100644 --- a/src/de/lmu/ifi/dbs/elki/data/spatial/PolygonsObject.java +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/PolygonsObject.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.spatial; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialComparable.java b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialComparable.java index c81ce10e..0783a748 100644 --- a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialComparable.java +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialComparable.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.spatial; 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 @@ -23,12 +23,13 @@ package de.lmu.ifi.dbs.elki.data.spatial; along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - /** * Defines the required methods needed for comparison of spatial objects. * * @author Elke Achtert + * + * @apiviz.landmark + * @apiviz.excludeSubtypes */ public interface SpatialComparable { /** @@ -55,4 +56,4 @@ public interface SpatialComparable { * @return the maximum coordinate at the specified dimension */ double getMax(int dimension); -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMaxComparator.java b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMaxComparator.java new file mode 100644 index 00000000..8e491b97 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMaxComparator.java @@ -0,0 +1,64 @@ +package de.lmu.ifi.dbs.elki.data.spatial; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +import java.util.Comparator; + +/** + * Comparator for sorting spatial objects by the maximum value in a single + * dimension. + * + * @author Erich Schubert + * + * @apiviz.uses SpatialComparable + */ +public class SpatialSingleMaxComparator implements Comparator<SpatialComparable> { + /** + * Current dimension. + */ + int dim; + + /** + * Constructor. + * + * @param dim Dimension to sort by. + */ + public SpatialSingleMaxComparator(int dim) { + super(); + this.dim = dim; + } + + /** + * Set the dimension to sort by. + * + * @param dim Dimension + */ + public void setDimension(int dim) { + this.dim = dim; + } + + @Override + public int compare(SpatialComparable o1, SpatialComparable o2) { + return Double.compare(o1.getMax(dim), o2.getMax(dim)); + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMeanComparator.java b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMeanComparator.java new file mode 100644 index 00000000..ec8f4a38 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMeanComparator.java @@ -0,0 +1,66 @@ +package de.lmu.ifi.dbs.elki.data.spatial; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +import java.util.Comparator; + +/** + * Comparator for sorting spatial objects by the mean value in a single + * dimension. + * + * @author Erich Schubert + * + * @apiviz.uses SpatialComparable + */ +public class SpatialSingleMeanComparator implements Comparator<SpatialComparable> { + /** + * Current dimension. + */ + int dim; + + /** + * Constructor. + * + * @param dim Dimension to sort by. + */ + public SpatialSingleMeanComparator(int dim) { + super(); + this.dim = dim; + } + + /** + * Set the dimension to sort by. + * + * @param dim Dimension + */ + public void setDimension(int dim) { + this.dim = dim; + } + + @Override + public int compare(SpatialComparable o1, SpatialComparable o2) { + final double v1 = o1.getMin(dim) + o1.getMax(dim); + final double v2 = o2.getMin(dim) + o2.getMax(dim); + return Double.compare(v1, v2); + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMinComparator.java b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMinComparator.java new file mode 100644 index 00000000..8156cbd1 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialSingleMinComparator.java @@ -0,0 +1,64 @@ +package de.lmu.ifi.dbs.elki.data.spatial; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +import java.util.Comparator; + +/** + * Comparator for sorting spatial objects by the minimum value in a single + * dimension. + * + * @author Erich Schubert + * + * @apiviz.uses SpatialComparable + */ +public class SpatialSingleMinComparator implements Comparator<SpatialComparable> { + /** + * Current dimension. + */ + int dim; + + /** + * Constructor. + * + * @param dim Dimension to sort by. + */ + public SpatialSingleMinComparator(int dim) { + super(); + this.dim = dim; + } + + /** + * Set the dimension to sort by. + * + * @param dim Dimension + */ + public void setDimension(int dim) { + this.dim = dim; + } + + @Override + public int compare(SpatialComparable o1, SpatialComparable o2) { + return Double.compare(o1.getMin(dim), o2.getMin(dim)); + } +} diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialUtil.java b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialUtil.java index 607acd1c..3d50f6e2 100644 --- a/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialUtil.java +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/SpatialUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.spatial; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/spatial/package-info.java b/src/de/lmu/ifi/dbs/elki/data/spatial/package-info.java index e418bcaf..a208bd04 100644 --- a/src/de/lmu/ifi/dbs/elki/data/spatial/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/spatial/package-info.java @@ -5,7 +5,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 diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterface.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterface.java index 363c6c3b..7988ade4 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterface.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterface.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.synthetic.bymodel; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterfaceDynamic.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterfaceDynamic.java index cd3f18b7..5523355f 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterfaceDynamic.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorInterfaceDynamic.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.synthetic.bymodel; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java index 603507c1..0dccaf77 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.synthetic.bymodel; 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 @@ -70,7 +70,7 @@ public class GeneratorMain { /** * List of clusters to generate. */ - protected LinkedList<GeneratorInterface> generators = new LinkedList<GeneratorInterface>(); + protected LinkedList<GeneratorInterface> generators = new LinkedList<>(); /** * Controls whether points are tested against the model during generation. @@ -109,9 +109,9 @@ public class GeneratorMain { } // Prepare result bundle MultipleObjectsBundle bundle = new MultipleObjectsBundle(); - VectorFieldTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<DoubleVector>(DoubleVector.FACTORY, dim); - bundle.appendColumn(type, new ArrayList<Object>()); - bundle.appendColumn(TypeUtil.CLASSLABEL, new ArrayList<Object>()); + VectorFieldTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim); + bundle.appendColumn(type, new ArrayList<>()); + bundle.appendColumn(TypeUtil.CLASSLABEL, new ArrayList<>()); bundle.appendColumn(TypeUtil.MODEL, new ArrayList<Model>()); // generate clusters diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorSingleCluster.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorSingleCluster.java index d2970de7..ccbeb9b7 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorSingleCluster.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorSingleCluster.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.synthetic.bymodel; 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 @@ -30,7 +30,7 @@ import java.util.Random; import de.lmu.ifi.dbs.elki.data.model.Model; import de.lmu.ifi.dbs.elki.math.linearalgebra.AffineTransformation; import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; -import de.lmu.ifi.dbs.elki.math.statistics.distribution.DistributionWithRandom; +import de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution; import de.lmu.ifi.dbs.elki.utilities.exceptions.UnableToComplyException; /** @@ -47,7 +47,7 @@ public class GeneratorSingleCluster implements GeneratorInterfaceDynamic, Model /** * The distribution generators for each axis */ - private List<DistributionWithRandom> axes = new ArrayList<DistributionWithRandom>(); + private List<Distribution> axes = new ArrayList<>(); /** * The transformation matrix @@ -121,7 +121,7 @@ public class GeneratorSingleCluster implements GeneratorInterfaceDynamic, Model * @throws UnableToComplyException thrown when no new generators may be added * anymore */ - public void addGenerator(DistributionWithRandom gen) throws UnableToComplyException { + public void addGenerator(Distribution gen) throws UnableToComplyException { if(trans != null) { throw new UnableToComplyException("Generators may no longer be added when transformations have been applied."); } @@ -231,11 +231,11 @@ public class GeneratorSingleCluster implements GeneratorInterfaceDynamic, Model */ @Override public List<Vector> generate(int count) throws UnableToComplyException { - ArrayList<Vector> result = new ArrayList<Vector>(count); + ArrayList<Vector> result = new ArrayList<>(count); while(result.size() < count) { double[] d = new double[dim]; int i = 0; - for(DistributionWithRandom axis : axes) { + for(Distribution axis : axes) { d[i] = axis.nextRandom(); i++; } @@ -269,7 +269,7 @@ public class GeneratorSingleCluster implements GeneratorInterfaceDynamic, Model double density = 1.0; int i = 0; - for(DistributionWithRandom axis : axes) { + for(Distribution axis : axes) { density = density * axis.pdf(o.get(i)); i++; } @@ -400,7 +400,7 @@ public class GeneratorSingleCluster implements GeneratorInterfaceDynamic, Model * @param i Generator axis i * @return Distribution */ - public DistributionWithRandom getDistribution(int i) { + public Distribution getDistribution(int i) { return axes.get(i); } }
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorStatic.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorStatic.java index 7075bcb4..b8b0dff0 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorStatic.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorStatic.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.synthetic.bymodel; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/package-info.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/package-info.java index 51dcd8e8..714a7835 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/package-info.java @@ -13,7 +13,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 diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/package-info.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/package-info.java index c311cf0b..98957f09 100644 --- a/src/de/lmu/ifi/dbs/elki/data/synthetic/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/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 diff --git a/src/de/lmu/ifi/dbs/elki/data/type/AlternativeTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/AlternativeTypeInformation.java index f4eba35e..f1d85620 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/AlternativeTypeInformation.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/AlternativeTypeInformation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 @@ -23,13 +23,13 @@ package de.lmu.ifi.dbs.elki.data.type; along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - /** * Class that combines multiple type restrictions into one using the "or" * operator. * * @author Erich Schubert + * + * @apiviz.composedOf TypeInformation */ public class AlternativeTypeInformation implements TypeInformation { /** @@ -49,8 +49,8 @@ public class AlternativeTypeInformation implements TypeInformation { @Override public boolean isAssignableFromType(TypeInformation type) { - for(int i = 0; i < restrictions.length; i++) { - if(restrictions[i].isAssignableFromType(type)) { + for (int i = 0; i < restrictions.length; i++) { + if (restrictions[i].isAssignableFromType(type)) { return true; } } @@ -59,8 +59,8 @@ public class AlternativeTypeInformation implements TypeInformation { @Override public boolean isAssignableFrom(Object other) { - for(int i = 0; i < restrictions.length; i++) { - if(restrictions[i].isAssignableFrom(other)) { + for (int i = 0; i < restrictions.length; i++) { + if (restrictions[i].isAssignableFrom(other)) { return true; } } @@ -70,12 +70,12 @@ public class AlternativeTypeInformation implements TypeInformation { @Override public String toString() { StringBuilder buf = new StringBuilder(); - for(int i = 0; i < restrictions.length; i++) { - if(i > 0) { + for (int i = 0; i < restrictions.length; i++) { + if (i > 0) { buf.append(" OR "); } buf.append(restrictions[i].toString()); } return buf.toString(); } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/data/type/CombinedTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/CombinedTypeInformation.java index 6d8c490c..efb22237 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/CombinedTypeInformation.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/CombinedTypeInformation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 @@ -23,11 +23,12 @@ package de.lmu.ifi.dbs.elki.data.type; along with this program. If not, see <http://www.gnu.org/licenses/>. */ - /** * Class that combines multiple type restrictions into one using an "and" operator. * * @author Erich Schubert + * + * @apiviz.composedOf TypeInformation */ public class CombinedTypeInformation implements TypeInformation { /** diff --git a/src/de/lmu/ifi/dbs/elki/data/type/NoSupportedDataTypeException.java b/src/de/lmu/ifi/dbs/elki/data/type/NoSupportedDataTypeException.java index 389d86dc..f1bfce91 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/NoSupportedDataTypeException.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/NoSupportedDataTypeException.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/type/SimpleTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/SimpleTypeInformation.java index 738c66f8..dcf155db 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/SimpleTypeInformation.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/SimpleTypeInformation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 @@ -30,6 +30,8 @@ import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer; * * @author Erich Schubert * + * @apiviz.composedOf ByteBuffererSerializer + * * @param <T> Java type we represent. */ public class SimpleTypeInformation<T> implements TypeInformation { diff --git a/src/de/lmu/ifi/dbs/elki/data/type/TypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/TypeInformation.java index d39afcad..d91a88c6 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/TypeInformation.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/TypeInformation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java b/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java index 27eb5c2f..ac3fd164 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 @@ -159,7 +159,7 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor label = ("".equals(label)) ? null : label; String sername = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer); ByteBufferSerializer<Object> serializer = (ByteBufferSerializer<Object>) Class.forName(sername).newInstance(); - return new SimpleTypeInformation<Object>(clz, label, serializer); + return new SimpleTypeInformation<>(clz, label, serializer); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Cannot deserialize - class not found: " + e, e); } catch (InstantiationException e) { @@ -240,7 +240,7 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor ByteBufferSerializer<DoubleVector> serializer = (ByteBufferSerializer<DoubleVector>) Class.forName(sername).newInstance(); int mindim = ByteArrayUtil.readSignedVarint(buffer); int maxdim = ByteArrayUtil.readSignedVarint(buffer); - return new VectorTypeInformation<DoubleVector>(clz, serializer, mindim, maxdim); + return new VectorTypeInformation<>(clz, serializer, mindim, maxdim); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Cannot deserialize - class not found: "+e, e); } catch (InstantiationException e) { @@ -338,9 +338,9 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor for (int i = 0; i < cols; i++) { labels[i] = ByteArrayUtil.readString(buffer); } - return new VectorFieldTypeInformation<DoubleVector>(factory, mindim, labels, serializer); + return new VectorFieldTypeInformation<>(factory, mindim, labels, serializer); } else { - return new VectorFieldTypeInformation<DoubleVector>(factory, mindim, maxdim, serializer); + return new VectorFieldTypeInformation<>(factory, mindim, maxdim, serializer); } } catch (UnableToComplyException e) { throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate factory: "+e, e); diff --git a/src/de/lmu/ifi/dbs/elki/data/type/TypeUtil.java b/src/de/lmu/ifi/dbs/elki/data/type/TypeUtil.java index ea5f2fc2..4236740b 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/TypeUtil.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/TypeUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 @@ -39,7 +39,7 @@ import de.lmu.ifi.dbs.elki.data.spatial.PolygonsObject; import de.lmu.ifi.dbs.elki.database.ids.DBID; import de.lmu.ifi.dbs.elki.database.ids.DBIDFactory; import de.lmu.ifi.dbs.elki.database.ids.DBIDs; -import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResult; +import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDList; import de.lmu.ifi.dbs.elki.math.linearalgebra.Matrix; import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil; @@ -63,42 +63,42 @@ public final class TypeUtil { /** * Input type for algorithms that accept anything. */ - public static final SimpleTypeInformation<Object> ANY = new SimpleTypeInformation<Object>(Object.class); + public static final SimpleTypeInformation<Object> ANY = new SimpleTypeInformation<>(Object.class); /** * Database IDs. */ - public static final SimpleTypeInformation<DBID> DBID = new SimpleTypeInformation<DBID>(DBID.class, DBIDFactory.FACTORY.getDBIDSerializer()); + public static final SimpleTypeInformation<DBID> DBID = new SimpleTypeInformation<>(DBID.class, DBIDFactory.FACTORY.getDBIDSerializer()); /** * Database ID lists. */ - public static final SimpleTypeInformation<DBIDs> DBIDS = new SimpleTypeInformation<DBIDs>(DBIDs.class); + public static final SimpleTypeInformation<DBIDs> DBIDS = new SimpleTypeInformation<>(DBIDs.class); /** * A string. */ - public static final SimpleTypeInformation<String> STRING = new SimpleTypeInformation<String>(String.class, ByteArrayUtil.STRING_SERIALIZER); + public static final SimpleTypeInformation<String> STRING = new SimpleTypeInformation<>(String.class, ByteArrayUtil.STRING_SERIALIZER); /** * A class label. */ - public static final SimpleTypeInformation<ClassLabel> CLASSLABEL = new SimpleTypeInformation<ClassLabel>(ClassLabel.class); + public static final SimpleTypeInformation<ClassLabel> CLASSLABEL = new SimpleTypeInformation<>(ClassLabel.class); /** * Simple class labels. */ - public static final SimpleTypeInformation<SimpleClassLabel> SIMPLE_CLASSLABEL = new SimpleTypeInformation<SimpleClassLabel>(SimpleClassLabel.class, SimpleClassLabel.SERIALIZER); + public static final SimpleTypeInformation<SimpleClassLabel> SIMPLE_CLASSLABEL = new SimpleTypeInformation<>(SimpleClassLabel.class, SimpleClassLabel.SERIALIZER); /** * A list of labels. */ - public static final SimpleTypeInformation<LabelList> LABELLIST = new SimpleTypeInformation<LabelList>(LabelList.class, LabelList.SERIALIZER); + public static final SimpleTypeInformation<LabelList> LABELLIST = new SimpleTypeInformation<>(LabelList.class, LabelList.SERIALIZER); /** * A list of neighbors. */ - public static final SimpleTypeInformation<DistanceDBIDResult<?>> NEIGHBORLIST = new SimpleTypeInformation<DistanceDBIDResult<?>>(DistanceDBIDResult.class); + public static final SimpleTypeInformation<DistanceDBIDList<?>> NEIGHBORLIST = new SimpleTypeInformation<>(DistanceDBIDList.class); /** * Either class label, object labels or a string - anything that will be @@ -110,90 +110,90 @@ public final class TypeUtil { /** * Number vectors of <em>variable</em> length. */ - public static final SimpleTypeInformation<? super NumberVector<?>> NUMBER_VECTOR_VARIABLE_LENGTH = new SimpleTypeInformation<NumberVector<?>>(NumberVector.class); + public static final SimpleTypeInformation<? super NumberVector<?>> NUMBER_VECTOR_VARIABLE_LENGTH = new SimpleTypeInformation<>(NumberVector.class); /** * Input type for algorithms that require number vector fields. */ - public static final VectorFieldTypeInformation<NumberVector<?>> NUMBER_VECTOR_FIELD = new VectorFieldTypeInformation<NumberVector<?>>(NumberVector.class); + public static final VectorFieldTypeInformation<NumberVector<?>> NUMBER_VECTOR_FIELD = new VectorFieldTypeInformation<>(NumberVector.class); /** * Input type for algorithms that require number vector fields. * * If possible, please use {@link #NUMBER_VECTOR_FIELD}! */ - public static final VectorFieldTypeInformation<DoubleVector> DOUBLE_VECTOR_FIELD = new VectorFieldTypeInformation<DoubleVector>(DoubleVector.class); + public static final VectorFieldTypeInformation<DoubleVector> DOUBLE_VECTOR_FIELD = new VectorFieldTypeInformation<>(DoubleVector.class); /** * Input type for algorithms that require number vector fields. * * If possible, please use {@link #NUMBER_VECTOR_FIELD}! */ - public static final VectorFieldTypeInformation<FloatVector> FLOAT_VECTOR_FIELD = new VectorFieldTypeInformation<FloatVector>(FloatVector.class); + public static final VectorFieldTypeInformation<FloatVector> FLOAT_VECTOR_FIELD = new VectorFieldTypeInformation<>(FloatVector.class); /** * Input type for algorithms that require number vector fields. */ - public static final VectorFieldTypeInformation<BitVector> BIT_VECTOR_FIELD = new VectorFieldTypeInformation<BitVector>(BitVector.class); + public static final VectorFieldTypeInformation<BitVector> BIT_VECTOR_FIELD = new VectorFieldTypeInformation<>(BitVector.class); /** * Sparse float vector field. */ - public static final SimpleTypeInformation<SparseNumberVector<?>> SPARSE_VECTOR_VARIABLE_LENGTH = new SimpleTypeInformation<SparseNumberVector<?>>(SparseNumberVector.class); + public static final SimpleTypeInformation<SparseNumberVector<?>> SPARSE_VECTOR_VARIABLE_LENGTH = new SimpleTypeInformation<>(SparseNumberVector.class); /** * Sparse vector field. */ - public static final VectorFieldTypeInformation<SparseNumberVector<?>> SPARSE_VECTOR_FIELD = new VectorFieldTypeInformation<SparseNumberVector<?>>(SparseNumberVector.class); + public static final VectorFieldTypeInformation<SparseNumberVector<?>> SPARSE_VECTOR_FIELD = new VectorFieldTypeInformation<>(SparseNumberVector.class); /** * Sparse float vector field. * * If possible, please use {@link #SPARSE_VECTOR_FIELD} instead! */ - public static final VectorFieldTypeInformation<SparseFloatVector> SPARSE_FLOAT_FIELD = new VectorFieldTypeInformation<SparseFloatVector>(SparseFloatVector.class); + public static final VectorFieldTypeInformation<SparseFloatVector> SPARSE_FLOAT_FIELD = new VectorFieldTypeInformation<>(SparseFloatVector.class); /** * Sparse double vector field. * * If possible, please use {@link #SPARSE_VECTOR_FIELD} instead! */ - public static final VectorFieldTypeInformation<SparseDoubleVector> SPARSE_DOUBLE_FIELD = new VectorFieldTypeInformation<SparseDoubleVector>(SparseDoubleVector.class); + public static final VectorFieldTypeInformation<SparseDoubleVector> SPARSE_DOUBLE_FIELD = new VectorFieldTypeInformation<>(SparseDoubleVector.class); /** * External ID type. */ - public static final SimpleTypeInformation<ExternalID> EXTERNALID = new SimpleTypeInformation<ExternalID>(ExternalID.class); + public static final SimpleTypeInformation<ExternalID> EXTERNALID = new SimpleTypeInformation<>(ExternalID.class); /** * Type for polygons. */ - public static final SimpleTypeInformation<PolygonsObject> POLYGON_TYPE = new SimpleTypeInformation<PolygonsObject>(PolygonsObject.class); + public static final SimpleTypeInformation<PolygonsObject> POLYGON_TYPE = new SimpleTypeInformation<>(PolygonsObject.class); /** * Double type, outlier scores etc. */ - public static final SimpleTypeInformation<Double> DOUBLE = new SimpleTypeInformation<Double>(Double.class, ByteArrayUtil.DOUBLE_SERIALIZER); + public static final SimpleTypeInformation<Double> DOUBLE = new SimpleTypeInformation<>(Double.class, ByteArrayUtil.DOUBLE_SERIALIZER); /** * Integer type. */ - public static final SimpleTypeInformation<Integer> INTEGER = new SimpleTypeInformation<Integer>(Integer.class, ByteArrayUtil.INT_SERIALIZER); + public static final SimpleTypeInformation<Integer> INTEGER = new SimpleTypeInformation<>(Integer.class, ByteArrayUtil.INT_SERIALIZER); /** * Vector type. */ - public static final SimpleTypeInformation<Vector> VECTOR = new SimpleTypeInformation<Vector>(Vector.class); + public static final SimpleTypeInformation<Vector> VECTOR = new SimpleTypeInformation<>(Vector.class); /** * Matrix type. */ - public static final SimpleTypeInformation<Matrix> MATRIX = new SimpleTypeInformation<Matrix>(Matrix.class); + public static final SimpleTypeInformation<Matrix> MATRIX = new SimpleTypeInformation<>(Matrix.class); /** * Cluster model type. */ - public static final SimpleTypeInformation<Model> MODEL = new SimpleTypeInformation<Model>(Model.class); + public static final SimpleTypeInformation<Model> MODEL = new SimpleTypeInformation<>(Model.class); /** * Make a type array easily. diff --git a/src/de/lmu/ifi/dbs/elki/data/type/VectorFieldTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/VectorFieldTypeInformation.java index 7de2a121..d05eed34 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/VectorFieldTypeInformation.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/VectorFieldTypeInformation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 diff --git a/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java index 4ba86a8b..7d568a55 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; 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 @@ -31,6 +31,8 @@ import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer; * * @author Erich Schubert * + * @apiviz.has FeatureVector + * * @param <V> Vector type */ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTypeInformation<V> { diff --git a/src/de/lmu/ifi/dbs/elki/data/type/package-info.java b/src/de/lmu/ifi/dbs/elki/data/type/package-info.java index 858efc7a..ad666ab4 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/package-info.java @@ -5,7 +5,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 |