I have created a model using the Roth-Erev reinforcement learning algorithm so that every round agents select their action a from a set of actions A. The actions count how often they are played throughout the entire game.
I would now like to create a histogram that has the frequency on the y-axis and the actions on the x-axis. I would also like to label every action with its parameters, but I understand that is not possible.
Merely using histogram count [n-played] of actions would not plot every action individually. I think plotxy comes closest but isn't suitable for histograms. Is there any build in solution or do I have to visualize data outside of Netlogo?
You won't be able to label the columns, but you are not limited to the histogram command for producing bar plot. Each plot pen has a mode that can be "line", "bar" or "point". By using the "bar" mode, you can produce bar plots with the plot or plotxy commands:
Here is the code for easy cut and paste:
plot-pen-reset
foreach map [ [ n-played ] of ? ] sort actions plot
Note that this uses the "concise task syntax" for passing plot to foreach. You can write [ plot ? ] if you prefer.
Related
I'm working through a textbook, and trying to plot the way a variable 'energy' changes over time, for two breeds, 'sheep' and 'wolves'.
When I try and plot the energy for wolves, I use the code:
plot [energy] of wolves
in the 'pen update commands' for my plot. When I try to run the model using the go procedure, I get the following error message:
PLOT expected input to be a number but got the list [105.09999999999982 129.59999999999982 112.09999999999982 112.09999999999982 112.09999999999982 108.59999999999982 129.59999999999982 115.59999999999982 108.59999999999982 119.09999999999982] instead.
error while observer running PLOT
called by plot 'Energy over Time' pen 'wolves' update code
called by procedure GO
called by Button 'go'
I'd appreciate it if anyone could tell me what I'm doing wrong, and how to get the plot to model the way the agents own variables change over time.
If you have 5 wolves, then you are asking NetLogo to plot a list of 5 numbers, but it needs a single number to plot (on y axis, and tick/time goes on x axis). You probably want the average energy of wolves. Try plot mean [energy] of wolves
Can someone instruct me how to produce a plot consisting of number of stochastic curves combined with deterministic curve for the same set of chemical reactions only by using particular icons (tabs) in simbiology?
I know how to draw deterministic curve for particular model
(SimBiology:Model:Add Task:Simulate model, and then choose solver i.e. ode)
And I know how to produce a bunch of stochastic curves
(SimBiology:Model:Add Task: Run ensemble simulation....)
But I don't know how to merge these curves (det. and stoch.) into one plot.
Here's one way to do it:
Add a Simuation Task to your project
Turn on the live plots section (by clicking the Live Plots button in the toolstrip)
Enable overlaying of results in the Live Plots (by right-clicking on the live plot and selecting the menu option "Overlay Results")
Configure the simulation settings as desired (for example, click on the Simulation Settings button and switch between deterministic and stochastic solvers)
Run the task
Repeat the configuration and running of the task
You can find more information on the Live Plots here and here.
I am trying to plot a graph that shows the variables of all agents of one breed. Although the number of agents is rather small, I think there must be a more elegant way than creating a pen for every agent. Is there?
Elegance, here, depends on what exactly you want to do. It can be perfectly legitimate to create one plot pen per turtle, using create-temporary-plot-pen. Among advantages, it means that you can give each plot pen a name and show a legend on your plot.
That being said, it's also very easy to use a single pen for all your agents. Suppose you have multiple turtles, of different colors, and you want to plot their sizes. You can put something like this in a pen's "update commands":
ask turtles [ set-plot-pen-color color plotxy ticks size ]
This will change the pen to the color of each turtle and plot a single point for that turtle. Just be sure to set your pen to "point" mode in the advanced pen options.
Also notice the use of plotxy instead of just plot, allowing you to specify an x coordinate instead of relying on the "auto advance" behavior of plot.
Is it possible to have plots that are updated at different time points?
My model looks like that (it is replicator dynamics):
to go
repeat 10 [do-something]
replicate
tick
end
Then I would like to have one plot that is updated on tick, just like usual, and the second one that is updated at do-something and then reset at tick.
I tried to find a solution in documentation but update-plots command updates ALL plots which is not what i want.
You can use the various manual plotting commands (eg plotxy, plot-pen-down, plot-pen-up) to explicitly plot things, see the plotting section of the user manual, but is often simpler to have the plot commands in the plot rather than the code.
To do it in the plot instead of code, you could change to a structure like this (if your full code is suitable):
to go
do-something
if ticks mod 10 = 0 [ replicate ]
tick
end
and use the automatic update of plots with tick. You would also use the if ticks mod 10 = 0 trick in the update section of your plot.
Is there a way to change the background color of a plot window in NetLogo?
(I want turtles to be black and white, and I'd like plot pens for statistics on the two kinds of turtles to match their colors. A white pen is not visible on a white background, obviously.)
Thanks.
NetLogo has not built-in way to change the background color of a plot. Arguably, this is something it should have. If you feel strongly enough about it, I would suggest sending a feature request to feedback#ccl.northwestern.edu or even opening an issue directly on GitHub.
Now, in the meanwhile, is there a way around it? Well, I feel almost dirty for even suggesting it, but you could do something like this:
Create a new plot pen of the color you wish your background to be, and set it to "line mode". This pen has to be the first one in your plot pen list so it's drawn before the other pens. (This might require deleting your other pens and recreating them, as NetLogo doesn't have an easy way to reorder plot pens, I think.)
Now put the following in your pen's update commands:
plot-pen-reset
let y plot-y-min
while [ y <= plot-y-max ] [
plotxy plot-x-min y
plotxy plot-x-max y
set y y + 0.05
]
This will draw lines, one by one, to fill your background. Depending on the size of your plot on the screen, you might want to play with the "interval" (0.05 here) to find the biggest value that doesn't leave white lines.
Be warned: this will slow down your model. If your plot axis are never rescaled, however, maybe you can get away with putting the code in your pen's setup commands so it's only executed once.