KX Community

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

Home Forums kdb+ how to understand the below code Re: how to understand the below code

  • Laura

    Administrator
    March 1, 2022 at 12:00 am

    Lets see what we can infer.

    .quantQ.stats.kendallTauRank:{[xS;yS]   //xS,yS -- arrays of values to compare the rank   // aggregate concordance statictics   stats: sum raze {.quantQ.stats.concordanceRoutine/:[y;(1+x?y)_x]}[t] each t: flip(xS,yS);   // return kendall's tau rank   :(stats[0]-stats[1])%0.5*count[xS]*count[xS]-1;   }

    flip(xS,yS) tells us that xS and yS must be same-width matrices otherwise there would be nothing to flip.

    The binary lambda {.quantQ.stats.concordanceRoutine/:[y;(1+x?y)_x]} is projected on t, which thus becomes the y in the lambda.

    The lambda could equally be written {y .quantQ.stats.concordanceRoutine/:(1+x?y)_x} from which it might be clearer how, with x set to t, the binary concordance routine is being iterated: each row of t against the rows that follow it.

    Two ways to express the same iteration:

    raze{.quantQ.stats.concordanceRoutine/:[y;(1+x?y)_x]}[t] each t t .quantQ.stats.concordanceRoutine'(1+til count t)_: t 

    Line 6 defines the result. Omitting the explicit Return : and the trailing semicolon would be better style. stats would be three integers; the difference could also be written -/[2#stats].