/// <summary> /// Compute a probability for a node. /// </summary> /// <returns>A probability of a node with a value (T/F), considering its parents and their values (T/F)</returns> public double ComputeProbabilityConsideringParents() { // The probability of a node is: // the probability of that node if has no parents // the probability conditioned by the parents if it has any if (0 == ListOfParents.Count) { switch (Status) { case Status.True: return(_probabilities[0, 0]); case Status.False: return(_probabilities[0, 1]); } } else { // The line in matrix is determined by a combination between TRUE/FALSE values of the parents. // The column is determined by TRUE/FALSE status of current node. // In case of TRUE, the column is 0, otherwise 1. // By default, the variable is set to TRUE. int column = 0; if (Status == Status.False) { column = 1; } bool[] correspondingValues = new bool[ListOfParents.Count]; for (int i = 0; i < ListOfParents.Count; ++i) { GenericNode parent = ListOfParents.ElementAt(i); if (parent.Status == Status.False) { correspondingValues[i] = false; } else if (parent.Status == Status.True) { correspondingValues[i] = true; } } for (int i = 0; i < ListOfParents.Count; i++) { correspondingValues[i] = correspondingValues[i] ^ true; } int val = 0; for (int i = 0; i < ListOfParents.Count; ++i) { val = (val << 1) | ToDigit(correspondingValues[i]); } return(_probabilities[val, column]); } return(-1); }
public override int GetHashCode() { unchecked { var hashCode = (ListOfParents != null ? ListOfParents.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TrueProbabilityTextBoxes != null ? TrueProbabilityTextBoxes.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (FalseProbabilityTextBoxes != null ? FalseProbabilityTextBoxes.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (_probabilities != null ? _probabilities.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)Status; return(hashCode); } }