probability

Is there a reverse way to find number of people with given 0.5 probability that two people will have same birthday but no using mathematical formula?

孤人 提交于 2020-02-25 06:16:06
问题 I'm doing birthday paradox, and want to know how many people can meet 0.5 probability that two people have same birthday by using python. I have tried no using mathematical formula to find probability with given the number of people by using random and randint in python import random def random_birthdays(): bdays = [] bdays = [random.randint(1, 365) for i in range(23)] bdays.sort() for x in range(len(bdays)): while x < len(bdays)-1: print x if bdays[x] == bdays[x+1]: #print(bdays[x]) return

Underflow in Forward Algorithm for HMMs

感情迁移 提交于 2020-02-20 09:10:10
问题 I'm implementing the forward algorithm for HMMs to calculate the probability of a given HMM emitting a given observation sequence. I'd like my algorithm to be robust to underflow. I can't work in log-space because the forward algorithm requires the multiplication AND addition of probabilities. What is the best way to avoid underflow? I've read some sources about this but the best suggestion I get is scaling the probabilities at each time step Section 6 Here. By the end of the algorithm you

Underflow in Forward Algorithm for HMMs

北慕城南 提交于 2020-02-20 09:08:28
问题 I'm implementing the forward algorithm for HMMs to calculate the probability of a given HMM emitting a given observation sequence. I'd like my algorithm to be robust to underflow. I can't work in log-space because the forward algorithm requires the multiplication AND addition of probabilities. What is the best way to avoid underflow? I've read some sources about this but the best suggestion I get is scaling the probabilities at each time step Section 6 Here. By the end of the algorithm you

Using Bayes formula

↘锁芯ラ 提交于 2020-02-08 10:01:43
问题 suppose the cave system contains 100 caves, of which 90 caves are without a hidden treasure and 10 caves contain a buried gold object. In 70% of the caves with a hidden treasure, the Wumpus has left behind his usual stench from digging about and bumping into walls. In the remaining caves with hidden treasures in them, the Wumpus has left no trace, i.e. they are non-smelly. Furthermore, all the caves without a hidden treasure are free from smell, since the Wumpus has fled the cave system. The

Will this give me proper random numbers based on these probabilities? C++

牧云@^-^@ 提交于 2020-02-01 04:25:06
问题 Code: int random = (rand() % 7 + 1) if (random == 1) { } // num 1 else if (random == 2) { } // num 2 else if (random == 3 || random == 4) { } // num 3 else if (random == 5 || random == 6) { } // num 4 else if (random == 7) { } // num 5 Basically I want each of these numbers with each of these probabilities: 1: 1/7 2: 1/7 3: 2/7 4: 2/7 5: 1/7 Will this code give me proper results? I.e. if this is run infinite times, will I get the proper frequencies? Is there a less-lengthy way of doing this?

Scala: how to know which probability correspond to which class?

旧街凉风 提交于 2020-01-26 04:54:44
问题 I create a classifier random forest to predict something. The label is either "yes" (=1.0) or "no" (=0.0) I apply my model on a test. Here is my code and my result for 20 lines: import org.apache.spark.ml.tuning.CrossValidatorModel import org.apache.spark.sql.types._ import org.apache.spark.sql._ import org.apache.spark.sql.functions.udf import org.apache.spark.sql.functions._ var modelrf = CrossValidatorModel.load("modelSupervise/newModel") var test = spark.sql("""select * from dc.newTest"""

Defining exponential distribution in R to estimate probabilities

泪湿孤枕 提交于 2020-01-24 12:44:27
问题 I have a bunch of random variables (X1,....,Xn) which are i.i.d. Exp(1/2) and represent the duration of time of a certain event. So this distribution has obviously an expected value of 2, but I am having problems defining it in R. I did some research and found something about a so-called Monte-Carlo Stimulation, but I don't seem to find what I am looking for in it. An example of what i want to estimate is: let's say we have 10 random variables (X1,..,X10) distributed as above, and we want to

how to enable probability estimates when using scikitlearn's LinearSVC classifier

丶灬走出姿态 提交于 2020-01-24 00:44:14
问题 How can I get the probability estimates of predictions from a sklearn.svm.LinearSVC model in similar fashion to sklearn.svm.SVC 's probability=True option that allows predict_proba() I need to avoid the quadratic fit penalty of the underlying libsvm of SVC as my training set is large. 回答1: sklearn.svm.LinearSVC does not have predict_proba method as you noticed correctly. However, you may try the following trick to circumvent this shortcoming: from sklearn.svm import LinearSVC from sklearn

Write a function to calculate the PDF in R?

夙愿已清 提交于 2020-01-16 02:22:09
问题 I'm to write a function to calculate the PDF of and it's been suggested that I use the if/elseif/else statements. However whenever I try and do so, I keep getting error messages but I'm not sure what I'm doing wrong? This is the PDF that the function is supposed to calculate: fx = 0.3 if (0<=x<1) 0.1 if (1<=x<2) 0.25 if (2<=x<3) 0.15 if (3<=x<4) 0.2 if (4<=x<5) 0 otherwise This is my code: fx = function(x) { if (0<=x<1) { pdf=0.3 } elseif (1<=x<2) { pdf=0.1 } elseif (2<=x<3) { pdf=0.25 }

MATLAB's “SIGMA must be symmetric and positive definite” error sometimes not making sense

大憨熊 提交于 2020-01-13 04:33:30
问题 I am not sure if this is a programming or statistics question, but I am %99 sure that there should be a numerical problem. So maybe a programmatic solution can be proposed. I am using MATLAB's mvnpdf function to calculate multi-variate Gaussian PDF of some observations. Frequently I get "SIGMA must be symmetric and positive definite" errors. However, I am obtaining the covarince matrix from the data, so the data should be legal. A code to regenerate the problem is: err_cnt = 0; for i = 1:1000