def ddm_response(ddm, width_ms, band_MHz=(1214., 1537.)): """ Returns the factor by which the S/N of a pulse of a given width observed in a particular radio band should decrease given an error in dispersion measure. ddm Difference from optimal dispersion measure in pc/cm^3 width_ms Pulse width in milliseconds band The bottom and top of the observing band in MHz (default: the Arecibo Mock band) """ if _np.isscalar(ddm): ddm = _np.array([ddm]) scal = True else: ddm = _np.array(ddm) scal = False band_MHz = _np.array(band_MHz) zeta = 6.91e-3 * ddm * _np.diff(band_MHz)[0] / (width_ms * (_np.mean(band_MHz)/1000.)**3) result = _np.zeros_like(ddm) where_nonzero = _np.where(zeta != 0) result[where_nonzero] = 0.5*_np.sqrt(_np.pi)*_erf(zeta[where_nonzero])/zeta[where_nonzero] result[zeta == 0] = 1. if scal: return result[0] else: return result
def _distribution_singular(y_eval, w_q_pdf, y, theta_y, clip=True): """ Obtain the distribution function from normalized weights (non-vectorized). .. note:: This will be deleted once the vectorized version has been tested. Parameters ---------- y_eval : numpy.ndarray The point to evaluate distribution (d_y,) [Not Vectorized] w_q_pdf : numpy.ndarray The normalized weight matrix or weight vector [(n, n_q), (n,)] y : numpy.ndarray The training outputs (n, d_y) theta_y : numpy.ndarray Hyperparameters that parametrises the kernel on y (d_y,) Returns ------- numpy.ndarray The distribution evaluated at y for each query point [(n_q,), 1] """ # (n, d_y) all_cdf = 0.5 * (1 + _erf((y_eval - y) / (np.sqrt(2) * theta_y))) # (n,) each_cdf = np.prod(all_cdf, axis=1) # (n_q,) or constant cdf = np.dot(each_cdf, w_q_pdf) # Clip the distribution if required return np.clip(cdf, 0, 1) if clip else cdf
def ddm_response(ddm, width_ms, band_MHz=(1214., 1537.)): """ Returns the factor by which the S/N of a pulse of a given width observed in a particular radio band should decrease given an error in dispersion measure. ddm Difference from optimal dispersion measure in pc/cm^3 width_ms Pulse width in milliseconds band The bottom and top of the observing band in MHz (default: the Arecibo Mock band) """ if _np.isscalar(ddm): ddm = _np.array([ddm]) scal = True else: ddm = _np.array(ddm) scal = False band_MHz = _np.array(band_MHz) zeta = 6.91e-3 * ddm * _np.diff(band_MHz)[0] / ( width_ms * (_np.mean(band_MHz) / 1000.)**3) result = _np.zeros_like(ddm) where_nonzero = _np.where(zeta != 0) result[where_nonzero] = 0.5 * _np.sqrt(_np.pi) * _erf( zeta[where_nonzero]) / zeta[where_nonzero] result[zeta == 0] = 1. if scal: return result[0] else: return result
def _Phi_prime_mu(s, sigma): """ Derivative of the helper function _Phi(s) with respect to the mean input """ if np.any(sigma < 0): raise ValueError('sigma needs to be larger than zero!') if np.any(sigma == 0): raise ZeroDivisionError('Function contains division by sigma!') return -np.sqrt(np.pi) / sigma * (s * np.exp(s**2 / 2.) * (1 + _erf(s / np.sqrt(2))) + np.sqrt(2) / np.sqrt(np.pi))
def _derivative_of_firing_rates_wrt_mean_input(V_0_rel, V_th_rel, mu, sigma, tau_m, tau_r): """ Derivative of the stationary firing rate without synaptic filtering with respect to the mean input Parameters ---------- tau_m : float Membrane time constant in seconds. tau_s : float Synaptic time constant in seconds. tau_r : float Refractory time in seconds. V_th_rel : float Relative threshold potential in mV. V_0_rel : float Relative reset potential in mV. mu : float Mean neuron activity in mV. sigma : float Standard deviation of neuron activity in mV. Returns ------- float Zero frequency limit of white noise transfer function in Hz/mV. """ if np.any(sigma == 0): raise ZeroDivisionError('Phi_prime_mu contains division by sigma!') y_th = (V_th_rel - mu) / sigma y_r = (V_0_rel - mu) / sigma nu0 = _firing_rates_for_given_input(V_0_rel, V_th_rel, mu, sigma, tau_m, tau_r) return (np.sqrt(np.pi) * tau_m * np.power(nu0, 2) / sigma * (np.exp(y_th**2) * (1 + _erf(y_th)) - np.exp(y_r**2) * (1 + _erf(y_r))))
def _Phi(s): """ helper function to calculate stationary firing rates with synaptic filtering corresponds to u^-2 F in Eq. 53 of the following publication Schuecker, J., Diesmann, M. & Helias, M. Reduction of colored noise in excitable systems to white noise and dynamic boundary conditions. 1–23 (2014). """ return np.sqrt(np.pi / 2.) * (np.exp(s**2 / 2.) * (1 + _erf(s / np.sqrt(2))))
def gaussian_cdf(x, sigma=1): """ Cumulative distribution function of a Gaussian distribution having area 1 and standard deviation sigme (i.e., the running integral of gaussian(x,sigma)). Parameters ---------- x: Distance from the center of the peak. sigma: Standard deviation of the underlying Gaussian distribution. """ return 0.5 * _erf(x / (_ROOT2 * sigma)) + 0.5
def __init__(self, sizeMin, sizeMax, rho, sgma, bc, a0): # mass of carbon atom m_C = 12.0107 * _u.u nominator = (3 * _np.exp(-4.5 * sgma**2) * bc * m_C) denominator = ((2 * _np.pi)**1.5 * rho * a0**3 * sgma * (1 + _erf((3 * sgma / _np.sqrt(2)) + (_np.log(a0 / 3.5 / _u.angstrom) / (sgma * _np.sqrt(2)))))) # FIXME: what do we do if the denominator is zero if denominator != 0: B = (nominator / denominator).decompose() def f(a): return B / a * _np.exp(-0.5 * (_np.log(a / a0) / sgma)**2) super().__init__(sizeMin, sizeMax, f) return
def _distribution_vector(y_eval, w_q_pdf, y, theta_y, clip=True): """ Obtain the distribution function from normalized weights (vectorized). Parameters ---------- y_eval : numpy.ndarray The point to evaluate distribution (n_eval, d_y) [Vectorized] w_q_pdf : numpy.ndarray The normalized weight matrix or weight vector [(n, n_q), (n,)] y : numpy.ndarray The training outputs (n, d_y) theta_y : numpy.ndarray Hyperparameters that parametrises the kernel on y (d_y,) Returns ------- numpy.ndarray The distribution evaluated at y for each query point [(n_eval, n_q), (n_eval,)] """ # (n_eval, n, d_y) y_dist = _dist(y_eval, y) # (n_eval, n, d_y) z = y_dist / (np.sqrt(2) * theta_y) # (n_eval, n, d_y) all_cdf = 0.5 * (1 + _erf(z)) # (n_eval, n) each_cdf = np.prod(all_cdf, axis=-1) # (n_eval, n_q) or (n_eval,) cdf = np.dot(each_cdf, w_q_pdf) # Clip the distribution if required return np.clip(cdf, 0, 1) if clip else cdf
def erf(z): return _erf(z.to(U.dimensionless_unscaled).value)