Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Help with understanding Simple Machine Learning Turtle model

63 views
Skip to first unread message

gladys haywood

unread,
Mar 31, 2025, 5:22:02 PMMar 31
to netlogo-users
For the  Simple Machine Learning turtles model at https://www.netlogoweb.org/launch#https://www.netlogoweb.org/assets/modelslib/IABM%20Textbook/chapter%208/Simple%20Machine%20Learning.nlogo 

Can someone help me understand how the inputs and operators combine to produce a heading for the turtle? Also, is there any modification that can get the turtle to its goal (the top right corner) exactly?

Thanks,
Anna Haywood

Dale Frakes

unread,
Apr 1, 2025, 11:35:27 AMApr 1
to netlog...@googlegroups.com
Hi Anna,

this was new to me and the key is that it's using map/reduce to construct a list of parts of a netlogo command.  That gets evaluated with run-result (which takes some text and executes is as a Netlogo command), which in this case does some math to generate a number.  This is covered starting with page 391 of Wilensky's textbook.  Depending on your institution, you might be able to get access to just that chapter here: https://www.jstor.org/stable/j.ctt17kk851

The first few lines set things up:



Each turtle has a strategy.  There are also the two globals that hold the possible operators and inputs.

The initial strategy gets set up here:



Breaking that down, let's go step by step (in the Command Center):
observer> show inputs
observer: ["heading " "xcor " "1 " "2 " "10 "]
observer> show (list one-of inputs)
observer: ["heading "]
observer> show (list one-of inputs)
observer: ["2 "]


To see how the rest works, I added a global variable stratx so we can walk through a version of that reporter.

observer> set stratx (list one-of inputs)
observer> show stratx
observer: ["10 "]

The next line has something like this that gets repeated 5 times:

observer> show (sentence stratx one-of operators one-of inputs)
observer: ["10 " "- " "1 "]

It's taken that original "10 " that got put into stratx (a list) and added one element randomly from operators and one from inputs.  When it gets repeated 5 times and stored in stratx, it might look like:

observer> repeat 5 [ set stratx (sentence stratx one-of operators one-of inputs) ]
observer> show stratx
observer: ["10 " "* " "1 " "* " "10 " "- " "1 " "- " "heading " "+ " "xcor "]

So that shows how the inputs and operators get randomly built into a strategy and if you ask the turtles their strategies after setup, you'll see something like this:

observer> ask turtles [ show strategy ]
(turtle 11): ["xcor " "- " "2 " "+ " "2 " "- " "10 " "- " "2 " "+ " "xcor "]
(turtle 0): ["10 " "* " "1 " "+ " "1 " "- " "1 " "* " "xcor " "* " "heading "]
(turtle 12): ["heading " "- " "xcor " "* " "xcor " "* " "heading " "- " "1 " "- " "heading "]
(turtle 4): ["heading " "+ " "xcor " "* " "xcor " "* " "2 " "* " "xcor " "- " "heading "]
(turtle 14): ["2 " "+ " "xcor " "+ " "2 " "- " "2 " "+ " "1 " "+ " "heading "]
(turtle 18): ["1 " "- " "2 " "+ " "10 " "* " "1 " "+ " "xcor " "* " "xcor "]
(turtle 5): ["2 " "- " "2 " "- " "xcor " "- " "2 " "- " "heading " "- " "2 "]
(turtle 17): ["xcor " "* " "2 " "- " "heading " "+ " "1 " "+ " "2 " "+ " "heading "]


The next part we need to look at is this:
set heading run-result reduce word strategy

Looking back at the stratx I made above, it converts that list of elements into a string that is a Netlogo expression:

observer> show reduce word stratx
observer: "10 * 1 * 10 - 1 - heading + xcor "

which is then evaluated with run-result.  If this were a turtle's strategy, the expression is:  10 * 1 * 10 - 1 - [turtle's current heading] + [turtle's current xcor]

Now for demonstration I've modified the code to only generate 1 turtle. 


From that I can see its strategy:


When it does run-result, it's going to evaluate 1 - 81 * 81 * 10 + 10 + 2... to -65597



Then when the heading is outside the typical range, Netlogo wraps it around to 0-360 appropriately (e.g. -65597 mod 360 = 283).


Note that go code has each turtle repeat the process 25 times, since as it adjusts heading and moves, some of the values of inputs like xcor and heading have changed.  This is what causes some of the turtles to move in arcs, etc.





Cheers!

Dale
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/netlogo-users/cd5ff409-3805-484e-a17d-27e8fe568b53n%40googlegroups.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Student
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/

Jackson Ville

unread,
Apr 14, 2025, 8:56:45 AMApr 14
to netlogo-users
Hj
Reply all
Reply to author
Forward
0 new messages