Ejemplo n.º 1
0
        public void UpdateOutcomes()
        {
            Node[]     parents     = Parents.ToArray();
            string[]   parentNames = new string[0];
            string[][] outcomes    = new string[0][];

            foreach (Node parent in parents)
            {
                Array.Resize(ref parentNames, parentNames.Length + 1);
                parentNames[parentNames.Length - 1] = parent.Name;
                Array.Resize(ref outcomes, outcomes.Length + 1);
                outcomes[outcomes.Length - 1] = parent.Definitions;
            }

            var conditionCombinations     = CartesianCompute.CartesianProduct(outcomes);
            HashSet <ValueOutcome> values = new HashSet <ValueOutcome>();

            if (conditionCombinations != null && conditionCombinations.Count() > 0)
            {
                foreach (var comb in conditionCombinations)
                {
                    string[]     combArr = comb.ToArray();
                    ValueOutcome value   = new ValueOutcome(combArr.ToArray(), parents, 0);

                    Console.WriteLine("ValueOutcome: " + value.ToString());
                    values.Add(value);
                }
            }
            this.outcomes = values.ToArray();
        }
Ejemplo n.º 2
0
        public void UpdateProbabilities()
        {
            Node[]     parents     = Parents.ToArray();
            string[]   parentNames = new string[0];
            string[][] outcomes    = new string[][] { Definitions };

            bool hasEventParent = false;

            foreach (Node parent in parents)
            {
                if (parent.Type == NodeType.Event)
                {
                    hasEventParent = true;
                }
                Array.Resize(ref parentNames, parentNames.Length + 1);
                parentNames[parentNames.Length - 1] = parent.Name;
                Array.Resize(ref outcomes, outcomes.Length + 1);
                outcomes[outcomes.Length - 1] = parent.Definitions;
            }

            var conditionCombinations   = CartesianCompute.CartesianProduct(outcomes);
            HashSet <Probability> probs = new HashSet <Probability>();

            foreach (var comb in conditionCombinations)
            {
                string[]    combArr = comb.ToArray();
                Probability prob    = null;
                if (hasEventParent)
                {
                    prob = new Probability(new string[] { combArr[0] }, new Node[] { owner }, combArr.Skip(1).ToArray(), parents);
                }
                else
                {
                    prob = new Probability(combArr, new Node[] { owner }.Concat(parents).ToArray(), new string[0], new Node[0]);
                }
                Console.WriteLine("Probability: " + prob.ToString());
                probs.Add(prob);
            }
            probabilities = probs.ToArray();
        }