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[]elementsVector elements.protected doublewsumThe 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 doubledoubleValue(int dimension)Returns the value in the specified dimension as double.double[]getArrayRef()Low-level access to the element array.intgetDimensionality()The dimensionality of the vector space where of this FeatureVector of V is an element.longlongValue(int dimension)Returns the value in the specified dimension as long.static Centroidmake(Relation<? extends NumberVector> relation, DBIDs ids)Static constructor from an existing relation.voidput(double[] val)Add a single value with weight 1.0.voidput(double[] val, double weight)Add data with a given weight.voidput(NumberVector val)Add a single value with weight 1.0.voidput(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:NumberVectorReturns 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:
 doubleValuein 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:NumberVectorReturns 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:
 longValuein 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:FeatureVectorThe dimensionality of the vector space where of this FeatureVector of V is an element.- Specified by:
 getDimensionalityin interfaceFeatureVector<java.lang.Number>- Specified by:
 getDimensionalityin interfaceSpatialComparable- Returns:
 - the number of dimensions of this FeatureVector of V
 
 
- 
toArray
public double[] toArray()
Description copied from interface:NumberVectorReturns a double array copy of this vector.- Specified by:
 toArrayin 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
 
 
 - 
 
 -