Skip to content

Commit 8cf2737

Browse files
authored
Add double exponential (#36)
1 parent 758929d commit 8cf2737

File tree

14 files changed

+119
-305
lines changed

14 files changed

+119
-305
lines changed

Makefile

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,6 @@ install-dev: ## Install development dependencies
2424
marimo: ## Run marimo for editing notebooks
2525
@./dev/marimo edit
2626

27-
.PHONY: notebook
28-
notebook: ## Run Jupyter notebook server
29-
@poetry run ./dev/start-jupyter 9095
30-
31-
32-
.PHONY: book
33-
book: ## Build static jupyter {book}
34-
poetry run jupyter-book build notebooks --all
35-
@cp notebooks/CNAME notebooks/_build/html/CNAME
36-
37-
38-
.PHONY: nbconvert
39-
nbconvert: ## Convert notebooks to myst markdown
40-
poetry run ./dev/nbconvert
41-
42-
.PHONY: nbsync
43-
nbsync: ## Sync python myst notebooks to .ipynb files - needed for vs notebook development
44-
poetry run ./dev/nbsync
45-
46-
.PHONY: sphinx-config
47-
sphinx-config: ## Build sphinx config
48-
poetry run jupyter-book config sphinx notebooks
49-
5027
.PHONY: docs
5128
docs: ## build documentation
5229
@cp docs/index.md readme.md
@@ -56,21 +33,10 @@ docs: ## build documentation
5633
docs-serve: ## serve documentation
5734
@poetry run mkdocs serve --livereload --watch quantflow --watch docs
5835

59-
.PHONY: sphinx
60-
sphinx: ## Build sphinx docs
61-
poetry run sphinx-build notebooks path/to/book/_build/html -b html
62-
63-
6436
.PHONY: publish
6537
publish: ## Release to pypi
6638
@poetry publish --build -u __token__ -p $(PYPI_TOKEN)
6739

68-
69-
.PHONY: publish-book
70-
publish-book: ## publish the book to github pages
71-
poetry run ghp-import -n -p -f notebooks/_build/html
72-
73-
7440
.PHONY: tests
7541
tests: ## Unit tests
7642
@./dev/test

app/double_exponential_sampling.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import marimo
2+
3+
__generated_with = "0.19.7"
4+
app = marimo.App(width="medium")
5+
6+
7+
@app.cell
8+
def _():
9+
import marimo as mo
10+
from app.utils import nav_menu
11+
nav_menu()
12+
return (mo,)
13+
14+
15+
@app.cell
16+
def _(mo):
17+
mo.md(r"""
18+
# Double Exponential Sampling
19+
20+
Here we sample the Asymmetric Laplace distribution, a.k.a double exponential
21+
We will set the mean to 0 and the variance to 1 so that the distribution is fully determined by the asymmetric parameter $\kappa$.
22+
23+
```python
24+
from quantflow.utils.distributions import DoubleExponential
25+
```
26+
""")
27+
return
28+
29+
30+
@app.cell
31+
def _():
32+
from quantflow.utils.distributions import DoubleExponential
33+
from quantflow.utils import bins
34+
import numpy as np
35+
36+
def simulate_double_exponential(log_kappa: float, samples: int):
37+
pr = DoubleExponential.from_moments(kappa=np.exp(log_kappa))
38+
data = pr.sample(samples)
39+
pdf = bins.pdf(data, num_bins=50, symmetric=0)
40+
pdf["simulation"] = pdf["pdf"]
41+
pdf["analytical"] = pr.pdf(pdf.index)
42+
cha = pr.pdf_from_characteristic()
43+
return pdf, cha
44+
return (simulate_double_exponential,)
45+
46+
47+
@app.cell
48+
def _(mo):
49+
samples = mo.ui.slider(start=100, stop=10000, step=100, value=1000, debounce=True, label="Samples")
50+
log_kappa = mo.ui.slider(start=-2, stop=2, step=0.1, value=0.1, debounce=True, label="Asymmetry - $\log \kappa$")
51+
52+
controls = mo.hstack([samples, log_kappa], justify="start")
53+
controls
54+
return log_kappa, samples
55+
56+
57+
@app.cell
58+
def _(log_kappa, samples, simulate_double_exponential):
59+
df, cha = simulate_double_exponential(log_kappa.value, samples.value)
60+
return cha, df
61+
62+
63+
@app.cell
64+
def _(cha, df):
65+
import plotly.graph_objects as go
66+
67+
simulation = go.Bar(x=df.index, y=df["simulation"], name="simulation")
68+
analytical = go.Scatter(x=df.index, y=df["analytical"], name="analytical")
69+
characteristic = go.Scatter(x=cha.x, y=cha.y, name="from characteristic", mode="markers")
70+
fig = go.Figure(data=[simulation, characteristic, analytical])
71+
fig
72+
return
73+
74+
75+
@app.cell
76+
def _():
77+
return
78+
79+
80+
if __name__ == "__main__":
81+
app.run()

app/gaussian_sampling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
def _():
99
import marimo as mo
1010
from app.utils import nav_menu
11-
1211
nav_menu()
1312
return (mo,)
1413

dev/marimo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
set -e
33

44
export PYTHONPATH=${PWD}:${PYTHONPATH}
5+
ENV_FILE="${PWD}/.env"
6+
touch ${ENV_FILE}
7+
export $(grep -v '^#' ${ENV_FILE} | xargs)
58

69
poetry run marimo "$@"

dev/nbconvert

Lines changed: 0 additions & 7 deletions
This file was deleted.

dev/nbsync

Lines changed: 0 additions & 7 deletions
This file was deleted.

dev/notebook_config.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

dev/start-jupyter

Lines changed: 0 additions & 11 deletions
This file was deleted.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ nav:
5757
- Examples:
5858
- Gaussian Sampling: examples/gaussian-sampling
5959
- Poisson Sampling: examples/poisson-sampling
60+
- Double Exponential Sampling: examples/double-exponential-sampling
6061
- Hurst: examples/hurst
6162
- Supersmoother: examples/supersmoother
6263
- API Reference:

notebooks/examples/exponential_sampling.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)