What if you’d like to find a distribution that has a particular property? For example, what if I’d like to find a distribution with a coinformation less that \(-0.5\)? This is where Hypothesis comes in:
In : from hypothesis import find In : from dit.utils.testing import distributions In : find(distributions(3, 2), lambda d: dit.multivariate.coinformation(d) < -0.5) NoSuchExampleTraceback (most recent call last) <ipython-input-3-12cee8225d2d> in <module>() ----> 1 find(distributions(3, 2), lambda d: dit.multivariate.coinformation(d) < -0.5) /home/docs/checkouts/readthedocs.org/user_builds/dit/conda/latest/lib/python2.7/site-packages/hypothesis/core.pyc in find(specifier, condition, settings, random, database_key) 1178 runner.valid_examples,)) 1179 -> 1180 raise NoSuchExample(get_pretty_function_description(condition)) NoSuchExample: No examples found of condition lambda d: dit.multivariate.coinformation(d) < -0.5
What hypothesis has done is use the
distributions() strategy to randomly test distributions. Once it finds a distribution satisfying the criteria we specified (coinformation less than \(-0.5\)) it then simplifies the example as much as possible. Here, we see that even though it could have found any distribution, it found the exclusive or distribution, and simplified the probabilities to be uniform.