Can we code to calculate the difference of tick values in netlogo - netlogo
Actually i need to calculate density increase/decrease rate of human population for my model, the model is same as i asked in unable to make non-stationary turtles change their direction if an obstacle a patch ahead (a specific area and a building within it, people are randomly visiting and going). What i thought that i will be needing to save the tick values for initial population value and after some time difference updated population value. Below is the procedure i want to plot graph for.
to density-increase-rate
store population-density at some initial time (ticks)
store updated-population-density at some later-time (ticks)
calculate density-increase-rate
( ( ( updated-pd - previous-pd ) / (updated-tick - previous-tick ) ) * 100 ) / 10
end
I am calculating population-density in my code as
total-density-inside-boundary count people with [inside-boundary?]
for any suggestion or code help i am very thankful.
If you just want to plot this change, there is no need to store it because the plot will update each tick.
globals [total-density-inside-boundary density-increase-rate]
to calc-plot-vars
let old-density total-density-inside-boundary
set total-density-inside-boundary count people with [inside-boundary?]
set density-increase-rate (total-density-inside-boundary - old-density) / 100
end
Then have a plot on the interface with plot total-density-inside-boundary and plot density-increase-rate. You may need to do some rescaling to have them both on the same plot.
If you want to have the rate based on total time, then create a variable to hold the initial value and calculate it at the specific time you think initial means (such as the end of the setup or at a specific tick).
globals [total-density-inside-boundary initial-density]
to setup
... (commands that create your people)
set initial-density count people with [inside-boundary?]
...
end
to go
...
if ticks = 1 [ set initial-density count people with [inside-boundary?] ]
...
end
Then have the rate plot in the interface have plot (total-density-inside-boundary - initial-density) / 100
Related
AnyLogic variable for cumulative sum in system dynamics
Good morning, in a System Dynamics model created on AnyLogic, I would like to compute the cumulative sum of a flow of the previous 7 days. My purpose is to calculate the reproduction ratio of a disease starting from the infectious population at time t over the cumulative sum of the infectious in a fixed time interval. The formula is the following: Formula where: I(t) = infectious population at time t --> I(t) is a flow in the model that changes a stock I(t-s) = infectious population at time t-s w(s) = gamma distribution s represents the time interval of the previous 7 days I have all the data but I am not able to calculate the sum of I(t-s). Thanks.
You have to do this manually. Create a variable mySum of type double. Then, add a cyclic event that regularly adds to it from the stock (something like myVar += myStock). You may need to use an additional variable that stores the temporary stock value from the last time you added, so you only add what was "new" since the last cycle. In short: use a cyclic event to "approximate" your integral.
Netlogo BehaviorSpace mean value after every repetition
in BehaviorSpace I have ["concetration" 0 0.2 1] and for each value of concetration I have to make 1000 repetiotions, but I have to bring a mean value of ticks after those repetition, not any other value. Someone knows how to do this? So what I want in result is: concetration = 0.0 <mean value of ticks after 1000 repetitions> concetration = 0.2 <mean value of ticks after 1000 repetitions> concetration = 0.4 <mean value of ticks after 1000 repetitions>
ticks is the number of time steps that the simulation ran for. Does it end naturally (like an epidemic runs out) or do you stop it after a certain number of ticks? If you stop it after a fixed number of ticks, then the mean of ticks doesn't make sense. Assuming that what you are asking is to calculate the average number of ticks that the simulation runs for before ending naturally (1) have BehaviorSpace just record the end of the simulation, not every step (2) look at the BehaviorSpace output and the variable [step] is the last step that the simulation did, which is also ticks if you have the normal setup / go structure.
Separate y-values depending if the x-value is increasing or decreasing
I try to analyze my data using a mixture of python and matlab, but I am stuck and could not find any discussion that solves my problem. My data consists of temperature and current measurements which are recorded at the same time but using two different devices. Afterwards these measurements are matched together using the time stamp of each measurement to get the "raw data plot". However, the current values differ at the same temperature depending if the sample was heated up or cooled down. Now, I would like to separate the heating and cooling values of the current measurements, and calculate the mean and standard deviation for all currents at one temperature for cooling and heating, respectively. What I do so far is first looking for all the values that are beloning to the same temperature, no matter if it's a cooling or heating cycle. That results in quite large standard deviation values. The two figures show a simple example how my data looks like. The first figure plots the temperature values against the number of data points and marks all values that belong to this temperature: The second figure shows the current data with the marked values that correspond to the temperature. The temperature is always kept constant for 180 s and then increased or decreased by 10°C. During the 180 s several current measurements are taking place, which results in several data point per temperature per cycle. The cycle is repeated itself several times (not shown here). To simplify the example here, I just used simple numbers instead of real temperature and current values. The repetition of the same number, indicates several measurements at one temperature. In reality the current values are not completely stable, but fluctuate around a certain value (which I also irgnoered here). The code which does that looks like this: Sample data: Test_T = [1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1] ; Test_I = [5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,7,7,7,7,7,6,6,6,6,6,5,5,5,5,5,4,4,4,4,4] ; Code: Test_T_sel =Test_T; Test_I_sel = Test_I; ll = 0; ul = 2; ID = Test_T_sel <ul & Test_T_sel >ll; Test_x_avg = mean(Test_T_sel(ID)); Test_y_avg = mean(Test_I_sel(ID)); figure('Position', [100 100 700 500]); plot(Test_T_sel); hold on; plot(find(ID), Test_T_sel(ID), '*r'); ylabel('Temperature [°C]') figure('Position', [900 100 700 500]); plot(Test_I_sel); hold on; plot(find(ID), Test_I_sel(ID), '.r'); ylabel('Current [µA]') And Test_T contains 90 values increasing stepwise from 1 to 5 each 10 values, while Test_I contains the current values. As you can see for Temperature = 1°C the current values is either 5 or 4. Now I would like to get a vector that only contains the values of T and the corresponding value of current if T increases and a second vector for the current values were T decreases. I thought using a if else comand, but I actually do not know how to implement this. Maybe something like this could work: if T2 == T1 and T2-T1 <= 0.2 "take corresponding I values" (this is true when the temperature is stable and only varies by 0.2°C) if T2-T1 > 0.2 "ignore I values until" T2 == T1 again and T2-T1 <= 0.2 (this would either be a stronger variation at one temperature or indicate a temperature change and waits until T is constant again) But now, I still need to distinguish if the temperature is generally increasing or decreasing after 5 measurements. if T2 > T1, T is increasing (Test_T_heat) and the correspnding I values should be written in a vector Test_I_heat if T2 < T1, T is decreasing (Test_T_cool) and the corresponding I values should be written in a vector Test_I_cool For the example given above this should look like this at the end: Test_T_heat: [1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5]; Test_I_heat: [5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9]; Test_T_cool: [4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1] ; Test_I_cool: [7,7,7,7,7,6,6,6,6,6,5,5,5,5,5,4,4,4,4,4] ; How has the "code" to be changed that I get such vectors?
How to create condition in NetLogo that 2 slider values cannot exceed defined value?
I created a model which as 2 different sliders, namely ratio1 and ratio2. They are located on the interface and their values should add up to 1 (here: labour-unit), and also cannot exceed this value. For now, NetLogo let's me exceed the condition. I tried this: to setup create-turtles number-of-turtles ;; number of firms to be defined through slider set labour-unit ratio1 + ratio2 set labour-unit 1 end Therefore, my question is: How to create a condition in the setup that 2 slider values cannot exceed a defined value?
Is there any reason you actually need two sliders if the values always add to 1? Could you just have one slider called "proportion with labor-type x" or whatever you're modelling? Then, you can just have reporters to return the values for the actual proportion you're after- for example: to-report ratio1 report proportion-slider end to-report ratio2 report precision ( 1 - proportion-slider ) 2 end Then on your interface you could have the slider (and monitors if needed):
Constructing a set of variables
I have a question about Netlogo. I have two breeds of turtles, breed1 and breed2. Breed2 has a variable called theta. First, a random number of breed1 turtles change to breed2; the breed2 then theta set at random. Later, another random number of breed1 become breed2, who will also have theta set at random. My two questions are: 1.) How can I ensure that only those turtles that change their breed in the second round of breed-changing set their theta variable? I don't want those that changed in the first round to lose the theta variable that was set for them immediately after changing. 2.) Is there a way I can construct a set of all the theta variables that have been set so far? I want my breed2 to later on make decisions based on the maximum value of theta that has been set so far. Thank you!
You should ask two separate questions separately, but ... There are many ways to do this. Example 1: If you always update to a nonzero value of theta, just test for a zero and only change a zero. Example 2: add a can-change-theta attribute to breed2 and always initialize it to true but change it to false after resetting theta. Example 3: gather your new breed2s into an agentset (or a list, if necessary) and change theta only for these turtles. If you really want the max, you don't need all values. Just add a global variable max-theta and update it each time you update a theta. If you really want all, add a thetas global and initialize it as an empty list; append to this list each time you update a theta attribute, and use max to pull out the max whenever you wish.