use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.
the class MinusLogGammaScaling method prepare.
@Override
public void prepare(OutlierResult or) {
meta = or.getOutlierMeta();
// Determine Minimum and Maximum.
DoubleMinMax mm = new DoubleMinMax();
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double score = scores.doubleValue(id);
if (!Double.isNaN(score) && !Double.isInfinite(score)) {
mm.put(score);
}
}
max = mm.getMax();
mlogmax = -FastMath.log(mm.getMin() / max);
// with the prescaling, do Gamma Scaling.
MeanVariance mv = new MeanVariance();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double score = scores.doubleValue(id);
score = preScale(score);
if (!Double.isNaN(score) && !Double.isInfinite(score)) {
mv.put(score);
}
}
final double mean = mv.getMean();
final double var = mv.getSampleVariance();
k = (mean * mean) / var;
theta = var / mean;
atmean = GammaDistribution.regularizedGammaP(k, mean / theta);
// logger.warning("Mean:"+mean+" Var:"+var+" Theta: "+theta+" k: "+k+"
// valatmean"+atmean);
}
use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.
the class MultiplicativeInverseScaling method prepare.
@Override
public void prepare(OutlierResult or) {
double max = Double.MIN_VALUE;
DoubleRelation scores = or.getScores();
for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
double val = scores.doubleValue(id);
double inv = Math.abs(1.0 / val);
if (!Double.isInfinite(inv) && !Double.isNaN(inv)) {
max = Math.max(max, inv);
}
}
scaleval = max;
}
use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation 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.database.relation.DoubleRelation in project elki by elki-project.
the class RankingPseudoOutlierScaling method prepare.
@Override
public void prepare(OutlierResult or) {
// collect all outlier scores
DoubleRelation oscores = or.getScores();
scores = new double[oscores.size()];
int pos = 0;
if (or.getOutlierMeta() instanceof InvertedOutlierScoreMeta) {
inverted = true;
}
for (DBIDIter iditer = oscores.iterDBIDs(); iditer.valid(); iditer.advance()) {
scores[pos] = oscores.doubleValue(iditer);
pos++;
}
if (pos != oscores.size()) {
throw new AbortException("Database size is incorrect!");
}
// sort them
Arrays.sort(scores);
}
use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation 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;
}
}
}
Aggregations