Search in sources :

Example 1 with UncertainObject

use of de.lmu.ifi.dbs.elki.data.uncertain.UncertainObject in project elki by elki-project.

the class WeightedDiscreteUncertainifier method newFeatureVector.

@Override
public <A> WeightedDiscreteUncertainObject newFeatureVector(Random rand, A array, NumberArrayAdapter<?, A> adapter) {
    UncertainObject uo = inner.newFeatureVector(rand, array, adapter);
    final int distributionSize = rand.nextInt((maxQuant - minQuant) + 1) + minQuant;
    DoubleVector[] samples = new DoubleVector[distributionSize];
    double[] weights = new double[distributionSize];
    double wsum = 0.;
    for (int i = 0; i < distributionSize; i++) {
        samples[i] = uo.drawSample(rand);
        double w = rand.nextDouble();
        while (w <= 0.) {
            // Avoid zero weights.
            w = rand.nextDouble();
        }
        weights[i] = w;
        wsum += w;
    }
    // Normalize to a total weight of 1:
    assert (wsum > 0.);
    for (int i = 0; i < distributionSize; i++) {
        weights[i] /= wsum;
    }
    return new WeightedDiscreteUncertainObject(samples, weights);
}
Also used : DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) WeightedDiscreteUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject) UncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.UncertainObject) WeightedDiscreteUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject)

Example 2 with UncertainObject

use of de.lmu.ifi.dbs.elki.data.uncertain.UncertainObject in project elki by elki-project.

the class UnweightedDiscreteUncertainifier method newFeatureVector.

@Override
public <A> UnweightedDiscreteUncertainObject newFeatureVector(Random rand, A array, NumberArrayAdapter<?, A> adapter) {
    UncertainObject uo = inner.newFeatureVector(rand, array, adapter);
    final int distributionSize = rand.nextInt((maxQuant - minQuant) + 1) + minQuant;
    DoubleVector[] samples = new DoubleVector[distributionSize];
    for (int i = 0; i < distributionSize; i++) {
        samples[i] = uo.drawSample(rand);
    }
    return new UnweightedDiscreteUncertainObject(samples);
}
Also used : UnweightedDiscreteUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.UnweightedDiscreteUncertainObject) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) UncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.UncertainObject) UnweightedDiscreteUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.UnweightedDiscreteUncertainObject)

Aggregations

DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)2 UncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.UncertainObject)2 UnweightedDiscreteUncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.UnweightedDiscreteUncertainObject)1 WeightedDiscreteUncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject)1