public bool compare(CTWContextTree other)
        {
            if (this.TreeSize != other.TreeSize ||
                this.Depth != other.Depth)
            {
                return(false);
            }

            for (int i = 0; i < this.Context.Count; i++)
            {
                if (!this.SameNode(this.Context[i], other.Context[i]))
                {
                    return(false);
                }
            }
            for (int i = 0; i < this.History.Count; i++)
            {
                if (this.History[i] != other.History[i])
                {
                    return(false);
                }
            }

            return(this.compare(this.RootI, other.Root));
        }
        public void TestCtwContextTreeNode()
        {
            var tree = new CTWContextTree(5);
            var n = new CTWContextTreeNode(tree);

            Assert.AreEqual(0.0, n.LogKt, 0.001);
            Assert.AreEqual(0.0, n.LogProbability, 0.001);
            Assert.AreEqual(0, n.SymbolCount(0));
            Assert.AreEqual(0, n.SymbolCount(1));
            Assert.AreEqual(0, n.NumberOf0S);
            Assert.AreEqual(0, n.NumberOf1S);
            Assert.AreEqual(tree, n.Tree);
            Assert.AreEqual(0, n.Visits());
            Assert.AreEqual(true, n.IsLeaf());
            Assert.AreEqual(1, n.Size());

            n.Update(1);
            n.Update(0);
            n.Update(0);
            n.Update(0);
            n.Update(1);

            Assert.AreEqual(-4.4465, n.LogKt, 0.001);
            Assert.AreEqual(-4.44656, n.LogProbability, 0.001);
            Assert.AreEqual(3, n.SymbolCount(0));
            Assert.AreEqual(2, n.SymbolCount(1));
            Assert.AreEqual(3, n.NumberOf0S);
            Assert.AreEqual(2, n.NumberOf1S);
            Assert.AreEqual(tree, n.Tree);
            Assert.AreEqual(5, n.Visits());
            Assert.AreEqual(true, n.IsLeaf());
            Assert.AreEqual(1, n.Size());

            n.Revert(1);

            Assert.AreEqual(-3.2425, n.LogKt, 0.001);
            Assert.AreEqual(-3.24259, n.LogProbability, 0.001);
            Assert.AreEqual(3, n.SymbolCount(0));
            Assert.AreEqual(1, n.SymbolCount(1));
            Assert.AreEqual(3, n.NumberOf0S);
            Assert.AreEqual(1, n.NumberOf1S);
            Assert.AreEqual(tree, n.Tree);
            Assert.AreEqual(4, n.Visits());
            Assert.AreEqual(true, n.IsLeaf());
            Assert.AreEqual(1, n.Size());

            //Todo:test non-leaf
        }
Esempio n. 3
0
        public void TestMethod1()
        {
            //here we make instances of CTWContextTreeFast and CTWContextTree and test if they behave in same way
            var ctf = new CTWContextTreeFast(9);
            var ct = new CTWContextTree(9);

            int[] input = { 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1 };
            ct.update_tree(input);
            ctf.update_tree(input);
            ct.revert_tree(4);
            ctf.revert_tree(4);
            int[] input2 = { 0, 0, 1 };
            ct.update_tree(input2);
            ctf.update_tree(input2);

            Assert.IsTrue(ctf.compare(ct));
        }
Esempio n. 4
0
 public CTWContextTreeNode(CTWContextTree tree)
 {
     this.Children = new Dictionary <int, CTWContextTreeNode>();
     this.Tree     = tree;
 }
Esempio n. 5
0
        public bool compare(CTWContextTree other)
        {
            if (this.TreeSize != other.TreeSize ||
                this.Depth != other.Depth)
            {
                return false;
            }

            for (int i = 0; i < this.Context.Count; i++) {
                if (!this.SameNode(this.Context[i], other.Context[i])) {
                    return false;
                }
            }
            for (int i=0; i<this.History.Count; i++){
                if (this.History[i] != other.History[i]){
                    return false;
                }
            }

            return this.compare(this.RootI, other.Root);
        }
Esempio n. 6
0
 public CTWContextTreeNode(CTWContextTree tree)
 {
     this.Children = new Dictionary<int, CTWContextTreeNode>();
     this.Tree = tree;
 }