summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/data/type
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/type')
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/AlternativeTypeInformation.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/CombinedTypeInformation.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/MultivariateSeriesTypeInformation.java93
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/NoSupportedDataTypeException.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/SimpleTypeInformation.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/TypeInformation.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java28
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/TypeUtil.java50
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/VectorFieldTypeInformation.java76
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/VectorTypeInformation.java84
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/type/package-info.java2
11 files changed, 247 insertions, 108 deletions
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 f1d85620..54a3c8c8 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) 2013
+ Copyright (C) 2014
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/CombinedTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/CombinedTypeInformation.java
index efb22237..a1c5d714 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) 2013
+ Copyright (C) 2014
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/MultivariateSeriesTypeInformation.java b/src/de/lmu/ifi/dbs/elki/data/type/MultivariateSeriesTypeInformation.java
new file mode 100644
index 00000000..fc2f7083
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/data/type/MultivariateSeriesTypeInformation.java
@@ -0,0 +1,93 @@
+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) 2014
+ 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.FeatureVector;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
+
+/**
+ * Type information for multi-variate time series.
+ *
+ * @author Sebastian Hollizeck
+ *
+ * @param <V> Vector type
+ */
+public class MultivariateSeriesTypeInformation<V extends FeatureVector<?>> extends VectorTypeInformation<V> {
+ /**
+ * Number of variates per dimension.
+ */
+ protected final int multiplicity;
+
+ /**
+ * Constructor for a type request without dimensionality constraints.
+ *
+ * @param cls Class constraint
+ * @param <V> vector type
+ */
+ public static <V extends FeatureVector<?>> MultivariateSeriesTypeInformation<V> typeRequest(Class<? super V> cls) {
+ return new MultivariateSeriesTypeInformation<>(cls, -1, Integer.MAX_VALUE, -1);
+ }
+
+ /**
+ * Constructor for an actual type.
+ *
+ * @param cls base class
+ * @param mindim Minimum dimensionality
+ * @param maxdim Maximum dimensionality
+ * @param multiplicity Number of variates
+ */
+ public MultivariateSeriesTypeInformation(Class<? super V> cls, int mindim, int maxdim, int multiplicity) {
+ super(cls, mindim, maxdim);
+ this.multiplicity = multiplicity;
+ }
+
+ /**
+ * Constructor for an actual type.
+ *
+ * @param factory Vector factory
+ * @param serializer Serializer
+ * @param mindim Minimum dimensionality
+ * @param maxdim Maximum dimensionality
+ * @param multiplicity Number of variates
+ */
+ public MultivariateSeriesTypeInformation(FeatureVector.Factory<V, ?> factory, ByteBufferSerializer<? super V> serializer, int mindim, int maxdim, int multiplicity) {
+ super(factory, serializer, mindim, maxdim);
+ this.multiplicity = multiplicity;
+ }
+
+ /**
+ * Get the multiplicity of the vector.
+ *
+ * @return Multiplicity
+ */
+ @Override
+ public int getMultiplicity() {
+ return multiplicity;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + ",multiplicity=" + multiplicity;
+ }
+}
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 f1bfce91..a762c197 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) 2013
+ Copyright (C) 2014
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 9fdabd36..8e428e8e 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) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,7 +23,7 @@ package de.lmu.ifi.dbs.elki.data.type;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
/**
* Class wrapping a particular data type.
@@ -43,12 +43,12 @@ public class SimpleTypeInformation<T> implements TypeInformation {
/**
* Type label.
*/
- private String label = null;
+ private String label;
/**
* Type serializer.
*/
- private ByteBufferSerializer<? super T> serializer = null;
+ private ByteBufferSerializer<? super T> serializer;
/**
* Constructor.
@@ -58,6 +58,8 @@ public class SimpleTypeInformation<T> implements TypeInformation {
public SimpleTypeInformation(Class<? super T> cls) {
super();
this.cls = cls;
+ this.label = null;
+ this.serializer = null;
}
/**
@@ -70,6 +72,7 @@ public class SimpleTypeInformation<T> implements TypeInformation {
super();
this.cls = cls;
this.label = label;
+ this.serializer = null;
}
/**
@@ -81,6 +84,7 @@ public class SimpleTypeInformation<T> implements TypeInformation {
public SimpleTypeInformation(Class<? super T> cls, ByteBufferSerializer<? super T> serializer) {
super();
this.cls = cls;
+ this.label = null;
this.serializer = serializer;
}
@@ -109,7 +113,7 @@ public class SimpleTypeInformation<T> implements TypeInformation {
@Override
public boolean isAssignableFromType(TypeInformation type) {
- if (!(type instanceof SimpleTypeInformation)) {
+ if(!(type instanceof SimpleTypeInformation)) {
return false;
}
final SimpleTypeInformation<?> simpleType = (SimpleTypeInformation<?>) type;
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 d91a88c6..aaf46ec7 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) 2013
+ Copyright (C) 2014
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 ac3fd164..e38a55e6 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) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -28,10 +28,10 @@ import java.nio.ByteBuffer;
import de.lmu.ifi.dbs.elki.data.DoubleVector;
import de.lmu.ifi.dbs.elki.data.NumberVector;
-import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil;
import de.lmu.ifi.dbs.elki.utilities.exceptions.UnableToComplyException;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteArrayUtil;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
/**
* Class to handle the serialization and deserialization of type information.
@@ -232,20 +232,22 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor
@Override
public VectorTypeInformation<?> fromByteBuffer(ByteBuffer buffer) throws IOException, UnsupportedOperationException {
try {
+ // Factory type!
String typename = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer);
- Class<DoubleVector> clz = (Class<DoubleVector>) Class.forName(typename);
+ NumberVector.Factory<DoubleVector> factory = (NumberVector.Factory<DoubleVector>) ClassGenericsUtil.instantiate(NumberVector.Factory.class, typename);
String label = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer);
label = ("".equals(label)) ? null : label;
String sername = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer);
ByteBufferSerializer<DoubleVector> serializer = (ByteBufferSerializer<DoubleVector>) Class.forName(sername).newInstance();
int mindim = ByteArrayUtil.readSignedVarint(buffer);
int maxdim = ByteArrayUtil.readSignedVarint(buffer);
- return new VectorTypeInformation<>(clz, serializer, mindim, maxdim);
+ // FIXME: should/must provide a factory now!
+ return new VectorTypeInformation<>(factory, serializer, mindim, maxdim);
+ } catch (UnableToComplyException e) {
+ throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate factory: "+e, e);
} catch (ClassNotFoundException e) {
throw new UnsupportedOperationException("Cannot deserialize - class not found: "+e, e);
- } catch (InstantiationException e) {
- throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e);
- } catch (IllegalAccessException e) {
+ } catch (InstantiationException | IllegalAccessException e) {
throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e);
}
}
@@ -265,8 +267,8 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor
} catch (SecurityException e) {
throw new UnsupportedOperationException("Serialization not possible.", e);
}
- // Type class
- ByteArrayUtil.writeString(buffer, object.getRestrictionClass().getName());
+ // Use *factory* class!
+ ByteArrayUtil.writeString(buffer, object.getFactory().getClass().getName());
// Name, or an empty string.
ByteArrayUtil.writeString(buffer, object.getLabel());
// Serializer class
@@ -320,7 +322,7 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor
try {
// Factory type!
String typename = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer);
- NumberVector.Factory<DoubleVector, ?> factory = (NumberVector.Factory<DoubleVector, ?>) ClassGenericsUtil.instantiate(NumberVector.Factory.class, typename);
+ NumberVector.Factory<DoubleVector> factory = (NumberVector.Factory<DoubleVector>) ClassGenericsUtil.instantiate(NumberVector.Factory.class, typename);
// Relation label
String label = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer);
label = ("".equals(label)) ? null : label;
@@ -346,9 +348,7 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor
throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate factory: "+e, e);
} catch (ClassNotFoundException e) {
throw new UnsupportedOperationException("Cannot deserialize - class not found: "+e, e);
- } catch (InstantiationException e) {
- throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e);
- } catch (IllegalAccessException e) {
+ } catch (InstantiationException | IllegalAccessException e) {
throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), 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 2eabf64b..94648aaf 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) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -40,10 +40,10 @@ 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.database.ids.distance.DistanceDBIDList;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList;
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;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteArrayUtil;
/**
* Utility package containing various common types.
@@ -99,7 +99,7 @@ public final class TypeUtil {
/**
* A list of neighbors.
*/
- public static final SimpleTypeInformation<DistanceDBIDList<?>> NEIGHBORLIST = new SimpleTypeInformation<>(DistanceDBIDList.class);
+ public static final SimpleTypeInformation<DoubleDBIDList> NEIGHBORLIST = new SimpleTypeInformation<>(DoubleDBIDList.class);
/**
* Either class label, object labels or a string - anything that will be
@@ -112,55 +112,75 @@ public final class TypeUtil {
/**
* Number vectors of <em>variable</em> length.
*/
- public static final SimpleTypeInformation<? super NumberVector<?>> NUMBER_VECTOR_VARIABLE_LENGTH = new SimpleTypeInformation<>(NumberVector.class);
+ public static final VectorTypeInformation<NumberVector> NUMBER_VECTOR_VARIABLE_LENGTH = VectorTypeInformation.typeRequest(NumberVector.class);
/**
* Input type for algorithms that require number vector fields.
*/
- public static final VectorFieldTypeInformation<NumberVector<?>> NUMBER_VECTOR_FIELD = new VectorFieldTypeInformation<>(NumberVector.class);
+ public static final VectorFieldTypeInformation<NumberVector> NUMBER_VECTOR_FIELD = VectorFieldTypeInformation.typeRequest(NumberVector.class);
+
+ /**
+ * Type request for two-dimensional number vectors
+ */
+ public static final VectorFieldTypeInformation<? super NumberVector> NUMBER_VECTOR_FIELD_1D = VectorFieldTypeInformation.typeRequest(NumberVector.class, 1, 1);
+
+ /**
+ * Type request for two-dimensional number vectors
+ */
+ public static final VectorFieldTypeInformation<? super NumberVector> NUMBER_VECTOR_FIELD_2D = VectorFieldTypeInformation.typeRequest(NumberVector.class, 2, 2);
+
+ /**
+ * Type request for multivariate time series.
+ */
+ public static final MultivariateSeriesTypeInformation<NumberVector> MULTIVARIATE_SERIES = MultivariateSeriesTypeInformation.typeRequest(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.class);
+ public static final VectorFieldTypeInformation<DoubleVector> DOUBLE_VECTOR_FIELD = VectorFieldTypeInformation.typeRequest(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.class);
+ public static final VectorFieldTypeInformation<FloatVector> FLOAT_VECTOR_FIELD = VectorFieldTypeInformation.typeRequest(FloatVector.class);
/**
- * Input type for algorithms that require number vector fields.
+ * Input type for algorithms that require bit vectors.
+ */
+ public static final VectorTypeInformation<BitVector> BIT_VECTOR = VectorTypeInformation.typeRequest(BitVector.class);
+
+ /**
+ * Input type for algorithms that require bit vector fields.
*/
- public static final VectorFieldTypeInformation<BitVector> BIT_VECTOR_FIELD = new VectorFieldTypeInformation<>(BitVector.class);
+ public static final VectorFieldTypeInformation<BitVector> BIT_VECTOR_FIELD = VectorFieldTypeInformation.typeRequest(BitVector.class);
/**
* Sparse float vector field.
*/
- public static final SimpleTypeInformation<SparseNumberVector<?>> SPARSE_VECTOR_VARIABLE_LENGTH = new SimpleTypeInformation<>(SparseNumberVector.class);
+ public static final VectorTypeInformation<SparseNumberVector> SPARSE_VECTOR_VARIABLE_LENGTH = VectorTypeInformation.typeRequest(SparseNumberVector.class);
/**
* Sparse vector field.
*/
- public static final VectorFieldTypeInformation<SparseNumberVector<?>> SPARSE_VECTOR_FIELD = new VectorFieldTypeInformation<>(SparseNumberVector.class);
+ public static final VectorFieldTypeInformation<SparseNumberVector> SPARSE_VECTOR_FIELD = VectorFieldTypeInformation.typeRequest(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.class);
+ public static final VectorFieldTypeInformation<SparseFloatVector> SPARSE_FLOAT_FIELD = VectorFieldTypeInformation.typeRequest(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.class);
+ public static final VectorFieldTypeInformation<SparseDoubleVector> SPARSE_DOUBLE_FIELD = VectorFieldTypeInformation.typeRequest(SparseDoubleVector.class);
/**
* External ID type.
@@ -200,7 +220,7 @@ public final class TypeUtil {
/**
* Any feature vector type.
*/
- public static final SimpleTypeInformation<FeatureVector<?>> FEATURE_VECTORS = new SimpleTypeInformation<>(FeatureVector.class);
+ public static final VectorTypeInformation<FeatureVector<?>> FEATURE_VECTORS = VectorTypeInformation.typeRequest(FeatureVector.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 d05eed34..448cb147 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) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -24,7 +24,7 @@ package de.lmu.ifi.dbs.elki.data.type;
*/
import de.lmu.ifi.dbs.elki.data.FeatureVector;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
/**
* Type information to specify that a type has a fixed dimensionality.
@@ -35,9 +35,26 @@ import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
*/
public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends VectorTypeInformation<V> {
/**
- * Object factory for producing new instances.
+ * Constructor for a type request without dimensionality constraints.
+ *
+ * @param cls Class constraint
+ * @param <V> vector type
+ */
+ public static <V extends FeatureVector<?>> VectorFieldTypeInformation<V> typeRequest(Class<? super V> cls) {
+ return new VectorFieldTypeInformation<>(cls, -1, Integer.MAX_VALUE);
+ }
+
+ /**
+ * Constructor for a type request with dimensionality constraints.
+ *
+ * @param cls Class constraint
+ * @param mindim Minimum dimensionality
+ * @param maxdim Maximum dimensionality
+ * @param <V> vector type
*/
- private final FeatureVector.Factory<V, ?> factory;
+ public static <V extends FeatureVector<?>> VectorFieldTypeInformation<V> typeRequest(Class<? super V> cls, int mindim, int maxdim) {
+ return new VectorFieldTypeInformation<>(cls, mindim, maxdim);
+ }
/**
* Labels.
@@ -53,8 +70,7 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
* @param serializer Serializer
*/
public VectorFieldTypeInformation(FeatureVector.Factory<V, ?> factory, int dim, String[] labels, ByteBufferSerializer<? super V> serializer) {
- super(factory.getRestrictionClass(), serializer, dim, dim);
- this.factory = factory;
+ super(factory, serializer, dim, dim);
this.labels = labels;
assert (labels == null || labels.length == dim) : "Created vector field with incomplete labels.";
}
@@ -68,8 +84,7 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
* @param serializer Serializer
*/
public VectorFieldTypeInformation(FeatureVector.Factory<V, ?> factory, int mindim, int maxdim, ByteBufferSerializer<? super V> serializer) {
- super(factory.getRestrictionClass(), serializer, mindim, maxdim);
- this.factory = factory;
+ super(factory, serializer, mindim, maxdim);
}
/**
@@ -80,8 +95,7 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
* @param serializer Serializer
*/
public VectorFieldTypeInformation(FeatureVector.Factory<V, ?> factory, int dim, ByteBufferSerializer<? super V> serializer) {
- super(factory.getRestrictionClass(), serializer, dim, dim);
- this.factory = factory;
+ super(factory, serializer, dim, dim);
}
/**
@@ -92,8 +106,7 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
* @param labels Labels
*/
public VectorFieldTypeInformation(FeatureVector.Factory<V, ?> factory, int dim, String[] labels) {
- super(factory.getRestrictionClass(), factory.getDefaultSerializer(), dim, dim);
- this.factory = factory;
+ super(factory, factory.getDefaultSerializer(), dim, dim);
this.labels = labels;
assert (labels == null || labels.length == dim) : "Created vector field with incomplete labels.";
}
@@ -105,9 +118,8 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
* @param mindim Minimum dimensionality request
* @param maxdim Maximum dimensionality request
*/
- public VectorFieldTypeInformation(Class<? super V> cls, int mindim, int maxdim) {
+ private VectorFieldTypeInformation(Class<? super V> cls, int mindim, int maxdim) {
super(cls, mindim, maxdim);
- this.factory = null;
}
/**
@@ -117,29 +129,7 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
* @param dim Dimensionality
*/
public VectorFieldTypeInformation(FeatureVector.Factory<V, ?> factory, int dim) {
- super(factory.getRestrictionClass(), factory.getDefaultSerializer(), dim, dim);
- this.factory = factory;
- }
-
- /**
- * Constructor for a request with fixed dimensionality.
- *
- * @param cls Vector restriction class.
- * @param dim Dimensionality request
- */
- public VectorFieldTypeInformation(Class<? super V> cls, int dim) {
- super(cls, dim, dim);
- this.factory = null;
- }
-
- /**
- * Constructor for a request without fixed dimensionality.
- *
- * @param cls Vector restriction class.
- */
- public VectorFieldTypeInformation(Class<? super V> cls) {
- super(cls);
- this.factory = null;
+ super(factory, factory.getDefaultSerializer(), dim, dim);
}
@Override
@@ -168,18 +158,6 @@ public class VectorFieldTypeInformation<V extends FeatureVector<?>> extends Vect
return mindim;
}
- /**
- * Get the object type factory.
- *
- * @return the factory
- */
- public FeatureVector.Factory<V, ?> getFactory() {
- if (factory == null) {
- throw new UnsupportedOperationException("Requesting factory for a type request!");
- }
- return factory;
- }
-
@Override
public String toString() {
StringBuilder buf = new StringBuilder(getRestrictionClass().getSimpleName());
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 7d568a55..8334e88d 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) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -24,7 +24,7 @@ package de.lmu.ifi.dbs.elki.data.type;
*/
import de.lmu.ifi.dbs.elki.data.FeatureVector;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
/**
* Construct a type information for vector spaces with fixed dimensionality.
@@ -37,31 +37,43 @@ import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
*/
public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTypeInformation<V> {
/**
- * Minimum dimensionality.
+ * Object factory for producing new instances.
*/
- protected final int mindim;
+ private final FeatureVector.Factory<V, ?> factory;
/**
- * Maximum dimensionality.
+ * Constructor for a type request without dimensionality constraints.
+ *
+ * @param cls Class constraint
+ * @param <V> vector type
*/
- protected final int maxdim;
-
+ public static <V extends FeatureVector<?>> VectorTypeInformation<V> typeRequest(Class<? super V> cls) {
+ return new VectorTypeInformation<>(cls, -1, Integer.MAX_VALUE);
+ }
+
/**
- * Constructor for an actual type.
+ * Constructor for a type request with dimensionality constraints.
*
- * @param cls base class
- * @param serializer Serializer
+ * @param cls Class constraint
* @param mindim Minimum dimensionality
* @param maxdim Maximum dimensionality
+ * @param <V> vector type
*/
- public VectorTypeInformation(Class<? super V> cls, ByteBufferSerializer<? super V> serializer, int mindim, int maxdim) {
- super(cls, serializer);
- assert (this.mindim <= this.maxdim);
- this.mindim = mindim;
- this.maxdim = maxdim;
+ public static <V extends FeatureVector<?>> VectorTypeInformation<V> typeRequest(Class<? super V> cls, int mindim, int maxdim) {
+ return new VectorTypeInformation<>(cls, mindim, maxdim);
}
/**
+ * Minimum dimensionality.
+ */
+ protected final int mindim;
+
+ /**
+ * Maximum dimensionality.
+ */
+ protected final int maxdim;
+
+ /**
* Constructor for a type request.
*
* @param cls base class
@@ -69,16 +81,27 @@ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTyp
* @param maxdim Maximum dimensionality
*/
public VectorTypeInformation(Class<? super V> cls, int mindim, int maxdim) {
- this(cls, null, mindim, maxdim);
+ super(cls);
+ this.factory = null;
+ assert (mindim <= maxdim);
+ this.mindim = mindim;
+ this.maxdim = maxdim;
}
/**
- * Constructor for a type request without dimensionality constraints.
+ * Constructor for an actual type.
*
- * @param cls Class constraint
+ * @param factory Vector factory
+ * @param serializer Serializer
+ * @param mindim Minimum dimensionality
+ * @param maxdim Maximum dimensionality
*/
- public VectorTypeInformation(Class<? super V> cls) {
- this(cls, null, -1, Integer.MAX_VALUE);
+ public VectorTypeInformation(FeatureVector.Factory<V, ?> factory, ByteBufferSerializer<? super V> serializer, int mindim, int maxdim) {
+ super(factory.getRestrictionClass(), serializer);
+ this.factory = factory;
+ assert (mindim <= maxdim);
+ this.mindim = mindim;
+ this.maxdim = maxdim;
}
@Override
@@ -122,6 +145,18 @@ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTyp
}
/**
+ * Get the object type factory.
+ *
+ * @return the factory
+ */
+ public FeatureVector.Factory<V, ?> getFactory() {
+ if(factory == null) {
+ throw new UnsupportedOperationException("Requesting factory for a type request!");
+ }
+ return factory;
+ }
+
+ /**
* Get the minimum dimensionality of the occurring vectors.
*
* @return dimensionality
@@ -145,6 +180,15 @@ public class VectorTypeInformation<V extends FeatureVector<?>> extends SimpleTyp
return maxdim;
}
+ /**
+ * Get the multiplicity of the vector.
+ *
+ * @return Multiplicity {@code 1} (except for subclasses)
+ */
+ public int getMultiplicity() {
+ return 1;
+ }
+
@Override
public String toString() {
StringBuilder buf = new StringBuilder(super.toString());
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 ad666ab4..941c9574 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) 2013
+Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team