2022.08.11 11:32 AM
Hi,
Hope this will be clear enough; I am trying to pass 2 parameters (x;y) to a function, for convergence:
The first "y" value sets the 1st convergence function applied to table "x". The resulting converged table, together with the second "y" value, then feed the next convergence... etc, up until the last item in the "y" list. Basically, the parameter "y" allows the condition(s), within the function to converge, to change as "y" is iterated and feeding the next loop.
The following pseudo code is what I am looking for:
Step 1
f:{[x;y]
cond based on 1st item of y;
x: <delete from x where cond>, until x is stable;
}/[initial table]/[first in list]
Step 2 & following: using table output from previous convergence, together with next element in list:
f:{[x;y]
cond based on n'th item of y;
x: <delete from x where cond>, until x is stable
}/[output table from previous step]/[next in list]
... obviously with the bizarre "/[table]/[list]" interpreted as <converge table> over <list>. I think it is possible to achieve this through encapsulation and/or .z.s, but my attempts have failed. Any help would be appreciated.
Thx
JP
2022.08.12 01:25 PM
Precisely (removing the <count>), many thanks:)
Funny, I dug into it this am and came up with {f/[x;1 2]}/[t], but didn't think (still not super fluent in q) about using the projection in the lambda.
Again, thank you for your time and input.
JP
2022.08.11 12:15 PM
q)t:([]til 10)
q)t{y x}/(5_;2_)
x

5
6
7
/ the intermediate steps
q)t{y x}\(5_;2_;2#)
+(,`x)!,5 6 7 8 9
+(,`x)!,5 6 7
+(,`x)!,5 6
2022.08.11 12:36 PM
Rolf,
I don't see any convergence in t{y x}/(5_;2_), but 2 composed operations on t , using atoms. Am I missing something?
JP
2022.08.11 02:31 PM
To illustrate what I am looking for:
/An example
t:([] a:100?10;b:100?1.)
/What I am looking for, (case of 2=count list)
{[x;it]
c1: (1_(>':) (it+1)>x`a),0b; /Cond1: ID first of each group of 1b's (source of convergence in this ex, til stable)
c2: 0.5>abs log ratios next x`b; /Cond2: Some value
cond: $[1=it; c1; c1&c2]; /Set condition according to current param in [1 2]
t: delete from x where condprev cond /Delete a duo of entries, where cond
}/[t] ... with each of [1 2] using the previously converged [t]
/with its equivalent sequence of processing:
{[x]
it: 2;
c1: (1_(>':) (it+1)>x`a),0b;
c2: 0.5>abs log ratios next x`b;
cond: $[1=it; c1; c1&c2];
t: delete from x where condprev cond
}/ [{
it: 1;
c1: (1_(>':) (it+1)>x`a),0b;
c2: 0.5>abs log ratios next x`b;
cond: $[1=it; c1; c1&c2];
t: delete from x where condprev cond
}/[t]]
2022.08.11 02:55 PM
/ our diadic function takes two arguments
/ x will be the table
/ y will be the elements in the list incrementally
/ converge form of over shows final result
q)t{y _ x}/2 3 4
x

6
/ using scan you can see the intermediate changes
q)t{y _ x}\2 3 4
+(,`x)!,2 3 4 5 6 7 8 9
+(,`x)!,2 3 4 5 6
+(,`x)!,,6
??
2022.08.11 03:42 PM
I perfectly understand your example, but there is no convergence per se. It is a standard iterative <over> a list applied to t, as in {y _ x}/[t;2 3 4]. I realize that the title of my post was not a work of art:)
I posted an example of what I am looking for just prior to your last reply; it uses a very short list of n=2 that needs to be fed into the convergence function (convergence in the sens of successive modifications to <t>, based on the current atom in the list, up until no further changes in <t>). Please look into it. Thx
2022.08.12 11:22 AM  edited 2022.08.12 11:23 AM
Is this the behavior you're looking for?
q)t:([] a:100?10;b:100?1.)
q)f:{[x;it]c1:(1_(>':) (it+1)>x`a),0b;c2: 0.5>abs log ratios next x`b;cond: $[1=it; c1; c1&c2];delete from x where condprev cond}
q)count {f[;y]/[x]}/[t;1 2]
56
2022.08.12 01:25 PM
Precisely (removing the <count>), many thanks:)
Funny, I dug into it this am and came up with {f/[x;1 2]}/[t], but didn't think (still not super fluent in q) about using the projection in the lambda.
Again, thank you for your time and input.
JP
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.