Get the prior density of sediment memory

        Returns
        -------
        y : ndarray
            Array giving the density.
        x : ndarray
            Array of Memory (ratio) values over which the density was evaluated.
161168
def prior_sediment_memory(*args, **kwargs):
        
        # "plot the prior for the memory (= accumulation rate varibility between neighbouring depths)"
        # PlotMemPrior @ Bacon.R ln 114 -> ln 1119 - 1141
        # w_a = mem_strength * mem_mean, w_b = mem_strength * (1 - mem_mean)
        # TODO(brews): Check that these stats are correctly translated to scipy.stats distribs.
        mem_shape = kwargs['mem_strength']  # aka. `mem_shape`
        mem_mean = kwargs['mem_mean']
        x = np.linspace(0, 1, 100)
        y = stats.beta.pdf(x, a=mem_shape * mem_mean,
                           b=mem_shape * (1 - mem_mean))
        return y, x
1033379
def nn_dims(self, x, y, dims_x, dims_y, k=1, radius=np.inf, eps=0.0, p=2):
        
        assert len(x) == len(dims_x)
        assert len(y) == len(dims_y)
        if len(dims_x) == 0:
            kdtree = scipy.spatial.cKDTree([np.array(data_y)[np.array(dims_y) - self.dim_x] for data_y in self.data[DATA_Y]])
        elif len(dims_y) == 0:
            kdtree = scipy.spatial.cKDTree([np.array(data_x)[dims_x] for data_x in self.data[DATA_X]])
        else:
            kdtree = scipy.spatial.cKDTree([np.hstack((np.array(data_x)[dims_x], np.array(data_y)[np.array(dims_y) - self.dim_x])) for data_x,data_y in zip(self.data[DATA_X], self.data[DATA_Y])])
        dists, idxes =  kdtree.query(np.hstack((x, y)), 
                               k = k, 
                               distance_upper_bound = radius,
                               eps = eps, 
                               p = p)
        if k == 1:
            dists, idxes = np.array([dists]), [idxes]
        return dists, idxes
825101
def getImemb(self):
        """"""
        self.imembPtr.gather(self.imembVec)
        return self.imembVec.as_numpy()
96255
def prior_to_xarray(self):
        """"""
        prior = self.prior
        # filter posterior_predictive and log_likelihood
        prior_predictive = self.prior_predictive
        if prior_predictive is None:
            prior_predictive = []
        elif isinstance(prior_predictive, str):
            prior_predictive = [prior_predictive]

        ignore = prior_predictive + ["lp__"]

        data = get_draws(prior, ignore=ignore)
        return dict_to_dataset(data, library=self.pystan, coords=self.coords, dims=self.dims)
1096481
def _getp(self):
        
        if self._p is not None:
            return self._p
        # buf = [y,prior]; D[a,i] = dp[a]/dbuf[i]
        pmean = _gvar.mean(self.palt).flat
        buf = (
            self.y.flat if self.prior is None else
            numpy.concatenate((self.y.flat, self.prior.flat))
            )
        D = numpy.zeros((self.cov.shape[0], len(buf)), float)
        for i, chivw_i in enumerate(self._chivw(_gvar.valder(pmean))):
            for a in range(D.shape[0]):
                D[a, i] = chivw_i.dotder(self.cov[a])

        # p[a].mean=pmean[a]; p[a].der[j] = sum_i D[a,i]*buf[i].der[j]
        p = []
        for a in range(D.shape[0]): # der[a] = sum_i D[a,i]*buf[i].der
            p.append(_gvar.gvar(pmean[a], _gvar.wsum_der(D[a], buf),
                     buf[0].cov))
        self._p = _reformat(self.p0, p)
        return self._p
1252657
def _ar_matrix(self):
        
        Y = np.array(self.data[self.max_lag:self.data.shape[0]])
        X = self.data[(self.max_lag-1):-1]

        if self.ar != 0:
            for i in range(1, self.ar):
                X = np.vstack((X,self.data[(self.max_lag-i-1):-i-1]))

        return X
1155885
def posterior_predictive_to_xarray(self):
        """"""
        data = {k: np.expand_dims(v, 0) for k, v in self.posterior_predictive.items()}
        return dict_to_dataset(data, library=self.pymc3, coords=self.coords, dims=self.dims)
675716
def get_autoregressive_bias(max_length: int, dtype: str = C.DTYPE_FP32) -> mx.sym.Symbol:
    
    length_array = mx.sym.arange(max_length, dtype=dtype)
    # matrix with lower triangle and main diagonal set to 0, upper triangle set to 1
    bias = mx.sym.broadcast_greater(mx.sym.reshape(length_array, shape=(1, -1)),
                                    mx.sym.reshape(length_array, shape=(-1, 1)))
    bias = bias * -C.LARGE_VALUES[dtype]
    bias = mx.sym.reshape(bias, shape=(1, max_length, max_length))
    return mx.sym.BlockGrad(bias)
655557
def get_image_ratio(self, image):
        
        x, y = self.get_image_size(image)
        return float(x) / y
468019
def posterior_predictive_to_xarray(self):
        """"""
        posterior = self.posterior
        posterior_predictive = self.posterior_predictive
        data = get_draws(posterior, variables=posterior_predictive)
        return dict_to_dataset(data, library=self.pystan, coords=self.coords, dims=self.dims)
1139741
def prior_to_xarray(self):
        """"""
        return dict_to_dataset(
            {k: np.expand_dims(v, 0) for k, v in self.prior.items()},
            library=self.pymc3,
            coords=self.coords,
            dims=self.dims,
        )
1076302
def posterior_to_xarray(self):
        """"""
        data = {}
        for idx, var_name in enumerate(self.var_names):
            # Use emcee3 syntax, else use emcee2
            data[var_name] = (
                self.sampler.get_chain()[(..., idx)].T
                if hasattr(self.sampler, "get_chain")
                else self.sampler.chain[(..., idx)]
            )
        return dict_to_dataset(data, library=self.emcee, coords=self.coords, dims=self.dims)
326373
def posterior(self, x, s=1.):
        """"""
        pr0 = 1. / self.sigma**2  # prior precision
        prd = x.size / s**2  # data precision
        varp = 1. / (pr0 + prd)  # posterior variance
        mu = varp * (pr0 * self.mu + prd * x.mean())
        return TruncNormal(mu=mu, sigma=np.sqrt(varp), a=self.a, b=self.b)
743844
def density(self):
        
        r = float(self.sp_index.npoints) / float(self.sp_index.length)
        return r
631859
def getResiduals(self):
        
        X = np.zeros((self.N*self.P,self.n_fixed_effs))
        ip = 0
        for i in range(self.n_terms):
            Ki = self.A[i].shape[0]*self.F[i].shape[1]
            X[:,ip:ip+Ki] = np.kron(self.A[i].T,self.F[i])
            ip += Ki
        y = np.reshape(self.Y,(self.Y.size,1),order='F')
        RV = regressOut(y,X)
        RV = np.reshape(RV,self.Y.shape,order='F')
        return RV
1188427
def extract_density(population, plane='xy', bins=100, neurite_type=NeuriteType.basal_dendrite):
    '''
    '''
    segment_midpoints = get_feat('segment_midpoints', population, neurite_type=neurite_type)
    horiz = segment_midpoints[:, 'xyz'.index(plane[0])]
    vert = segment_midpoints[:, 'xyz'.index(plane[1])]
    return np.histogram2d(np.array(horiz), np.array(vert), bins=(bins, bins))
799324
def get_size_for_density(self, size, target_density):
        
        current_size = size
        current_density = DENSITY_MAP[self.source_density]
        target_density = DENSITY_MAP[target_density]

        return int(current_size * (target_density / current_density))