KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Convergence using binary?

  • Convergence using binary?

    Posted by jp on August 11, 2022 at 12:00 am

    Hi,

    Hope this will be clear enough; I am trying to pass 2 parameters (x;y) to a function, for convergence:

    • “x” being an initial table, which the convergence function will gradually modify until no change, using…
    • “y”, a list, which current value allows defining current conditions within the convergence function.

    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

    jp replied 9 months, 2 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • jp

    Member
    August 12, 2022 at 12:00 am

    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

  • jfealy

    Member
    August 12, 2022 at 12:00 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 cond|prev cond} 
    q)count {f[;y]/[x]}/[t;1 2] 
    56

     

     

     

Log in to reply.