I am running a series of experiments using behaviourspace and outputting my results in spreadsheet mode. My model runs at a temporal rate of 1 day per tick. Every 365 days a year variable increments. I would like to report the value of another variable to the spreadsheet at the end of each year.
Does anyone know how to accomplish this using the behaviourspace "Measure Runs using these reporters" box? It seems that I can either report the value at every tick or at the end of the model. Ideally I would like to report every x ticks.
I have attempted to put a conditional statement in the reporters box but behaviourspace throws an error. An alternative option would be to create a list as the model runs and export it at the end of each run - but this produces unwieldy output for analysis. Is this my only option or am I missing something?
Any advice much appreciated. Thanks
I don't think you can report occasionally. Instead, I would do the following:
In your code, define a function called yearly-report and always report a value.
to-report yearly-report
ifelse (ticks mod 365) = 0
[report your-calculation-here ]
[report ""; where "" is an empty placeholder text that you may ignore.]
end
Then in your behavior-space commands, call yearly-report
Related
I am using MIJ to execute an ImageJ macro within Matlab. The macro has to be executed multiple times in a "for" loop. The problem is that Matlab does not wait until the macro ends. Initially I solved the problem with a "while" loop, checking if the "Results" table generated from the macro was empty or not. However, it only solves the problem the first time, then from the second time the "Results" table is not empty anymore.
I also thought about generating a variable at the end of the macro and use it to check if the macro finished, but I don't know how to read it in Matlab.
Do you have any suggestion about how I can solve the problem?
Thanks a lot in advance,
Alessia
Here is an example of my code:
javaaddpath 'C:/Program Files/MATLAB/R2019a_x64/java/ij.jar'
javaaddpath 'C:/Program Files/MATLAB/R2019a_x64/java/mij.jar'
MIJ.start('C:/fiji-win64/Fiji.app/plugins');
IJ=ij.IJ();
macro_path=...
'C:/Macro_waterinoil.ijm';
for pos=1:16
im = mijread(strcat('E:/droplets.tif'));
figure(1)
imshow(im,[0 255])
IJ.runMacroFile(java.lang.String(macro_path));
res_Hough=0;
res_Hough=MIJ.getResultsTable();
while res_Hough==0;
res_Hough=MIJ.getResultsTable();
end
im_res=MIJ.getCurrentImage();
MIJ.run('Clear Results');
MIJ.run('Close All');
end
Edit: Ignore the below, I was on the right track but wasn’t paying as much attention as I should have been. I think this issue is the line right after you set res_Hough to 0 (i.e. res_Hough=MIJ.getResultsTable();). Try deleting it so that the next line is the while loop, then we can check the output and see if the below might also apply
If I am understanding correctly, you are using the while loop to continuously ping until the table is full, then store those values in res_Hough, right? I'm wondering if this is a limitation inherent to ImageJ/FIJI. The reason I think this might be the case is that a very simple explanation for your issue is that the table retains the previous values, and so will always be full after the first loop unless cleared manually somehow. Do you think that could be the case? Perhaps add a print statement after the while loop and see if it prints the same values for the duration of the for loop.
I suppose the next thing to do is for me to actually try to offer a solution regardless of the above. My idea is to try having the while loop check against the previous iteration's table values until they are different, then stash the updated values. Does that make sense? Something like:
while (res_Hough[i]==0) or (res_Hough[i-1]==MIJ.getResultsTable());
res_Hough[i]=MIJ.getResultsTable();
Where i is incremented by the for loop
I am trying to use the formula below to set conditions in LibreOffice but I keep getting an error. What am I doing wrong with the statement below:
=IF(G2<=2,'negative',IF(OR(G2>2 & G2<=3,'neutral',IF(OR(G2>=4,'positive))))))
Thanks
It seems, that in your formula is missing the last ':
'positive))))))
should be 'positive'))))))
Also the
&
is string-concatenation in LibreOffice, so you need here the equivalent to OR() and that is AND().
But you can simplify your formula to
=IF(G2<=2,'negative',IF(AND(G2>2,G2<=3),'neutral','positive'))
The first test is if the number is lower than 2 (negative),
the second test is if the number is between 2 and 3 (neutral)
and then there is no further test needed as it is the only remainig possiblity.
For a different locale, a slightly shorter, and I'd say simpler, version that also avoids the need for OR/AND:
=IF(G2<=2,"negative",IF(G2<=3,"neutral","positive"))
Once <=2 first test is handled (either but outputting negative or by proceeding to the 'result if FALSE') there is no longer the possibility of 2 or less, so the AND is not necessary.
The above though does fill a gap left by OP between 3 and 4.
I have created an experiment in Behavior Space for my NetLogo model. I would like to save the value of some variables for each individual turtle, later to be processed with statistical software (Stata or R). My first attempt at a reporter was:
[my-variable] of turtles
This kind of works, but the formatting of the resulting CSV file is problematic. All values for an individual variable are stored in a space-separated list:
"run", "[my-variable] of turtles"
"1", "[48.234967724191584, 15.361986575058953, 19.613022950636537, ... ]"
...
What I would like:
"run", "[my-variable] of turtle_0", "[my-variable] of turtle_1", ...
"1", "48.234967724191584", "15.361986575058953", ... ]"
...
I am looking for something like the split() method in Python. Any suggestions? Thanks.
UPDATE: Cross-sectional analysis is predicated on the assumption that, during the same run of the model, all reporters list turtles-own variables in the same order. So, if I have two reporters:
[my-variable-1] of turtles => "[1 2]"
[my-variable-2] of turtles => "[3 4]"
I need to be sure that both reporters take turtles in the same order, so that turtle 0 has my-variable-1 equal to 1 and my-variable-2equal to 3, whereas turtle 1 has my-variable-1 equal to 2 and my-variable-2equal to 4. I cannot find a mention of this in the NetLogo documentation. Can anyone confirm this?
I can give you an answer to the latter part of your question. [my-variable-1] of turtles will give you the values of my-variable-1 in random order as of takes the agents in random order. (This is documented at http://ccl.northwestern.edu/netlogo/5.0/docs/dictionary.html#O).
If you want a fixed order by who number, then you can use sort and map.
map [[my-variable-1] of ?] sort turtles
sort turtles creates a sorted list of turtles and then that list is given to the `map' primitive to create the list of values ordered by the who number of the turtle. Of course you'd need be careful that no turtles die or are created during the run.
As for the writing of the observations to a CSV file, there are other posts that look at that specifically. You might also want to look at the stats extension to see if that would help by allowing you to write out all the results at the end of the run from a list of lists that is easily handled by the CSV extension.
Charles
[ set list N = 1 () set list N = 1
lput number-of-patches destination origin list N N + 1]
I wish to be able to store information about collections of patches and when the criteria for the filling of the list is met the number of the list will be increased. Will this code work?
Just looking at it, it will give you several syntax errors, regardless of whether the structure will do what you want. For example, the way you should construct a list with element '1' and name 'N' (which is what I think the first line is supposed to do) would be set N (list 1). You can test this by writing code as below and running test (eg by typing test in the command center at the bottom of the interface).
globals [N]
to test
set N (list 1)
print N
end
When writing code, your life is a lot easier if you build up the code in pieces, testing each one as you go either by inspecting agents to see if their property values change as you expect and/or putting print statements in lots of places to see what happens to your variables. This way you are introducing and fixing only a small number of errors in each step. Also, this means you are never writing code that you can't test immediately.
I have a crosstab with a formula field. The query returns something like
CategoryID Company MarketValue PaymentMode
1 ABC 1000 H
1 xyz 2000 H
3 efg 9800 H
Payment mode is half yearly indicated by 'H'
I made a formula field to evaluate payment mode by
WhileReadingRecords;
numberVar mode;
if({PaymentMode}='H') then mode:=2 else mode:=12
Then I made another formula field
WhileReadingRecords;
numberVar mode;
numberVar result:={MarketValue}/mod;
result
However it returns division by zero error. Why is my formula for Payment Mode not evaluating properly. I tried placing the payment mode formula in report head and cross tab is 2nd header but it still throws the same error.
Two problems.
First syntax error - or rather typo here, last 'e' is missing :)
numberVar result:={MarketValue}/mode;
Second - you need to evaluate formuals in specified order. Say your first formula has name 'calc_mode', then second one should start with next statement:
EvaluateAfter({#calc_mode});
I'm glad you already found Arvo's answer, but I have a few suggestions to simplify your code:
Mode is a buit-in Crystal function (see Crystal's help files). So when I saw you using that word as the name for a custom variable, my brain did a backflip. How about calling it "numPayPeriods" instead?
Since your sample formula includes field values, Crystal implements WhileReadingRecords by default (again, see Crystal's help files). So adding it is redundant in this case. You can take that out entirely.
There's no need for 2 separate formulae in your example. Also, your Result variable is unnecessary in Crystal syntax. You can simplify the whole thing to just 1 formula:
if({PaymentMode}='H') then
{MarketValue}/2
else
{MarketValue}/12;