I need to power some values in librebasic macrocode.
We have func POWER(A; B) but its Syntax is "cell-formula"
But I need something like "pow" as native basic func.
I tried SQL func
POWER(X,Y)
Returns the value of X raised to the power of Y.
in code
rs1(i) = 1/(1+POWER(e, (x1)*(-1)))
But it shows mistake that subprogram isnt determined.
Oh! This "language" has operator "^"! My "cpp brain" is blew up.
Related
I tried writing a Q Code which will allow me to pass parameters however I am getting a results as Qprojection. I tried using
qpython.sync() is returning a QProjection instead of the queried data
but solution isn't working(new to Q/kdb world)
Any ideas on what exactly I should change?
q.sync(
'''{[x;y;z]select from quotestackevent where date within(x;y),sym=z}''',
[np.datetime64('2018-04-14','D'), #start date
np.datetime64('2018-04-14','D'), #end date
np.string_('GBPUSD')])
In Q/KDB the functional format is {......}[x;y;z], with x y z being the arguments. If you have left a blank argument then the function becomes a projection.
qpython allows you to pass python arguments to a q function, with the format being q.sync('{......}',x,y,z).
In your example the square brackets is causing the inputs to be passed as a single array to the function, resulting in a projection. This can be fixed by removing the square bracket.
q.sync('{[x;y;z]select from quotestackevent where date within(x;y),sym=z}', np.datetime64('2018-04-14','D'), np.datetime64('2018-04-14','D'), np.string_('GBPUSD'))
Hope this helps!
I'm porting matlab code to python and come across the code below. Looks like it creates a matrix but I'm not sure what the shape of the matrix would be. Can anybody help me understand what this code mean especially '...' and '].^2'?
somevarialbe = [var1...
var2...
var3].^2;
It is the item-wise operator and power each item to 2. In the other words, it is equivalent to the following code:
somevarialbe = [var1^2...
var2^2...
var3^2];
And ... means next line in the code. Hence, it is equivalent to the following code:
somevarialbe = [var1^2 var2^2 var3^2];
I have written a macro for ImageJ/FIJI to deconvolve my confocal microscopy images and run the "3D Object Counter" plugin. The macro successfully runs all required commands and saves all required data in the specified places.
However, I have found that the 3D-OC autothreshold (as shown in the plugin dialog box) is to stringent resulting in objects being lost or divided.
To remedy this I would like to reduce the autothreshold by a predetermined function something similar to what was done here (from:How to get threshold value used by auto threshold Plugin) which resulted in this code:
setAutoThreshold();
getThreshold(lower,upper);
v=setThreshold(lower,upper*0.5);
run("3D Objects Counter", "threshold="v" slice=10 min.=400 max.=20971520 objects statistics summary");
The idea was to call the AutoThreshold values, modify them and set them to a variable. However when these lines are run the following error is returned:
Number or numeric function expected in line 3.
v=<setThreshold>(lower,upper*0.5);
And if the variable is inserted directly into the threshold key for run(3D-OC) the following msg is encountered:
Numeric value expected in run() function
Key:"threshold"
Value or variable name:"setThreshold(lower,upper*0.5"
Any suggestions or help on how to designate the 3D-OC threshold value as a variable as described would be greatly appreciated (as would any work arounds of course :) ).
Cheers
Edit: After testing Jan's response below (which works perfectly), it appears I need to call the threshold set by the 3D-OC plugin. Anyone know how to do this?
The getThreshold(lower, upper) function returns the lower and upper threshold levels in the provided variables. There is no need to assign any value to a new variable, and as you observed, setThreshold does not have any return value.
Instead, you can use the value(s) returned from getThreshold and use them as parameters in the run method (in the correct way, by string concatenation, see here):
setAutoThreshold();
getThreshold(lower, v);
run("3D Objects Counter", "threshold=" + v + " slice=10 min.=400 max.=20971520 objects statistics summary");
Alternatively, you can use &v in the second parameter to avoid string concatenation in the last line (see the documentation for the run() macro function):
run("3D Objects Counter", "threshold=&v slice=10 min.=400 max.=20971520 objects statistics summary");
You might have to use the lower instead of the upper threshold value, depending on whether you count bright or dark objects.
I give a simple example of what I want to do in Matlabs MuPad
S := matrix([[0,S_1,S_2]]);
sum(S[k]*(k < 2)* S[k] * (TRUE), k=1..3)
should be: "S_1^2 + S_2"
however I get: Error: The first argument must be of type 'Type::Arithmetical'. [sum]
I understand the error, I just don't know how to succeed.
Advice appreciated. I'm looking for some kind of indicator function.
The question:
Start with the inner term. To have a valid number 0 or 1, I used the following expression:
piecewise([A[k]>a*B[l],1],[Otherwise,0])
The rest is straight forward:
sum(sum(A[k]*B[l]*piecewise([A[k]>a*B[l],1],[Otherwise,0]), l=1..L), k=1..K)
S := matrix([[0,S_1,S_2]]);
sum(S[k]^(4-k), k=1..3)
I'm to really sure what you are trying to do.
How would I go about getting a list of available functions and their parameters in a given namespace?
http://code.kx.com/q/ref/syscmds/#f-functions
\f .
\f .namspace
For functions you will have to check parameters individually by just giving the name of function
.n.function
will give you not only the parameters but the whole function definition.
this can surely be improved upon, but thought I'd share as a quick way to get the ball rolling. This will retrieve every global user defined function in every workspace and create a dictionary of namespapaces to functions to parameters.
q)getparams:{k!{n[w]!#'[;1] value each f w:where 100h=type each f:get each ".",/:"." sv/:string x,/:n:y x}[;m] each key m:k!system each "f .",/:string k:key `}
q)f1:{x+y+z}
q).n1.f2:{x*x}
q).n1.a:2
q).n2.f3:{y+y}
q)show r:getparams[]
q | `aj`aj0`asc`asof`avgs`cols`cor`cov`cross`cut`desc`dev`each`ej`except`fby`..
Q | `Cf`IN`L`S`V`addmonths`bv`chk`cn`d0`dd`def`dpft`dpt`dsftg`dt`en`f`fc`ff`f..
h | `cd`code`data`eb`ec`ed`edsn`es`fram`ha`hb`hc`hn`hr`ht`hta`htac`htc`html`h..
n1| (,`f2)!,,`x
n2| (,`f3)!,`x`y
q)r[`n1;`f2]
,`x
[EDIT] the original function was wrong. It missed the global namespace (`) and didn't capture composition, or functions defined with an adverb. The below corrects this, but seems overly convoluted. I'll still leave it here though in case anyone wants to post a nicer solution (so that I too can learn from that)
getparams:{k!{n[w][w2]!#'[;1] v w2:where 0h=type each v:value/[{type[x] in y}[;t]; ] each f:f w:where in[ ;(t:"h"$100,105+til 7)] type each f:get each `$".",/:"." sv/:string x,/:n:y x}[;m] each key m:k!system each "f .",/:string k:`,key `}
I addition to Naveen's answer, you can call value functionName which will give you a list of items, e.g. parameter names and the compiled byte code