Skip to content

Instantly share code, notes, and snippets.

@brandonwillard
Created June 17, 2016 21:18
Show Gist options
  • Save brandonwillard/5d59a1cefd0c2503d969dd32da7b1271 to your computer and use it in GitHub Desktop.
Save brandonwillard/5d59a1cefd0c2503d969dd32da7b1271 to your computer and use it in GitHub Desktop.
Sympy Mixture Model Moments Test
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"%pylab notebook\n",
"import sympy.stats\n",
"import sympy.stats as sps\n",
"import sympy as sp"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"I = sps.Bernoulli('I', sp.Symbol('pi', positive=True))\n",
"X_1 = sps.Normal('X_1', sp.Symbol('mu_1', real=True), sp.Symbol('sigma_1', positive=True))\n",
"X_2 = sps.Normal('X_2', sp.Symbol('mu_2', real=True), sp.Symbol('sigma_2', positive=True))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"mu_1*pi + mu_2*(-pi + 1)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sps.E(I*X_1 + (1-I)*X_2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sps.variance(I*X_1 + (1-I)*X_2)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11+"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment