条件概率在计算机中的应用,条件概率计算(Conditional Probability Calculation)

条件概率计算(Conditional Probability Calculation)

我正在尝试制作马尔可夫模型,与此相关,我需要计算某些字母的条件概率/质量概率。 我已经创建了一个字母频率的二元组。

如何计算我的字母的条件概率/质量概率?

I am trying to make a Markov model and in relation to this I need to calculate conditional probability/mass probability of some letters. I have created a bigram of the freqency of the letters.

How would I manage to calculate the conditional probability/mass probability of my letters?

原文:https://stackoverflow.com/questions/27993316

更新时间:2020-01-24 14:01

最满意答案

计算条件概率的最简单方法是循环模型计数中的情况1)条件发生的情况和2)条件和目标字母出现的情况。 条件概率是这两者的比率。

def cp(target, given):

'Given is a one or two tuple and target is the letter following'

g = 0.0

g_and_t = 0.0

n = len(given)

for case, count in model.iteritems():

if case[:n] == given:

g += count

if case[n] == target:

g_and_t += count

return g_and_t / g if g else 0.0

print cp(target='r', given=('f', 'o'))

The simplest way to compute the conditional probability is to loop through the cases in the model counting 1) cases where the condition occurs and 2) cases where the condition and target letter occur. The conditional probability is the ratio of those two.

def cp(target, given):

'Given is a one or two tuple and target is the letter following'

g = 0.0

g_and_t = 0.0

n = len(given)

for case, count in model.iteritems():

if case[:n] == given:

g += count

if case[n] == target:

g_and_t += count

return g_and_t / g if g else 0.0

print cp(target='r', given=('f', 'o'))

相关问答

所有可能结果的概率总和必须总和为1.因此,如果某些结果被消除并因此被赋予零概率,那么您必须重新标准化,以便所有剩余概率的总和加起来为1。 The sum of the probabilities of all possible outcomes must always sum to 1. So if some outcomes are eliminated and hence assigned zero probability, then YES, you must re-normalise so

...

De Michele等人提出的建构原则 (2017)在三变量的情况下被广泛称为藤copula或pair-copula构造 。 如果你想使用这些模型,我建议先阅读更多关于它们的内容。 Aas等人的论文是一个很好的起点。 (2009) ,你会在http://www.vine-copula.org或google学者上找到更多。 现在回答你的问题:通过连锁规则,我们获得了这一点 ,因此, 这一点 。 R中的一个例子是: # required package

library(VineCopula)

##

...

你有正确的想法 - 棘手的部分是将所有变量加载到适当的数组中。 如果您的完整数据集太大而无法放入内存,则可能需要一次处理其中的一个子集。 data have;

/*Set length 3 for binary vars to save a bit of memory later*/

length col1-col5 3;

input col1-col5;

cards;

1 0 1 0 0

0 0 0 1 1

0 0 0 0 0

1 0 0

...

我认为你正在寻找这个: initial

colnames(initial)

tin

colnames(tin)

ta

...

为了将来参考,对于任何试图这样做的人来说,概率函数看起来像: double probability (vector &yesprobabilities, unsigned int numOfPeople, unsigned int yesNumber, unsigned int startIndex) {

double kprobability = 0;

// Not enough people!

if (numOfPeople-1 < yesNumber)

...

据我所知,这是你想要实现的目标: #python_test2.py

import random, time

virus_probabilities= { "CompA" : 0.50, "CompB" : .25, "CompC" : .25, "CompBD" : .125,

"CompBE" : .125, "CompCD" : .125, "CompCE" : .125}

def check_probability(computer_name, n_

...

这个怎么样? probability = [.3 .2 .4 .7];

n = numel(probability);

combs = dec2bin(0:2^n-1).'-'0'; %'// each column is a combination of n values,

%// where each value is either 0 or 1. A 1 value will represent an event

%// that happens; a 0 value will repre

...

你是对的。 连续分布中任何特定值的概率为零。 您发布的等式不是概率的公式,它是概率密度函数的公式 在概率论中,概率密度函数(PDF)或连续随机变量的密度是一个函数,其在样本空间中的任何给定样本(或点)处的值(随机变量采用的可能值集合)可以解释为提供随机变量的值等于该样本的相对可能性。 换句话说,虽然连续随机变量对任何特定值的绝对可能性为0(因为有一组无限可能的值开始),可以使用两个不同样本的PDF值来推断在随机变量的任何特定绘制中,与其他样本相比,随机变量与一个样本相等的可能性更大。 You ar

...

nltk.ConditionalFreqDist期望其数据为(condition, item)元组的序列。 nltk.trigrams返回长度为3的元组,这会导致您发布的确切错误。 从你的帖子来看,你不清楚你想要用什么作为条件,但是在做语言建模时的惯例是调整其前辈的最后一个词。 以下代码演示了如何实现它。 brown_trigrams = nltk.trigrams(brown.words())

condition_pairs = (((w0, w1), w2) for w0, w1, w2 in

...

计算条件概率的最简单方法是循环模型计数中的情况1)条件发生的情况和2)条件和目标字母出现的情况。 条件概率是这两者的比率。 def cp(target, given):

'Given is a one or two tuple and target is the letter following'

g = 0.0

g_and_t = 0.0

n = len(given)

for case, count in model.iteritems():

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值