PascalLesage / presamples

Package to write, load, manage and verify numerical arrays, called presamples.
BSD 3-Clause "New" or "Revised" License
14 stars 11 forks source link

Create exchanges with bounded random parameters and fixed sum to be used in Monte Carlo #8

Open cardosan opened 7 years ago

cardosan commented 7 years ago

Hi Pascal, I am looking for a way to create exchanges with bounded random parameters and fixed sum to be used in Montecarlo, see this stackoverflow post for details. Chris told me you are working on something similar here. Is something to deal with my issue already implemented or there is anything similar I could start from? If not yet there and you find it useful I would be happy to contribute in developing it.

PascalLesage commented 6 years ago

The function inputs_sum_to_fixed_amount_sample does just this and is functional. It has been tested outside the formal testing procedures and been shown to work. You may be interested in the kronecker_delta_selector that will set all inputs in a specified set to 0 except one, which is set to its original value or to 1, depending on passed arguments - useful for market mixes where you can use one input or another, but not really a mix of inputs.

cardosan commented 6 years ago

Thanks Pascal, it is indeed what I would need....but unfortunately the story is a bit more tricky.

In inputs_sum_to_fixed_amount_sample you (as I would have also done) generate some random numbers based on the distribution of the exchanges and then rescale them based on the (pre-defined) total amount. The problem with this approach it that it falls into the case described here which produce non (truly) random results. I have been checking and testing a bit the function and indeed it seems to give the aforementioned problem (see notebook here).

I can fix the issue when the distribution of the exchanges is uniformly distributed (if you wish can go ahead and push a commit) but for the other cases, when the distribution is not uniform, will need to think and check if and how feasible.

P.S: is it already functional this package or any expected release date? It looks very much useful for my need and would certainly be of help for me....I could be your test-case :)

PascalLesage commented 6 years ago

Ah! Well, I hadn't seen this (nor tested it this way). Thanks for flagging.

I'd gladly accept any fix, but cases where all parameters are uniformly distributed will be the exception.

As for your PS: we expect a release date by end of year. There are dependencies to dev branches of bw2_calc and bw2_parametersets, and there are tests and docs to write, but both @cmutel and I are aiming for end of year. If you want to get involved, that would be great. PM me or Chris, and we'll get you on our next planning conversation.

cmutel commented 6 years ago

As you note, this is a known problem, and to the best of my understanding there is no way to preserve the shape of a distribution when summing and normalizing it with other uncertain parameters. There are a few alternatives:

  1. Don't use your underlying distribution. It is probably wrong in any case. Or just accept that your shape will be distorted.
  2. Use the actual input data which already sums to one, e.g. electricity dispatch data as presamples directly.
  3. Use the Dirichlet distribution which is guaranteed to sum to X.