quantiles: list first number, last number, and numbers in-between

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

quantiles: list first number, last number, and numbers in-between

16 Sep 2018, 11:49

- I needed to do some quality testing. I wanted to test the first item, the last item, and an even spread of numbers of in-between, so I created the function below.
- If there are any similar scripts it would be interesting to know. Thanks.

- Note: If you split a range by n-tiles, you get n segments, n-1 values within the range, and n+1 values including the start/end of the range.
- E.g. if you split the range 0-100 into quartiles (4-tiles), you get 4 segments, 3 values with then range (25, 50, 75), and 5 values including the start/end of the range (0, 25, 50, 75, 100).

Code: Select all

q:: ;get all quantiles, or one quantile
oArray := JEE_Quantiles(0, 100, 4)
MsgBox, % JEE_ObjListSimple(oArray)

MsgBox, % JEE_Quantiles(0, 100, 4, 1)

oArray := JEE_Quantiles(1, 15, 7)
MsgBox, % JEE_ObjListSimple(oArray)
return

JEE_Quantiles(vFirst, vLast, vParts, vNum:="")
{
	vDiff := vLast-vFirst
	if !(vNum = "")
		return vFirst + ((vDiff*vNum)/vParts)
	oArray := []
	Loop, % vParts + 1
		oArray.Push(vFirst + ((vDiff*(A_Index-1))/vParts))
	return oArray
}

JEE_ObjListSimple(oArray, vSep:=" ", vSep2:="`r`n")
{
	for vKey, vValue in oArray
		vOutput .= vKey vSep vValue vSep2
	return SubStr(vOutput, 1, -StrLen(vSep2))
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: quantiles: list first number, last number, and numbers in-between

19 Sep 2018, 05:37

- If there are any similar scripts it would be interesting to know.
The same, although, mine is more efficient.

Cheers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: quantiles: list first number, last number, and numbers in-between

19 Sep 2018, 05:49

- Interesting, calculate the ratio first, rather than the difference. Plus use SetCapacity.
- Yes, the function is basically 'for i = a to b (step c)', but instead of the step size, you specify the step count, I hadn't really noticed that, I was coming at it from a different angle (trying to find equidistant points, thinking that is was different from quantiles, then thinking it was the same).
- Have you seen any languages that allow you to use step count instead of step size?
- You know, I recently read your description of the function and I didn't realise its significance.
- Do you use it a lot? Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: ArkuS and 67 guests