Here is one way to implement this for 1.

2 is similar but uses Discrete distributions and integer random variables.

John

// The model

var numCoins =
Variable.New<int>();

var numTosses =
Variable.New<int>();

Range c =
new Range(numCoins);

Range t =
new Range(numTosses);

var coin =
Variable.DiscreteUniform(c);

var toss =
Variable.Array<bool>(t);

var coinPrior =
Variable.Array<Bernoulli>(c);

using (Variable.Switch(coin))

{

toss[t] = Variable<bool>.Random(coinPrior[coin]).ForEach(t);

}

// Observations. true = heads, baised coin is first one

bool[] observedTosses =
new bool[] {
true, true, true,
false, true };

Bernoulli[] observedCoinPriors =
new Bernoulli[] {

new Bernoulli(0.9),
new Bernoulli(0.5),
new Bernoulli(0.5) };

// Hook up the observations

numCoins.ObservedValue = observedCoinPriors.Length;

coinPrior.ObservedValue = observedCoinPriors;

numTosses.ObservedValue = observedTosses.Length;

toss.ObservedValue = observedTosses;

// Run the inference

InferenceEngine engine =
new InferenceEngine();

Discrete postCoin = engine.Infer<Discrete>(coin);

Console.WriteLine("Probability I picked biased coin =
{0:0.000}", postCoin.GetProbs()[0]);