-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
[ADD] : maths joint probabilty distribution #10508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 26 commits
710f64e
32279e0
8fb17b5
0f872bf
6c3d5a2
77c3a91
ba59bad
c9e1d69
61661ad
a6d6ad8
6a26182
eea508d
acebaa0
53f630b
8ce6629
257ea79
4b07535
232b7b8
b301636
824a378
a3d1b12
5a86c99
f99e4d5
d80e546
6a4b223
a0c7fdb
198558b
cc3db54
848077e
c453741
7a94fe2
e5e5a91
544b648
463c067
a9b592f
bb64341
74ca473
d853110
c5bcbb1
66c5acb
9168beb
26cf878
c1009e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# https://en.wikipedia.org/wiki/Joint_probability_distribution | ||
# Function to calculate the joint probability distribution | ||
def calculate_joint_probability( | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
x_values: list, y_values: list, x_probabilities: list, y_probabilities: list | ||
) -> dict: | ||
""" | ||
Given two random variables that are defined on the same probability space, | ||
[1] the joint probability distribution is the corresponding probability distribution on all possible pairs of outputs. | ||
The joint distribution can just as well be considered for any given number of random variables. | ||
|
||
Args: | ||
lst (List[int]): The X values. | ||
2nd (List[int]): The y values. | ||
3rd (List[int]): The x probability. | ||
4th (List[int]): The y probability. | ||
|
||
Returns: | ||
List[int]: The Joint probability. | ||
|
||
Examples: | ||
>>> calculate_joint_probability([1],[1],[1],[1]) | ||
{(1,1):1} | ||
>>> calculate_joint_probability([1][1,2][0.5][0.1,0.5]) | ||
{(1,1):0.05 , (1,2):0.25} | ||
|
||
""" | ||
joint_distribution = {} | ||
|
||
# Calculate the joint probability for all combinations of (X, Y) | ||
for x, x_prob in zip(x_values, x_probabilities): | ||
for y, y_prob in zip(y_values, y_probabilities): | ||
joint_prob = x_prob * y_prob | ||
joint_distribution[(x, y)] = joint_prob | ||
return joint_distribution | ||
|
||
|
||
def main() -> None: | ||
leonado10000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print(calculate_joint_probability([1],[1,2],[0.5],[0.1,0,5])) | ||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
ans = main() | ||
doctest.testmod() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error occurred while parsing the file:
maths/joint_probability_distribution.py