ProbabilityPewter 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,253 @@
1
+ Metadata-Version: 2.4
2
+ Name: ProbabilityPewter
3
+ Version: 0.5.0
4
+ Summary: A package for simulating and visualising probability, for gaming, statistics, and other uses.
5
+ Author: Feamaika
6
+ Author-email: 6xx122r3f@mozmail.com
7
+ Project-URL: GitHub, https://github.com/Feamaika/ProbabilityPewter
8
+ Project-URL: Changelog, https://github.com/Feamaika/ProbabilityPewter/blob/main/HISTORY.md
9
+ Keywords: dice,distributions,probability,rpg,simulation
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Education
12
+ Classifier: Intended Audience :: Information Technology
13
+ Classifier: Intended Audience :: Other Audience
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Games/Entertainment :: Simulation
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy>=1.24.0
29
+ Requires-Dist: py-rolldice>=0.4.0
30
+ Requires-Dist: matplotlib>=3.5.0
31
+ Dynamic: author
32
+ Dynamic: author-email
33
+ Dynamic: classifier
34
+ Dynamic: description
35
+ Dynamic: description-content-type
36
+ Dynamic: keywords
37
+ Dynamic: license-file
38
+ Dynamic: project-url
39
+ Dynamic: requires-dist
40
+ Dynamic: requires-python
41
+ Dynamic: summary
42
+
43
+ # ProbabilityPewter
44
+ **My first public Python package.**
45
+ ***Craft odds like metals!***
46
+ The idea is my own, and the inspiration to publish it comes from [DataCamp](https://app.datacamp.com/learn/courses/developing-python-packages).
47
+
48
+ ## What This Package Is For
49
+ ProbabilityPewter is a collection of probability tools for RPG play, practical statistics, and easy exploratory analysis.
50
+
51
+ Its contents are currently divided into three parts:
52
+ - [**calculator**](#1-calculator): calculation tools for directly working with probabilities
53
+ - [**roll_stats**](#2-roll-stats): roll statistics tools for dice rolls and comparisons in game design and play
54
+ - [**visualiser**](#3-visualiser): visualisation tools for easily plotting probability distributions and highlighting probabilities of interest
55
+
56
+ ## Installation
57
+ The easiest way to install the package is to install it from PyPI:
58
+ ```bash
59
+ pip install ProbabilityPewter
60
+ ```
61
+
62
+ ## Quick Start
63
+ ```python
64
+ import ProbabilityPewter as PP
65
+
66
+ PP.plot_normal() # One of the core functions exposed at top level, for easier access
67
+ ```
68
+
69
+ ## Package Modules
70
+
71
+ ### 1) Calculator
72
+ Functions for direct probability calculations.
73
+
74
+ #### combined_prob
75
+ Calculate combined probability for independent events, like the odds of both winning the lottery and being struck by lightning in any given year:
76
+
77
+ ```python
78
+ combined_prob(A=0.0000000715, B=0.000001, output_scale='odds')
79
+ # 1:14000000000000
80
+ ```
81
+
82
+ #### bayes_updater
83
+ Apply Bayes' theorem to update a prior probability after evidence.
84
+
85
+ A clear Bayes example: estimate the probability that a person is a smoker, given that the person has been diagnosed with lung cancer.
86
+
87
+ Suppose:
88
+ - P(smoker) = 0.10
89
+ - P(lung cancer | smoker) = 0.13
90
+ - P(lung cancer | not smoker) = 0.015
91
+
92
+ ```python
93
+ from ProbabilityPewter.calculator.bayes import bayes_updater
94
+
95
+ p_smoker_given_cancer = bayes_updater(
96
+ prior_A=0.10,
97
+ likelihood_B_given_A=0.13,
98
+ likelihood_B_given_not_A=0.015,
99
+ )
100
+
101
+ print(p_smoker_given_cancer)
102
+ # 0.49056603773584906
103
+ ```
104
+
105
+ So in this example, the probability is about 49%.
106
+
107
+ #### at_least_k_of_n
108
+ Compute the probability of getting at least k successes in n Bernoulli trials.
109
+
110
+ ```python
111
+ from ProbabilityPewter.calculator.series import at_least_k_of_n
112
+
113
+ # Probability of at least 1 six in 6 rolls
114
+ at_least_k_of_n(1, 6, 1/6)
115
+ # 0.6651020233196159
116
+ ```
117
+
118
+ #### gambler_ruin
119
+ Calculate the probability of ending up in a specific state after a series of wins and losses, given the probability of winning a bet each round.
120
+
121
+ ```python
122
+ from ProbabilityPewter.calculator.series import gambler_ruin
123
+ gambler_ruin(2, 4, 0.25) # P of ending up with €4, after starting at €2, when the chance of winning €1 is p=0.25
124
+ # 0.1
125
+ ```
126
+
127
+ ### 2) Roll Stats
128
+ Functions for exact dice-expression comparison and simulation-style play support.
129
+
130
+ #### rpg_dice
131
+ Roll RPG notation and optionally show a verbose breakdown.
132
+
133
+ ```python
134
+ import random
135
+ random.seed(42)
136
+ rpg_dice('4D10*2', output='verbose')
137
+ # Rolling 4D10 with * 2:
138
+ # Result: [2, 1, 5, 4] = 12
139
+ # 12 * 2 = 24
140
+ # 24
141
+ ```
142
+
143
+ #### prob_table (compare)
144
+ Compare one or more dice expressions using exact probabilities.
145
+
146
+ ```python
147
+ from ProbabilityPewter.roll_stats.compare import prob_table
148
+
149
+ print(prob_table(['1D8', '2D4', '1D6+2'], target=5))
150
+ # expression mean std min max p_beat
151
+ # 1D8 4.500 2.291 1 8 0.500
152
+ # 2D4 5.000 1.581 2 8 0.625
153
+ # 1D6+2 5.500 1.708 3 8 0.667
154
+ ```
155
+
156
+ #### combat_odds / risk_odds / ti_odds / aa_odds
157
+ Estimate combat win probabilities for popular strategy games. Currently supported games are Risk, Twilight Imperium 4 (TI), and Axis & Allies.
158
+
159
+ ```python
160
+ from ProbabilityPewter.roll_stats import ti_odds
161
+
162
+ r = ti_odds({'Cruiser+': 2}, {'Carrier': 1, 'Fighter': 3}, output='result')
163
+ plot_combat(r)
164
+ ```
165
+
166
+ The TI and Axis & Allies functions use Monte Carlo simulation, while `risk_odds` uses exact state probabilities. The `combat_odds` function is a unified entrypoint for all supported games, and will call the appropriate function based on the `game` parameter.
167
+
168
+ ```python
169
+ combat_odds(10, 8, game='risk')
170
+ # Risk odds - attacker win: 64.64%, defender win: 35.36%, avg survivors (A/D): 4.05/1.23
171
+ ```
172
+
173
+ ### 3) Visualiser
174
+ Plot exact and analytical distributions with highlight options.
175
+
176
+ #### plot_dice
177
+ Plot exact distribution of a dice expression.
178
+
179
+ ```python
180
+ plot_dice('2D6+3', highlight=8, highlight_type='>=')
181
+ ```
182
+ <p float="left">
183
+ <img src="screenshots/distribution2D6+3.png" title="Example dice roll distribution, showing all outcomes >=8 highlighted, with an annotation of the probability P for that outcome" alt="[Screenshot example dice plot]" style="width:80%; height:auto;">
184
+ </p>
185
+
186
+ #### plot_normal
187
+ Plot a standard or custom normal distribution with calculations around specific values, _z_-scores or percentiles:
188
+
189
+ ```python
190
+ plot_normal(mean=100, std=15, highlight=2.2, highlight_type='above', as_z=True)
191
+ ```
192
+ <p float="left">
193
+ <img src="screenshots/distribution100-15-above2.2.png" title="Example normal distribution, with an annotation of how much area falls above the given z-score" alt="[Screenshot example normal distribution]" style="width:80%; height:auto;">
194
+ </p>
195
+
196
+
197
+ #### compare_normals
198
+ Overlay two normal distributions, shade their overlap, and report the exact probability that one exceeds the other, along with the overlap coefficient and the Cohen's _d_ effect size. Handy for quick A/B-test intuition, since the difference of two independent normals is itself normal, so P(A > B) is exact - no simulation needed.
199
+
200
+ ```python
201
+ from ProbabilityPewter.visualiser import compare_normals
202
+
203
+ compare_normals(a=(104, 10), b=(100, 15), labels=('New', 'Control'))
204
+ # P(New > Control) = 58.8%, Overlap = 77.8%, Cohen's d = 0.31 (small)
205
+ ```
206
+
207
+ #### plot_poisson
208
+ Plot a Poisson distribution with optional highlighted outcomes, similar to the other plot functions in the submodule:
209
+
210
+ ```python
211
+ from ProbabilityPewter.visualiser.distributions import plot_poisson
212
+
213
+ plot_poisson(lam=4.5, highlight=6, highlight_type='>=')
214
+ ```
215
+
216
+ ## API Overview
217
+
218
+ | Function | Module | Purpose | Core |
219
+ |---|---|---|---|
220
+ | combined_prob | calculator.combiner | Combine independent events (AND/OR/NOT/XOR/etc.) | ✅ |
221
+ | bayes_updater | calculator.bayes | Bayes update for posterior probability | |
222
+ | at_least_k_of_n | calculator.series | At least k successes in n trials | |
223
+ | gambler_ruin | calculator.series | Probability of reaching a target without reaching 0 | |
224
+ | rpg_dice | roll_stats.dice | Roll RPG dice notation | ✅ |
225
+ | prob_table | roll_stats.compare | Exact comparison stats for dice expressions | ✅ |
226
+ | combat_odds | roll_stats.combat | Unified battle-odds entrypoint (Risk/TI/A&A) | ✅ |
227
+ | risk_odds | roll_stats.combat | Exact Risk battle odds | |
228
+ | ti_odds | roll_stats.combat | TI4 battle odds via simulation | |
229
+ | aa_odds | roll_stats.combat | Axis & Allies battle odds via simulation | |
230
+ | plot_dice | visualiser.distributions | Exact discrete dice distribution plot | ✅ |
231
+ | plot_normal | visualiser.distributions | Normal distribution plot with highlights | ✅ |
232
+ | plot_poisson | visualiser.distributions | Poisson distribution plot with highlights | |
233
+ | compare_normals | visualiser.distributions | Overlay two normals and report exact P(A > B) | |
234
+ | plot_combat | roll_stats.combat | Bar chart for combat outcome probabilities | ✅ |
235
+
236
+ ## Dice Syntax
237
+ Dice syntax for `rpg_dice` is the same as in the [py-rolldice](https://github.com/fionafibration/py-rolldice/) package from Fiona Blackett, which itself is based on CritDice.
238
+
239
+ ## Changelog
240
+ See the [changelog](https://github.com/Feamaika/ProbabilityPewter/blob/main/HISTORY.md) for a history of notable changes.
241
+
242
+ ## Suggestions
243
+ If you have any other ideas for features, just make a suggestion and I will see what I can do.
244
+
245
+ ## Planned Features
246
+ - Adopt an alternative dependency for the `rpg_dice` function, since the aforementioned py-rolldice module uses `node.n`, which will be removed in newer Python versions, potentially breaking the package.
247
+ - Expand dice roll visualisation to support rolls for specific RPG systems like Savage Worlds and Shadowrun.
248
+ - Support for more than two events in `combined_prob`.
249
+ - ...
250
+
251
+ ## Support
252
+ If you had fun or were helped by my code, feel free to buy me a coffee:
253
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E81X4KSI)
@@ -0,0 +1,16 @@
1
+ ProbabilityPewter/__init__.py,sha256=ITmPiK2kWzo_SbPMbroW_AXgyPK3_2QN-55MNZ9NWMM,1114
2
+ ProbabilityPewter/calculator/__init__.py,sha256=lYUoXelDvqHHTIAUj3dpM-MbTqo7x-TfymsvOCeWuC4,130
3
+ ProbabilityPewter/calculator/bayes.py,sha256=gm2yJ_nfcofbakTjKPLeBeVEcA8-DvFbzIqxtF9OMdI,1509
4
+ ProbabilityPewter/calculator/combiner.py,sha256=wVC4rCQbBNxq2nUetY5UGfRI6GbFX_9BGQZk0tcnLXk,5463
5
+ ProbabilityPewter/calculator/series.py,sha256=Ic41yaQW-1kmKYPY-qzpCZrIx-0iZxsIDXe2OA_pgxw,2034
6
+ ProbabilityPewter/roll_stats/__init__.py,sha256=5YSWUTYCcMXZfT_Vdee5Y866_rnMioymrhczzNoAMOw,227
7
+ ProbabilityPewter/roll_stats/combat.py,sha256=ny5IQVoj-HDCfKJlkYcfIj5i3esax4OgDcQI6W7mW84,28361
8
+ ProbabilityPewter/roll_stats/compare.py,sha256=8i4bVyZBOu0eqJfNRmG18pHpKnIGwXKRzRniRQ6jOmQ,4563
9
+ ProbabilityPewter/roll_stats/dice.py,sha256=E3ZlMatABej2Q2SV5shYJ_I19weBJRGR-l6DmniFJZo,5953
10
+ ProbabilityPewter/visualiser/__init__.py,sha256=Nzj-vrvMfM_-7tGkfwPiCmnnFh2PLZ83q-ioaEFmCAc,239
11
+ ProbabilityPewter/visualiser/distributions.py,sha256=Gw6DgdbKSUs5oD3m6BDsHx_HkmPfrXXXyBWcuL3yoBQ,30128
12
+ probabilitypewter-0.5.0.dist-info/licenses/LICENSE,sha256=TNO92oCjNn6HdgXQbXailCY-mDlzf-zddKrXhG5sDOw,1086
13
+ probabilitypewter-0.5.0.dist-info/METADATA,sha256=mfXi2eAHqYTCwhN3K4DvIs4OfgBr82JkGHkPJNlLZaE,10156
14
+ probabilitypewter-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ probabilitypewter-0.5.0.dist-info/top_level.txt,sha256=-QARBlQhd94lEE0NQAY2BlokUfpaNwh99Lcm5K8tX4s,18
16
+ probabilitypewter-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Feamaika
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ ProbabilityPewter