mindspore.nn.probability.distribution.Logistic
- class mindspore.nn.probability.distribution.Logistic(loc=None, scale=None, seed=None, dtype=mstype.float32, name='Logistic')[源代码]
- Logistic分布(Logistic distribution)。 连续随机分布,取值范围为 \((-\inf, \inf)\) ,概率密度函数为 \[f(x, a, b) = 1 / b \exp(\exp(-(x - a) / b) - x).\]- 其中 \(a, b\) 为分别为Logistic分布的位置参数和比例参数。 - 参数:
- loc (float, list, numpy.ndarray, Tensor) - Logistic分布的位置。默认值: - None。
- scale (float, list, numpy.ndarray, Tensor) - Logistic分布的尺度。默认值: - None。
- seed (int) - 采样时使用的种子。如果为None,则使用全局种子。默认值: - None。
- dtype (mindspore.dtype) - 事件样例的类型。默认值: - mstype.float32。
- name (str) - 分布的名称。默认值: - 'Logistic'。
 
 - 说明 - scale 必须大于零。 
- dtype 必须是float,因为Logistic分布是连续的。 
 - 异常:
- ValueError - scale 中元素小于0。 
- TypeError - dtype 不是float的子类。 
 
- 支持平台:
- Ascend- GPU
 - 样例: - >>> import mindspore >>> import mindspore.nn as nn >>> import mindspore.nn.probability.distribution as msd >>> from mindspore import Tensor >>> # To initialize a Logistic distribution of loc 3.0 and scale 4.0. >>> l1 = msd.Logistic(3.0, 4.0, dtype=mindspore.float32) >>> # A Logistic distribution can be initialized without arguments. >>> # In this case, `loc` and `scale` must be passed in through arguments. >>> l2 = msd.Logistic(dtype=mindspore.float32) >>> >>> # Here are some tensors used below for testing >>> value = Tensor([1.0, 2.0, 3.0], dtype=mindspore.float32) >>> loc_a = Tensor([2.0], dtype=mindspore.float32) >>> scale_a = Tensor([2.0, 2.0, 2.0], dtype=mindspore.float32) >>> loc_b = Tensor([1.0], dtype=mindspore.float32) >>> scale_b = Tensor([1.0, 1.5, 2.0], dtype=mindspore.float32) >>> >>> # Private interfaces of probability functions corresponding to public interfaces, including >>> # `prob`, `log_prob`, `cdf`, `log_cdf`, `survival_function`, and `log_survival`, >>> # have the same arguments as follows. >>> # Args: >>> # value (Tensor): the value to be evaluated. >>> # loc (Tensor): the location of the distribution. Default: self.loc. >>> # scale (Tensor): the scale of the distribution. Default: self.scale. >>> # Examples of `prob`. >>> # Similar calls can be made to other probability functions >>> # by replacing 'prob' by the name of the function >>> ans = l1.prob(value) >>> print(ans.shape) (3,) >>> # Evaluate with respect to distribution b. >>> ans = l1.prob(value, loc_b, scale_b) >>> print(ans.shape) (3,) >>> # `loc` and `scale` must be passed in during function calls >>> ans = l1.prob(value, loc_a, scale_a) >>> print(ans.shape) (3,) >>> # Functions `mean`, `mode`, `sd`, `var`, and `entropy` have the same arguments. >>> # Args: >>> # loc (Tensor): the location of the distribution. Default: self.loc. >>> # scale (Tensor): the scale of the distribution. Default: self.scale. >>> # Example of `mean`. `mode`, `sd`, `var`, and `entropy` are similar. >>> ans = l1.mean() >>> print(ans.shape) () >>> ans = l1.mean(loc_b, scale_b) >>> print(ans.shape) (3,) >>> # `loc` and `scale` must be passed in during function calls. >>> ans = l1.mean(loc_a, scale_a) >>> print(ans.shape) (3,) >>> # Examples of `sample`. >>> # Args: >>> # shape (tuple): the shape of the sample. Default: () >>> # loc (Tensor): the location of the distribution. Default: self.loc. >>> # scale (Tensor): the scale of the distribution. Default: self.scale. >>> ans = l1.sample() >>> print(ans.shape) () >>> ans = l1.sample((2,3)) >>> print(ans.shape) (2, 3) >>> ans = l1.sample((2,3), loc_b, scale_b) >>> print(ans.shape) (2, 3, 3) >>> ans = l1.sample((2,3), loc_a, scale_a) >>> print(ans.shape) (2, 3, 3) - property loc
- 返回分布位置。 - 返回:
- Tensor,分布的位置值。 
 
 - property scale
- 返回分布比例。 - 返回:
- Tensor,分布的比例值。 
 
 - cdf(value, loc, scale)
- 在给定值下计算累积分布函数(Cumulatuve Distribution Function, CDF)。 - 参数:
- value (Tensor) - 要计算的值。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,累积分布函数的值。 
 
 - cross_entropy(dist, loc_b, scale_b, loc, scale)
- 计算分布a和b之间的交叉熵。 - 参数:
- dist (str) - 分布的类型。 
- loc_b (Tensor) - 对比分布位置参数。 
- scale_b (Tensor) - 对比分布比例参数。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,交叉熵的值。 
 
 - entropy(loc, scale)
- 计算熵。 - 参数:
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,熵的值。 
 
 - kl_loss(dist, loc_b, scale_b, loc, scale)
- 计算KL散度,即KL(a||b)。 - 参数:
- dist (str) - 分布的类型。 
- loc_b (Tensor) - 对比分布位置参数。 
- scale_b (Tensor) - 对比分布比例参数。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,KL散度。 
 
 - log_cdf(value, loc, scale)
- 计算给定值对于的累积分布函数的对数。 - 参数:
- value (Tensor) - 要计算的值。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,累积分布函数的对数。 
 
 - log_prob(value, loc, scale)
- 计算给定值对应的概率的对数。 - 参数:
- value (Tensor) - 要计算的值。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,累积分布函数的对数。 
 
 - log_survival(value, loc, scale)
- 计算给定值对应的生存函数的对数。 - 参数:
- value (Tensor) - 要计算的值。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,生存函数的对数。 
 
 - mean(loc, scale)
- 计算期望。 - 参数:
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,概率分布的期望。 
 
 - mode(loc, scale)
- 计算众数。 - 参数:
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,概率分布的众数。 
 
 - prob(value, loc, scale)
- 计算给定值下的概率。对于连续是计算概率密度函数(Probability Density Function)。 - 参数:
- value (Tensor) - 要计算的值。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,概率值。 
 
 - sample(shape, loc, scale)
- 采样函数。 - 参数:
- shape (tuple) - 样本的shape。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,根据概率分布采样的样本。 
 
 - sd(loc, scale)
- 计算标准差。 - 参数:
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,概率分布的标准差。 
 
 - survival_function(value, loc, scale)
- 计算给定值对应的生存函数。 - 参数:
- value (Tensor) - 要计算的值。 
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,生存函数的值。 
 
 - var(loc, scale)
- 计算方差。 - 参数:
- loc (Tensor) - 分布位置参数。默认值: - None。
- scale (Tensor) - 分布比例参数。默认值: - None。
 
- 返回:
- Tensor,概率分布的方差。