def test_exponential(scale, shift, high, rng): n = 100 dist = dists.Exponential(scale, shift=shift, high=high) samples = dist.sample(n, rng=rng) assert np.all(samples >= shift) assert np.all(samples <= high) # approximation of 95% confidence interval ci = scale * 1.96 / np.sqrt(n) if scale + ci < high: assert abs(np.mean(samples - shift) - scale) < ci
def ThresholdingEnsembles(threshold, intercept_width=0.15, radius=1.0): """Configuration preset for a thresholding ensemble. This preset adjust ensemble parameters for thresholding. The ensemble's neurons will only fire for values above threshold. One can either decode the represented value (if it is above the threshold) or decode a step function if binary classification is desired. This preset: - Sets intercepts to be between ``threshold`` and ``radius`` with an exponential distribution (shape parameter of ``intercept_width``). This clusters intercepts near the threshold for better approximation. - Sets encoders to 1. - Sets evaluation points to be uniformly distributed between ``threshold`` and ``radius``. - Sets the radius. Parameters ---------- threshold : float Point at which ensembles should start firing. intercept_width : float, optional Controls how widely distributed the intercepts are. Smaller values give more clustering at the threshold, larger values give a more uniform distribution. radius : float, optional Ensemble radius. Returns ------- `nengo.Config` Configuration with presets. """ config = Config(Ensemble) config[Ensemble].radius = radius config[Ensemble].intercepts = dists.Exponential(intercept_width, threshold, radius) config[Ensemble].encoders = dists.Choice([[1]]) config[Ensemble].eval_points = dists.Uniform(threshold / radius, 1) return config