probability

Python: NLTK ValueError: A Lidstone probability distribution must have at least one bin?

笑着哭i 提交于 2021-02-08 11:27:33
问题 For a task I am to use ConditionalProbDist using LidstoneProbDist as the estimator, adding +0.01 to the sample count for each bin. I thought the following line of code would achieve this, but it produces a value error fd = nltk.ConditionalProbDist(fd,nltk.probability.LidstoneProbDist,0.01) I'm not sure how to format the arguments within ConditionalProbDist and haven't had much luck in finding out how to do so via python's help feature or google, so if anyone could set me right, it would be

Probability of collision with truncated SHA-256 hash

耗尽温柔 提交于 2021-02-07 18:28:18
问题 I have a database-driven web application where the primary keys of all data rows are obfuscated as follows: SHA256(content type + primary key + secret), truncated to the first 8 characters. The content type is a simple word, e.g. "post" or "message" and the secret is a 20-30 char ASCII constant. The result is stored in a separate indexed column for fast DB lookup. How do I calculate the probability of a hash collision in this scenario? I am not a mathematician at all, but a friend claimed

Three colors triangles

大城市里の小女人 提交于 2021-02-07 12:52:38
问题 I am trying to make a code for this problem: (Source: https://www.codewars.com/kata/insane-coloured-triangles/train/c) A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer colour than the last, are generated by considering the two touching colours in the previous row. If these colours are identical, the same colour is used in the new row. If they are different, the missing colour is used in the new row. This is

Three colors triangles

旧巷老猫 提交于 2021-02-07 12:51:47
问题 I am trying to make a code for this problem: (Source: https://www.codewars.com/kata/insane-coloured-triangles/train/c) A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer colour than the last, are generated by considering the two touching colours in the previous row. If these colours are identical, the same colour is used in the new row. If they are different, the missing colour is used in the new row. This is

Is there a Python equivalent to R's sample() function?

蹲街弑〆低调 提交于 2021-02-07 11:17:45
问题 I want to know if Python has an equivalent to the sample() function in R. The sample() function takes a sample of the specified size from the elements of x using either with or without replacement. The syntax is: sample(x, size, replace = FALSE, prob = NULL) (More information here) 回答1: I think numpy.random.choice(a, size=None, replace=True, p=None) may well be what you are looking for. The p argument corresponds to the prob argument in the sample() function. 回答2: In pandas (Python's closest

Simple binary logistic regression using MATLAB

元气小坏坏 提交于 2021-02-06 11:00:02
问题 I'm working on doing a logistic regression using MATLAB for a simple classification problem. My covariate is one continuous variable ranging between 0 and 1, while my categorical response is a binary variable of 0 (incorrect) or 1 (correct). I'm looking to run a logistic regression to establish a predictor that would output the probability of some input observation (e.g. the continuous variable as described above) being correct or incorrect. Although this is a fairly simple scenario, I'm

Simple binary logistic regression using MATLAB

こ雲淡風輕ζ 提交于 2021-02-06 10:59:44
问题 I'm working on doing a logistic regression using MATLAB for a simple classification problem. My covariate is one continuous variable ranging between 0 and 1, while my categorical response is a binary variable of 0 (incorrect) or 1 (correct). I'm looking to run a logistic regression to establish a predictor that would output the probability of some input observation (e.g. the continuous variable as described above) being correct or incorrect. Although this is a fairly simple scenario, I'm

JavaScript: How To Code a Heads/Tails With Specific Probability Chance Percentage?

£可爱£侵袭症+ 提交于 2021-02-05 12:18:50
问题 I've implemented the function: function coinFlip() { return(Math.floor(Math.random()*2) === 0) ? 'Heads' : 'Tails'; } And it's all working fine (I already tested it). My problem is, how do I make this function so that the probability of getting 'Heads' is 30% while the probability of getting 'Tails' is 70%? Thanks in advance 回答1: function coinFlip() { return(Math.random() < 0.3) ? 'Heads' : 'Tails'; } 回答2: If one of three toss coin is head it doesn't mean that in 10 toss, there will be 3

Buffon's needle simulation in python

我只是一个虾纸丫 提交于 2021-02-05 11:53:17
问题 import numpy as np import matplotlib.pylab as plt class Buffon_needle_problem: def __init__(self,x,y,n,m): self.x = x #width of the needle self.y = y #witdh of the space self.r = []#coordinated of the centre of the needle self.z = []#measure of the alingment of the needle self.n = n#no of throws self.m = m#no of simulations self.pi_approx = [] def samples(self): # throwing the needles for i in range(self.n): self.r.append(np.random.uniform(0,self.y)) self.z.append(np.random.uniform(0,self.x/2

Python: Integral and funcion nested in another integral using scipy quad

梦想的初衷 提交于 2021-01-29 09:40:28
问题 I have managed to write a few lines of code using scipy.integrate.quad for my stochastic process class I have the Markov transition function for standard Brownian motion import numpy as np def p(x,t): return (1/np.sqrt(2*np.pi*t))*np.exp(-x**2/(2*t)) But I want to compute the following that I am going to write in code that would not work. I write it like this so we can understand the problem without the use of latex. from scipy.integrate import quad integral = quad(quad(p(y-x),1,np.inf)*p(x,1