Instructions to use ReasoningKingdom/LITOperator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LeRobot
How to use ReasoningKingdom/LITOperator with LeRobot:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Add the Particles field project
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091#!/usr/bin/env python3"""potentials.py — random strongly convex scalar potential fields.
Every field is built with a known global minimum at c and V(c)=0:
V(q) = 1/2 (q-c)^T A (q-c) + sum_i w_i psi(q_i - c_i)
A is SPD with eigenvalues in [mu, lmax]; every psi is convex withpsi(0)=0, psi(t)>=0 and psi'(0)=0. Hence the Hessian is >= mu I:strong convexity is the certificate, and the global minimum is c."""import numpy as np
KINDS = ("quadratic", "logcosh", "softplus", "huber")
class StrongConvexField: def __init__(self, dim=2, seed=0, kind=None, mu=0.1, lmax=2.0): rng = np.random.default_rng(seed) self.dim = int(dim) self.seed = int(seed) self.mu = float(mu) self.kind = kind or str(rng.choice(KINDS)) self.c = rng.uniform(-1.0, 1.0, size=self.dim) q, _ = np.linalg.qr(rng.normal(size=(self.dim, self.dim))) lam = rng.uniform(self.mu, lmax, size=self.dim) self.A = (q * lam) @ q.T self.w = rng.uniform(0.05, 0.5, size=self.dim) self.delta = float(rng.uniform(0.5, 1.2))
# -- the convex radial term, with min 0 at t=0 ---------------- def psi(self, t): t = np.asarray(t, dtype=float) if self.kind == "quadratic": return 0.5 * t * t if self.kind == "logcosh": return np.logaddexp(t, -t) - np.log(2.0) if self.kind == "softplus": return np.logaddexp(0.0, t) - np.log(2.0) - 0.5 * t if self.kind == "huber": a = np.abs(t) return np.where(a <= self.delta, 0.5 * t * t, self.delta * (a - 0.5 * self.delta)) raise ValueError(self.kind)
def dpsi(self, t): t = np.asarray(t, dtype=float) if self.kind == "quadratic": return t if self.kind == "logcosh": return np.tanh(t) if self.kind == "softplus": return 1.0 / (1.0 + np.exp(-t)) - 0.5 if self.kind == "huber": return np.clip(t, -self.delta, self.delta) raise ValueError(self.kind)
def d2psi(self, t): t = np.asarray(t, dtype=float) if self.kind == "quadratic": return np.ones_like(t) if self.kind == "logcosh": return 1.0 - np.tanh(t) ** 2 if self.kind == "softplus": s = 1.0 / (1.0 + np.exp(-t)) return s * (1.0 - s) if self.kind == "huber": return (np.abs(t) <= self.delta).astype(float) raise ValueError(self.kind)
# -- the potential ------------------------------------------------ def V(self, x): z = np.asarray(x, dtype=float) - self.c return float(0.5 * z @ self.A @ z + np.sum(self.w * self.psi(z)))
def grad(self, x): z = np.asarray(x, dtype=float) - self.c return self.A @ z + self.w * self.dpsi(z)
def minimum(self): return self.c.copy(), 0.0
def smoothness(self): d2 = {"quadratic": 1.0, "logcosh": 1.0, "softplus": 0.25, "huber": 1.0}[self.kind] return float(np.linalg.eigvalsh(self.A).max() + np.max(self.w) * d2)
def certificate(self): return {"mu": self.mu, "L": self.smoothness(), "min": 0.0, "kind": self.kind, "dim": self.dim, "seed": self.seed}sandbox/particles/potentials.pyAdded+91