Creating distributions of values for an agent.
Let's say you want to create a distribution of happiness across a set of Individuals. If you want to assign a simple random value for happiness you could simply:
- Create an Individual "Happiness" attribute an give it type Real. Set the "Gather Data" property to true.
- Create an Individual Initialize Rule.
- Create an Evaluate Action, name it "Initial Happiness" and a random function such as "Random Unit" which gives a uniformly distributed random number between 0.0 and 1.0.
- Create a child Set Action with Happiness as the Attribute and "Initial Happiness" as the To value.
But typically you will want to parameterize the value, and you may even want to have the value depend on other agent attributes. You could do all of that manually, but AMF has built in support for creating more elaborate distributions easily. This looks more complicated than it is!
- Add Agent States for factors that might affect happiness. Perhaps Relative Income (Low, Average,Maximum) and Philosophy (Optimist, Realist, Stoic).
- Create an Evaluate Action with function "Random State" and a corresponding Set Action for Relative Income.
- Do the same for Philosophy. These should be children Actions for the above actions.
- Drag the "Initial Happiness" Action to become a child node of the Set Action for Philosophy.
- Change the function to "Distribution: Uniform Add Distribution".
- Open the first "Multiple Values" entry in the Evaluate Action, select "Initial Happiness State and select the ... button next to the Multiple State properties. (You might have to open the "Misc" category.)
- In the dialog, select the Relative Income and Philosophy states and add them. Click OK.
- You'll see that a bunch of Attributes have been created in the enclosing context. Assign some ranges for them. (Though it's generally good practice to assign a default value for everything, 0 will be assumed if you don't specify anything else.
- The factor values will be added to one another so add an Evaluate Action with function: "Minimum", input 1 value "Initial Happiness" and input 2 value of "Unit".
- Drag the Set Action is a child of the new Evaluate, and change it's to attribute to the new Minimum evaluation you've just created.
Your model should look something like this:
You can download the model here: http://download.eclipse.org/amp/examples/models/Happiness.metaabm. When you run the model, you can see that the agents have been assigned values according to the distributions.
TODO: There is an issue with code generation for the other distribution functions. https://bugs.eclipse.org/bugs/show_bug.cgi?id=290191. Unfortunately, there is only support for uniform distributions now. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=290195. We need to add functions for creating gaussian and other distributions from normal.