Hi Jack,
Repeating the mmin function:
q)mmin
k){(x-1)&':/y}
Lets say we try 3 mmin 1 5 3
If we break the expression down into two parts:
-
the min operator combined with the each prior adverb
-
the x f/y expression, meaning iterate y using f, by x times
For (1), we can combine verbs in brackets to make an adverb. In this case, combining min (&) and each priot (':)
q) minprev:(&':)
&: is taking each item of the right operand and applying it to its predecessor
Now for part (2), using our adverb minprev as the function, f, in the x f/y expression.
q)2 minprev\ 1 5 3
1 1 1
Iterate the list1 5 3using minprev 2 times
And if we change Over into Scan (\ into /) to get the intermediate results as well:
q)2 minprev\ 1 5 3
1 5 3
1 1 3
1 1 1
The original list is returned first: 1 5 3
The first iteration of the function returns
(min 0N 1; min 1 5; min 5 3)
113
The second iteration of the function returns
(min 0N 1; min 1 1; min 1 3)
111
For your original example, using 3 mmin til 6, as you say correctly translates to 2&:/til 6
Or in terms of the minprev Ive defined:
3 mmin til 6
becomes
q)2 minprev\ 0 1 2 3 4 5
0 1 2 3 4 5
0 0 1 2 3 4/ 1 iteration
0 0 0 1 2 3/ 2 iterations
Looking just at the final result with Over:
q)2 minprev/ 0 1 2 3 4 5
0 0 0 1 2 3
To calculate the 3, we look at the 3 4 5 (window size 3)
To calculate the 2, we look at the 2 3 4 (window size 3)
etc
The result only requires n-1 iterations for n sized window.
Thanks,
Matthew McAuley
KDB+ Developer, AquaQ Analytics Ltd
This email, its contents and any files attached are a confidential communication and are intended only for the named addressees indicated in the message.
If you are not the named addressee or if you have received this email in error, you may not, without the consent of AquaQ Analytics, copy, use or rely on any information or attachments in any way. Please notify the sender by return email and delete it from your email system.
Unless separately agreed, AquaQ Analytics does not accept any responsibility for the accuracy or completeness of the contents of this email or its attachments. Please note that any views, opinion or advice contained in this communication are those of the sending individual and not those of AquaQ Analytics and AquaQ Analytics shall have no liability whatsoever in relation to this communication (or its content) unless separately agreed