public double EnumerateAll(List <GenericNode> affections) { if (affections.Count == 0) { return(1.0); } GenericNode affection = affections.ElementAt(0); affections.RemoveAt(0); if (affection.Status == Status.False || affection.Status == Status.True) { double val = affection.ComputeProbabilityConsideringParents(); return(val * EnumerateAll(affections)); } else { // Use something else here. List <GenericNode> copy1 = new List <GenericNode>(affections); List <GenericNode> copy2 = new List <GenericNode>(affections); affection.Status = Status.False; double falseValue = affection.ComputeProbabilityConsideringParents(); falseValue *= EnumerateAll(copy1); affection.Status = Status.True; double trueValue = affection.ComputeProbabilityConsideringParents(); trueValue *= EnumerateAll(copy2); affection.Status = Status.Unspecified; return(falseValue + trueValue); } }
public void ComputeProbabilityConsideringParentsTest_1() { GenericNode node = new GenericNode("Gripa"); double val = node.ComputeProbabilityConsideringParents(); Assert.AreEqual(-1, val); }
public void ComputeProbabilityConsideringParentsTest_3() { GenericNode node = new GenericNode("Gripa"); node.LoadProbabilitiesFromMatrix(); node.SetProbabilities(true); node.Status = Status.False; double val = node.ComputeProbabilityConsideringParents(); Assert.AreEqual(0.9, val); }
public void ComputeProbabilityConsideringParentsTest_6() { GenericNode node = new GenericNode("Oboseala"); node.LoadProbabilitiesFromMatrix(); node.SetProbabilities(true); node.Status = Status.True; node.ListOfParents.Add(new GenericNode("Febra")); node.ListOfParents.ElementAt(0).Status = Status.True; double val = node.ComputeProbabilityConsideringParents(); Assert.AreEqual(0.6, val); }