-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSampler.java
87 lines (71 loc) · 2.88 KB
/
Sampler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package dk.alexandra.fresco.stat;
import dk.alexandra.fresco.framework.DRes;
import dk.alexandra.fresco.framework.builder.numeric.ProtocolBuilderNumeric;
import dk.alexandra.fresco.framework.value.SInt;
import dk.alexandra.fresco.lib.fixed.SFixed;
import java.util.List;
/** This computation library contains functions which samples random values from various distributions. */
public interface Sampler {
static Sampler using(ProtocolBuilderNumeric builder) {
return new DefaultSampler(builder);
}
/**
* Draw a sample from a Bernoulli distribution with parameter <i>p</i> with <i>0 ≤ p ≤
* 1</i>.
*/
DRes<SInt> sampleBernoulliDistribution(DRes<SFixed> p);
/**
* Draw a sample from a Bernoulli distribution with parameter <i>p</i> with <i>0 ≤ p ≤
* 1</i>.
*/
DRes<SInt> sampleBernoulliDistribution(double p);
/**
* Draw a sample from the set <i>{0, ..., probabilities.size() - 1}</i> with
* <i>probabilities.get(i)</i> indicating the probability of drawing <i>i</i>. Note that the sum
* of probabilities should be equal to 1.
*/
DRes<SInt> sampleCategoricalDistribution(List<DRes<SFixed>> probabilities);
/**
* Draw a sample from the set <i>{0, ..., probabilities.length - 1}</i> with
* <i>probabilities[i]</i> indicating the probability of drawing <i>i</i>. Note that the sum of
* probabilities should be equal to 1.
*/
DRes<SInt> sampleCategoricalDistribution(double[] probabilities);
/**
* Draw a sample from the set <i>{0, ..., probabilities.size() - 1}</i> with
* <i>probabilities.get(i)</i> indicating the probability of drawing <i>i</i>. If it is not known
* whether the sum of the probabilities is equal to 1, the <i>normalized</i> parameter should be
* set to <code>false</code>.
*/
DRes<SInt> sampleCategoricalDistribution(List<DRes<SFixed>> probabilities, boolean normalized);
/**
* Draw a sample from an exponential distribution with parameter <i>λ = 1 / b</i> with <i>b gt;
* 0</i>.
*/
DRes<SFixed> sampleExponentialDistribution(DRes<SFixed> b);
/**
* Draw a sample from an exponential distribution with parameter <i>λ = 1 / b</i> with <i>b gt;
* 0</i>.
*/
DRes<SFixed> sampleExponentialDistribution(double b);
/**
* Draw a sample from a Laplace distribution with location <i>0</i> and scale <i>b > 0</i>.
*/
DRes<SFixed> sampleLaplaceDistribution(double b);
/**
* Draw a sample from a Laplace distribution with location <i>0</i> and scale <i>b gt; 0</i>.
*/
DRes<SFixed> sampleLaplaceDistribution(DRes<SFixed> b);
/**
* Draw a sample from a normal distribution with mean 0 and variance 1.
*/
DRes<SFixed> sampleNormalDistribution();
/**
* Draw a sample from a Rademacher distribution.
*/
DRes<SInt> sampleRademacherDistribution();
/**
* Draw a sample form a uniform distribution on <i>[0, 1)</i>.
*/
DRes<SFixed> sampleUniformDistribution();
}