您好,我正在尝试使用 bayesian_optimization库和自定义内核函数(具体来说是使用 kendall 距离的RBF版本)来执行贝叶斯优化。
我试图将kendall distance作为参数传递给位于 scipy.spatial.distance 中的cdist和pdist函数。我正在重用scipy.stats.kendalltau中的 kendalltau 函数的代码,具体来说,我的 kendall 距离定义如下:
def kendall_distance(x,y):
perm = np.argsort(y) # sort on y and convert y to dense ranks
x, y = x[perm], y[perm]
y = np.r_[True, y[1:] != y[:-1]].cumsum(dtype=np.intp)
# stable sort on x and convert x to dense ranks
perm = np.argsort(x, kind='mergesort')
x, y = x[perm], y[perm]
x = np.r_[True, x[1:] != x[:-1]].cumsum(dtype=np.intp)
dis = _kendall_dis(x, y) # discordant …
Run Code Online (Sandbox Code Playgroud)