Esempio n. 1
0
        /// <summary>
        /// Calculate G.
        /// </summary>
        /// <param name="network">The network to calculate for.</param>
        /// <param name="e">The event to calculate for.</param>
        /// <param name="parents">The parents.</param>
        /// <returns>The value for G.</returns>
        public double CalculateG(BayesianNetwork network,
                                 BayesianEvent e, IList <BayesianEvent> parents)
        {
            double result = 1.0;
            int    r      = e.Choices.Count;

            var args = new int[parents.Count];

            do
            {
                double n = EncogMath.Factorial(r - 1);
                double d = EncogMath.Factorial(CalculateN(network, e,
                                                          parents, args) + r - 1);
                double p1 = n / d;

                double p2 = 1;
                for (int k = 0; k < e.Choices.Count; k++)
                {
                    p2 *= EncogMath.Factorial(CalculateN(network, e, parents, args, k));
                }

                result *= p1 * p2;
            } while (EnumerationQuery.Roll(parents, args));

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Reset the truth table to zero.
        /// </summary>
        public void Reset()
        {
            _lines.Clear();
            IList <BayesianEvent> parents = _event.Parents;
            int l = parents.Count;

            int[] args = new int[l];

            do
            {
                for (int k = 0; k < _event.Choices.Count; k++)
                {
                    AddLine(0, k, args);
                }
            } while (EnumerationQuery.Roll(parents, args));
        }