refactored
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user