use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.
the class ClusterContingencyTable method averageSymmetricGini.
/**
* Compute the average Gini for each cluster (in both clusterings -
* symmetric).
*
* @return Mean and variance of Gini
*/
public MeanVariance averageSymmetricGini() {
MeanVariance mv = new MeanVariance();
for (int i1 = 0; i1 < size1; i1++) {
double purity = 0.0;
if (contingency[i1][size2] > 0) {
// sum, as double.
final double cs = contingency[i1][size2];
for (int i2 = 0; i2 < size2; i2++) {
double rel = contingency[i1][i2] / cs;
purity += rel * rel;
}
mv.put(purity, cs);
}
}
for (int i2 = 0; i2 < size2; i2++) {
double purity = 0.0;
if (contingency[size1][i2] > 0) {
// sum, as double.
final double cs = contingency[size1][i2];
for (int i1 = 0; i1 < size1; i1++) {
double rel = contingency[i1][i2] / cs;
purity += rel * rel;
}
mv.put(purity, cs);
}
}
return mv;
}
use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.
the class HeDESNormalizationOutlierScaling method prepare.
@Override
public <A> void prepare(A array, NumberArrayAdapter<?, A> adapter) {
MeanVariance mv = new MeanVariance();
DoubleMinMax minmax = new DoubleMinMax();
final int size = adapter.size(array);
for (int i = 0; i < size; i++) {
double val = adapter.getDouble(array, i);
if (!Double.isNaN(val) && !Double.isInfinite(val)) {
mv.put(val);
minmax.put(val);
}
}
mean = mv.getMean();
stddev = mv.getSampleStddev();
scaledmax = getScaled(minmax.getMax());
scaledmin = getScaled(minmax.getMin());
}
use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.
the class HeDESNormalizationOutlierScaling method prepare.
@Override
public void prepare(OutlierResult or) {
MeanVariance mv = new MeanVariance();
DoubleMinMax minmax = new DoubleMinMax();
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);
minmax.put(val);
}
}
mean = mv.getMean();
stddev = mv.getSampleStddev();
scaledmax = getScaled(minmax.getMax());
scaledmin = getScaled(minmax.getMin());
}
use of de.lmu.ifi.dbs.elki.math.MeanVariance 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.math.MeanVariance in project elki by elki-project.
the class OutlierGammaScaling method prepare.
@Override
public <A> void prepare(A array, NumberArrayAdapter<?, A> adapter) {
MeanVariance mv = new MeanVariance();
final int size = adapter.size(array);
for (int i = 0; i < size; i++) {
double score = adapter.getDouble(array, i);
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);
}
Aggregations