def _check_branching(X,Xsamples,restart,threshold=0.25):
""" Check whether time series branches.
Args:
X (np.array): current time series data.
Xsamples (np.array): list of previous branching samples.
restart (int): counts number of restart trials.
threshold (float, optional): sets threshold for attractor
identification.
Returns:
check = true if branching realization, Xsamples = updated list
"""
check = True
if restart == 0:
Xsamples.append(X)
else:
for Xcompare in Xsamples:
Xtmax_diff = np.absolute(X[-1,:] - Xcompare[-1,:])
# If the second largest element is smaller than threshold
# set check to False, i.e. at least two elements
# need to change in order to have a branching.
# If we observe all parameters of the system,
# a new attractor state must involve changes in two
# variables.
if np.partition(Xtmax_diff,-2)[-2] < threshold:
check = False
if check:
Xsamples.append(X)
if not check:
logg.m('realization {}:'.format(restart), 'no new branch', v=4)
else:
logg.m('realization {}:'.format(restart), 'new branch', v=4)
return check, Xsamples
评论列表
文章目录