Files
simulationexam/play_around.ipynb
T
2015-12-20 13:43:45 -05:00

221 lines
4.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from network.gibbs import *\n",
"from network.network import pp_network, can_antenna_be_turned_on\n",
"from collections import defaultdict\n",
"from random import Random\n",
"from numpy import matrix"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mc = defaultdict(dict)\n",
"random = Random(66)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"prec_network = 0\n",
"\n",
"for i, network in zip(range(10**5), get_random_networks(2, random)):\n",
" if network not in mc[prec_network]:\n",
" mc[prec_network][network] = 0\n",
" mc[prec_network][network] += 1\n",
" prec_network = network"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"defaultdict(dict,\n",
" {0: {0: 964, 1: 3671, 2: 1844, 4: 1759, 6: 1835, 8: 938, 9: 3387},\n",
" 1: {0: 891, 1: 3646, 2: 1832, 4: 1839, 6: 1729, 8: 938, 9: 3663},\n",
" 2: {0: 1810, 2: 3548, 4: 3517, 6: 3611, 8: 1811},\n",
" 4: {0: 1779, 2: 3519, 4: 3490, 6: 3486, 8: 1796},\n",
" 6: {0: 1885, 2: 3554, 4: 3465, 6: 3475, 8: 1757},\n",
" 8: {0: 3633, 1: 3553, 8: 3654, 9: 3572},\n",
" 9: {0: 3436, 1: 3668, 8: 3518, 9: 3527}})"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mc"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def get_prob(from_, to):\n",
" return mc[from_][to]/ sum(mc[from_].values())\n",
"\n",
"def get_matrix(mc):\n",
" n = len(mc)\n",
" mat = [[] for i in range(n)]\n",
" for i, from_ in enumerate(mc):\n",
" for j in enumerate(mc):\n",
" pass\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"for key in mc:\n",
" print(key)\n",
" print( pp_network(key, 2))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"□-□\n",
"■-□\n",
"\n",
"1 True\n"
]
}
],
"source": [
"ant = 1\n",
"print(get_prob(0, 2))\n",
"print(ant, can_antenna_be_turned_on(ant, 4, 2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"0.5**4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"m = matrix([[1, 2], [3, 4]])\n",
"v = matrix([[1, 3]])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from numpy import std"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"42.73458667121028"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"std([1432, 1376, 1461, 1436, 1436, 1363, 1496])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3+"
}
},
"nbformat": 4,
"nbformat_minor": 0
}