<a href="https://colab.research.google.com/github/alanexplorer/Robotic-Algorithm-Tutorial/blob/master/robotic_probabilistic.ipynb" target="_parent"></a>


```python
from math import *
from sympy import Symbol, symbols, Matrix, sin, cos
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
```


```python
#set variables

mu, sigma = symbols('\mu, \sigma')
```

# The Total Probability Rule

the total probability rule (tpr) is

$P(A) = P(A | B) P(B) + P(A | B^C) P(B^C)$


# Probability Density Function

The normal probability density function (pdf) is

$f(x | \mu, \sigma) = \frac{1}{\sigma\sqrt{2\pi}} e^{- \frac{(\mu - x)^2}{2\sigma^2}}$
---




```python
 def gaussian(mu, sigma, x):
          # calculates the probability of x for 1-dim Gaussian with mean mu and var. sigma
          return exp(- ((mu - x) ** 2) / (sigma ** 2) / 2.0) / sqrt(2.0 * pi * (sigma ** 2))
```

# New Mean and Variance

$\mu^{'} = \frac{\sigma^{2}_{2} \dot \mu_{1} + \sigma^{2}_{1} \dot \mu_{2}}{\sigma^{2}_{2} + \sigma^{2}_{1}}$

$\sigma^{'} = \frac{1}{\frac{1}{\sigma^{2}_{2}} + \frac{1}{\sigma^{2}_{1}}}$


```python
def SumGaussian(m1, m2, s1, s2):
  m3 = (s2**2*m1 + s1**2*m2)/(s2**2+ s1**2)
  s3 = 1/((1/s2**2)+ (1/s1**2))
  return m3, s3
```


```python
mu1 = 10
sigma1 = 0.5

x1 = np.linspace(mu1 - 3*sigma1, mu1 + 3*sigma1, 100)
plt.plot(x1, stats.norm.pdf(x1, mu1, sigma1), color="blue", label="P(z|x)")

mu2 = 8
sigma2 = 0.3

x2 = np.linspace(mu2 - 3*sigma2, mu2 + 3*sigma2, 100)
plt.plot(x2, stats.norm.pdf(x2, mu2, sigma2), color="red", label="P(x)")

mu3, sigma3 = SumGaussian(mu1, mu2, sigma1, sigma2)

x3 = np.linspace(mu3 - 3*sigma3, mu3 + 3*sigma3, 100)
plt.plot(x3, stats.norm.pdf(x3, mu3, sigma3), color="green", label="P(x|z)"
)

plt.legend()

plt.show()

```

20649dc9cdc1306616b1f3381c186c282b1086eb
ipynb
Jupyter Notebook
robotic_probabilistic.ipynb
alanexplorer/contatosalan-outlook.com
e315c59054ae7d68200263a581f38c02b754491e
MIT
2020-04-13T16:58:41.000Z
2020-04-13T16:58:41.000Z
robotic_probabilistic.ipynb
alanexplorer/Robotic-Algorithm-Tutorial
e315c59054ae7d68200263a581f38c02b754491e
MIT
robotic_probabilistic.ipynb
alanexplorer/Robotic-Algorithm-Tutorial
e315c59054ae7d68200263a581f38c02b754491e
MIT
Qwen/Qwen-72B
1. YES
2. YES