## Re: [netlogo-users] Comparing lists

Expand Messages
• ... Not sure if I understand. Something like this? Given two lists, convert the first to true/false values representing the occurrence of elements from first
Message 1 of 8 , Jul 31, 2011
• 0 Attachment
On Jul 31, 2011, at 10:25 AM, t.timmermans wrote:

I´m trying to compare two lists in netlogo.

The first list register previous actions of agents and therefore is indexed by who numbers. For each who number the list contains a single value.

The second list is a simple sequence of numbers, i.e. 4, 7, 10, 13...

I´m looking for a code to compare both lists and to see whether the number in list 1 is part of the sequence in list 2, preferable with true/false outcome.

Not sure if I understand. Something like this? Given two lists, convert the first to true/false values representing the occurrence of elements from first list in the second. To convert a list based on some operation, we use the `map` primitive. To test if a value is in a list we use the `member?` primitive.

to test
let \$result-list n-values 10 [random 50]  ; turtle results list
let \$seq-list [5 10 13 25 33 41]  ; some kind of sequence
; convert results list to true/false values, true if result occurs in seq-list
let \$occurence-list map [member? ? \$seq-list] \$result-list
print \$result-list
print \$seq-list
print \$occurence-list
end

observer> test
[46 34 33 35 26 13 40 40 15 41]
[5 10 13 25 33 41]
[false false true false false true false false false true]

HTH,
Jim
• Thank you Jim, that worked fine!
Message 2 of 8 , Aug 16, 2011
• 0 Attachment
Thank you Jim, that worked fine!
• This begs the question to me, and i do not know the answer, = how can one use who numbers in a mathematical sense.... E.g. suppose i wanted turtles that had
Message 3 of 8 , Feb 5, 2012
• 0 Attachment
This begs the question to me, and i do not know the answer, =
how can one use "who numbers" in a mathematical sense....

E.g. suppose i wanted turtles that had "who numbers"
an operation on these numbers?

That is test who number of the turtle (pull it out of its turtle context??)

--- In netlogo-users@yahoogroups.com, Jim Lyons <jimlyons@...> wrote:
>
> On Jul 31, 2011, at 10:25 AM, t.timmermans wrote:
>
> > I´m trying to compare two lists in netlogo.
> >
> > The first list register previous actions of agents and therefore is indexed by who numbers. For each who number the list contains a single value.
> >
> > The second list is a simple sequence of numbers, i.e. 4, 7, 10, 13...
> >
> > I´m looking for a code to compare both lists and to see whether the number in list 1 is part of the sequence in list 2, preferable with true/false outcome.
>
> Not sure if I understand. Something like this? Given two lists, convert the first to true/false values representing the occurrence of elements from first list in the second. To convert a list based on some operation, we use the `map` primitive. To test if a value is in a list we use the `member?` primitive.
>
> to test
> let \$result-list n-values 10 [random 50] ; turtle results list
> let \$seq-list [5 10 13 25 33 41] ; some kind of sequence
> ; convert results list to true/false values, true if result occurs in seq-list
> let \$occurence-list map [member? ? \$seq-list] \$result-list
> print \$result-list
> print \$seq-list
> print \$occurence-list
> end
>
> observer> test
> [46 34 33 35 26 13 40 40 15 41]
> [5 10 13 25 33 41]
> [false false true false false true false false false true]
>
> HTH,
> Jim
>
• ... kennuth1 E.g. suppose i wanted turtles that had who numbers kennuth1 divisible by 5... How can i gain access to, or perform an kennuth1 operation on
Message 4 of 8 , Feb 6, 2012
• 0 Attachment
>>>>> "kennuth1" == kennuth1 <kennuth1@...> writes:

kennuth1> E.g. suppose i wanted turtles that had "who numbers"
kennuth1> divisible by 5... How can i gain access to, or perform an
kennuth1> operation on these numbers?

observer> crt 100
observer> show count turtles with [who mod 5 = 0 ]
observer: 20

--
Seth Tisue | Northwestern University | http://tisue.net
• Hi, I want to compare two bitstrings (just lists of 0 s and 1 s), but with some of the values arbitrary for a reasonable genetic algorithm in a market model.
Message 5 of 8 , Sep 8, 2012
• 0 Attachment
Hi, I want to compare two bitstrings (just lists of 0's and 1's), but with some of the values arbitrary for a reasonable genetic algorithm in a market model. The indices of the values in the bitstrings correspond to a particular condition that I have decided to use, if the market is in that condition, the value is 1, if not, it's 0.

Anyway, I'm using 2 as my arbitrary place holder. So if my market state list is [0 1 0 1 1], and my rule list is [0 2 0 2 1] I want to be able to say those are equal, since 2 is a placeholder saying it doesn't matter what the value of that particular condition is.

Sorry if this is unclear so far, but basically I want to say that the list [0 2 0 2 1] could be equal to market condition [0 0 0 0 1], [0 0 0 1 1], [0 1 0 0 1], or [0 1 0 1 1]

Without going crazy with loops, is there any reasonable way to do this?

Thanks
• ... Using list primitives `reduce` and multi-list `map` in the compact notation of NL5: to-report accept? [ #test-list #rule-list ] report reduce and (map [?2
Message 6 of 8 , Sep 9, 2012
• 0 Attachment
On Sep 8, 2012, at 3:38 PM, flyingdoritos <flyingdoritos@...> wrote:

Hi, I want to compare two bitstrings (just lists of 0's and 1's), but with some of the values arbitrary for a reasonable genetic algorithm in a market model. The indices of the values in the bitstrings correspond to a particular condition that I have decided to use, if the market is in that condition, the value is 1, if not, it's 0.

Anyway, I'm using 2 as my arbitrary place holder. So if my market state list is [0 1 0 1 1], and my rule list is [0 2 0 2 1] I want to be able to say those are equal, since 2 is a placeholder saying it doesn't matter what the value of that particular condition is.

Sorry if this is unclear so far, but basically I want to say that the list [0 2 0 2 1] could be equal to market condition [0 0 0 0 1], [0 0 0 1 1], [0 1 0 0 1], or [0 1 0 1 1]

Without going crazy with loops, is there any reasonable way to do this?

Using list primitives `reduce` and multi-list `map` in the compact notation of NL5:

to-report accept? [ #test-list #rule-list ]
report reduce and (map [?2 = 2 or ?1 = ?2] #test-list #rule-list)
end

observer> show accept? [0 1 0 1 1] [0 2 0 2 1]
observer: true

HTH,
Jim
• Thank you so much. I had figured out a very clumsy way to do it and it was a very long string of code in every loop but your way is much cleaner and much
Message 7 of 8 , Sep 10, 2012
• 0 Attachment
Thank you so much. I had figured out a very clumsy way to do it and it was a very long string of code in every loop but your way is much cleaner and much easier to understand as well.

--- In netlogo-users@yahoogroups.com, Jim Lyons <jimlyons@...> wrote:
>
> On Sep 8, 2012, at 3:38 PM, flyingdoritos <flyingdoritos@...> wrote:
>
> > Hi, I want to compare two bitstrings (just lists of 0's and 1's), but with some of the values arbitrary for a reasonable genetic algorithm in a market model. The indices of the values in the bitstrings correspond to a particular condition that I have decided to use, if the market is in that condition, the value is 1, if not, it's 0.
> >
> > Anyway, I'm using 2 as my arbitrary place holder. So if my market state list is [0 1 0 1 1], and my rule list is [0 2 0 2 1] I want to be able to say those are equal, since 2 is a placeholder saying it doesn't matter what the value of that particular condition is.
> >
> > Sorry if this is unclear so far, but basically I want to say that the list [0 2 0 2 1] could be equal to market condition [0 0 0 0 1], [0 0 0 1 1], [0 1 0 0 1], or [0 1 0 1 1]
> >
> > Without going crazy with loops, is there any reasonable way to do this?
>
> Using list primitives `reduce` and multi-list `map` in the compact notation of NL5:
>
> to-report accept? [ #test-list #rule-list ]
> report reduce and (map [?2 = 2 or ?1 = ?2] #test-list #rule-list)
> end
>
> observer> show accept? [0 1 0 1 1] [0 2 0 2 1]
> observer: true
>
> HTH,
> Jim
>
Your message has been successfully submitted and would be delivered to recipients shortly.