update getting started readme
@@ -11,25 +11,29 @@ public class WetGrass {
public static void main(String[] args) {
- Flip rain = new Flip(0.2);
+ BoolVertex rain = new Flip(0.2);
- BoolVertex sprinkler = If.isTrue(rain)
- .then(new Flip(0.01))
- .orElse(new Flip(0.4));
+ BoolVertex sprinkler = new Flip(
+ If.isTrue(rain)
+ .then(0.01)
+ .orElse(0.4)
+ );
- CPTVertex<BooleanTensor> wetGrass = CPT.of(sprinkler, rain)
- .when(false, false).then(new Flip(0.0))
- .when(false, true).then(new Flip(0.8))
- .when(true, false).then(new Flip(0.9))
- .orDefault(new Flip(0.99));
+ BoolVertex wetGrass = new Flip(
+ CPT.of(sprinkler, rain)
+ .when(false, false).then(1e-2)
+ .when(false, true).then(0.8)
+ .when(true, false).then(0.9)
+ .orDefault(0.99)
+ );
- wetGrass.observe(BooleanTensor.scalar(true));
+ wetGrass.observe(true);
- NetworkSamples posteriorSamples = RejectionSampler.getPosteriorSamples(
+ NetworkSamples posteriorSamples = MetropolisHastings.getPosteriorSamples(
new BayesianNetwork(wetGrass.getConnectedGraph()),
Arrays.asList(sprinkler, rain),
100000
- );
+ ).drop(10000).downSample(2);
double probabilityOfRainGivenWetGrass = posteriorSamples.get(rain).probability(isRaining -> isRaining.scalar() == true);
