use of de.lmu.ifi.dbs.elki.math.Mean in project elki by elki-project.
the class StandardDeviationScaling method prepare.
@Override
public void prepare(OutlierResult or) {
if (fixedmean == null) {
MeanVariance mv = new MeanVariance();
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = scores.doubleValue(id);
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
mv.put(val);
}
}
mean = mv.getMean();
factor = lambda * mv.getSampleStddev() * MathUtil.SQRT2;
if (factor == 0.0) {
factor = Double.MIN_NORMAL;
}
} else {
mean = fixedmean;
Mean sqsum = new Mean();
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = scores.doubleValue(id);
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
sqsum.put((val - mean) * (val - mean));
}
}
factor = lambda * FastMath.sqrt(sqsum.getMean()) * MathUtil.SQRT2;
if (factor == 0.0) {
factor = Double.MIN_NORMAL;
}
}
}
use of de.lmu.ifi.dbs.elki.math.Mean in project elki by elki-project.
the class StandardDeviationScaling method prepare.
@Override
public <A> void prepare(A array, NumberArrayAdapter<?, A> adapter) {
if (fixedmean == null) {
MeanVariance mv = new MeanVariance();
final int size = adapter.size(array);
for (int i = 0; i < size; i++) {
double val = adapter.getDouble(array, i);
if (!Double.isInfinite(val)) {
mv.put(val);
}
}
mean = mv.getMean();
factor = lambda * mv.getSampleStddev() * MathUtil.SQRT2;
if (factor == 0.0) {
factor = Double.MIN_NORMAL;
}
} else {
mean = fixedmean;
Mean sqsum = new Mean();
final int size = adapter.size(array);
for (int i = 0; i < size; i++) {
double val = adapter.getDouble(array, i);
if (!Double.isInfinite(val)) {
sqsum.put((val - mean) * (val - mean));
}
}
factor = lambda * FastMath.sqrt(sqsum.getMean()) * MathUtil.SQRT2;
if (factor == 0.0) {
factor = Double.MIN_NORMAL;
}
}
}
use of de.lmu.ifi.dbs.elki.math.Mean in project elki by elki-project.
the class MinusLogStandardDeviationScaling method prepare.
@Override
public void prepare(OutlierResult or) {
if (fixedmean == null) {
MeanVariance mv = new MeanVariance();
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = -FastMath.log(scores.doubleValue(id));
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
mv.put(val);
}
}
mean = mv.getMean();
factor = lambda * mv.getSampleStddev() * MathUtil.SQRT2;
} else {
mean = fixedmean;
Mean sqsum = new Mean();
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = -FastMath.log(scores.doubleValue(id));
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
sqsum.put((val - mean) * (val - mean));
}
}
factor = lambda * FastMath.sqrt(sqsum.getMean()) * MathUtil.SQRT2;
}
}
use of de.lmu.ifi.dbs.elki.math.Mean in project elki by elki-project.
the class DWOF method initializeRadii.
/**
* This method prepares a container for the radii of the objects and
* initializes radii according to the equation:
*
* initialRadii of a certain object = (absoluteMinDist of all objects) *
* (avgDist of the object) / (minAvgDist of all objects)
*
* @param ids Database IDs to process
* @param distFunc Distance function
* @param knnq kNN search function
* @param radii WritableDoubleDataStore to store radii
*/
private void initializeRadii(DBIDs ids, KNNQuery<O> knnq, DistanceQuery<O> distFunc, WritableDoubleDataStore radii) {
FiniteProgress avgDistProgress = LOG.isVerbose() ? new FiniteProgress("Calculating average kNN distances-", ids.size(), LOG) : null;
double absoluteMinDist = Double.POSITIVE_INFINITY;
double minAvgDist = Double.POSITIVE_INFINITY;
// to get the mean for each object
Mean mean = new Mean();
// Iterate over all objects
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
KNNList iterNeighbors = knnq.getKNNForDBID(iter, k);
// skip the point itself
mean.reset();
for (DBIDIter neighbor1 = iterNeighbors.iter(); neighbor1.valid(); neighbor1.advance()) {
if (DBIDUtil.equal(neighbor1, iter)) {
continue;
}
for (DBIDIter neighbor2 = iterNeighbors.iter(); neighbor2.valid(); neighbor2.advance()) {
if (DBIDUtil.equal(neighbor1, neighbor2) || DBIDUtil.equal(neighbor2, iter)) {
continue;
}
double distance = distFunc.distance(neighbor1, neighbor2);
mean.put(distance);
if (distance > 0. && distance < absoluteMinDist) {
absoluteMinDist = distance;
}
}
}
double currentMean = mean.getMean();
radii.putDouble(iter, currentMean);
if (currentMean < minAvgDist) {
minAvgDist = currentMean;
}
LOG.incrementProcessed(avgDistProgress);
}
LOG.ensureCompleted(avgDistProgress);
// Initializing the radii of all objects.
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
radii.putDouble(iter, (minAvgDist > 0) ? (absoluteMinDist * radii.doubleValue(iter) / minAvgDist) : Double.POSITIVE_INFINITY);
}
}
use of de.lmu.ifi.dbs.elki.math.Mean in project elki by elki-project.
the class AttributeWiseMeanNormalizationTest method defaultParameters.
/**
* Test with default parameters.
*/
@Test
public void defaultParameters() {
String filename = UNITTEST + "normalization-test-1.csv";
AttributeWiseMeanNormalization<DoubleVector> filter = new ELKIBuilder<AttributeWiseMeanNormalization<DoubleVector>>(AttributeWiseMeanNormalization.class).build();
MultipleObjectsBundle bundle = readBundle(filename, filter);
int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
// We verify that all columns have a mean of 0:
Mean[] ms = Mean.newArray(dim);
for (int row = 0; row < bundle.dataLength(); row++) {
DoubleVector d = get(bundle, row, 0, DoubleVector.class);
for (int col = 0; col < dim; col++) {
final double val = d.doubleValue(col);
if (val > Double.NEGATIVE_INFINITY && val < Double.POSITIVE_INFINITY) {
ms[col].put(val);
}
}
}
for (int col = 0; col < dim; col++) {
assertEquals("Mean is not 1", 1., ms[col].getMean(), 1e-14);
}
}
Aggregations