AIXI.MC_AIXI_CTW.Search C# (CSharp) Method

Search() public method

public Search ( ) : int
return int
        public override int Search()
        {
            CtwContextTreeUndo undoInstance = new CtwContextTreeUndo(this);

            MonteCarloSearchNode searchTree = new MonteCarloSearchNode(MonteCarloSearchNode.DecisionNode);

            for (int i = 0; i < this.McSimulations; i++) {
                searchTree.Sample(this, this.Horizon);
                this.model_revert(undoInstance);
            }

            //searchTree.PrintBs();

            int bestAction=-1;
            double bestMean = double.NegativeInfinity;

            foreach (int action in this.Environment.ValidActions) {

                if (!searchTree.Children.ContainsKey(action)) {
                    continue;
                }

                double mean = searchTree.Children[action].Mean + Utils.RandomDouble(0, 0.0001);
                if (mean > bestMean) {
                    bestMean = mean;
                    bestAction = action;
                }
            }
            return bestAction;
        }