Re: [netlogo-devel] Suggestion: other-than reporter

66 views
Skip to first unread message

Nicolas Payette

unread,
Apr 26, 2013, 7:29:54 PM4/26/13
to Arthur Hjorth, netlog...@googlegroups.com
> set my-home one-of intersections
> set my-workplace one-of intersections other-than my-home
>
> Or do we already have this? That would be great (and embarrassing!)

set my-workplace one-of intersections with [ self != my-home ]

Ken Kahn

unread,
Apr 27, 2013, 6:09:33 AM4/27/13
to hermeshj...@u.northwestern.edu, netlog...@googlegroups.com
Hi.

Why special case removing one element from a set? turtle-set does union of sets but also treats single agents as singleton sets. Perhaps what would be nice is turtle-set-difference that would work as Arthur's other-than but the second parameter could be an agent or agentset.

And then why not also turtle-set-intersection?

Best,

-ken



On 27 April 2013 04:45, <hermeshj...@u.northwestern.edu> wrote:
Well, it's certainly more elegant than both my code options, but it's not really what I asked for.

The more general problem is being able to report an agentset without a particular agent or agentset. I feel like it's in the same vein as 'other' (which you can code your way around with a with [who != etc.]). It's not that you can't do it with the existing language. But having a primitive like other-than would just enable you to write code that reads more easily, and fits better with a natural language articulation of what we want to do.

--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Arthur Hjorth

unread,
Apr 27, 2013, 2:34:49 PM4/27/13
to Ken Kahn, netlog...@googlegroups.com
Hi Ken!

My hope was actually that it would not special case it. My suggestion was to have it follow an agentset reporter and and take either an agent or an agentset (or a nobody, just to avoid runtime errors) and remove them from the reported agentset. That way, other-than could be a general primitive for removing turtle(s) from agentsets.

I really like turtle-set-intersection and turtle-set-difference. However, neither would do what I need it to do. I want an agentset minus the intersection with a (turtle | agentset | nobody).

Cheers,
Arthur

--
Arthur Hjorth
PhD Student, Learning Sciences
Northwestern University

s: arthurhjorth

Ken Kahn

unread,
Apr 28, 2013, 2:52:15 AM4/28/13
to arthur...@u.northwestern.edu, netlog...@googlegroups.com
I think we are proposing the same thing with different names and frameworks.

Set difference of U and A, denoted U \ A, is the set of all members of U that are not members of A
The set difference {1,2,3} \ {2,3,4} is {1} , while, conversely, the set difference {2,3,4} \ {1,2,3} is {4} .


'nobody' is just an empty set and isn't a special case. The conversion of agent x to the set {x} is useful.

My vote is to use reporter names that come from set theory.

I think James' alternatives only behave the same as Arthur's proposed reporter when the second parameter is a singleton.

Best,

-ken

P.S. I learned set theory in elementary school. As did all my classmates. http://en.wikipedia.org/wiki/New_math -- New math is generally considered a failure but personally I'm glad I learned it early on.

Arthur Hjorth

unread,
Apr 28, 2013, 7:32:46 AM4/28/13
to Ken Kahn, netlog...@googlegroups.com
Doh! I even looked up set theory terminology on Wikipedia to make sure I knew what you meant. Looks like I failed, like New Math. And we didn't even have New Math in Denmark when I grew up!

Yes. I definitely agree that having set-difference and set-intersection for agentsets would be great. If this would follow naming/conceptual conventions for set theory, then I also think that using those names would make it much easier for people to find the primitives than anything we (or I) would come up with. 

Thanks for the lesson, Ken :)

Cheers,
Arthur

Seth Tisue

unread,
Apr 29, 2013, 12:50:34 PM4/29/13
to netlog...@googlegroups.com
>>>>> "Nicolas" == Nicolas Payette <nicolas...@gmail.com> writes:

>> set my-home one-of intersections set my-workplace one-of
>> intersections other-than my-home
>>
>> Or do we already have this? That would be great (and embarrassing!)

Nicolas> set my-workplace one-of intersections with [ self != my-home ]

I also very much like James Steiner's suggestion of

set my-workplace [one-of other intersections] of my-home

If this is a solution that comes naturally to your mind, then you've
really learned how to think in NetLogo!

That doesn't cover the general set-difference case though, which I tend
to agree is a hole in the language. I don't have a real strong feeling
about it though since it isn't that hard to do:

to-report intersect [xs ys]
report xs with [member? ? ys]
end

The argument for adding it to the language would be strengthened by the
opportunity to provide an implementation that is asymptotically more
efficient that what you get with the above code. Does that opportunity
exist? Well, at present `member?` is O(n) on ordinary, non-breed
agentsets, so the above code is O(n * m), whereas if the code for the
proposed `intersect` primitive constructed a hash table from one of the
two sets, it could be O(n + m). But actually, it might not be necessary
to add the primitive to get the speedup. We could have `member?`
construct and cache the hash table, and then other sorts of code that
used `member?` would benefit too. Something to think about. It's
actually kind of crummy that agentset membership is O(n); generally
things called "sets" in programming languages are supposed to have
an O(1) or O(log n) membership test in order to earn the name.

--
Seth Tisue | http://tisue.net

Seth Tisue

unread,
Apr 29, 2013, 12:55:21 PM4/29/13
to netlog...@googlegroups.com

One more naming possibility: `besides`. As in `turtles besides x`,
`turtles besides people`, etc.

James Steiner

unread,
Apr 29, 2013, 1:27:02 PM4/29/13
to netlog...@googlegroups.com
When working with agentsets where breed is all the same, does using an interim breed reduce the thingla from o(n*m) to o(n+m)? Does it provide any additional efficiency?

;; assume all members are of same known original breed A

;; all N not members of M

;; O(n*m) ?
let R  N with [ not member? self M ]

;; O(n+m)?
ask M [ set breed B ]
let R N with [ breed = A ]

If breed must be reset back to original breed A

;; O(?)
ask M [ set breed B ]
let R N with [ breed = A ]
ask M [ set breed A ]

~~James


 



Seth Tisue

unread,
Apr 30, 2013, 11:31:37 PM4/30/13
to netlog...@googlegroups.com
>>>>> "James" == James Steiner <ja...@turtlezero.com> writes:

James> When working with agentsets where breed is all the same, does
James> using an interim breed reduce the thingla from o(n*m) to o(n+m)?
James> Does it provide any additional efficiency?

`member?` is O(log n) on breed agentsets (as compared to O(n) on regular
agentsets). So, heh, I suppose it's actually conceivable you could have
an agent change breeds temporarily in order to get a fast membership
test -- though I certainly wouldn't count on it without benchmarking it.
(If I found myself really needing the speedup, I'd be more inclined to
reach for the table extension.)

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/

Ken Kahn

unread,
May 2, 2013, 7:53:08 AM5/2/13
to Seth Tisue, netlog...@googlegroups.com
Regarding naming does there need to be 3 versions (turtle, patch, link)?

(turtle-set turtles patches)

causes

ERROR: TURTLE-SET expected this input to be a list or turtle agentset or turtle, but got a 
patch agentset instead 

so should turtles besides patches be an error or just return turtles?

Seems to me there should be some consistency between set union (turtle-set, link-set, patch-set) and the proposed set difference.

Best,

-ken




Seth Tisue

unread,
May 3, 2013, 7:27:56 AM5/3/13
to netlog...@googlegroups.com
>>>>> "Ken" == Ken Kahn <toon...@gmail.com> writes:

Ken> Regarding naming does there need to be 3 versions (turtle, patch,
Ken> link)?

The reason the turtle-set, patch-set, and link-set primitives have the
agent kind in the name is that in NetLogo, even an empty agentset have
an agent kind. So the union primitives must have some way of knowing
what type the result should be if there are no agents in the input,
otherwise it can't build an agentset at all.

That's also why we have `no-turtles`, `no-patches`, and `no-links`
instead of a single `no-agents` primitive.

The set difference primitives don't have this problem, since we'd always
have a starting agentset to determine the kind. Doesn't mean the naming
*couldn't* include the agent kind, but the choice isn't forced.

As for why an empty agentset must have an agent kind, well... that I
don't remember. It's been baked into the code since day 1, predating my
involvement with NetLogo, and it would be rather difficult to change at
this point.
Reply all
Reply to author
Forward
0 new messages