本文主要是介绍【函数讲解】botorch中的函数 is_non_dominated():用于计算非支配(non-dominated)前沿,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# 获取训练目标值,计算Pareto前沿(非支配解集合),然后从样本中提取出Pareto最优解。train_obj = self.samples[1]pareto_mask = is_non_dominated(train_obj)pareto_y = train_obj[pareto_mask]
这里用到了一个函数 is_non_dominated(),来看下该函数的源码:
def is_non_dominated(Y: Tensor, deduplicate: bool = True) -> Tensor:r"""Computes the non-dominated front.Note: this assumes maximization.Args:Y: A `(batch_shape) x n x m`-dim tensor of outcomes.deduplicate: A boolean indicating whether to only returnunique points on the pareto frontier.Returns:A `(batch_shape) x n`-dim boolean tensor indicating whethereach point is non-dominated."""Y1 = Y.unsqueeze(-3)Y2 = Y.unsqueeze(-2)dominates = (Y1 >= Y2).all(dim=-1) & (Y1 > Y2).any(dim=-1)nd_mask = ~(dominates.any(dim=-1))if deduplicate:# remove duplicates# find index of first occurrence of each unique elementindices = (Y1 == Y2).all(dim=-1).long().argmax(dim=-1)keep = torch.zeros_like(nd_mask)keep.scatter_(dim=-1, index=indices, value=1.0)return nd_mask & keepreturn nd_mask
这篇关于【函数讲解】botorch中的函数 is_non_dominated():用于计算非支配(non-dominated)前沿的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!