Exemplo n.º 1
0
        private ADNode MakeADTree(int i, BitArray recordNums, int depth, Varset variables)
        {
            // since this is index i, there are (variableCount - i) remaining variables.
            // therefore, it will have that many children
            int count = 0;
            for(int idx = 0; idx < recordNums.Count; idx++)
            {
                if (recordNums[idx])
                {
                    count += 1;
                }
            }
            ADNode adn = new ADNode(network.Size() - i, count);

            // check if we should just use a leaf list
            if (adn.Count < rMin)
            {
                BitArray leafList = new BitArray(recordNums);
                adn.LeafList = leafList;
                return adn;
            }

            // for each of the remaining variables
            for (int j = i; j < network.Size(); j++)
            {
                // create a vary node
                variables.Set(j, true);
                Varset newVariables = new Varset(variables);
                VaryNode child = MakeVaryNode(j, recordNums, depth, newVariables);
                adn.SetChild(j - i, child);
            }

            return adn;
        }
Exemplo n.º 2
0
 private void CreateTree()
 {
     BitArray countIndices = new BitArray(recordCount);
     countIndices.SetAll(true);
     Varset empty = new Varset(network.Size());
     root = MakeADTree(0, countIndices, 0, empty);
 }
Exemplo n.º 3
0
        private ContingencyTableNode MakeContab(Varset remainingVariables, ADNode node, int nodeIndex)
        {
            // check base case
            if (remainingVariables.Equals(zero))
            {
                ContingencyTableNode ctn = new ContingencyTableNode(node.Count, 0, 1);
                return ctn;
            }

            int firstIndex = remainingVariables.FindFirst();
            int n = network.GetCardinality(firstIndex);
            VaryNode vn = node.GetChild(firstIndex - nodeIndex - 1);
            ContingencyTableNode ct = new ContingencyTableNode(0, n, 0);
            Varset newVariables = Varset.ClearCopy(remainingVariables, firstIndex);

            ContingencyTableNode ctMcv = MakeContab(newVariables, node, nodeIndex);

            for (int k = 0; k < n; k++)
            {
                if (vn.GetChild(k) == null)
                {
                    continue;
                }

                ADNode adn = vn.GetChild(k);

                ContingencyTableNode child = null;
                if (adn.LeafList.Count == 0) // これ注意
                {
                    child = MakeContab(newVariables, adn, firstIndex);
                }
                else
                {
                    child = MakeContabLeafList(newVariables, adn.LeafList);
                }

                ct.SetChild(k, child);
                ct.LeafCount += child.LeafCount;

                ctMcv.Subtract(ct.GetChild(k));
            }
            ct.SetChild(vn.Mcv, ctMcv);
            ct.LeafCount += ctMcv.LeafCount;

            return ct;
        }
Exemplo n.º 4
0
 public void SetChild(int index, ADNode child)
 {
     children[index] = child;
 }