Пример #1
0
    def setup_method(self, _):
        from mlpy.mdp.stateaction import State, Action
        State.nfeatures = None
        Action.description = None
        Action.nfeatures = None

        case_template = {
            "state": {
                "type": "float",
                "value": "data.state",
                "is_index": True,
                "retrieval_method": "knn",
                "retrieval_method_params": 5
            },
            "act": {
                "type": "float",
                "value": "data.action",
                "is_index": False,
                "retrieval_method": "cosine",
            },
            "delta_state": {
                "type": "float",
                "value": "data.next_state - data.state",
                "is_index": False,
            }
        }

        from mlpy.knowledgerep.cbr.engine import CaseBase
        self.cb = CaseBase(case_template, retention_method_params={'max_error': 1e-5})

        from mlpy.auxiliary.io import load_from_file
        self.data = load_from_file(os.path.join(os.getcwd(), 'tests', 'data/jointsAndActionsData.pkl'))
Пример #2
0
class TestCaseBase(object):

    def setup_method(self, _):
        from mlpy.mdp.stateaction import State, Action
        State.nfeatures = None
        Action.description = None
        Action.nfeatures = None

        case_template = {
            "state": {
                "type": "float",
                "value": "data.state",
                "is_index": True,
                "retrieval_method": "knn",
                "retrieval_method_params": 5
            },
            "act": {
                "type": "float",
                "value": "data.action",
                "is_index": False,
                "retrieval_method": "cosine",
            },
            "delta_state": {
                "type": "float",
                "value": "data.next_state - data.state",
                "is_index": False,
            }
        }

        from mlpy.knowledgerep.cbr.engine import CaseBase
        self.cb = CaseBase(case_template, retention_method_params={'max_error': 1e-5})

        from mlpy.auxiliary.io import load_from_file
        self.data = load_from_file(os.path.join(os.getcwd(), 'tests', 'data/jointsAndActionsData.pkl'))

    def test_cb_run(self):
        from mlpy.mdp.stateaction import Experience, State, Action

        for i in xrange(len(self.data.itervalues().next())):
            for j in xrange(len(self.data.itervalues().next()[0][i]) - 1):
                # noinspection PyTypeChecker
                experience = Experience(State(self.data["states"][i][:, j]), Action(self.data["actions"][i][:, j]),
                                        State(self.data["states"][i][:, j + 1]))
                self.cb.run(self.cb.case_from_data(experience))

    def teardown_method(self, _):
        pass