I have a problem in Netlogo, where i should check if a neighbor patch of a specific patch is already colored black.
This is how i thought it could work:
ifelse [ask patch xcoord-temp ycoord-temp [ask patches in-radius rnd_radius [pcolor = black]]]?
[print "true"]
[print "false"]
Error Message is: Expected a TRUE/FALSE here, rather than a list or block.
xcoord-temp and ycoord-temp are calculated coordinates.
rnd_radius is a random radius between 1 and 15.
So does someone has an idea how to solve this?
Thanks!
Regards,
John
Okay first, the reporter patch receives an identificator that's linked to a patch. If you want to ask something to a patch at a certain position you want to use [patch-at]1.
Second, I don't understand the use of question mark in your code ?.
Third, by using [pcolor = black] the compiler understands you want to set rather than get.
Lastly, you can use the word of to access values of an agent.
So I would put it out like this:
to myprocedure
ask patch-at xcoord-temp ycoord-temp
[
check-color
]
end
to check-color
ifelse [pcolor] of (patches in-radius rnd_radius) = black
[print "true"]
[print "false"]
end
Note than I'm using an extra procedure that may not be complete, perhaps it would have to receive the temporal coordinates you use; unless these coordinates are global variables that change overtime, then you can use the procedures like that.
Please tell us if this helps you, I don't have NetLogo installed right now, I did that based on the dictionary.
Edit:
As stated in the comments
[pcolor] of (patches in-radius rnd_radius) will return a list, thus it can never equal black.
You'll have to ask for an specific neighbor of the patch or perhaps use one-of in the list resulting from the previous statement..
The simplest and least verbose way would be to write a reporter procedure like this
to-report any-black-neighbors-in-radius? [r]
report any? patches in-radius r with [pcolor = black]
end
You can then ask a patch to run this procedure using r as a parameter, and either print the value, or use it for something else. Like this:
ask one-of patches [print any-black-neighbors-in-radius 5]
If you want to ask a particular patch to run it, just ask that patch using patch, like so:
ask patch 5 -5 [print any-black-neighbors-in-radius 3]
Related
I'm trying to simulate a car production factory and trying to keep separate lists of turtles who are on jobs and who are not on jobs.
I have a turtles-own variable: is-on-job?
I want to have a agent set of turtles not on jobs not-working-turtles
I want to have a agent set of turtles on jobs working-turtles
Whenever a turtle is on a job, is there a way to remove that specific turtle from the not-working-turtles agentset and add it to the working-turtles agentset?
Also on a different topic, is there a way to sort turtles based on distance to a specific patch and then if the closest turtle is on a job then go to the second turtle and so on?
You can create your two agentsets as:
let not-working-turtles turtles with [not is-on-job?]
let working-turtles turtles with [is-on-job?]
To move a turtle from one to the other, you will need code along the lines of:
to make-me-work
let free one-of not-working-turtles
ask free
[ set is-on-job? true
set not-working-turtles other not-working-turtles
]
set working-turtles (turtle-set working-turtles free)
end
Here I used the very convenient other primitive to remove the turtle doing the asking. You are more likely to want to do this as a procedure that takes arguments and pass the turtle to the procedure rather than randomly select one within the procedure, but the code would be similar.
On your question about choosing the closest, you don't need to sort. Instead, look at min-one-of in the NetLogo dictionary. If you can't work it out, please do a new question (StackOverflow should be only one question per question) with the relevant code.
I'm working on making my program interact with an overarching framework that transfers information with lists.
I have a breed called 'people' and I export information about them with
to srti-lists
ask people [ foreach [self] of people [
set traits-list (list (who) (color) (heading)(xcor)(ycor)(shape)]]
set master-list [traits-list] of people
end
It works great for exporting that information. What I'm having trouble with is creating or updating people with information that I then receive in the form of a master-list.
I've been approaching it as probably a foreach problem, but the problem is that while that lets me execute commands for every item of the master-list, I haven't figured out how to then access the individual nested items.
So, say:
foreach master-list
[create person
set who item 0 master-list
etc. The problem is that syntax would create a person and then set the who as an entire sublist. Omitting the list throws up an error, and selecting the items more specifically is untenable since it'd be a list of variable length.
Any ideas how to iteratively select items from nested lists? Is foreach even the right approach?
I can't test it but this looks wrong to me:
to srti-lists
ask people [ foreach [self] of people [
set traits-list (list (who) (color) (heading)(xcor)(ycor)(shape)]]
set master-list [traits-list] of people
end
ask already loops through the people, so this looks like it is assigning to each turtle the list of traits for all turtles, and then the master-list is a list of those lists. You probably want:
to srti-lists
ask people [
set traits-list (list (who) (color) (heading)(xcor)(ycor)(shape)]
set master-list [traits-list] of people
end
On the setting of traits, the who number cannot be set - it is assigned automatically when the turtle is created and can never be changed. For example, try the following complete (broken) model and you will get an error:
to testme
create-turtles 5
ask one-of turtles [set who 10 ]
end
So I don't know what you mean when you say that who is assigned an entire sublist - who is always an integer and assigned sequentially.
Concerning your stated question - your syntax set who item 0 master-list would be find if you were trying to set a variable that you could actually set.
I am currently having a problem understanding np.where in relation to if statements. (https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.where.html) I have heard of it being more efficient. I am trying to get a better understanding of the np.where function but I havent found any examples that are making it clear. This is the if statement I really want to convert, can anyone assist? When you convert this can you give some more conditional examples perhaps. Would numpy conditional statements work better if np.where isn't a probably solution.
For the sake of a better explaination true_list and flat_list arent really list in the real problem, they're arrays I'm appending. So I'm just going to change their name to true_arr and flat_arr.
Heres more code:
combo = list(element)
flat_arr = np.concatenate(combo) #changes array dimensions to what I need
sum_flat_arr=flat_arr.sum(axis=0)
salary = sum_flat_arr[2]
values = sum_flat_arr[3]
if salary <= 5000 and values > 150:
true_arr = true_arr + flat_arr
true_arr is just an empty numpy array(not sure whats the best way to handle it to prefill it with the number of empty rows and columns or leave it completely blank and just append it)
flat_arr is just one whole array it looks like:
Out:
[['Johnny Tsunami' 'Driver' 1000 39]
['Snow White' 'Pistol' 2000 40]
['Michael B. Jackson' 'Pistol' 2500 46]
['Greg Ritcher' 'Lookout' 200 25]]
Essentially Name Job Salary and Value, instead of dataframes I'm trying to do everything in Numpy for speed. The reason why I'm not using np.concatenate is because I hear it's slower then adding them like list. If I'm wrong please explain.
Its just appending a list. If you cant do it this way and it needs to be a function it could be np.append or np.concatenate.
End all be all if non of this applies and I have been thinking totally the wrong way I'm simply looking for a numpy way to do if statements more efficiently(faster).
Can someone shoot me in the right direction.
In Netlogo, I have turtles-own lists, which means I set a turtle's variable to be a list. Each tick, another value is added to the list. After a few thousand ticks, these lists are quite long... and the problem arises that I can't open the agent monitor in the GUI any more because it takes too long to load the list.
reproducible code:
breed [persons person]
turtles-own [examplelist]
to setup
clear-all
reset-ticks
create-persons 1 [setxy 0 0]
ask turtles [set examplelist []]
end
to go
ask turtles [set examplelist lput ticks examplelist]
tick
end
I would need the agent monitor to watch another turtle-own variable; I don't need to watch the lists (they are just used to do a calculation every 8760 ticks).
Is there maybe a possibility, to e.g. hide the list from the agent monitor? Or do I need to handle the lists as global variables instead? Being quite unhandy as I would need to create and name separate lists for every turtle...
I can see three options:
1/ If you are creating a modelling framework, I assume that your user cannot actually code in NetLogo. This means that you have to predefine the scenarios for them anyway (for example, they could choose the calculation), so you only need to have the possible calculations stored instead of all the input values to those calculations.
2/ It is not clear from your question why any user would open an inspect window or otherwise access the individual turtle. If the user doesn't need it directly, instead of adding all this information to the turtles, you could export it to a file, adding a line each tick. The user would do the analysis of the simulation in R or Excel or whatever.
3/ You could create a shadow turtle for every turtle. This is not something I would recommend, but the idea is that the shadow turtle has a subset of variables (not the lists) and the variable values it does have are identical to the turtle it is shadowing. The limited set of variables version of the turtle is the one that would accessible to monitor.
I run SegNet on my own dataset (by Segnet tutorial). I see great results via test_segmentation.py.
my problem is that I want to see the real net results and not test_segmentation own colorisation (via classes).
for example, if I have trained net with 2 classes, so after the train I will see not only 2 colors (as we see with the classes), but we will see the real net color segmentation ([0.22,0.19,0.3....) lighter and darker as the net see it]
I hope that I explained myself well. thanks for helping.
You could use a python script to achieve what you want. Take a look at this script.
The command out = out['argmax'], extracts the raw output, so you can get a segmentation map with 'lighter and darker' values as you wanted.
When you say the 'real' net color segmentation I will assume that you mean the probability maps. Effectively the last layer will have one map for every class; and if you check the function predict in inference.py, they take the argmax; that is the channel (which represents the class) with the highest probability. If you want to get these maps, you just have to get the data without computing the argmax; something like:
predicted = net.blobs['prob'].data
I solve it. the solution is to range cmin and cmax from 0 to 1 in the scipy saving method. for example: scipy.misc.toimage(output, cmin=0.0, amax=1).save(/path/.../image.png)