AIXI.CTWContextTreeNode.Revert C# (CSharp) Method

Revert() public method

public Revert ( int symbol ) : void
symbol int
return void
        public void Revert(int symbol)
        {
            int thisSymbolCount = this.SymbolCount(symbol);
            if (thisSymbolCount > 1)
            {
                this.SetSymbolCount(symbol, thisSymbolCount-1);
            }
            else {
                this.SetSymbolCount(symbol, 0);
            }

            if (this.Children.ContainsKey(symbol) && Children[symbol].Visits()==0) {    //note: this piece was not tested with rest of class
                this.Tree.TreeSize -= Children[symbol].Size();
                this.Children.Remove(symbol);    //low-todo: check if this truly free memory
            }

            this.LogKt -= this.LogKtMultiplier(symbol);
            this.UpdateLogProbability();
        }

Usage Example

        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
        }
All Usage Examples Of AIXI.CTWContextTreeNode::Revert