mlpy.knowledgerep.cbr.engine.CaseBase¶
-
class
mlpy.knowledgerep.cbr.engine.CaseBase(case_template, reuse_method=None, reuse_method_params=None, revision_method=None, revision_method_params=None, retention_method=None, retention_method_params=None, plot_retrieval=None, plot_retrieval_names=None)[source]¶ Bases:
objectThe case base engine.
The case base engine maintains the a database of all cases entered into the case base. It manages retrieval, revision, reuse, and retention of cases.
Parameters: case_template: dict
The template from which to create a new case.
Example: An example template for a feature named
statewith the specified feature parameters.datais the data from which to extract the case from. In this example it is expected thatdatahas a member variablestate.{ "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, } }
reuse_method : str
The reuse method name to be used during the reuse step. Default is defaultreusemethod.
reuse_method_params : dict
Non-positional initialization parameters for the reuse method instantiation.
revision_method : str
The revision method name to be used during the revision step. Default is defaultrevisionmethod.
revision_method_params : dict
Non-positional initialization parameters for the revision method instantiation.
retention_method : str
The retention method name to be used during the retention step. Default is defaultretentionmethod.
retention_method_params : dict
Non-positional initialization parameters for the retention method instantiation.
plot_retrieval : bool
Whether to plot the result or not. Default is False.
plot_retrieval_names : str or list[str]
The names of the feature which to plot.
Examples
Create a case base:
>>> from mlpy.auxiliary.io import load_from_file >>> >>> template = {} >>> cb = CaseBase(template)
Fill case base with data read from file:
>>> from mlpy.mdp.stateaction import Experience, State, Action >>> >>> data = load_from_file("data/jointsAndActionsData.pkl") >>> for i in xrange(len(data.itervalues().next())): ... for j in xrange(len(data.itervalues().next()[0][i]) - 1): ... if not j == 10: # exclude one experience as test case ... experience = Experience(State(data["states"][i][:, j]), ... Action(data["actions"][i][:, j]), ... State(data["states"][i][:, j + 1])) ... cb.run(cb.case_from_data(experience))
Loop over all cases in the case base:
>>> for i in len(cb): ... pass
Retrieve case with
id=0:>>> case = cb[0]
Attributes
counterThe case counter. Methods
add(case)Add a new case without any checks. case_from_data(data)Convert data into a case using the case template. get_new_id()Return an unused case id. load(filename)next()plot_retention(case, case_matches)Plot the retention result. plot_retrieval(case, case_id_list[, names])Plot the retrieved data. plot_reuse(case, case_matches, revised_matches)Plot the reuse result. plot_revision(case, case_matches)Plot revision results. retain(case, case_matches)Retain new case. retrieve(case[, names, validity_check])Retrieve cases similar to the query case. reuse(case, case_matches)Performs the reuse step revision(case, case_matches)Evaluate solution provided by problem-solving experience. run(case)Run the case base. save(filename)