EvoForest-WM: Discovered Neuro-Symbolic Foundational World Model for Multivariate Time-Series · GitHub
/" data-turbo-transient="true" />
Skip to content
-->
Search Gists
Search Gists
Sign in
Sign up
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
Instantly share code, notes, and snippets.
kayuksel/evoforest_wm.py
Last active<br>June 24, 2026 23:29
Show Gist options
Download ZIP
Star
(0)
You must be signed in to star a gist
Fork
(0)
You must be signed in to fork a gist
Embed
Select an option
Embed<br>Embed this gist in your website.
Share<br>Copy sharable link for this gist.
Clone via HTTPS<br>Clone using the web URL.
No results found
Learn more about clone URLs
Clone this repository at <script src="https://gist.github.com/kayuksel/cbb304038471befead2c1926610e9ff4.js"></script>
" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-42f8e52b-8141-4dd8-be4b-982762eacce3" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-sized-down" />
Save kayuksel/cbb304038471befead2c1926610e9ff4 to your computer and use it in GitHub Desktop.
Embed
Select an option
Embed<br>Embed this gist in your website.
Share<br>Copy sharable link for this gist.
Clone via HTTPS<br>Clone using the web URL.
No results found
Learn more about clone URLs
Clone this repository at <script src="https://gist.github.com/kayuksel/cbb304038471befead2c1926610e9ff4.js"></script>
" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-4858522a-bf2a-4370-9b77-98f89c449e05" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-original" />
Save kayuksel/cbb304038471befead2c1926610e9ff4 to your computer and use it in GitHub Desktop.
Download ZIP
EvoForest-WM: Discovered Neuro-Symbolic Foundational World Model for Multivariate Time-Series
Raw
evoforest_wm.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br>Learn more about bidirectional Unicode characters
Show hidden characters
import math
import torch
import torch.nn.functional as F
L = 64
def _g(seed):
return torch.Generator().manual_seed(seed)
class WMTransform:
"""The frozen TS-WM patch encoder phi: (B, L) -> (B, 141). Pure closed form over seeded banks."""
def __init__(self, L=L, device="cpu", dtype=torch.float32):
self.L = L
self.device = device
# --- seeded random-projection banks (the only stochastic content; fixed integer seeds) ---
self.trf_mu = torch.rand(12, generator=_g(11)) # Gaussian-window centers in [0,1]
self.trf_sig = torch.exp(torch.rand(12, generator=_g(12)) * 2.59 - 3.51) # window widths
self.srf_W = torch.randn(12, 6, 12, generator=_g(21)) / 3.4641 # random MLP on the 12 stats
self.srf_b = torch.randn(12, 6, generator=_g(22))
self.srf_u = torch.randn(12, 6, generator=_g(23)) / 2.4495
self.crf_w = torch.randn(16, 1, 9, generator=_g(31)) # 16 random conv kernels (size 9)
for k in ("trf_mu", "trf_sig", "srf_W", "srf_b", "srf_u", "crf_w"):
setattr(self, k, getattr(self, k).to(device=device, dtype=dtype))
# the column width and ordered builders of the 18 families
self._families = [
("stats", 12), ("srf_mlp", 12), ("autocorr", 2), ("spectral", 2), ("turning", 2),
("trf_gausswin", 12), ("crf_ppv", 32), ("hilbert_env", 2), ("crf_max", 32),
("morphology_updown", 4), ("fftbands", 6), ("perm_entropy", 3), ("curvature", 3),
("conv_position", 3), ("ar_residual", 4), ("acf_first_min", 3), ("histogram_mode", 3),
("ricker_wavelet", 4),
# ----- family 0: stats (12) — also consumed by srf_mlp -----
def stats(self, w):
m = w.mean(1); s = w.std(1).clamp(min=1e-8); c = w - w.mean(1, keepdim=True)
return torch.stack([
m, s,
(c ** 3).mean(1) / (s ** 3 + 1e-8), # skew
(c ** 4).mean(1) / (s ** 4 + 1e-8) - 3.0, # excess kurtosis
torch.quantile(w, 0.25, dim=1), torch.quantile(w, 0.5, dim=1), torch.quantile(w, 0.75, dim=1),
torch.quantile(w, 0.75, dim=1) - torch.quantile(w, 0.25, dim=1), # IQR
(c[:, :-1] * c[:, 1:]).sum(1) / ((c[:, :-1] ** 2).sum(1).sqrt() * (c[:, 1:] ** 2).sum(1).sqrt() + 1e-8),
(w[:, 1:] - w[:, :-1]).abs().mean(1), w.amin(1), w.amax(1),
], dim=1)
# ----- family 1: random-MLP projection of the stats vector (12) -----
def srf_mlp(self, w, st):
h = torch.relu(torch.einsum("nm,kdm->nkd", st, self.srf_W) + self.srf_b.unsqueeze(0))
return (h * self.srf_u.unsqueeze(0)).sum(2)
# ----- family 2:...