Files
pyRBM/src/rbm/helper.py
T
jens 6ef577c769 - fixed armadillo data read
- added shape to layer
- changed construction of layer from Stack factory
- fixed rms_error_accu scaling
- RBM: added image display using opencv
- improved Status print
2025-12-17 17:05:40 +01:00

27 lines
748 B
Python

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