All Questions

Tagged with
Filter by
Sorted by
Tagged with
30 votes
5 answers
31k views

Create Bayesian Network and learn parameters with Python3.x [closed]

I'm searching for the most appropriate tool for python3.x on Windows to create a Bayesian Network, learn its parameters from data and perform the inference. The network structure I want to define ...
Spu's user avatar
  • 483
6 votes
2 answers
316 views

How can I generate random numbers given I have probability of varous ranges specified in python

I want to fill in the dummy data of attendance. I want that,for example, 60% students have attendance in the range of 70-100,25% in the range of 40-60 and 15% in the range of 0-40. How can I generate ...
Sagarika Nangia's user avatar
5 votes
2 answers
26k views

Probability Mass Function of a Binomial Distribution in Python

I am using Python3 to compute the Probability Mass Function (PMF) of this wikipedia example: I tried to follow this scipy documentation: https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/...
user avatar
4 votes
1 answer
2k views

About how numpy.random.choice works

I'm trying to writing a program that simulate the Coupon collector's problem. Here is quick reference for the problem: Given n coupons, how many coupons do you expect you need to draw with ...
Axlp1210's user avatar
  • 193
4 votes
1 answer
1k views

How is scipy.stats.multivariate_normal.pdf different from the same function written using numpy?

I need to use the multivariate normal distribution in a script. I have noticed that my version of it gives a different answer from scipy's method. I can't really figure out why... Here is my function:...
Fern's user avatar
  • 43
3 votes
2 answers
3k views

How to select items from a list based on probability

I have lists a and b a = [0.1, 0.3, 0.1, 0.2, 0.1, 0.1, 0.1] b = [apple, gun, pizza, sword, pasta, chicken, elephant] Now I want to create a new list c of 3 items the 3 items are chosen form list ...
gokul gupta's user avatar
3 votes
3 answers
2k views

probability of T total eyes when throwing N dice with S sides

I want to calculate the probability of the event that the sum of all eyes of n dice with s sides (numbered from 1 to s) is equal to t. My language is Python 3. My current approach is pretty much a ...
Byte Commander's user avatar
3 votes
4 answers
2k views

Python program that simulates rolling a 6 sided die and adds up the result of each roll till you roll a 1

so this is the code I wrote that attempts to answer the question in the title : import random print("Well, hello there.") while True: a = random.randint(1,6) sum = 0 if(a==1): #If a one ...
ggezpython3's user avatar
2 votes
1 answer
2k views

Probability distributions and float variables, probability must add to 1

I'm working on a script which goes like this: the program analyses a bunch of text documents in a certain language, draws the probability distributions for each k, where k is the first character ...
mickkk's user avatar
  • 1,182
2 votes
1 answer
213 views

Function interpreter in python

Suppose I have a function in Python that includes mathematical expressions from Python's base and some mathematical expressions from Numpy and Scipy, including maybe some distributions. As a running ...
Sergio's user avatar
  • 205
2 votes
1 answer
3k views

memory error by using rbf with scipy

I want to plot some points with the rbf function like here to get the density distribution of the points: if i run the following code, it works fine: from scipy.interpolate.rbf import Rbf # radial ...
Dark's user avatar
  • 189
2 votes
1 answer
55 views

Indexing dynamic vector of class probabilities

For my code, I have a large (up to 40,000) vector of class probabilities. This set of class probabilities also needs to be reweighted regularly, so assume it will change on every call of the code. The ...
Daniel de Marchi's user avatar
1 vote
2 answers
2k views

python: choose element from a list following a certain probability

I'm looking for a python function that would allow me, given a list and a certain probability, to return only the elements that "pass" the lottery. For instance: my_list = ['A', 'B', 'C'] ...
mel's user avatar
  • 2,760
1 vote
3 answers
209 views

Calculating with items enclosed in list positions (genetic algorithms fitness)

population = [[[0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1], [1], [0]], [[0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1], [3], [1]], [[0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0], [4], [2]],...
vferraz's user avatar
  • 459
1 vote
1 answer
4k views

How do I calculate the probability of every value in a dataframe column quickly in Python?

I want to calculate the probability of all the data in a column dataframe according to its own distribution.For example,my data like this: data 0 1 1 1 2 2 3 3 4 2 5 ...
giser_yugang's user avatar
  • 6,138
1 vote
2 answers
577 views

Calculating conditional probability from list

Trying to calculate the conditional probability from a given list. Say I have the following list: [[ 1, 0, 0, 0, 1, 5], [ 0, 1, 0, 1, 0, 3], [ 1, 0, 0, 0, 1, 5], [ 0, 0, 1, 1, 0, 2], [ 0, 0, 1, 0, ...
datanewbie96's user avatar
1 vote
2 answers
286 views

How to skew random choice probability towards one option?

I am using the random library in python to select win or lose. import random choice = random.choice(['win','lose']) Is there anyway I can say set the probability in the code to say I want more ...
RustyShackleford's user avatar
1 vote
2 answers
3k views

How can I calculate probability for all each numpy value at once?

I have a function for calculating probability like below: def multinormpdf(x, mu, var): # calculate probability of multi Gaussian distribution k = len(x) det = np.linalg.det(var) inv = np....
YeongHwa Jin's user avatar
1 vote
1 answer
1k views

Generate exponential distribution in Python

I'm aware of the random.expovariate function but this is not what I need. I'd like to generate a stream of length N in which each element i between 1 and M is chosen with probability 1/(2^(i+1)) Thus,...
Tiffany's user avatar
  • 263
1 vote
1 answer
262 views

probability difference between categorical target and one-hot encoding target using OneVsRestClassifier

A bit confused with the probability between categorical target and one-hot encoding target from OneVsRestClassifier of sklean. Using iris data with simple logistic regression as an example. When I use ...
user5843090's user avatar
1 vote
1 answer
297 views

Generate one sample following two different distributions

I would like to generate randomly a sample in the interval [0;1000] of size 1E4. But following two different distribution : one in the [0;1] interval following an increasing exponential distribution ...
Julien Drevon's user avatar
1 vote
1 answer
1k views

Python - Trigram Probability Distribution Smoothing Technique (Kneser Ney) in NLTK Returns Zero

I have the frequency distribution of my trigram followed by training the Kneser-Ney. When I check for kneser_ney.prob of a trigram that is not in the list_of_trigrams I get zero! What am I doing wrong?...
Roshna Omer's user avatar
1 vote
1 answer
69 views

Is there a way to find the probability of different values in matrices

I thought there would be a library that would help me to do this task instead of writing many lines of codes. I tried finding some solutions from books related to my problem, but I could not find any. ...
Abdulaziz Al Jumaia's user avatar
1 vote
1 answer
301 views

Is there a way to calculate probability with probability tree instead of simulation

I want to implement a function in python that gives me the exact probability (if possible in fraction form) of my following problem: You have a list of 8 elements let's say l=[1,2,3,4,5,6,7,8], then ...
Wick's user avatar
  • 115
1 vote
2 answers
69 views

How do I combine later elements of a list to earlier elements, while maintaining the list’s order prior to those later elements?

Long story short, I’m rolling unfair dice and trying to find the probability of any given sum after x number of rolls. In practice there are hundreds of faces and hundreds of rolls, so I can't simply ...
ShayStiers's user avatar
1 vote
1 answer
2k views

How can I use Python to convert an adjacency matrix to a transition matrix?

I am trying to convert a matrix like 1 1 0 0 1 1 0 1 1 to become 1 ⅓ 0 0 ⅓ ½ 0 ⅓ ½ I was thinking about summing the rows and then dividing by them, but I was wondering if there was a better way ...
324's user avatar
  • 704
1 vote
1 answer
9k views

Python program that runs a game of pig with a human player and the computer

So in a nutshell, who goes first is decided randomly. When the human players turn does come up, he/she has the option to either hold or roll. If he chooses to roll, a dice is rolled and the values are ...
ggezpython3's user avatar
1 vote
1 answer
1k views

Python program that calculates the probability of getting 1 at least twice when rolling a fair die 12 times

import random import sys bestcounter1 = 0 bestcounter2=0 get_sample = int(sys.argv[1]) for i in range(get_sample): for i in range(12): if (random.randint(1,6)==1): ...
ggezpython3's user avatar
1 vote
1 answer
202 views

Iteration performance

I made a function to evaluate the following problem experimentally, taken from a A Primer for the Mathematics of Financial Engineering. Problem: Let X be the number of times you must flip a fair ...
Josmoor98's user avatar
  • 1,791
1 vote
1 answer
402 views

Cumulative sum of relative probabilities in an non-ordered list

population_d = {'0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1': 6, '0,0,1,1,1,0,0,1,1,0,1,1,0,0,0,1': 3, '0,1,1,0,1,1,0,0,1,1,1,0,0,1,0,0': 5, '1,0,0,1,1,1,0,0,1,1,0,1,1,0,0,0': 1} def ProbabilityList(...
vferraz's user avatar
  • 459
1 vote
1 answer
4k views

Calculate probabilities in a probability tree

I have the following dictionary: dict = {1000021: [[0.6, [1000024, 1, -2]], [0.4, [1000022, 21]]], 1000024: [[0.7, [1000022, 11, -12]], [0.3, [1000022, 2, -1]]]} which corresponds to the ...
pfnuesel's user avatar
  • 14.7k
1 vote
0 answers
70 views

Can i make SimPy Sum(Indexed(Random_probabilistic_Variable, i ), (i,1,n)) works?

from sympy import * from sympy.stats import * init_printing(use_unicode=True) x, y, a, b, i, n, t, z, mi, sigma, theta, μ, σ, σ2, θ, λ = symbols('x y a b i n t z mi sigma theta μ σ σ2 θ λ') pdf = θ*...
Anselmo Clemente's user avatar
1 vote
2 answers
111 views

Loop over finite probability weights with SciPy/NumPy

Let us have a single event probability prob which is a scalar between 0-1. If I want to iterate over every possible probability with 0.1 increments, then I can use: prob = np.arange(0.01, 1, 0.1) ...
independentvariable's user avatar
1 vote
0 answers
40 views

My own methods return None instead of a valid value

My own class methods do not work when I check how my function 'linker' operates. These methods return None value. When I run these methods in the interactive mode, they work and each returns a new ...
aspiring's user avatar
  • 357
1 vote
1 answer
63 views

Relating The Concept of All Possible Outcomes With Number of Angles (& Sides) Within a Polygon

I am trying to find all possible angles and sides in a given shape. However, I am struggling. This is the start of my code. SidesNumber = int(input("How many sides does your shape have: ")) ...
ObGamEr OGE's user avatar
0 votes
2 answers
2k views

Determine all combinations of flipping a coin without using "itertools.product"

I went through similar posts on the forum but all of them suggest using itertools.product but I was wondering if it can be solved without using it. I want to print all the combinations of outcomes ...
Sandeep's user avatar
  • 1,247
0 votes
2 answers
141 views

calculate conditional probability

Input cust_Id category product purchased 1 Elec light 0 1 Elec light 1 1 Elec light 0 1 HA Table 1 1 HH Pen 1 2 ...
rakesh's user avatar
  • 123
0 votes
1 answer
1k views

python3: normalize matrix of transition probabilities

I have a Python code partially borrowed from Generating Markov transition matrix in Python: # xstates is a dictionary # n - is the matrix size def prob(xstates, n): # we want to do smoothing, so ...
Mark's user avatar
  • 6,192
0 votes
2 answers
2k views

Using Monte Carlo method to find a specific probability of a certain dice output in Python 3.2

I'm in a statistics class and we are constantly being given "dice problems" with various constrains. This is a probability problem, where I need to evaluate the probability of an event by using the ...
user2227808's user avatar
0 votes
1 answer
23 views

TF1 from TF2 How to get the probability of the model?

Hi I have the following model generated and I have successfully convert the TF 1 example o TF 2 using the Tf migration script. Here is the model: tf.compat.v1.reset_default_graph X = tf.compat....
Jaffer Wilson's user avatar
0 votes
1 answer
432 views

Find probability of a single occurrence in map_query in pgmpy

I am working on a bayesian network which looks like this bn I want to find the probability of P(+j|-e) which means that finding the probability that JohnCalls is true given earthquake is false. Here ...
user avatar
0 votes
1 answer
325 views

How to calculate the probability in the event that a number is not the one from the list?

I have a list: lst = [10,20,39,50] How to calculate the probability in Python that a number picked up from the list is not 10? (An event can be supposed)
Atom Store's user avatar
0 votes
1 answer
303 views

Write a program that counts the number of occurrences of "11" in an input sequence of zeros and ones in PYTHON3

Suppose I enter a list like [0,0,1,1,1,0], the program should print 2. I wrote a simple program like this: def count11(seq): n= len(seq) print (n) cnt=0 #i=0; print(cnt) #...
Harikrishnan Aravindakshan's user avatar
0 votes
1 answer
561 views

Get topic probability distribution for new document

I have a working topic model called model, with the following settings: model = LdaModel(corpus=corpus, id2word=id2word, num_topics=10, ...
Emil's user avatar
  • 1,622
0 votes
3 answers
249 views

How to get random index of the array without current idx?

I'm iterating over a list (numpy array with one dimension to be exact) and I need to pick an index form this list that is random and different than current iterator. The most important thing is ...
Gryfit's user avatar
  • 23
0 votes
1 answer
602 views

Python: Roll a dice for 12 times, calculate the probability if each number equally shows up twice

I've drafted the below code for the captioned question, but the return result is always 0. Could anyone please help me figure out what's the problem here? Thanks a lot! import random dice_sides = 6 ...
Valerie Wu's user avatar
0 votes
1 answer
1k views

Downsample numpy array while preserving distribution

I'm trying to write a function that can randomly sample a numpy.ndarray that has floating point numbers while preserving the distribution of the numbers in the array. I have this function for now: ...
mlenthusiast's user avatar
  • 1,114
0 votes
2 answers
4k views

Python program that simulates a game of dice with both players controlled by the computer

The program should randomly choose which player goes first. It should keep a total score for each player, and alternate turns between the computer players until one player ends its turn with a score ...
ggezpython3's user avatar
0 votes
1 answer
1k views

Python program that simulates a full one player game of pig, starting at a totalscore of 0 and playing turn after turn until it reaches 100 points

So here is a sample output: - rolled a 2 - rolled a 1 Pigged out! Turn score = 0 New total score = 0 - rolled a 1 Pigged out! Turn score = 0 New total ...
ggezpython3's user avatar
0 votes
1 answer
130 views

Python generate random right skewed gaussian with constraints

I need to generate a unit curve that is going to look like a right skewed gaussian and I have the following constraints: The X axis is Days (variable but usually 45+) All values on the Y axis sum to ...
DBA108642's user avatar
  • 2,053