17 lines
796 B
Python
17 lines
796 B
Python
"""Standalone NumPy speed-command policy; no simulated state or critic access."""
|
|
from pathlib import Path
|
|
import numpy as np
|
|
|
|
|
|
class Policy:
|
|
def __init__(self,path):
|
|
with np.load(Path(path),allow_pickle=False) as d:self.layers=[(d[f'w{i}'].copy(),d[f'b{i}'].copy()) for i in range(3)]
|
|
for (w,b),shape in zip(self.layers,[(64,196),(64,64),(2,64)]):
|
|
if w.shape!=shape or b.shape!=(shape[0],) or not np.isfinite(w).all() or not np.isfinite(b).all():raise ValueError('Invalid speed actor')
|
|
def reset(self):pass
|
|
def __call__(self,obs):
|
|
x=np.asarray(obs,dtype=np.float32)
|
|
if x.shape!=(196,) or not np.isfinite(x).all():raise ValueError('Expected measured IMU/command history196')
|
|
for w,b in self.layers:x=np.tanh(w@x+b)
|
|
return x
|