use of org.apache.commons.math3.distribution.EnumeratedIntegerDistribution in project pyramid by cheng-li.
the class BMDistribution method sample.
List<MultiLabel> sample(int numSamples) {
List<MultiLabel> list = new ArrayList<>();
double[] proportions = Arrays.stream(logProportions).map(Math::exp).toArray();
double[][] classProbs = new double[numComponents][numLabels];
for (int k = 0; k < numComponents; k++) {
for (int l = 0; l < numLabels; l++) {
classProbs[k][l] = Math.exp(logClassProbs[k][l][1]);
}
}
int[] components = IntStream.range(0, numComponents).toArray();
EnumeratedIntegerDistribution enumeratedIntegerDistribution = new EnumeratedIntegerDistribution(components, proportions);
BernoulliDistribution[][] bernoulliDistributions = new BernoulliDistribution[numComponents][numLabels];
for (int k = 0; k < numComponents; k++) {
for (int l = 0; l < numLabels; l++) {
bernoulliDistributions[k][l] = new BernoulliDistribution(classProbs[k][l]);
}
}
for (int num = 0; num < numSamples; num++) {
MultiLabel multiLabel = new MultiLabel();
int k = enumeratedIntegerDistribution.sample();
for (int l = 0; l < numLabels; l++) {
int v = bernoulliDistributions[k][l].sample();
if (v == 1) {
multiLabel.addLabel(l);
}
}
list.add(multiLabel);
}
return list;
}
Aggregations