| … | … | @@ -7,7 +7,7 @@ from opencog.type_constructors import * |
| 7 | 7 | from opencog.utilities import set_default_atomspace |
| 8 | 8 | |
| 9 | 9 | from rocca.agents import OpencogAgent |
| 10 | | from rocca.agents.utils import agent_log |
| 10 | from rocca.agents.utils import TRUE_TV, agent_log |
| 11 | 11 | from rocca.envs.malmo_demo.flatworld_env import * |
| 12 | 12 | from rocca.envs.wrappers import MalmoWrapper |
| 13 | 13 | from opencog.ure import ure_logger |
| … | … | @@ -46,6 +46,33 @@ class AbstractMalmoWrapper(MalmoWrapper): |
| 46 | 46 | print("Error sending command:", e) |
| 47 | 47 | return obs_list, mk_evaluation("Reward", reward), done |
| 48 | 48 | |
| 49 | class FlatworldAgent(OpencogAgent): |
| 50 | def __init__(self, env, atomspace): |
| 51 | set_default_atomspace(atomspace) |
| 52 | |
| 53 | # Create Action Space. The set of allowed actions an agent can take. |
| 54 | # TODO take care of action parameters. |
| 55 | action_space = { |
| 56 | ExecutionLink(SchemaNode("go_to_the_key")), |
| 57 | ExecutionLink(SchemaNode("go_to_the_house")), |
| 58 | ExecutionLink(SchemaNode("go_to_the_diamonds")), |
| 59 | } |
| 60 | # Create Goal |
| 61 | pgoal = EvaluationLink(PredicateNode("Reward"), NumberNode("1")) |
| 62 | ngoal = EvaluationLink(PredicateNode("Reward"), NumberNode("0")) |
| 63 | |
| 64 | # Call super ctor |
| 65 | OpencogAgent.__init__(self, env, atomspace, action_space, pgoal, ngoal) |
| 66 | |
| 67 | # Overwrite some OpencogAgent parameters |
| 68 | self.polyaction_mining = False |
| 69 | self.monoaction_general_succeedent_mining = True |
| 70 | self.temporal_deduction = True |
| 71 | self.true_cogscm = True |
| 72 | self.empty_vardecl_cogscm = True |
| 73 | # Todo: restart the environment to get an initial reward |
| 74 | self.initial_reward = EvaluationLink(PredicateNode("Reward"), NumberNode("0")) |
| 75 | |
| 49 | 76 | if __name__ == "__main__": |
| 50 | 77 | atomspace = AtomSpace() |
| 51 | 78 | set_default_atomspace(atomspace) |
| … | … | @@ -53,30 +80,19 @@ if __name__ == "__main__": |
| 53 | 80 | # Init loggers |
| 54 | 81 | log.set_level("info") |
| 55 | 82 | # log.set_sync(True) |
| 56 | | agent_log.set_level("debug") |
| 83 | agent_log.set_level("fine") |
| 57 | 84 | # agent_log.set_sync(True) |
| 58 | 85 | ure_logger().set_level("info") |
| 59 | 86 | |
| 60 | 87 | # |
| 61 | 88 | wrapped_env = AbstractMalmoWrapper(missionXML=missionXML, validate=True) |
| 62 | 89 | |
| 63 | | # Create Goal |
| 64 | | pgoal = EvaluationLink(PredicateNode("Reward"), NumberNode("1")) |
| 65 | | ngoal = EvaluationLink(PredicateNode("Reward"), NumberNode("0")) |
| 66 | | |
| 67 | | # Create Action Space. The set of allowed actions an agent can take. |
| 68 | | # TODO take care of action parameters. |
| 69 | | action_space = { |
| 70 | | ExecutionLink(SchemaNode("go_to_the_key")), |
| 71 | | ExecutionLink(SchemaNode("go_to_the_house")), |
| 72 | | ExecutionLink(SchemaNode("go_to_the_diamonds")), |
| 73 | | } |
| 74 | | |
| 75 | | cog_agent = OpencogAgent(wrapped_env, atomspace, action_space, pgoal, ngoal) |
| 76 | | |
| 90 | cog_agent = FlatworldAgent(wrapped_env, atomspace) |
| 91 | reward_t0 = cog_agent.record(cog_agent.initial_reward, 0, TRUE_TV) |
| 92 | agent_log.info("Initial reward: {}".format(reward_t0)) |
| 77 | 93 | |
| 78 | 94 | # Training/learning loop |
| 79 | | lt_iterations = 3 # Number of learning-training iterations |
| 95 | lt_iterations = 2 # Number of learning-training iterations |
| 80 | 96 | lt_period = 50 # Duration of a learning-training iteration |
| 81 | 97 | for i in range(lt_iterations): |
| 82 | 98 | cog_agent.reset_action_counter() |