algorithm challenge , optimize outlier values in an array, sum of total should not change

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

algorithm challenge , optimize outlier values in an array, sum of total should not change

21 May 2023, 13:29

Code: Select all

arr:=[2,3,4,3,4,5,8,6,6,2,7,7,14,8,9,10,12,14,19,13,14,14,21,15,3,4,14,15,16,16,17]

here in this array arr[7] , arr[10] ,arr[13] , arr[19], arr[23], arr[25] , arr[26] are outliers as there is abrupt change in value comparing nearby values.
how can these outlier which are lesser than near by values be increased by borrowing from nearby values and similarly the outlier values which are much higher than near by values be reduced by giving to nearby values.
total sum of the array should not change.

any idea ?
User avatar
Chunjee
Posts: 1453
Joined: 18 Apr 2014, 19:05
Contact:

Re: algorithm challenge , optimize outlier values in an array, sum of total should not change

21 May 2023, 21:35

To find the outliers this is what I came up with:

Code: Select all

fn_findOutliers(param_arr) {
    outlier_locations := []
    loop, % param_arr.count() {
        current_value := param_arr[A_Index]
        if (A_Index > 1 && abs(current_value - previous_value) > 3) {
            outlier_locations.push(A_Index)
        }
        previous_value := current_value
    }
    return outlier_locations
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 176 guests