Search in sources :

Example 1 with WeightedDiscreteUncertainObject

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

the class WeightedUncertainSplitFilter method filterSingleObject.

@Override
protected WeightedDiscreteUncertainObject filterSingleObject(NumberVector vec) {
    final int dim = vec.getDimensionality();
    if (dim % mod != 0) {
        throw new AbortException("Vector length " + dim + " not divisible by the number of dimensions + 1 (for probability): " + mod);
    }
    final int num = dim / mod;
    final DoubleVector[] samples = new DoubleVector[num];
    final double[] weights = new double[dims];
    final double[] buf = new double[dims];
    for (int i = 0, j = 0, k = 0, l = 0; i < mod; i++) {
        if (l++ == probcol) {
            weights[k] = vec.doubleValue(i);
        } else {
            buf[j++] = vec.doubleValue(i);
        }
        if (l == mod) {
            samples[k] = DoubleVector.copy(buf);
            j = 0;
            l = 0;
            k++;
        }
    }
    return new WeightedDiscreteUncertainObject(samples, weights);
}
Also used : DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) LessConstraint(de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessConstraint) GreaterEqualConstraint(de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint) WeightedDiscreteUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 2 with WeightedDiscreteUncertainObject

use of de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject 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)

Aggregations

DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)2 WeightedDiscreteUncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject)2 UncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.UncertainObject)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 GreaterEqualConstraint (de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint)1 LessConstraint (de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessConstraint)1