if(logger.isDebugging()) {
logger.debug("Dimensionality: " + dim);
}
final NeighborSetPredicate npred = getNeighborSetPredicateFactory().instantiate(spatial);
CovarianceMatrix covmaker = new CovarianceMatrix(dim);
WritableDataStore<Vector> deltas = DataStoreUtil.makeStorage(attributes.getDBIDs(), DataStoreFactory.HINT_TEMP, Vector.class);
for(DBID id : attributes.iterDBIDs()) {
final O obj = attributes.get(id);
final DBIDs neighbors = npred.getNeighborDBIDs(id);
// Compute the median vector
final Vector median;
{
double[][] data = new double[dim][neighbors.size()];
int i = 0;
// Load data
for(DBID n : neighbors) {
// TODO: skip object itself within neighbors?
O nobj = attributes.get(n);
for(int d = 0; d < dim; d++) {
data[d][i] = nobj.doubleValue(d + 1);
}
i++;
}
double[] md = new double[dim];
for(int d = 0; d < dim; d++) {
md[d] = QuickSelect.median(data[d]);
}
median = new Vector(md);
}
// Delta vector "h"
Vector delta = obj.getColumnVector().minus(median);
deltas.put(id, delta);
covmaker.put(delta);
}
// Finalize covariance matrix:
Vector mean = covmaker.getMeanVector();
Matrix cmati = covmaker.destroyToSampleMatrix().inverse();
DoubleMinMax minmax = new DoubleMinMax();
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(attributes.getDBIDs(), DataStoreFactory.HINT_STATIC);
for(DBID id : attributes.iterDBIDs()) {
Vector temp = deltas.get(id).minus(mean);