refactored

This commit is contained in:
2025-12-18 07:56:08 +01:00
parent c06fc7f485
commit eb975da018
4 changed files with 5 additions and 5 deletions
+26
View File
@@ -0,0 +1,26 @@
import numpy as np
import time
rng = np.random.default_rng(int(time.monotonic()))
def uniform(shape: tuple, mu: float = 0.5, std: float = 1.0) -> np.ndarray:
return std * (rng.uniform(size=shape) + mu - 0.5)
def gaussian(shape: tuple, mu: float = 0.5, std: float = 1.0) -> np.ndarray:
return rng.normal(size=shape, loc=mu, scale=std)
def sample(src: np.ndarray) -> np.ndarray:
return (src > uniform(src.shape)).astype(float)
def prob(src: np.ndarray) -> np.ndarray:
return 1.0 / (1 + np.exp(-src))
def rms_error(d_err: np.ndarray):
d_err_squared = d_err * d_err
return np.sum(d_err_squared, 1) / d_err_squared[1]
def rms_error_accu(d_err: np.ndarray):
d_err_squared = d_err * d_err
s = np.sum(d_err_squared) / d_err.size
return s