use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.
the class OutlierLinearScaling method prepare.
@Override
public void prepare(OutlierResult or) {
if (usemean) {
MeanVariance mv = new MeanVariance();
DoubleMinMax mm = (max == null) ? new DoubleMinMax() : null;
boolean skippedzeros = false;
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = scores.doubleValue(id);
if (nozeros && val == 0.0) {
skippedzeros = true;
continue;
}
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
mv.put(val);
}
if (max == null) {
mm.put(val);
}
}
if (skippedzeros && mm.getMin() == mm.getMax()) {
mm.put(0.0);
mv.put(0.0);
}
min = mv.getMean();
if (max == null) {
max = mm.getMax();
}
} else {
if (min == null || max == null) {
boolean skippedzeros = false;
DoubleMinMax mm = new DoubleMinMax();
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = scores.doubleValue(id);
if (nozeros && val == 0.0) {
skippedzeros = true;
continue;
}
mm.put(val);
}
if (skippedzeros && mm.getMin() == mm.getMax()) {
mm.put(0.0);
}
if (min == null) {
min = mm.getMin();
}
if (max == null) {
max = mm.getMax();
}
}
}
factor = (max - min);
}
use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.
the class OutlierLinearScaling method prepare.
@Override
public <A> void prepare(A array, NumberArrayAdapter<?, A> adapter) {
if (usemean) {
MeanVariance mv = new MeanVariance();
DoubleMinMax mm = (max == null) ? new DoubleMinMax() : null;
boolean skippedzeros = false;
final int size = adapter.size(array);
for (int i = 0; i < size; i++) {
double val = adapter.getDouble(array, i);
if (nozeros && val == 0.0) {
skippedzeros = true;
continue;
}
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
mv.put(val);
}
if (max == null) {
mm.put(val);
}
}
if (skippedzeros && mm.getMin() == mm.getMax()) {
mm.put(0.0);
mv.put(0.0);
}
min = mv.getMean();
if (max == null) {
max = mm.getMax();
}
} else {
if (min == null || max == null) {
boolean skippedzeros = false;
DoubleMinMax mm = new DoubleMinMax();
final int size = adapter.size(array);
for (int i = 0; i < size; i++) {
double val = adapter.getDouble(array, i);
if (nozeros && val == 0.0) {
skippedzeros = true;
continue;
}
mm.put(val);
}
if (skippedzeros && mm.getMin() == mm.getMax()) {
mm.put(0.0);
}
if (min == null) {
min = mm.getMin();
}
if (max == null) {
max = mm.getMax();
}
}
}
factor = (max - min);
}
use of de.lmu.ifi.dbs.elki.math.MeanVariance 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.MeanVariance 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.MeanVariance 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;
}
}
Aggregations