My problem is as follows and the code below is what I have so far
def log_upload_weighted_coin_flip(current_percent, lower_likelihood=1/11, upper_likelihood=1/1.5, lower_percent=60, upper_percent=99):
likelihood_index = upper_likelihood - lower_likelihood
percent_diff = current_percent - lower_percent
probability = lower_likelihood + (percent_diff * likelihood_index)
# My reasoning is, as current_percent = lower_percent this will just return lower_likelihood
# and something larger and larger as the current_percent approaches upper_percent
I am working on a bespoke device that seems to behaving in weird manner.
When the system performs certain maintenance duty and uploads some files to a server, sometimes the device behaves wonky depending on how much of the file system has been utilized.
This wonky behavior can happen at file system usages as low as sixty but seems to occur more frequently when the usage reaches above 90.
I am writing a test that systematically fills up the storage a small number of % points at a time and triggers a file upload manually at a certain probability. The likelihood of the file upload being triggered needs to be higher and tied to how much of the file system is is in use.
TL;DR - if k
is diff between lower_percent
and current_percent
. I need True
to be returned with a probability that is k
of the way between lower_likelihood
and upper_likelihood
. But I feel either my mathematical reasoning is off, also how do I translate this probability value into a function that returns True
with that probability when invoked?
EDIT:
I got it to return a weighted probability! I just need to invoke a function now that returns True
at a given probability!
This is what i wrote
In [11]: def log_upload_weighted_coin_flip(current_percent, lower_likelihood=1/11.0, upper_likelihood=1/1.5, lower_percent=60, upper_percent=99):
...: likelihood_index = float(upper_likelihood - lower_likelihood)
...: percent_index = upper_percent - lower_percent
...: percent_diff = current_percent - lower_percent
...: likelihood = lower_likelihood + (percent_diff/(percent_index)*likelihood_index)
...: return (lower_likelihood,likelihood,upper_likelihood)
...: # My reasoning is, as current_percent = lower_percent this will just return lower_likelihood
...: # and something larger and larger as the current_percent approaches upper_percent
...:
In [12]: log_upload_weighted_coin_flip(100)
Out[12]: (0.09090909090909091, 0.6814296814296813, 0.6666666666666666)
In [13]: log_upload_weighted_coin_flip(80)
Out[13]: (0.09090909090909091, 0.3861693861693861, 0.6666666666666666)
In [14]: log_upload_weighted_coin_flip(90)
Out[14]: (0.09090909090909091, 0.5337995337995338, 0.6666666666666666)
In [15]: log_upload_weighted_coin_flip(95)
Out[15]: (0.09090909090909091, 0.6076146076146076, 0.6666666666666666)
In [16]: log_upload_weighted_coin_flip(99)
Out[16]: (0.09090909090909091, 0.6666666666666666, 0.6666666666666666)