Package elki.math.linearalgebra
Class Centroid
- java.lang.Object
-
- elki.math.linearalgebra.Centroid
-
- All Implemented Interfaces:
FeatureVector<java.lang.Number>
,NumberVector
,SpatialComparable
- Direct Known Subclasses:
ProjectedCentroid
public class Centroid extends java.lang.Object implements NumberVector
Class to compute the centroid of some data.This is a more numerically stable approach than simply taking the sum divided by the count repeatedly, and allows weighting.
- Since:
- 0.4.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface elki.data.NumberVector
NumberVector.Factory<V extends NumberVector>
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
elements
Vector elements.protected double
wsum
The current weight.-
Fields inherited from interface elki.data.FeatureVector
TYPE
-
Fields inherited from interface elki.data.NumberVector
ATTRIBUTE_SEPARATOR, FIELD, FIELD_1D, FIELD_2D, VARIABLE_LENGTH
-
-
Constructor Summary
Constructors Constructor Description Centroid(int dim)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
doubleValue(int dimension)
Returns the value in the specified dimension as double.double[]
getArrayRef()
Low-level access to the element array.int
getDimensionality()
The dimensionality of the vector space where of this FeatureVector of V is an element.long
longValue(int dimension)
Returns the value in the specified dimension as long.static Centroid
make(Relation<? extends NumberVector> relation, DBIDs ids)
Static constructor from an existing relation.void
put(double[] val)
Add a single value with weight 1.0.void
put(double[] val, double weight)
Add data with a given weight.void
put(NumberVector val)
Add a single value with weight 1.0.void
put(NumberVector val, double weight)
Add data with a given weight.double[]
toArray()
Returns a double array copy of this vector.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface elki.data.FeatureVector
toString
-
Methods inherited from interface elki.data.NumberVector
byteValue, floatValue, getMax, getMin, getValue, intValue, shortValue
-
-
-
-
Method Detail
-
put
public void put(double[] val)
Add a single value with weight 1.0.- Parameters:
val
- Value
-
put
public void put(double[] val, double weight)
Add data with a given weight.- Parameters:
val
- dataweight
- weight
-
put
public void put(NumberVector val)
Add a single value with weight 1.0.- Parameters:
val
- Value
-
put
public void put(NumberVector val, double weight)
Add data with a given weight.- Parameters:
val
- dataweight
- weight
-
doubleValue
public double doubleValue(int dimension)
Description copied from interface:NumberVector
Returns the value in the specified dimension as double.Note: this might seem redundant with respect to
getValue(dim).doubleValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
doubleValue
in interfaceNumberVector
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
longValue
public long longValue(int dimension)
Description copied from interface:NumberVector
Returns the value in the specified dimension as long.Note: this might seem redundant with respect to
getValue(dim).longValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
longValue
in interfaceNumberVector
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
getDimensionality
public int getDimensionality()
Description copied from interface:FeatureVector
The dimensionality of the vector space where of this FeatureVector of V is an element.- Specified by:
getDimensionality
in interfaceFeatureVector<java.lang.Number>
- Specified by:
getDimensionality
in interfaceSpatialComparable
- Returns:
- the number of dimensions of this FeatureVector of V
-
toArray
public double[] toArray()
Description copied from interface:NumberVector
Returns a double array copy of this vector.- Specified by:
toArray
in interfaceNumberVector
- Returns:
- Copy as
double[]
-
make
public static Centroid make(Relation<? extends NumberVector> relation, DBIDs ids)
Static constructor from an existing relation.- Parameters:
relation
- Relation to useids
- IDs to use- Returns:
- Centroid
-
getArrayRef
public double[] getArrayRef()
Low-level access to the element array.- Returns:
- Array access
-
-