Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scale_values[scale_values == 0] = np.nan
scale_hists = np.zeros(((len(hist_bins),) + n_zeros.shape))
scale_hists[0, :] = n_zeros
scale_hists[1:, :] = np.apply_along_axis(self._make_hist, 0,
scale_values,
hist_bins=hist_bins)
# Convert voxel-wise histograms to voxel-wise null distributions.
null_distribution = scale_hists / np.sum(scale_hists, axis=0)
null_distribution = np.cumsum(null_distribution[::-1, :], axis=0)[::-1, :]
null_distribution /= np.max(null_distribution, axis=0)
# Get the hist_bins associated with each voxel's ale value, in order to
# get the p-value from the associated bin in the null distribution.
n_bins = len(hist_bins)
ale_bins = round2(ale_values * step).astype(int)
ale_bins[ale_bins > n_bins] = n_bins
# Get p-values by getting the ale_bin-th value in null_distribution
# per voxel.
p_values = np.empty_like(ale_bins).astype(float)
for i, (x, y) in enumerate(zip(null_distribution.transpose(), ale_bins)):
p_values[i] = x[y]
z_values = p_to_z(p_values, tail='one')
return p_values, z_values
def _ale_to_p(self, ale_values):
"""
Compute p- and z-values.
"""
step = 1 / np.mean(np.diff(self.null_distributions['histogram_bins']))
# Determine p- and z-values from ALE values and null distribution.
p_values = np.ones(ale_values.shape)
idx = np.where(ale_values > 0)[0]
ale_bins = round2(ale_values[idx] * step)
p_values[idx] = self.null_distributions['histogram_weights'][ale_bins]
z_values = p_to_z(p_values, tail='one')
return p_values, z_values