Skip to content

Commit

Permalink
update installation instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
teddygroves committed Feb 20, 2024
1 parent 12cd362 commit 34462dc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"href": "week1.html#things-to-set-up",
"title": "Introduction to Bayesian inference",
"section": "Things to set up",
"text": "Things to set up\n\nPython\nFirst get a recent (ideally 3.11+) version of Python This can be very annoying so talk to me if necessary!\nNext get used to Python virtual environments.\nThe method I like is to put the virtual environment in a folder .venv inside the root of my project:\n$ python -m venv .venv --prompt=bscb\nThen to use: Tip: use an ergonomic alias to activate venvs e.g. alias va=\"source .venv/bin/activate\"\n$ source .venv/bin/activate\n# ... do work\n$ deactivate\n\n\nGit and ssh\ngit clone [email protected]:teddygroves/bayesian_statistics_for_systems_biologists.git\n\n\nCmdstanpy and cmdstan\nfrom cmdstanpy import CmdStanModel\nfilename = \"example_stan_program.stan\" \ncode = \"data {} parameters {real t;} model {t ~ std_normal();}\"\nwith open(filename, \"w\") as f:\n f.write(code)\nmodel = CmdStanModel(stan_file=filename)\nmcmc = model.sample()",
"text": "Things to set up\n\nPython\nFirst get a recent (ideally 3.11+) version of Python This can be very annoying so talk to me if necessary!\nNext get used to Python virtual environments.\nThe method I like is to put the virtual environment in a folder .venv inside the root of my project:\n$ python -m venv .venv --prompt=bscb\nThen to use: Tip: use an ergonomic alias to activate venvs e.g. alias va=\"source .venv/bin/activate\"\n$ source .venv/bin/activate\n# ... do work\n$ deactivate\n\n\nGit and ssh\ngit clone [email protected]:teddygroves/bayesian_statistics_for_systems_biologists.git\n\n\nCmdstanpy and cmdstan\nFirst install them:\n$ pip install cmdstanpy\n$ python -m cmdstanpy.instsall_cmdstan\nNow test if they work\nfrom cmdstanpy import CmdStanModel\nfilename = \"example_stan_program.stan\" \ncode = \"data {} parameters {real t;} model {t ~ std_normal();}\"\nwith open(filename, \"w\") as f:\n f.write(code)\nmodel = CmdStanModel(stan_file=filename)\nmcmc = model.sample()",
"crumbs": [
"Course materials",
"Introduction to Bayesian inference"
Expand Down
18 changes: 11 additions & 7 deletions docs/week1.html
Original file line number Diff line number Diff line change
Expand Up @@ -5253,13 +5253,17 @@ <h3 class="anchored" data-anchor-id="git-and-ssh">Git and ssh</h3>
</section>
<section id="cmdstanpy-and-cmdstan" class="level3">
<h3 class="anchored" data-anchor-id="cmdstanpy-and-cmdstan">Cmdstanpy and cmdstan</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> cmdstanpy <span class="im">import</span> CmdStanModel</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>filename <span class="op">=</span> <span class="st">&quot;example_stan_program.stan&quot;</span> </span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>code <span class="op">=</span> <span class="st">&quot;data </span><span class="sc">{}</span><span class="st"> parameters {real t;} model {t ~ std_normal();}&quot;</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> <span class="bu">open</span>(filename, <span class="st">&quot;w&quot;</span>) <span class="im">as</span> f:</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> f.write(code)</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>model <span class="op">=</span> CmdStanModel(stan_file<span class="op">=</span>filename)</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>mcmc <span class="op">=</span> model.sample()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>First install them:</p>
<pre class="shell"><code>$ pip install cmdstanpy
$ python -m cmdstanpy.instsall_cmdstan</code></pre>
<p>Now test if they work</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> cmdstanpy <span class="im">import</span> CmdStanModel</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>filename <span class="op">=</span> <span class="st">&quot;example_stan_program.stan&quot;</span> </span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>code <span class="op">=</span> <span class="st">&quot;data </span><span class="sc">{}</span><span class="st"> parameters {real t;} model {t ~ std_normal();}&quot;</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> <span class="bu">open</span>(filename, <span class="st">&quot;w&quot;</span>) <span class="im">as</span> f:</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> f.write(code)</span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>model <span class="op">=</span> CmdStanModel(stan_file<span class="op">=</span>filename)</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>mcmc <span class="op">=</span> model.sample()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
</section>
</section>
Expand Down
9 changes: 9 additions & 0 deletions materials/week1.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ git clone [email protected]:teddygroves/bayesian_statistics_for_systems_biologists.

### Cmdstanpy and cmdstan

First install them:

```shell
$ pip install cmdstanpy
$ python -m cmdstanpy.instsall_cmdstan
```

Now test if they work

```python
from cmdstanpy import CmdStanModel
filename = "example_stan_program.stan"
Expand Down

0 comments on commit 34462dc

Please sign in to comment.