自定义
DiscreteCustomPrior
基类:DiscretePriorDistribution
一个子类,表示离散自定义先验分布。
此类允许创建具有自定义概率质量函数的先验分布,该函数由 prior_dist
张量定义。例如,如果我的数据有 4 个类别,并且我想要 [.3, .2, .4, .1] 作为 4 个类别的概率。
源代码在 bionemo/moco/distributions/prior/discrete/custom.py
中
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
__init__(prior_dist, num_classes=10)
初始化 DiscreteCustomPrior 分布。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
prior_dist
|
张量
|
表示先验分布的概率质量函数的张量。 |
必需 |
num_classes
|
整数
|
先验分布中的类别数量。默认为 10。 |
10
|
注意
prior_dist
张量的总和应接近 1.0,因为它表示概率质量函数。
源代码在 bionemo/moco/distributions/prior/discrete/custom.py
中
33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
sample(shape, mask=None, device='cpu', rng_generator=None)
从离散自定义先验分布中采样。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
shape
|
元组
|
指定要生成的样本形状的元组。 |
必需 |
mask
|
Optional[张量]
|
可选的张量掩码,应用于样本,可广播到样本形状。默认为 None。 |
无
|
device
|
Union[str, device]
|
在其上生成样本的设备,指定为字符串或 :class: |
'cpu'
|
rng_generator
|
Optional[Generator]
|
可选的 :class: |
无
|
返回值
类型 | 描述 |
---|---|
张量
|
从先验分布中抽取的样本张量。 |
源代码在 bionemo/moco/distributions/prior/discrete/custom.py
中
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|