Beispiel #1
0
        public void Evaluate(
            IGridWorldPolicy policy,
            IGridWorldRewarder gridWorldRewarder,
            int sweepLimit = -1)
        {
            var sweep = 0;
            var largestValueChange = 0.0;

            do
            {
                largestValueChange = 0.0;

                foreach (var state in _world.AllStates())
                {
                    var originalValue = Value(state);
                    var newValue      = CalculateValue(state, policy, gridWorldRewarder);

                    _values[state.Position1D] = newValue;

                    var valueChange = Math.Abs(originalValue - newValue);
                    if (valueChange > largestValueChange)
                    {
                        largestValueChange = valueChange;
                    }
                }

                if (sweepLimit > 0 && ++sweep == sweepLimit)
                {
                    break;
                }
            } while (largestValueChange > 0.000001);
        }
Beispiel #2
0
        public static GreedyGridWorldPolicy Create(
            GridWorld world,
            GridWorldValueTable gridWorldValueTable,
            IGridWorldRewarder gridWorldRewarder)
        {
            var greedyPolicy = new GreedyGridWorldPolicy();

            foreach (var state in world.AllStates())
            {
                greedyPolicy._actions[state] = FindBestAction(world, state, gridWorldValueTable, gridWorldRewarder);
            }

            return(greedyPolicy);
        }
Beispiel #3
0
 public GridWorldValueTable(GridWorld world)
 {
     _world  = world;
     _values = new double[world.AllStates().Count()];
 }