Exemplo n.º 1
0
 /// <summary>
 /// Creates a new IndependencyCalculator
 /// </summary>
 /// <param name="probCalculator">Provider for probability distributions</param>
 /// <param name="tolerance">Tolerance level for double calculations</param>
 /// <param name="config">BayesianLearningConfiguration object for optional settings</param>
 public IndependencyCalculator(IProbabilityDistributionCalculator probCalculator, double tolerance, BayesianLearningConfiguration?config = null)
 {
     _config         = config ?? BayesianLearningConfiguration.Default;
     _probCalculator = probCalculator;
     _tolerance      = tolerance;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a Bayesian Network from a given DagPattern which has to be a DAG and calculates the conditional distributions according to the DAG structure.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown when the given DagPattern is no DAG</exception>
        public static BayesianNetwork FromDagPattern(DagPattern <RandomVariable> dag, IProbabilityDistributionCalculator calc)
        {
            if (!dag.IsDag())
            {
                throw new ArgumentException("BayesianNetworks need a DAG, but the given DAG was actually a DAG pattern!");
            }
            var network = new BayesianNetwork(dag);

            foreach (var rvar in dag.Nodes)
            {
                var parents      = dag.GetParents(rvar).ToList();
                var distribution = calc.CalculateConditionalProbabilityDistribution(rvar, parents);
                network.Distributions[rvar] = new ProbabilityDistribution(rvar, parents, distribution);
            }
            return(network);
        }