Skip to content

Commit

Permalink
added tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
mbruno46 committed Aug 20, 2022
1 parent c0d7d70 commit f35259a
Showing 1 changed file with 187 additions and 0 deletions.
187 changes: 187 additions & 0 deletions doc/tutorials/create-tutorial-2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b70897aa",
"metadata": {},
"source": [
"# Replicas, streams, irregular chains"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "9f5ae534",
"metadata": {},
"outputs": [],
"source": [
"import pyobs\n",
"import numpy\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib notebook"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0e37a805",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random generator initialized with seed = 2458954236 [tutorial-v2]\n"
]
}
],
"source": [
"mu = 0.5 # central values\n",
"cov = (mu*0.5)**2 # error^2\n",
"\n",
"# autocorrelation time\n",
"tau=4.0\n",
"\n",
"rng = pyobs.random.generator('tutorial-v2')\n",
"data1 = rng.markov_chain(mu,cov,tau,1000)\n",
"\n",
"data2 = rng.markov_chain(mu,cov,tau,600)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "634fa543",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Observable with shape = (1,)\n",
" - description: Observable A\n",
" - created by mbruno at macthxbruno.fritz.box on Sat Aug 20 14:42:09 2022\n",
" - size: 73 KB\n",
" - mean: [0.57392611]\n",
" - Ensemble EnsA\n",
" - Replica replica1 with ncnfg 1000\n",
" - Replica replica2 with ncnfg 600\n",
" temporary additional memory required 0.015 MB\n",
"\n"
]
}
],
"source": [
"obsA = pyobs.observable(description='Observable A')\n",
"obsA.create('EnsA',[data1,data2],rname=['replica1','replica2'])\n",
"obsA.peek()"
]
},
{
"cell_type": "markdown",
"id": "a2f17cd7",
"metadata": {},
"source": [
"Now we artificially create a stream with holes. To make sure that the autocorrelations are still treated properly we must provide the configuration index"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "01ee647d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Observable with shape = (1,)\n",
" - description: MC history w/o holes\n",
" - created by mbruno at macthxbruno.fritz.box on Sat Aug 20 14:42:09 2022\n",
" - size: 46 KB\n",
" - mean: [0.77002284]\n",
" - Ensemble EnsA\n",
" - Replica 0 with ncnfg 1000\n",
" temporary additional memory required 0.015 MB\n",
"\n",
"Observable with shape = (1,)\n",
" - description: MC history w/ holes\n",
" - created by mbruno at macthxbruno.fritz.box on Sat Aug 20 14:42:09 2022\n",
" - size: 32 KB\n",
" - mean: [0.6241264]\n",
" - Ensemble EnsA\n",
" - Replica 0 with ncnfg 515\n",
" temporary additional memory required 0.015 MB\n",
"\n"
]
}
],
"source": [
"mask = rng.sample_boolean(1000)\n",
"icnfg = numpy.arange(1000)\n",
"\n",
"obsB = pyobs.observable(description='MC history w/o holes')\n",
"obsB.create('EnsA',data1, icnfg=list(icnfg))\n",
"obsB.peek()\n",
"\n",
"obsC = pyobs.observable(description='MC history w/ holes')\n",
"obsC.create('EnsA',data1[mask], icnfg=list(icnfg[mask]))\n",
"obsC.peek()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "0caa3599",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Full MC history\n",
"{'EnsA': [array([3.82836706]), array([1.05540797])]}\n",
"MC history w/ holes\n",
"{'EnsA': [array([3.91062104]), array([1.37858042])]}\n"
]
}
],
"source": [
"print('Full MC history')\n",
"print(obsB.tauint())\n",
"print('MC history w/ holes')\n",
"print(obsC.tauint())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "71580391",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit f35259a

Please sign in to comment.