-
Couldn't load subscription status.
- Fork 2
Understanding simple_production_v3.py
From the code tab at the top, download simple_production_v3.py into your ccm suite folder.
Right-click it and select "open in Idle."
You can read over the comments in the file. This page has more detailed descriptions of the code. Python ACT-R actually re-programs parts of Python, being it to its will. If you already understand how to program in Python, you might get some interference, because certain functions have been redefined!
import ccm
log=ccm.log()
from ccm.lib.actr import *
For now, these commands should be in every Python ACT-R model you make.
They import the necessary functions for everything to run, and saves a record of what happened into a variable called "log."
This is where we will eventually put things that are in the agent's environment--that is, not concepts in the head, but in the (simulated) world. But we're trying to keep things simple, so, for now, we will have nothing in the environment. To do this, we just put in 'pass.'
class MyEnvironment(ccm.Model):
pass
In the following code, we create an instance of the ACTR class, called MyAgent.
class MyAgent(ACTR):
The focus buffer is where we put goals. But we need to create the buffer, empty, first.
focus=Buffer()
The init() function gets run automatically. We want the agent to start with a goal, a focus on something. Here we set the focus of the agent to the goal of making a sandwich, and, specifically, the bread, because getting the first piece of bread is the first step.
def init():
focus.set('goal:sandwich object:bread')
Productions are created using the
defcommand. If you already know how to program in Python, don't get confused by this! It works differently, because Python ACT-R rewrites some of how Python works at all.
The arguments of the def, the stuff that goes in the parentheses after the production name, is the list of preconditions. That is, the left-hand side (LHS) of the production. For the production to "match," these preconditions need to be satisfied. In this case, the focus needs to be goal:sandwich and object:bread.
The body of the def function describes the right-hand side (RHS) of the production. In this case, we're just printing out "I have a piece of bread," then setting the goal to the next step in making a sandwich, which is to get the cheese.
def bread_bottom(focus='goal:sandwich object:bread'):
## In future models, it will actually do something.
## For now it just prints something out for us to see.
print "I have a piece of bread"
## To move on to the next step, we change the chunk that
## is in focus buffer by setting it to something new.
focus.set('goal:sandwich object:cheese')