vault backup: 2026-01-11 12:50:45
This commit is contained in:
+56
-45
@@ -11,6 +11,8 @@ tags:
|
||||
---
|
||||
# Decrease in Sigma
|
||||
|
||||
## Normal PDF
|
||||
|
||||
```tikz
|
||||
\usepackage{pgfplots}
|
||||
\pgfplotsset{compat=1.16}
|
||||
@@ -47,53 +49,62 @@ tags:
|
||||
\end{document}
|
||||
```
|
||||
|
||||
^pdf
|
||||
## Lognormal PDF
|
||||
|
||||
```tikz
|
||||
\usepackage{pgfplots}
|
||||
\pgfplotsset{compat=1.16}
|
||||
![[lognormal-pdf.gif]]
|
||||
|
||||
\pgfmathdeclarefunction{erfapprox}{1}{%
|
||||
\pgfmathparse{%
|
||||
% save sign and work with |x|
|
||||
( (#1<0) ? -1 : 1 )
|
||||
* ( 1 - (1 + 0.278393*abs(#1) + 0.230389*abs(#1)^2 + 0.000972*abs(#1)^3 + 0.078108*abs(#1)^4)^(-4) )
|
||||
}%
|
||||
}
|
||||
%%
|
||||
```python
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.stats import lognorm
|
||||
import imageio.v2 as imageio
|
||||
import os
|
||||
|
||||
% Normal CDF using erf approximation:
|
||||
% F(x;mu,sigma) = 0.5*(1 + erf((x-mu)/(sigma*sqrt(2))))
|
||||
\pgfmathdeclarefunction{normcdf}{3}{%
|
||||
\pgfmathparse{ 0.5*(1 + erfapprox((#1-#2)/(#3*sqrt(2)))) }%
|
||||
}
|
||||
mean_target = 10.0
|
||||
sigmas = np.linspace(1.0, 0.1, 25)
|
||||
x = np.linspace(0.001, 40, 2000)
|
||||
|
||||
\begin{document}
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[
|
||||
width=13cm,
|
||||
height=7cm,
|
||||
axis lines=middle,
|
||||
xlabel={$x$},
|
||||
ylabel={$F(x;\mu,\sigma)$},
|
||||
xmin=-6, xmax=6,
|
||||
ymin=0, ymax=1.05,
|
||||
samples=400,
|
||||
domain=-6:6,
|
||||
legend style={draw=none, fill=none, at={(0.02,0.98)}, anchor=north west},
|
||||
legend cell align=left,
|
||||
ytick={0,0.5,1},
|
||||
]
|
||||
|
||||
% Normal CDF: 0.5*(1 + erf((x-mu)/(sigma*sqrt(2))))
|
||||
\addplot[thick]
|
||||
{ normcdf(x,0,1.8) };
|
||||
\addlegendentry{$\mu=0,\ \sigma=1.8$}
|
||||
|
||||
\addplot[thick, dashed]
|
||||
{ normcdf(x,0.8) };
|
||||
\addlegendentry{$\mu=0,\ \sigma=0.8$}
|
||||
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{document}
|
||||
# Precompute global y-limit
|
||||
pdf_max = 0.0
|
||||
for sigma in sigmas:
|
||||
mu = np.log(mean_target) - 0.5 * sigma**2
|
||||
pdf = lognorm.pdf(x, s=sigma, scale=np.exp(mu))
|
||||
pdf_max = max(pdf_max, pdf.max())
|
||||
|
||||
frames = []
|
||||
tmp_dir = "frames"
|
||||
os.makedirs(tmp_dir, exist_ok=True)
|
||||
|
||||
for i, sigma in enumerate(sigmas):
|
||||
mu = np.log(mean_target) - 0.5 * sigma**2
|
||||
pdf = lognorm.pdf(x, s=sigma, scale=np.exp(mu))
|
||||
|
||||
plt.figure(figsize=(6, 4))
|
||||
plt.plot(x, pdf)
|
||||
plt.axvline(mean_target, linestyle="--", linewidth=1)
|
||||
plt.text(
|
||||
mean_target, pdf_max * 0.95,
|
||||
"mean",
|
||||
rotation=90,
|
||||
verticalalignment="top",
|
||||
horizontalalignment="right"
|
||||
)
|
||||
|
||||
plt.title(f"Lognormal PDF\nmean = {mean_target}, sigma = {sigma:f}")
|
||||
plt.xlabel("x")
|
||||
plt.ylabel("density")
|
||||
plt.ylim(0, pdf_max * 1.05)
|
||||
plt.tight_layout()
|
||||
|
||||
frame_path = f"{tmp_dir}/frame_{i:02d}.png"
|
||||
plt.savefig(frame_path, dpi=120)
|
||||
plt.close()
|
||||
|
||||
frames.append(imageio.imread(frame_path))
|
||||
|
||||
os.makedirs("out", exist_ok=True)
|
||||
gif_path = "out/lognormal-pdf.gif"
|
||||
imageio.mimsave(gif_path, frames, duration=0.15)
|
||||
```
|
||||
%%
|
||||
Reference in New Issue
Block a user