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 files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119#!/usr/bin/env python3"""field_world.py — one particle in a scalar potential field.
State: the particle position q. Action: a step of length `lr` in oneof the coordinate directions, or a sampled random direction. Judge:V(q) <= tol, i.e. the particle reached the known global minimum.No position() method is exposed, so the physical-world detour guard isoff: in a potential field a detour can be the path to the minimum.
T is the learning rate; H = V(q) + T. The search minimizes H."""import hashlibimport osimport sys
import numpy as np
HERE = os.path.dirname(os.path.abspath(__file__))REPO = os.path.dirname(os.path.dirname(HERE))sys.path.insert(0, os.path.join(REPO, "lit_operator"))
from lit_world import LitAction # noqa: E402
class FieldWorld: def __init__(self, field, lr=0.1, box=3.0, tol=1e-3, seed=0): self.field = field self.lr = float(lr) self.box = float(box) self.tol = float(tol) self.rng = np.random.default_rng(seed) self.np_rng = np.random.default_rng(seed + 12345) d = field.dim self.dirs = [] for i in range(d): e = np.zeros(d) e[i] = 1.0 self.dirs.append(e) self.dirs.append(-e) self.extra = {} # sampled direction code -> vector self.next_code = len(self.dirs) self.q = None self.best = float("inf") self.best_q = None
def dir_vec(self, code): if code < len(self.dirs): return self.dirs[code] return self.extra[code]
# -- the world ---------------------------------------------------- def reset(self): self.q = self.rng.uniform(-self.box, self.box, size=self.field.dim) v = self.field.V(self.q) if v < self.best: self.best, self.best_q = v, self.q.copy() return self.q.copy()
def step(self, action): v = self.dir_vec(action) self.q = np.clip(self.q + self.lr * v, -self.box, self.box) return self.q.copy()
def key(self, q): qq = np.round(np.asarray(q) / 0.1).astype(np.int64) h = hashlib.blake2b(digest_size=8) h.update(self.field.seed.to_bytes(8, "little")) h.update(qq.tobytes()) return (0, int.from_bytes(h.digest(), "little"))
def energy(self, q): """H = V + T, where T is the learning rate.""" return self.field.V(q) + self.lr
def judge(self, q): v = self.field.V(q) if v < self.best: self.best, self.best_q = v, np.array(q) return (v <= self.tol, False)
# -- the open action set ----------------------------------------- def suggest(self, obs, rng): """One-step lookahead, no gradient: coordinates + random directions.""" q = np.asarray(obs) best, best_v = None, float("inf") for code in range(len(self.dirs)): nq = np.clip(q + self.lr * self.dirs[code], -self.box, self.box) v = self.field.V(nq) if v < best_v: best_v, best = v, code for _ in range(8): v = self.np_rng.normal(size=self.field.dim) v /= np.linalg.norm(v) + 1e-12 nq = np.clip(q + self.lr * v, -self.box, self.box) e = self.field.V(nq) if e < best_v: code = self.next_code self.next_code += 1 self.extra[code] = v best_v, best = e, code return best
def actions(self, q): return list(range(len(self.dirs)))
def encode(self, action): return LitAction(kind=int(action), id=0, x=0, y=0, cost=1)
def decode(self, act): return int(act.kind)
def sample(self, q, rng): _ = rng v = self.np_rng.normal(size=self.field.dim) v /= np.linalg.norm(v) + 1e-12 code = self.next_code self.next_code += 1 self.extra[code] = v return codesandbox/particles/field_world.pyAdded+119