Hello i am trying to write a code in which i can know the difference in the composition of turtles every time a new tick has passed. Explicitly, i need to count the turtles let say of color blue in a population of turtles with different colors in the first time or tick 1, and then count again in the next time or tick 2 and calculate the difference of turtles with color blue between the time step and need to use that value for other purpose so what kind of primitive can i use?
let current-population-count map [count turtles with [color = ?]] colors
let new-population-count (map[?1 * (savage ?2)] current-population-count colors)
set new-population-count map [num-turtles * ? / sum new-population-count] new-population-count
Try to using this code but this not work for my purposes. Any suggestions?
If you just need one timestep previous then the easiest is to store it in a global variable. If you need to keep a full history over all timesteps, you will need to use a list. This is the one timestep code and just one colour (not tested).
globals [lastblue]
to go
...
let thisblue count turtles with [color = blue]
if ticks > 1 [do whatever you want with thisblue and lastblue]
set lastblue thisblue
tick
end
Related
How to create two different random color groups in NetLogo 6.1.1?
I am trying to create two different groups from the group of 250 turtles. The starting situation is that all 250 turtles are gray and then they will turn to yellow and pink groups one by one.
This code of mine makes all turtles in the beginning to be gray and then they will all turn to pink. I do not want this but I want two randomly made groups where pink turtles is typically either larger or smaller group of turtles than the yellow group of turtles in the end of the code run.
I just started to code with NetLogo 6.1.1. Thank you for understanding and all help and have a nice day.
[
time
person
]
turtles-own [ x ]
to setup
clear-all
reset-ticks
set time 0
create-turtles 250
[
setxy random-xcor random-ycor
]
ask turtles
[
set shape "person"
set size 1
set color gray
]
end
to go
ask turtles
[
show random 2 = x
if x = 1 [set color yellow]
if x = 0 [set color pink]
]
end ```
I don't see any place where the values for the turtle variable x are set, so they will always have the default value of 0. In NetLogo = is used to check equality, not for assignment, so show random 2 = x is just going to print true or false depending on if random 2 is 0 or not (in case you thought that was assignment). You'd want something like this:
to go
ask turtles
[
set x random 2
if x = 1 [set color yellow]
if x = 0 [set color pink]
]
end
Or you could move the set x random 2 to the setup procedure if you just want to set the value once to use later in go.
I am working on tracking a human. I have calculated the centroid and points(Head,hands and legs). Depending on the image, these points can be at maximum 5 or at least 2 depending on the pose of the person. I want to assign labels like left leg,right leg, left hand, right hand and head to these points. But the problem is that unless i plot them i dont know which point is what.
I want to use some logic like if its above centroid then head or below centroid then legs or some other idea/heuristics but i dont know if its possible in Matlab. I am attaching an image with detected points and centroid. I will appreciate if anyone can suggest some ideas.
If you have the centroids xy coordinates and those of these point you can just make logic based on this, right?
please provide some code. I do not understand your question.
EDIT:
For instance: matrix_with_point = [0.5 1;0.25 0.5;0.75 0.5]; and centroid = [0.5 0.5] with colnum 1 being x and 2 being y then:
for i = 1:size(matrix_with_point,1)
%check x direction
if matrix_with_points(i,1) < centroid(1,1) %left
% however you would like to label
text(matrix_with_point(i,1),matrix_with_point(i,2),'Left')
elseif matrix_with_points(i,1) >= centroid(1,1) %right
% however you would like to label
text(matrix_with_point(i,1),matrix_with_point(i,2),'Right')
end
end
you can gone but you get it I think?
I would like to let my turtle wander until its energy level < [totalattract] of patch-here. The code here works fine:
to move-turtles
ifelse ([totalattract] of patch-here < energy)
[ rt random 90 lt random 90
jump random 3
]
[move-to max-one-of patches in-radius 3 [totalattract]
]
if energy = 0 [die]
end
However, I want to let it wander within 1 tick - to start with the wandering (jumping) and at the end of jumping (when its energy < [totalattract] of patch-here) move-it to patch with highest [totalattract] value in splotch in-radius X. I was trying to implement the while condition or to repeat, however for repeat I need a specific number of movement and this one depends of turtle's energy and patch's [totalattract]. How can I deal with? I will really appreciate every help or advises !!
If you want all of the turtles to do their procedures in 1 tick you want to put the tick statement inside your go procedure. Like this:
to go
ask turtles [move-turtles]
;Some other code here...
tick
end
If you want only one turtle to do its procedure in 1 tick you want to put the tick statement inside your move-tutle procedure. Like this:
to move-turtles
ifelse ([totalattract] of patch-here < energy)
[ rt random 90 lt random 90
jump random 3
]
[move-to max-one-of patches in-radius 3 [totalattract]
]
if energy = 0 [die]
tick
end
I am trying to create land use model in a city. Every GO or tick x percent (according to slider) migrants (turtles) will be sprouted in random patches which there are no turtles on it.
Currently I am still using below code, it doesn't use slider but specific number 1000 > 9 which is close to 2% according to number of turtles I created in setup.
to go
ask patches with [pcolor = green and any? turtles-here = false]
[ if random 1000 < 9 [sprout-migrants 1 [
set color red
set shape "default"
set size 1
set-income
find-residence]]]
tick
end
Assuming you have a slider named x that you want to control the percent change, then replace:
random 1000 < 9
with
random 100 < x
If the slider can take on non-integer values, then do
random-float 100 < x
you could also use this code. this way you don't need to run the if-statement to all of the patch.
assuming the slider is x as percent and turtle-numbers is contain the number of turtles you setup
let migrants-to-sprout ((x / 100) * turtle-numbers)
you set the number of turtles you want to sprout first and then make it as the loop indicator
repeat migrants-to-sprout [
ask patches with [pcolor = green and not any? turtles-here]
[
sprout-migrants 1 [...]
]
]
I have to use region-based to classify foreground (FG) and background (BG). I read many papers about that problem. However, almost papers that I read, they often using mean feature to compare the mean square error such as
(I(x)-mean(FG)).^2>(I(x)-mean(BG)).^2=>x belong to BG
Some authors add some condition that used statistical reigon (add sigma term). How about the other feature to discribe image region. Could you suggest to me some feature? Thank you so much
Try this function I created in Matlab called 'Quantisation', note this is for grey scale images. it automatically finds thresholds in the image and will classify all pixels under 1 of the categories, FG or BG:
function [quant2_A_min,quant2_A_max] = Quantization(fname)
% If there is less that one input argument 'B20.BMP' will be read in.
if nargin <1
fname='B20.BMP'
end
% define fname as the variable 'X'.
X=fname;
%splits the image into 2 levels by obtaining 2 threshold values.
thresh = multithresh(X,1);
%Contructs a vector of max values so that the max value in each
%quantization interval is assigned to the 2 levels of o/p image
valuesMax = [thresh max(X(:))];
[quant2_A_max, index] = imquantize(X,thresh,valuesMax);
%Contructs a vector of min values so that the min value in each
%quantization interval is assigned to the 2 levels of the o/p image
valuesMin = [min(X(:)) thresh];
%use the output argument index to assign the MIN values to the output image
%instead if called imquantize again.
quant2_A_min = valuesMin(index);
%Display both 2 level images side by side
imshowpair(quant2_A_min,quant2_A_max,'montage');...
title('Quantised Images (Min & Max)', 'FontSize',14,...
'fontweight','bold');
end