Exemplo n.º 1
0
    def test_model_creation(self):
        from mlpy.mdp import MDPModelFactory

        # create discrete model
        with pytest.raises(ValueError):
            MDPModelFactory.create('discretemodel')

        from mlpy.mdp.stateaction import Action
        Action.description = {
            'out': {'value': [-0.004]},
            'in': {'value': [0.004]},
            'kick': {'value': [-1.0]}
        }
        MDPModelFactory.create('discretemodel')

        # create decision tree model
        MDPModelFactory.create('decisiontreemodel')
        MDPModelFactory.create('decisiontreemodel', explorer_type='unknownbonusexplorer')
        MDPModelFactory.create('decisiontreemodel', explorer_type='leastvisitedbonusexplorer',
                               explorer_params={'rmax': 1.0})

        with pytest.raises(ValueError):
            MDPModelFactory.create('decisiontreemodel', explorer_type='undefined')

        # create CASML model
        case_template = {
            "state": {
                "type": "float",
                "value": "data.state",
                "is_index": True,
                "retrieval_method": "radius-n",
                "retrieval_method_params": 0.01
            },
            "delta_state": {
                "type": "float",
                "value": "data.next_state - data.state",
                "is_index": False,
            }
        }
        MDPModelFactory.create('casml', case_template)
Exemplo n.º 2
0
        demo = data["state"]
    except IOError:
        sys.exit(sys.exc_info()[1])
    except KeyError, e:
        sys.exit("Key not found: {0}".format(e))

    kwargs = {}
    if args.model == "decisiontreemodel":
        kwargs = {"use_reward_trees": args.use_reward_trees}
        if args.explorer_type in ["unvisitedbonusexplorer", "leastvisitedbonusexplorer", "unknownbonusexplorer"]:
            kwargs.update({"explorer_type": args.explorer_type, "rmax": args.rmax})
        if args.explorer_type == "leastvisitedbonusexplorer" and args.thresh:
            kwargs.update({"thresh": args.thresh})
    else:
        args.ignore_unreachable = False
    model = MDPModelFactory.create(args.model, **kwargs)

    explorer = None
    if args.explorer_type in ["egreedyexplorer", "softmaxexplorer"]:
        explorer = ExplorerFactory.create(args.explorer_type, args.explorer_params, args.decay)

    if args.learner == "apprenticeshiplearner":
        learner = None
        if args.progress:
            try:
                learner = ApprenticeshipLearner.load(args.savefile)
            except IOError:
                pass

        if not learner:
            try: