Source code for algorithms.RL_Algorithm.optimizers.utils.math

import torch
import math


[docs]def normal_entropy(std): ''' :param std: std value :return: calculate normal distribution entropy ''' var = std.pow(2) entropy = 0.5 + 0.5 * torch.log(2 * var * math.pi) return entropy.sum(1, keepdim=True)
[docs]def normal_log_density(x, mean, log_std, std): ''' :param x: x var :param mean: mean for the normal distribution :param log_std: log std :param std: std :return: log density of x var given the distribution ''' var = std.pow(2) log_density = -(x - mean).pow(2) / (2 * var) - 0.5 * math.log(2 * math.pi) - log_std return log_density.sum(1, keepdim=True)