public void iterate(IMap <IRandomVariable, object> possibleWorld, double probability) { foreach (IRandomVariable rv in possibleWorld.GetKeys()) { RVInfo rvInfo = quotient.randomVarInfo.Get(rv); qRVs[rvInfo.getRadixIdx()] = rvInfo .getIdxForDomain(possibleWorld.Get(rv)); } if (null != diff) { // Start from 0 off the diff dMRN.SetCurrentValueFor(new int[diff.Size()]); do { foreach (IRandomVariable rv in diff.GetKeys()) { RVInfo drvInfo = diff.Get(rv); RVInfo qrvInfo = quotient.randomVarInfo.Get(rv); qRVs[qrvInfo.getRadixIdx()] = dMRN .GetCurrentNumeralValue(drvInfo .getRadixIdx()); } updateQuotient(probability); } while (dMRN.Increment()); } else { updateQuotient(probability); } }
public void testSetCurrentValueFor() { MixedRadixNumber mrn; // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 0, 0, 0, 0 }); Assert.AreEqual(0, mrn.IntValue()); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 2, 2, 1, 1 }); Assert.AreEqual(35, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 1, 2, 0, 1 }); Assert.AreEqual(25, mrn.IntValue()); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 2, 2, 1, 0 }); Assert.AreEqual(17, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 2, 2, 0, 0 }); Assert.AreEqual(8, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 4, 5, 6 }); mrn.SetCurrentValueFor(new int[] { 2, 3, 4, 5 }); Assert.AreEqual(359, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(3, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(4, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(5, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 6, 5, 4, 3 }); mrn.SetCurrentValueFor(new int[] { 5, 4, 3, 2 }); Assert.AreEqual(359, mrn.IntValue()); Assert.AreEqual(5, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(4, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(3, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(3)); }