def trajectory_score_array(posterior, slope=None, intercept=None, w=None, weights=None, normalize=False):
"""Docstring goes here
This is the score that Davidson et al. maximizes, in order to get a linear trajectory,
but here we kind of assume that that we have the trajectory already, and then just score it.
w is the number of bin rows to include in score, in each direction. That is, w=0 is only the modes,
and w=1 is a band of width=3, namely the modes, and 1 bin above, and 1 bin below the mode.
The score is NOT averaged!"""
rows, cols = posterior.shape
if w is None:
w = 0
if not float(w).is_integer:
raise ValueError("w has to be an integer!")
if slope is None or intercept is None:
slope, intercept, _ = linregress_array(posterior=posterior)
x = np.arange(cols)
line_y = np.round((slope*x + intercept)) # in position bin #s
# idea: cycle each column so that the top w rows are the band surrounding the regression line
if np.isnan(slope): # this will happen if we have 0 or only 1 decoded bins
return np.nan
else:
temp = column_cycle_array(posterior, -line_y+w)
if normalize:
num_non_nan_bins = round(np.nansum(posterior))
else:
num_non_nan_bins = 1
return np.nansum(temp[:2*w+1,:])/num_non_nan_bins
评论列表
文章目录