Controling the Order of Procedures in Netlogo - procedure

min-one-of is reporting an error which I do not understand. I understand that min-one-of requires a reporter procedure. I have this, which is noted as reporter-procedure below.
However my reporter procedures takes as its input the output of another procedure. My intention is that the output of other-procedure will be fed into reporter-procedure as its input.
Netlogo is telling me that this other procedure, other-procedure in the code section below, is expected to be a reporter. Why?
Note that other-procedure takes four variables as inputs.
let best-taxi min-one-of available-taxis [reporter-procedure ( other-procedure var1 var2 var3 var4) ]
Now if I try this without parentheses, the error message is that reporter-procedure expected 1 input:
let best-taxi min-one-of available-taxis [reporter-procedure other-procedure var1 var2 var3 var4]
So I am guessing reporter-procedure executes first. If so, why doesn't the first set of code (the code with parentheses) work by making other-procedure execute first?

The error doesn't actually have anything to do with with min-one-of.
My intention is that the output of other-procedure will be fed into reporter-procedure as its input.
Only reporters have output. For other-procedure to have output that's fed into reporter-procedure, other-procedure must be a reporter.
You probably just need to declare other-procedure with to-report instead of to and make sure there's a report at the end of it with the output.

Related

reduce_max function in tensorflow

Screenshot
>>> boxes = tf.random_normal([ 5])
>>> with s.as_default():
... s.run(boxes)
... s.run(keras.backend.argmax(boxes,axis=0))
... s.run(tf.reduce_max(boxes,axis=0))
...
array([ 0.37312034, -0.97431135, 0.44504794, 0.35789603, 1.2461706 ],
dtype=float32)
3
0.856236
.
Why am I getting 0.8564. I expect the value to be 1.2461. since 1.2461 is big.right?
I am getting correct answer if i use tf.constant.
But I am not getting correct answer while using radom_normal
Each time a new boxes is regenerated when you run s.run() with radom_normal. So your three results are different. If you want to get consistent results, you should only run s.run() once.
result = s.run([boxes,keras.backend.argmax(boxes,axis=0),tf.reduce_sum(boxes,axis=0)])
print(result[0])
print(result[1])
print(result[2])
#print
[ 0.69957364 1.3192859 -0.6662426 -0.5895929 0.22300807]
1
0.9860319
In addition, the code should be given in text format rather than picture format.
TensorFlow is different from numpy because TF only uses symbolic operations. That means when you instantiate the random_normal, you don't get numeric values, but a symbolic normal distribution, so each time you evaluate it, you get different numbers.
Each time you operate with this distribution, with any other operation, you are getting different numbers, and that explains the results you see.

How to return empty when reducing a flux

Given this simplified sample code:
Flux.empty()
.cast(Integer.class)
.reduce(Integer.valueOf(1), (i,j) -> i+j)
.subscribe(System.out::println);
How to achieve that the result of the reduce operation is also empty?
You can't with this particular variant. Half the purpose of the Integer.valueOf(1) is to provide a seed that ensures there's a value even if the source is empty.
However you can use the variant without a seed/seed supplier:
Flux.empty()
.cast(Integer.class)
.reduce((i,j) -> i+j)
.subscribe(System.out::println);
An empty sequence or single-valued sequence will be reproduced as-is (the javadoc is maybe a bit unclear on that), so:
the code above would produce an empty Mono.
replacing Flux.empty().cast(Integer.class) with Flux.just(1) would produce a Mono that emits 1.
replacing with Flux.just(3, 4) would produce a Mono that emits 7

where I should print my results

I'm talking about good practies, expetially in C/C++ or Python field ( but my question is not based on a specific programming language).
When I want to print a result, where I should put my printf or cout or print?
If this result is computed by a function and then it is returned to main, I should print it in the main or not?
Should the main be free from console output?
If this result is computed by a function and then it is returned to
main, I should print it in the main or not?
Yes, print it on main. In your case I think you can just do the print of the function like: print(functionWithReturnType());
You can also define a variable equal to the function type, and define it equal to the value that the function return, in case you want to use that value more than once.
Should the main be free from console output?
No. You should allways put the console output in main.

Modify values programmatically SPSS

I have a file with more than 250 variables and more than 100 cases. Some of these variables have an error in decimal dot (20445.12 should be 2.044512).
I want to modify programatically these data, I found a possible way in a Visual Basic editor provided by SPSS (I show you a screen shot below), but I have an absolute lack of knowledge.
How can I select a range of cells in this language?
How can I store the cell once modified its data?
--- EDITED NEW DATA ----
Thank you for your fast reply.
The problem now its the number of digits that number has. For example, error data could have the following format:
Case A) 43998 (five digits) ---> 4.3998 as correct value.
Case B) 4399 (four digits) ---> 4.3990 as correct value, but parsed as 0.4399 because 0 has been removed when file was created.
Is there any way, like:
IF (NUM < 10000) THEN NUM = NUM / 1000 ELSE NUM = NUM / 10000
Or something like IF (Number_of_digits(NUM)) THEN ...
Thank you.
there's no need for VB script, go this way:
open a syntax window, paste the following code:
do repeat vr=var1 var2 var3 var4.
compute vr=vr/10000.
end repeat.
save outfile="filepath\My corrected data.sav".
exe.
Replace var1 var2 var3 var4 with the names of the actual variables you need to change. For variables that are contiguous in the file you may use var1 to var4.
Replace vr=vr/10000 with whatever mathematical calculation you would like to use to correct the data.
Replace "filepath\My corrected data.sav" with your path and file name.
WARNING: this syntax will change the data in your file. You should make sure to create a backup of your original in addition to saving the corrected data to a new file.

Logic behind COBOL code

I am not able to understand what is the logic behind these lines:
COMPUTE temp = RESULT - 1.843E19.
IF temp IS LESS THAN 1.0E16 THEN
Data definition:
000330 01 VAR1 COMP-1 VALUE 3.4E38. // 3.4 x 10 ^ 38
Here are those lines in context (the sub-program returns a square root):
MOVE VAR1 TO PARM1.
CALL "SQUAREROOT_ROUTINE" USING
BY REFERENCE PARM1,
BY REFERENCE RESULT.
COMPUTE temp = RESULT - 1.843E19.
IF temp IS LESS THAN 1.0E16 THEN
DISPLAY "OK"
ELSE
DISPLAY "False"
END-IF.
These lines are just trying to test if the result returned by the SQUAREROOT_ROUTINE is correct. Since the program is using float-values and rather large numbers this might look a bit complicated. Let's just do the math:
You start with 3.4E38, the squareroot is 1.84390889...E19.
By subtracting 1.843E19 (i.e. the approximate result) and comparing the difference against 1.0E16 the program is testing whether the result is between 1.843E19 and 1.843E19+1.0E16 = 1.844E19.
Not that this test would not catch an error if the result from SQUAREROOT_ROUTINE was too low instead of too high. To catch both types of wrong results you should compare the absolute value of the difference against the tolerance.
You might ask "Why make things so complicated"? The thing is that float-values usually are not exact and depending on the used precision you will get sightly different results due to rounding-errors.
well the logic itself is very straight forward, you are subtracting 1.843*(10^19) from the result you get from the SQUAREROOT_ROUTINE and putting that value in the variable called temp and then If the value of temp is less than 1.0*(10^16) you are going to print a line out to the SYSOUT that says "OK", otherwise you are going to print out "False" (if the value was equal to or greater than).
If you mean the logic as to why this code exists, you will need to talk to the author of the code, but it looks like a debugging display that was left in the program.

Resources