Skip to content

Commit 1efe84c

Browse files
committed
making math rendering work in github pages
1 parent bc56cd2 commit 1efe84c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

_includes/mathjax.html

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
<script id="MathJax-script" async
2-
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
3-
</script>
1+
<script>
2+
window.MathJax = {
3+
tex: {
4+
inlineMath: [['$', '$'], ['\\(', '\\)']],
5+
displayMath: [['$$', '$$'], ['\\[', '\\]']],
6+
processEscapes: true,
7+
},
8+
options: {
9+
renderActions: {
10+
addMenu: [0, '', ''],
11+
}
12+
}
13+
};
14+
</script>
15+
16+
<script id="MathJax-script" async
17+
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
18+
</script>
19+

index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ An **LSTM (Long Short-Term Memory)** is a **recurrent neural network (RNN)** arc
2121
In a **reconstruction-based anomaly detection** setup, an LSTM Autoencoder is trained to reconstruct normal behaviour. When model is tested, windows that deviate from learned dynamics give higher **reconstruction errors** and are flagged as anomalies if the errors exceed the set threshold. The training methods studied are:
2222
- **Standard MSE loss**: model **minimizes the pointwise reconstruction error between the input and it's reconstruction**. Though being simple, it's generally stable and widely applicable. However, it presents limitations in understanding the dynamics of the system, so every reconstruction minimizing MSE is considered acceptable, even if not physically normal.
2323
- **Physics-informed loss**: add MSE loss term to a residual penalty that embeds the damped oscillator equation $x'' + 2\zeta\omega_0 x' + \omega_0^2 x = 0$. To achieve this, I approximate $x'$ and $x''$ with **finite differences** on the reconstructed sequence and penalize the squared residual, thus obtaining the total loss:
24+
2425
$$
2526
L = \mathrm{MSE}(x, \hat{x}) + \lambda_{\mathrm{phys}} \cdot \left\| x'' + 2\zeta\omega_0 x' + \omega_0^2 x \right\|^2
2627
$$
28+
2729
where $\lambda_{\mathrm{phys}}$ controls how much the physics loss contributes to total loss estimation, thus enforcing the autoencoder to understand reconstruction that are both close to the input but also physically consistent with system's dynamics, **improving sensitivity** to physically implausable deviations.
2830

2931
Comparing these objectives on the same dataset, I can assess wether pure MSE loss or embedded physical knowledge into the training can improve anomaly detection without lossing performance.
3032

3133
## Dataset
3234
I simulate the **dynamics of a 1-dimensional noisy damped harmonic oscillator**. Dynamics of the system are governed by the equation:
35+
3336
$$
3437
x(t) = e^{-\zeta \omega_0 t} \cos\!\left(\omega_0 \sqrt{1 - \zeta^2}\, t\right) + \varepsilon(t),
3538
\qquad \varepsilon(t) \sim \mathcal{N}(0, \sigma^2)
3639
$$
40+
3741
where $\zeta$ is the damping ratio, $\omega_0$ the natural angular frequency and $\varepsilon(t)$ the Gaussian noise. I generate $T = 60,000$ samples spanning $t = 0$ to $t = 599.99$ with $dt = 0.01$ step. I then inject four types of anomalies:
3842
- **Spikes**: isolated points with abnormal impulses $x_i + a \rightarrow x_i$, with $a \in [2.5, 5.5]$
3943
- **Level shifts**: 400-width segments are shifted by constant offset
@@ -44,9 +48,11 @@ The feature analyzed is the displacement $x_t$. To preprocess the data I create
4448
- length $W = 128$ and stride $s = 32$
4549
- for each start index $k$, I extract $X_k = (x_k, x_{k+1},...,x_{k+W-1}) \in \mathbb{R}^{128 \times 1}$
4650
- window label $y_k$ is set to 1 if at least 5% of it's points are anomalous
51+
4752
$$
4853
y_k = \mathbf{1}\!\left( \frac{1}{W} \sum_{j=0}^{W-1} y_{k+j}^{\text{point}} \ge 0.05 \right)
4954
$$
55+
5056
otherwise $y_k = 0$. After windowing process, I get 1,872 windows with approximately anomaly rate ≈ 31.7%.
5157

5258
I split normal windows in:
@@ -59,6 +65,7 @@ I split anomaly windows in:
5965
- 50% validation anomalies
6066

6167
Finally, before model training, (normal) data is **scaled** using ```StandardScaler``` on the flattened windows and **normalized** so that training distribution has zero mean and unit variance
68+
6269
$$
6370
\tilde{x} = \frac{x - \mu_{\text{train}}}{\sigma_{\text{train}}}
6471
$$

0 commit comments

Comments
 (0)