[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[wcurry@ctron.com: Re: thinking like a tree]



>Could you post the starlogo TREE algebra code you describe?

I don't have the exact code that was written in Costa Rica, but here is a
similar version. (The full StarLogo project is attached to this message,
with text of the procedures reprinted below.)

As you guessed in your message, the program uses a local/decentralized
approach, in which each turtle compares its "root" to the neighboring
turtles. As you noted, the teachers used a somewhat different strategy at
the workshop, since they compared their "roots" with ALL other teachers,
not just neighboring teachers.

Each turtle's guess/root is indicated by its x-coordinate. Eventually, the
turtles "settle" on one (or two) roots. You might want to use turtle
monitors to keep track of the value of several turtles' x-coordinates.

Note that the program uses a NOISE slider to control the amount of
randomness that the turtles use in making their "guesses." It is generally
effective to start with a high level of randomness, then gradually reduce
it. (This technique is known as "simulated annealing.")

Of course, this is just one approach. If you have other approaches, please
share them with the list.

-- Mitchel

----------------------

turtles-own [nextturtle prevturtle error]

to setup
ca
crt 101
setc red
setnextturtle (who + 1) mod 101
setprevturtle (who - 1) mod 101
sety who
setx random 101
end

to go
seterror abs function
if error > (error-of prevturtle)
   [setx (xcor-of prevturtle) + jiggle]
seterror abs function
if error > (error-of nextturtle)
   [setx (xcor-of nextturtle) + jiggle]
end

to jiggle
ifelse random 2
  [output .1 * random noise]
  [output -.1 * random noise]
end

to function
output (2 * xcor * xcor) - (7 * xcor) - 3075
end


turtles-own [nextturtle prevturtle error]

to setup
ca
crt 101
setc red
setnextturtle (who + 1) mod 101
setprevturtle (who - 1) mod 101
sety who
setx random 101
end

to go
seterror abs function
if error > (error-of prevturtle)
   [setx (xcor-of prevturtle) + jiggle]
seterror abs function
if error > (error-of nextturtle)
   [setx (xcor-of nextturtle) + jiggle]
end

to jiggle
ifelse random 2
  [output .1 * random noise]
  [output -.1 * random noise]
end

to function
output (2 * xcor * xcor) - (7 * xcor) - 3075
end
@#$#@#$#@
BUTTON
19
14
95
43
button1
setup
NIL
1
NIL

SLIDER
15
102
105
127
slider1
noise
1
50
40
1

BUTTON
21
56
95
85
button2
go
T
2
NIL

@#$#@#$#@
THINKING LIKE A TREE

(A StarLogo program to accompany the short essay written by
Mitchel Resnick)

In this example, the turtles collectively find the root(s)
of a quadratic equation.

Each turtle takes a guess at the root (indicated by its
x-coordinate), then compares its guess with those of the
neighboring turtles. If a neighbor's guess was closer, then
the turtle makes a new guess (that is, changes its
x-coordinate) to a number close to its neighbor's guess.

Eventually, the turtles converge on the root(s) of the
equation.

Note that the program uses a NOISE slider to control the
amount of randomness that the turtles use in making their
"guesses." It is generally effective to start with a high
level of randomness, then gradually reduce it. (This
technique is known as "simulated annealing.")

The equation is given by the FUNCTION procedure. In this
case, the equation is 2x^2 - 7x + 29 = 3104 (or, in standard
form: 2x^2 - 7x - 3075 = 0)

Note that the program converges "perfectly" only for integer
roots.
@#$#@#$#@
StarLogo 2.0
@#$#@#$#@
(install-shapenames 'NIL)
@#$#@#$#@
@#$#@#$#@


--------------------------------
Mitchel Resnick
MIT Media Lab
mres@media.mit.edu
617-253-9783
617-253-6215 (fax)
http://www.media.mit.edu/~mres/