probability

Create Bayesian Network and learn parameters with Python3.x

一个人想着一个人 提交于 2019-12-03 01:23:32
问题 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 myself as follows: It is taken from this paper. All the variables are discrete (and can take only 2 possible states) except "Size" and "GraspPose", which are continuous and should be modeled as Mixture of Gaussians. Authors use Expectation-Maximization algorithm to learn the parameters for

An interview question: About Probability

北战南征 提交于 2019-12-03 00:16:49
问题 An interview question: Given a function f(x) that 1/4 times returns 0, 3/4 times returns 1. Write a function g(x) using f(x) that 1/2 times returns 0, 1/2 times returns 1. My implementation is: function g(x) = { if (f(x) == 0){ // 1/4 var s = f(x) if( s == 1) {// 3/4 * 1/4 return s // 3/16 } else { g(x) } } else { // 3/4 var k = f(x) if( k == 0) {// 1/4 * 3/4 return k // 3/16 } else { g(x) } } } Am I right? What's your solution?(you can use any language) 回答1: If you call f(x) twice in a row,

How do Markov Chain Chatbots work?

半世苍凉 提交于 2019-12-03 00:02:24
问题 I was thinking of creating a chatbot using something like markov chains, but I'm not entirely sure how to get it to work. From what I understand, you create a table from data with a given word and then words which follow. Is it possible to attach any sort of probability or counter while training the bot? Is that even a good idea? The second part of the problem is with keywords. Assuming I can already identify keywords from user input, how do I generate a sentence which uses that keyword? I

mathematics behind modulo behavor

寵の児 提交于 2019-12-02 21:52:34
问题 Preamble This question is not about the behavior of (P)RNG and rand() . It's about using power of two values uniformly distributed against modulo. Introduction I knew that one should not use modulo % to convert a value from a range to another, for example to get a value between 0 and 5 from the rand() function: there will be a bias. It's explained here https://bitbucket.org/haypo/hasard/src/ebf5870a1a54/doc/common_errors.rst?at=default and in this answer Why do people say there is modulo bias

Combining individual probabilities in Naive Bayesian spam filtering

≡放荡痞女 提交于 2019-12-02 20:36:08
I'm currently trying to generate a spam filter by analyzing a corpus I've amassed. I'm using the wikipedia entry http://en.wikipedia.org/wiki/Bayesian_spam_filtering to develop my classification code. I've implemented code to calculate probability that a message is spam given that it contains a specific word by implementing the following formula from the wiki: My PHP code: public function pSpaminess($word) { $ps = $this->pContentIsSpam(); $ph = $this->pContentIsHam(); $pws = $this->pWordInSpam($word); $pwh = $this->pWordInHam($word); $psw = ($pws * $ps) / ($pws * $ps + $pwh * $ph); return $psw

Google Interview Puzzle [closed]

廉价感情. 提交于 2019-12-02 18:17:30
Given n dice, each of 'a' sides and a sum b, return the number of ways in which the sum b can be obtained. How can you reduce the time complexity and space complexity? This was asked in a Google interview and I am unsure of the answer. This is asking you to find the number of ways to write b as a sum of n positive integers. The answer is the number of compositions of b into n parts, which is (b-1 choose n-1) . Now if we take into account the constraint that the size of the parts is limited to a , the problem gets a little more interesting. I recommend using generating functions for this. The

How to do weighted random sample of categories in python

孤者浪人 提交于 2019-12-02 17:32:08
Given a list of tuples where each tuple consists of a probability and an item I'd like to sample an item according to its probability. For example, give the list [ (.3, 'a'), (.4, 'b'), (.3, 'c')] I'd like to sample 'b' 40% of the time. What's the canonical way of doing this in python? I've looked at the random module which doesn't seem to have an appropriate function and at numpy.random which although it has a multinomial function doesn't seem to return the results in a nice form for this problem. I'm basically looking for something like mnrnd in matlab. Many thanks. Thanks for all the

R: Calculate and interpret odds ratio in logistic regression

ぃ、小莉子 提交于 2019-12-02 16:50:46
I am having trouble interpreting the results of a logistic regression. My outcome variable is Decision and is binary (0 or 1, not take or take a product, respectively). My predictor variable is Thoughts and is continuous, can be positive or negative, and is rounded up to the 2nd decimal point. I want to know how the probability of taking the product changes as Thoughts changes. The logistic regression equation is: glm(Decision ~ Thoughts, family = binomial, data = data) According to this model, Thought s has a significant impact on probability of Decision (b = .72, p = .02). To determine the

Is this a good or bad 'simulation' for Monty Hall? How come?

随声附和 提交于 2019-12-02 15:58:25
Through trying to explain the Monty Hall problem to a friend during class yesterday, we ended up coding it in Python to prove that if you always swap, you will win 2/3 times. We came up with this: import random as r #iterations = int(raw_input("How many iterations? >> ")) iterations = 100000 doors = ["goat", "goat", "car"] wins = 0.0 losses = 0.0 for i in range(iterations): n = r.randrange(0,3) choice = doors[n] if n == 0: #print "You chose door 1." #print "Monty opens door 2. There is a goat behind this door." #print "You swapped to door 3." wins += 1 #print "You won a " + doors[2] + "\n"

Representing continuous probability distributions

走远了吗. 提交于 2019-12-02 15:37:40
I have a problem involving a collection of continuous probability distribution functions, most of which are determined empirically (e.g. departure times, transit times). What I need is some way of taking two of these PDFs and doing arithmetic on them. E.g. if I have two values x taken from PDF X, and y taken from PDF Y, I need to get the PDF for (x+y), or any other operation f(x,y). An analytical solution is not possible, so what I'm looking for is some representation of PDFs that allows such things. An obvious (but computationally expensive) solution is monte-carlo: generate lots of values of