当前位置: 首页>>代码示例>>C#>>正文


C# Set.remove方法代码示例

本文整理汇总了C#中Set.remove方法的典型用法代码示例。如果您正苦于以下问题:C# Set.remove方法的具体用法?C# Set.remove怎么用?C# Set.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set.remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkIsDAGAndCollectVariablesInTopologicalOrder

        // END-BayesianNetwork
        //

        //
        // PRIVATE METHODS
        //
        private void checkIsDAGAndCollectVariablesInTopologicalOrder()
        {

            // Topological sort based on logic described at:
            // http://en.wikipedia.org/wiki/Topoligical_sorting
            Set<Node> seenAlready = new Set<Node>();
            Map<Node, List<Node>> incomingEdges = new Map<Node, List<Node>>();
            Set<Node> s = new Set<Node>();
            foreach (Node n in this.rootNodes)
            {
                walkNode(n, seenAlready, incomingEdges, s);
            }
            while (!(s.Count == 0))
            {
                HashSet<Node>.Enumerator enumerator = s.GetEnumerator();
                enumerator.MoveNext();
                Node n = enumerator.Current;
                s.remove(n);
                variables.Add(n.getRandomVariable());
                varToNodeMap.put(n.getRandomVariable(), n);
                foreach (Node m in n.getChildren())
                {
                    List<Node> edges = incomingEdges.get(m);
                    edges.Remove(n);
                    if (edges.Count == 0)
                    {
                        s.add(m);
                    }
                }
            }

            foreach (List<Node> edges in incomingEdges.values())
            {
                if (!(edges.Count == 0))
                {
                    throw new IllegalArgumentException(
                        "Network contains at least one cycle in it, must be a DAG.");
                }
            }
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:46,代码来源:BayesNet.cs

示例2: calculateVariables

        // END-BayesInference
        //

        //
        // PROTECTED METHODS
        //
        /**
         * <b>Note:</b>Override this method for a more efficient implementation as
         * outlined in AIMA3e pgs. 527-28. Calculate the hidden variables from the
         * Bayesian Network. The default implementation does not perform any of
         * these.<br>
         * <br>
         * Two calcuations to be performed here in order to optimize iteration over
         * the Bayesian Network:<br>
         * 1. Calculate the hidden variables to be enumerated over. An optimization
         * (AIMA3e pg. 528) is to remove 'every variable that is not an ancestor of
         * a query variable or evidence variable as it is irrelevant to the query'
         * (i.e. sums to 1). 2. The subset of variables from the Bayesian Network to
         * be retained after irrelevant hidden variables have been removed.
         * 
         * @param X
         *            the query variables.
         * @param e
         *            observed values for variables E.
         * @param bn
         *            a Bayes net with variables {X} &cup; E &cup; Y /* Y = hidden
         *            variables //
         * @param hidden
         *            to be populated with the relevant hidden variables Y.
         * @param bnVARS
         *            to be populated with the subset of the random variables
         *            comprising the Bayesian Network with any irrelevant hidden
         *            variables removed.
         */

        protected void calculateVariables(RandomVariable[] X,
                                          AssignmentProposition[] e, BayesianNetwork bn,
                                          Set<RandomVariable> hidden, List<RandomVariable> bnVARS)
        {

            bnVARS.AddRange(bn.getVariablesInTopologicalOrder());
            hidden.addAll(bnVARS);

            foreach (RandomVariable x in X)
            {
                hidden.remove(x);
            }
            foreach (AssignmentProposition ap in e)
            {
                hidden.removeAll(ap.getScope());
            }

            return;
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:54,代码来源:EliminationAsk.cs

示例3: sumOut

        public ProbabilityTable sumOut(params RandomVariable[] vars)
        {
            Set<RandomVariable> soutVars = new Set<RandomVariable>(
                this.randomVarInfo.keySet());
            foreach (RandomVariable rv in vars)
            {
                soutVars.remove(rv);
            }
            ProbabilityTable summedOut = new ProbabilityTable(soutVars);
            if (1 == summedOut.getValues().Length)
            {
                summedOut.getValues()[0] = getSum();
            }
            else
            {
                // Otherwise need to iterate through this distribution
                // to calculate the summed out distribution.
                Object[] termValues = new Object[summedOut.randomVarInfo
                    .size()];
                //ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {

                //        int i = 0;
                //        foreach (RandomVariable rv in summedOut.randomVarInfo.keySet()) {
                //            termValues[i] = possibleWorld.get(rv);
                //            i++;
                //        }
                //        summedOut.getValues()[summedOut.getIndex(termValues)] += probability;
                //    }
                //};
                //iterateOverTable(di);
                //TODO:
            }

            return summedOut;
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:37,代码来源:ProbabilityTable.cs


注:本文中的Set.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。