Python bottleneck.nansum() Examples
The following are 4
code examples of bottleneck.nansum().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bottleneck
, or try the search function
.
Example #1
Source File: region.py From mHTM with MIT License | 6 votes |
def _update_inhibition_radius(self): """ Sets the inhibition radius based off the average receptive field size. The average receptive field size is the distance of the connected synapses with respect to to their input column. In other words, it is the distance between a column and its input source averaged across all connected synapses. The distance used is the Euclidean distance. Refer to the initialization of self.syn_dist for more details. NOTE - This should only be called after phase 1. - The minimum inhibition radius is lower-bounded by 1. """ self.inhibition_radius = max(bn.nansum(self.syn_dist * self.syn_c) / max(bn.nansum(self.syn_c), 1), 1)
Example #2
Source File: region.py From mHTM with MIT License | 6 votes |
def _phase1(self): """ Execute phase 1 of the SP region. This phase is used to compute the overlap. Note - This should only be called once the input has been updated. """ # Compute the connected synapse mask self.syn_c = self.p >= self.syn_th # Compute the overlaps self.overlap[:, 1:] = self.overlap[:, :-1] # Shift self.overlap[:, 0] = bn.nansum(self.x[self.syn_map] * self.syn_c, 1) self.overlap[:, 0][self.overlap[:, 0] < self.seg_th] = 0 self.overlap[:, 0] = self.overlap[:, 0] * self.boost
Example #3
Source File: accessors.py From vectorbt with GNU General Public License v3.0 | 5 votes |
def sum(self, **kwargs): """Return sum of non-NaN elements.""" return self.wrap_reduced(nansum(self.to_2d_array(), axis=0), **kwargs)
Example #4
Source File: hmm.py From sima with GNU General Public License v2.0 | 4 votes |
def _pixel_distribution(dataset, tolerance=0.001, min_frames=1000): """Estimate the distribution of pixel intensities for each channel. Parameters ---------- tolerance : float The maximum relative error in the estimates that must be achieved for termination. min_frames: int The minimum number of frames that must be evaluated before termination. Returns ------- mean_est : array Mean intensities of each channel. var_est : Variances of the intensity of each channel. """ # TODO: separate distributions for each plane sums = np.zeros(dataset.frame_shape[-1]).astype(float) sum_squares = np.zeros_like(sums) counts = np.zeros_like(sums) t = 0 for frame in it.chain.from_iterable(dataset): for plane in frame: if t > 0: mean_est = sums / counts var_est = (sum_squares / counts) - (mean_est ** 2) if t > min_frames and np.all( np.sqrt(var_est / counts) / mean_est < tolerance): break sums += np.nan_to_num(nansum(nansum(plane, axis=0), axis=0)) sum_squares += np.nan_to_num( nansum(nansum(plane ** 2, axis=0), axis=0)) counts += np.isfinite(plane).sum(axis=0).sum(axis=0) t += 1 assert np.all(mean_est > 0) assert np.all(var_est > 0) return mean_est, var_est