This piece of code
coefs = coefs - np.sum(coefs) + 1 # now sum to 1
is wrong: the sum won’t be equal to 1. I suggest to change it to this:
coefs = coefs - np.mean(coefs) + 1/k # now sum to 1
This piece of code
coefs = coefs - np.sum(coefs) + 1 # now sum to 1
is wrong: the sum won’t be equal to 1. I suggest to change it to this:
coefs = coefs - np.mean(coefs) + 1/k # now sum to 1