Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array subset optimization with composite aggregate functions

I have an array P = [1, 5, 3, 6, 4, ...] of size N and average A.

I want to find the most efficient way to maximize the following 3D function:

f(x, y) = 1 / ( (1+e^(-6(x-2))) * (1+e^(-6(y-2))) * (1+e^(-0.1x-0.3y+1.5)) )

Function gcontour plot

where x = c(S) = Count(S) and y = m(S) = Min(S[0]/A, S[1]/A, ..., S[n]/A), and S is a subset of P. The subset does not have to be continuous in P.

I have a feeling that this can maybe be reduced to some variant of the subset sum problem but I really have no idea where to start other than sorting P. The goal is to implement the algorithm in PHP, but really any pseudocode would help a lot.

like image 421
Mat Avatar asked Jul 14 '18 00:07

Mat


1 Answers

If you are looking for a clever math reduction, agree with others, the place is the math exchange. Otherwise, start with the Math_Combinatorics library. Then you should be able to grind through all unique combinations of S with:

require_once 'Math/Combinatorics.php';
$combos = new Math_Combinatorics;

$P = [1, 5, 3, 6, 4, ...];
for ($n = 1; $n <= count($P); $n++) {
    foreach ($combos->combinations($P, $n) as $S) {
        ... your calculations on S go here ...
    }
}
like image 123
wordragon Avatar answered Nov 15 '22 18:11

wordragon