netlogo: how to position turtles in certain location - positioning

I want to position my turtles in a certain squared location. Why does this code below not work? Netlogo accepts it, but does not compile, saying "can't set turtle variable XCOR to non-number false" It should be pretty simple, but I somewhat can't get around it.
crt 50
[
set size 2
set xcor xcor >= 81 and xcor <= 90 ;set initial location
set ycor ycor >= 81 and ycor <= 90 ;of turtles
set start-patch patch-here
pen-down
]

The error message pretty much says it all: set xcor should be followed by an expression that evaluates to a number. In your code, however, set xcor is followed by a boolean expression (i.e., something that evaluates to true or false): xcor >= 81 and xcor <= 90.
In other words, xcor >= 81 and xcor <= 90 does not mean "give me a number between 81 and 90", it is a question meaning "is xcor between 81 and 90?" and NetLogo does not know how to set xcor to the answer to this question.
If you want NetLogo to give you a number that is in a certain range, you generally need to use the random function. In your case, you could simply do:
set xcor 81 + random 10
set ycor 81 + random 10
Note that random will only give you integers. If you wanted your turtles to be at non-integer coordinates, you could use random-float instead.

Related

Plot amount of turtle going through x time the model

I am working on my first Netlogo program and I blocking on something.
As saied in the title, I want to create a plot which can count amount of turtles going through x times of the distance of the model.
For this I add an new variable inside turtles call memory-of-distance for keeping in memory the distance of each turtle.
I succed to create something manualy but I cannot find a way to transform it into an automatic plot.
This the way I do it now. It's going until 30 and I need to create each time a globals variable. After I ask to the plot to have a pen for each global variable.
set count-model-distance1 0
set count-model-distance2 0
set count-model-distance3 0
set count-model-distance4 0
set count-model-distance5 0
ask turtles [
if memory-of-distance >= 129 * 1 [ set count-model-distance1 count-model-distance1 + 1]
if memory-of-distance >= 129 * 2 [ set count-model-distance2 count-model-distance2 + 1 set count-model-distance1-oxygens count-model-distance1 - 1]
if memory-of-distance >= 129 * 3 [ set count-model-distance3 count-model-distance3 + 1 set count-model-distance2-oxygens count-model-distance2 - 1]
if memory-of-distance >= 129 * 4 [ set count-model-distance4 count-model-distance4 + 1 set count-model-distance3-oxygens count-model-distance3 - 1]
if memory-of-distance >= 129 * 5 [ set count-model-distance5 count-model-distance5 + 1 set count-model-distance4-oxygens count-model-distance4 - 1]
My model lenght is 129 patches and distance is counting with patches. That's why superior to 129 patches.
There is an example with number: an turtle have as memory-of-distance 400, it's superior to 387 (129 *3) so it's more than three time model distance. Do it for turtle present inside the model and to create plot capable of each tick to show how many turtle are at 2 or 3 or 4 ect. Here are turtle is 3 so +1 for counter 3 but when it will travel 4 times the model, it will be 4.
You will find just above how I do with the plot. I ask at each global variable a counting.
plottings
I hope it's clear otherwise ask me to explain again or details.
Thanks you in advance for your help !
Anton

"Reverse" the x(integer) giving y=0 of a trigonometric graph

Hello
The graph for y=sin(x*pi/5)*2*sin(x*pi4) looks like this:
Some y=0 are 4,5,8,10,12,15,16
Is there a general technique (imagine the equation having more components) - that can give us a new equation where the integers that satisfy y(x)=0 will be an arbitrary nonzero number, and the integers with a nonzero numbers will be set to zero?
In python I can easily find the nonzero with this code:
#for 100 first integers
for i < 100
if y != 0:
print x
1 += 1
But I wonder if this can be done mathematically - preferably as a trigonometric function.

R dtw package: cumulative cost matrix decreases at some points along the path?

I am exploring the results of Dynamic Time Warping as implemented in the dtw package. While doing some sanity checks I came across a result which I cannot rationalize. At some points along the warp path, the cumulative distance appears to decrease. Example below:
mat= structure(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.01,0.01,0.02,0.03,0.04,0.06,0.09,0.11,0.13,0.16,0.18,0.2,0.22,0.24,0.24,0.22,0.22,0.22,0.22,0.21,0.2,0.19,0.2,0.23,0.29,0.34,0.41,0.51,0.62,0.73,0.82,0.9,0.95,1,1,1,0.92,0.92,0.89,0.89,0.84,0.79,0.7,0.53,0.37,0.23,0.17,0.13,0.11,0.09,0.08,0.07,0.07,0.07,0.07,0.07,0.07,0.08,0.08,0.08,0.09,0.1,0.13,0.15,0.19,0.22,0.27,0.29,0.34,0.35,0.36,0.35,0.38,0.37,0.37,0.32,0.3,0.26,0.24,0.21,0.19,0.17,0.15,0.14,0.12,0.1,0.09,0.09,0.08,0.08,0.07,0.07,0.07,0.07,0.06,0.06,0.06,0.05,0.05,0.05,0.05,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.03,0.04,0.04,0.04,0.03,0.03,0.03,0.04,0.04,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.01,0.01,0.01,0.02,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.1,0.12,0.12,0.13,0.14,0.15,0.17,0.19,0.2,0.21,0.22,0.24,0.23,0.24,0.26,0.3,0.32,0.33,0.35,0.39,0.44,0.49,0.55,0.61,0.67,0.71,0.76,0.83,0.9,0.97,1,0.99,0.86,0.68,0.5,0.41,0.33,0.28,0.23,0.2,0.17,0.15,0.13,0.12,0.1,0.1,0.1,0.11,0.11,0.11,0.11,0.11,0.11,0.11,0.13,0.15,0.17,0.18,0.2,0.21,0.24,0.25,0.28,0.29,0.32,0.35,0.36,0.34,0.32,0.3,0.3,0.28,0.26,0.23,0.22,0.19,0.17,0.15,0.14,0.12,0.1,0.09,0.09,0.08,0.08,0.07,0.07,0.07,0.06,0.06,0.05,0.05,0.05,0.05,0.05,0.05,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04),.Dim=c(149L,2L))
tw = dtw(mat[,1], mat[,2], keep.internals = T, step.pattern = asymmetricP05)
.
d.phi = tw$costMatrix[ cbind(tw$index1, tw$index2) ]
which(diff(d.phi) < 0)
# 45 50 53 54 61 70 72 73 80 81 101 115 117 120 124 125 129 139 184 189 191 193
plot(diff(d.phi))
This should not be the case, as d_phi is a sum of non-negative distance measures, multiplied by m which takes values 0 or 1.
I doubt this is an implementation problem with the dtw package, so where am I making a mistake?
Another sanity check (taken from the reference below) plots the path on top of the costMatrix. Below is plotted indices 45:55 in which we see 45, 50, 53, and 54 have decreasing cumulative cost (from above diff(d.phi)). The first transition is diff(d.phi)[45].
i = 45:55
i1 = tw$index1[i]
i2 = tw$index2[i]
r= range(c(i1,i2))
s = r[1]:r[2]
ccm <- tw$costMatrix[s,s]
image(x=1:nrow(ccm),y=1:ncol(ccm),ccm)
text(row(ccm),col(ccm),label=round(ccm,3))
lines(i1-r[1]+1,i2-r[1]+1)
If this is the actual path taken by the DP algorithm, how can the cumulative distance along this path decrease at those points?
http://cran.r-project.org/web/packages/dtw/vignettes/dtw.pdf
This is due to the use of a "multi-step" recursion like asymmetricP05. Such a pattern allows the warping path to be composed of long segments, e.g. knight's moves.
To verify the monotonicity, you should only consider the starting positions of each of the "knight's moves" - not all of the cells passed through. The index1 and index2 properties do include the intermediate cells (to provide a smoother curve), which explains your observation.
To convince yourself: (1) try another, more intuitive, pattern like asymmetric; and (2) note how the stepsTaken property has a different length than index1/2.

Normalise values based on two bands

I have data that comes from different sources with different typical ranges, like so:
VALUE LOWERBAND UPPERBOUND
5 2 7
6 1 10
2 1 4
22 3 8
...
I would like to normalise VALUEs with respect to LOWERBAND and UPPERBOUND, but as I have no background in statistics I really can't see how it could be done. Any pointers?
To put it in other words, I guess I would like to rescale VALUES so they would all belong to the same LOWERBAND and UPPERBOUND (perhaps the global mean LOWERBANDs and UPPERBOUNDs?)
I guess what you are after is something like the following:
Move the lower bound to zero:
newValue = oldValue - LOWERBOUND
Calculate the value as a percentage of the upper bound (scale 0 - 100)
newValuePercent = (newValue / UPPERBOUND) * 100
In you example the last value is btw. outside the [LOWERBOUND, UPPERBOUND] range... so not sure whether you want to limit it at the end or not

Finding the opposite of a number in a 0 to 10 scale

This is probably something silly and simple in vectors or something, but I can't figure it out with my remedial Algebra. (Sorry for the initial confusion, I didn't fully explain this as I didn't think the 2nd half of my operation was relevant.)
I have a variable between 0 and 10. I want to find its opposite in that same scale, but I also want to change the "depth" of what that opposite means.
Variables:
X = User input variable between 0-10 (really 0-1.0)
Y = User input Depth between 0-10 (really 0-1.0)
Z = My result I'm looking for.
Example if my depth (Y) is Full (10), X would be:
X=0's opposite would be 10
X=1's opposite would be 9
X=2's opposite would be 8
etc..
Example if my depth (Y) is None (0), X would be:
X=0's opposite would be 0
X=1's opposite would be 1
X=2's opposite would be 2
etc..
I'm trying to accomplish this in Reaktor, a program for designing musical synthesizers. Specifically designing a "depth" parameter on a Chorus effect that inverts the left and right signal delay. So that the "rate" (X in this example) for the left signal is the opposite of the "rate" for the right signal, and the difference of how opposite they are is controlled by the "depth" (Y).
If x is your number, then what you're looking for is simply (10 - x).
edit One functional form that satisfies your updated spec is (x + y - (x * y) / 5.0). This is designed for values of x and y between 0 and 10.
X = 10 - Y where Y is input and X is output
0's opposite is 10: 10 = 10-0
1's opposite is 9: 9 = 10-1
2's opposite is 8: 8 = 10-2

Resources