- Added documentation for model functions and
sq.samplein README. - Adds support for Python 3.13, drops support for Python 3.9 and 3.10.
- Uses prettier
tqdmoutput that is now aware of Jupyter notebooks. bayes.updatenow supportslognormandgammadistributions in addition tonormandbeta.- Allow
zero_inflatedto accept 0 or 1 as probabilities. - [New feature] Added
die(sides, explode_on=None)andcoin()as distribution objects for dice and coins. These support all distribution operations like~,@,+,-, etc. Thediedistribution also supports "exploding dice" mechanics via theexplode_onparameter. - [Breaking change] Removed
roll_dieandflip_coinfunctions. Usesq.die(sides) @ nor~sq.coin()instead.
- Fixes a bug where
max_gainandmodeled_gainwere incorrect in kelly output. - Fixes a bug where
errorwas not correctly passed fromhalf_kelly,third_kelly, andquarter_kelly. - Added
invlognormas a new distribution. - Added
bucket_percentagesto more easily get the percentage of values within a bucket. - Added
third_kellyas an alias forkellywith deference = 0.66. - Allows Bernoulli distributions to be defined with p=0 or p=1
- Added a
Makefileto help simplify testing and linting workflows
- [Breaking change]
sq.paretopreviously sampled from a Lomax distribution due to a complication with numpy. Now it properly samples from a Pareto distribution. - [Breaking change] lclip / rclip have been removed from triangular distribution because that doesn't make sense.
- [Breaking change] You now can nest mixture and discrete distributions within mixture distributions.
- [Breaking change]
sq.kellynow raises an error if you put in a price below the market price. You can passerror=Falseto disable this and return to the old behavior. - Added
pertdistribution. - Added
sharpe_ratioto utilities. get_percentiles,get_log_percentiles,get_mean_and_ci, andget_median_and_cinow can all take an optionalweightsparameter to do a weighted version.
- [Breaking change] This package now only supports Python 3.9 and higher.
- [Breaking change]
get_percentilesandget_log_percentilesnow always return a dictionary, even if there's only one element. - [Breaking change]
.typeis now removed from distribution objects. - You can now create correlated variables using
sq.correlate. - Added
geometricdistribution. - Distribution objects now have the version of squigglepy they were created with, which can be accessed via
obj._version. This should be helpful for debugging and noticing stale objects, especially when squigglepy distributions are stored in caches. - Distributions can now be hashed with
hash. - Fixed a bug where
tdistwould not return multiple samples if defined withtalone. - Package load time is now ~2x faster.
- Mixture sampling is now ~2x faster.
- Pandas and matplotlib as removed as required dependencies, but their related features are lazily enabled when the modules are available. These packages are still available for install as extras, installable with
pip install squigglepy[plots](for plotting-related functionality, matplotlib for now),pip install squigglepy[ecosystem](for pandas, and in the future other related packages), orpip install squigglepy[all](for all extras). - Multicore distribution now does extra checks to avoid crashing from race conditions.
- Using black now for formatting.
- Switched from
flake8toruff.
- [Breaking change]
lognormcan now be defined either referencing the mean and sd of the underlying normal distribution vianorm_mean/norm_sdor via the mean and sd of the lognormal distribution itself vialognorm_mean/lognorm_sd. To further disambiguate,meanandsdare no longer variables that can be passed tolognorm.
- Added
plotas a method to more easily plot distributions. - Added
dist_loganddist_expoperators on distributions. - Added
growth_rate_to_doubling_timeanddoubling_time_to_growth_rateconvenience functions. These take numbers, numpy arrays or distributions. - Mixture distributions now print with weights in addition to distributions.
- Changes
get_log_percentilesto report in scientific notation. bayesnow supports separate arguments formemcache_loadandmemcache_saveto better customize how memcache behavior works.memcacheremains a parameter that sets bothmemcache_loadandmemcache_saveto True.
- Distributions can now be negated with
-(e.g.,-lognorm(0.1, 1)). - Numpy ints and floats can now be used for determining the number of samples.
- Fixed some typos in the documentation.
- Added
paretodistribution. - Added
get_median_and_cito return the median and a given confidence interval for data. discreteandmixturedistributions now give more detail when printed.- Fixed some typos in the documentation.
- Added
extremizeto extremize predictions. - Added
normalizeto normalize a list of numbers to sum to 1. - Added
get_mean_and_cito return the mean and a given confidence interval for data. - Added
is_distto determine if an object is a Squigglepy distribution. - Added
is_sampleableto determine if an object can be sampled usingsample. - Support for working within Pandas is now explicitly added.
pandashas been added as a requirement. discretesampling now will compress a large array if possible for more efficient sampling.clip,lclip, andrclipcan now be used without needing distributions.- Some functions (e.g,
geomean) previously only supported lists, dictionaries, and numpy arrays. They have been expanded to support all iterables. dist_maxanddist_minnow support pipes (>>)get_percentilesnow coerces output to integer ifdigitsis less than or equal to 0, instead of just exactly 0.
- Mixture sampling is now 4-23x faster.
- You can now get the version of squigglepy via
sq.__version__. - Fixes a bug where the tqdm was displayed with the incorrect count when collecting cores during a multicore
sample.
- Fixes how package dependencies are handled in
setup.pyan specifies Python >= 3.7 must be used. This should fix install errors.
- Fixes a bug where
lclipand/orrcliponmixturedistribution were not working correctly. - Fixes a bug where
dist_fndid not work withnp.vectorizefunctions. - Fixes a bug where in-memory caching was invoked for
bayesnetwhen not desired.
- [Breaking change]
bayesnetcaching is now based on binary files instead of pickle files (usesmsgspecas the underlying library). - [Breaking change]
samplecaching is now based on numpy files instead of pickle files. - A cache can now be loaded via
sample(load_cache=cachefile)orbayesnet(load_cache=cachefile), without needing to pass the distribution / function. bayesnetandsamplenow take an argumentcores(default 1). If greater than 1, will run the calculations on multiple cores using the pathos package.
- Functions that take
weightsnow can instead take a parameterrelative_weightswhere waits are automatically normalized to sum to 1 (instead of erroring, which is still the behavior if usingweights). - Verbose output for
bayesnetandsampleis now clearer (and slightly more verbose).
- [Breaking change] The default
tfor t-distributions has changed from 1 to 20. sampleresults can now be cached in-memory usingmemcache=True. They can also be cached to a file -- usedump_cache_fileto write the file andload_cache_fileto load from the file.- (Non-visible backend change) Weights that are set to 0 are now dropped entirely.
- When
verbose=Trueis used insample, the progress bar now pops up in more relevant places and is much more likely to get triggered when relevant. discrete_sampleandmixture_samplenow can takeverboseparameter.
zero_inflatedcan create an arbitrary zero-inflated distribution.- Individual sampling functions (
normal_sample,lognormal_sample, etc.) can now take an argumentsamplesto generate multiple samples. - A large speedup has been achieved to sampling from the same distribution multiple times.
requirements.txthas been updated.
- [Breaking change]
bayesnetfunction now refers to parametermemcachewhere previously this parameter was calledcache. - [Breaking change] If
get_percentilesorget_log_percentilesis called with just one elemement forpercentiles, it will return that value instead of a dict. - Fixed a bug where
get_percentileswould not round correctly. bayesnetresults can now be cached to a file. Usedump_cache_fileto write the file andload_cache_fileto load from the file.discretenow works with numpy arrays in addition to lists.- Added
one_inas a shorthand to convert percentages into "1 in X" notation. - Distributions can now be compared with
==and!=.
- Nested sampling now works as intended.
- You can now use
>>for pipes for distributions. For example,sq.norm(1, 2) >> dist_ceil - Distributions can now be compared with
>,<,>=, and<=. dist_maxcan be used to get the maximum value between two distributions. This family of functions are not evaluated until the distribution is sampled and they work with pipes.dist_mincan be used to get the minimum value between two distributions.dist_roundcan be used to round the final output of a distribution. This makes the distribution discrete.dist_ceilcan be used to ceiling round the final output of a distribution. This makes the distribution discrete.dist_floorcan be used to floor round the final output of a distribution. This makes the distribution discrete.lclipcan be used to clip a distribution to a lower bound. This is the same functionality that is available within the distribution and thesamplemethod.rclipcan be used to clip a distribution to an upper bound. This is the same functionality that is available within the distribution and thesamplemethod.clipcan be used to clip a distribution to both an upper bound and a lower bound. This is the same functionality that is available within the distribution and thesamplemethod.samplecan now be used directly on numbers. This makesconstfunctionally obsolete, butconstis maintained for backwards compatibility and in case it is useful.sample(None)now returnsNoneinstead of an error.
- Sample shorthand notation can go in either order. That is,
100 @ sq.norm(1, 2)now works and is the same assq.norm(1, 2) @ 100, which is the same assq.sample(sq.norm(1, 2), n=100).
- Distributions now implement math directly. That is, you can do things like
sq.norm(2, 3) + sq.norm(4, 5), whereas previously this would not work. Thanks to Dawn Drescher for helping me implement this. ~sq.norm(1, 2)is now a shorthand forsq.sample(sq.norm(1, 2)). Thanks to Dawn Drescher for helping me implement this shorthand.sq.norm(1, 2) @ 100is now a shorthand forsq.sample(sq.norm(1, 2), n=100)
- [Breaking change]
tdistandlog_tdisthave been modified to better approximate the desired credible intervals. tdistnow can be defined by justt, producing a classic t-distribution.tdistnow has a default value fort: 1.- Added
chisquaredistribution. lognormalnow returns an error if it is defined with a zero or negative value.
- All functions now have docstrings.
- Added
kellyto calculate Kelly criterion for bet sizing with probabilities. - Added
full_kelly,half_kelly,quarter_kellyas helpful aliases.
- [Breaking change]
credibilityis now defined using a number out of 100 (e.g.,credibility=80to define an 80% CI) rather than a decimal out of 1 (e.g.,credibility=0.8to define an 80% CI). - Distribution objects now print their parameters.
goemeanandgeomean_oddsnow can take the nested-list-based and dictionary-based formats for passing weights.
- [Breaking change]
bayes.updatenow updates normal distributions from the distribution rather than from samples. - [Breaking change]
bayes.updateno longer takes atypeparameter but can now infer the type from the passed distribution. - [Breaking change] Corrected a bug in how
bayes.updateimplementedevidence_weightwhen updating normal distributions.
- Distributions are now implemented as classes (rather than lists).
- Fixes an issue with sampling from the
bernoullidistribution. - Fixes a bug with the implementation of
lclipandrclip.
- Adds
discreteto calculate a discrete distribution. Example:discrete({'A': 0.3, 'B': 0.3, 'C': 0.4})will return A 30% of the time, B 30% of the time, and C 40% of the time. - Adds
poisson(lam)to calculate a poisson distribution. - Adds
gamma(size, scale)to calculate a gamma distribution.
- Adds
bayes.bayesnetto do bayesian inferece (see README). bayes.updatenow can take anevidence_weightparameter. Typically this would be equal to the number of samples.- [Breaking change]
bayes.bayeshas been renamedbayes.simple_bayes.
- [Breaking change]
credibility, which defines the size of the interval (e.g.,credibility=0.8for an 80% CI), is now a property of the distribution rather than the sampler. That is, you should now callsample(norm(1, 3, credibility=0.8))whereas previously it wassample(norm(1, 3), credibility=0.8). This will allow mixing of distributions with different credible ranges. - [Breaking change] Numbers have been changed from functions to global variables. Use
thousandorKinstead ofthousand()(old/deprecated). samplenow has a nice progress reporter ifverbose=True.- The
exponentialdistribution now implementslclipandrclip. - The
mixturedistribution can infer equal weights if no weights are given. - The
mixturedistribution can infer the last weight if the last weight is not given. geomeanandgeomean_oddscan infer the last weight if the last weight is not given.- You can use
flip_coinandroll_die(sides)to flip a coin or roll a die. event_happensandeventare aliases forevent_occurs.get_percentileswill now cast output tointifdigits=0.get_log_percentilesnow has a default value forpercentiles.- You can now set the seed for the RNG using
sq.set_seed.
- Now has tests via pytest.
- The random numbers now come from a numpy generator as opposed to the previous deprecated
np.randommethods. - The
samplemodule (containing thesamplefunction) has been renamedsamplers.
- Add
triangular(left, mode, right)to calculate a triangular distribution. - Add
binomial(n, p)to calculate a binomial distribution. - Add
beta(a, b)to calculate a beta distribution. - Add
bernoulli(p)to calculate a bernoulli distribution. - Add
exponential(scale)to calculate an exponential distribution.
- Add
bayes.updateto get a posterior distribution from a prior distribution and an evidence distribution. - Add
bayes.averageto average distributions (via a mixture).
- Add
laplaceto calculate Laplace's Law of Succession. Ifsandnare passed, it will calculate(s+1)/(n+2). Ifs,time_passed, andtime_remainingare passed, it will use the time invariant version. Usetime_fixed=Truefor fixed time periods andtime_fixed=False(default) otherwise. - Add
geomeanto calculate the geometric mean. - Add
p_to_oddsto convert probability to odds. Alsoodds_to_pto convert odds to probability. - Add
geomean_oddsto calculate the geometric mean of odds, converted to and from probabilities.
- If a distribution is defined with
sdbut notmean,meanwill be inferred to be 0. samplecan now takelclipandrclipdirectly, in addition to defininglclipandrclipon the distribution itself. If both are defined, the most restrictive of the two bounds will be used.
- Fix critical bug to
tdistandlog_tdistintroduced in v0.3.
- Fix critical bug introduced in v0.3.
- Be able to define distributions using
meanandsdinstead of defining the interval.
- [Breaking change] Change
distributed_logtomixture(to follow Squiggle) and allow it to implement any sub-distribution. - [Breaking change] Changed library to single import.
- [Breaking change] Remove
weighted_logas a distribution.
- Initial library