强化学习奖励函数 —— 双曲惩罚函数 —— 用于奖励函数设计

def hyperbolic_function(x, x_min, x_max, lam=0.001, tau=0):
        """
        双曲惩罚函数,用于奖励函数设计

        参数:
            x: 自变量
            x_min:自变量允许的最小值
            x_max:自变量允许的最大值
            lam
            tau

        返回:
            函数值
        """
        term1 = lam * (x - x_min)
        term2 = math.sqrt((lam ** 2) * ((x - x_min) ** 2) + (tau ** 2))
        term3 = lam * (x_max - x)
        term4 = math.sqrt((lam ** 2) * ((x_max - x) ** 2) + (tau ** 2))
        return term1 - term2 + term3 - term4




以下内容豆包生成:




双曲惩罚函数曲线图


image




import math
import numpy as np
import matplotlib.pyplot as plt

# 设置matplotlib正常显示中文和负号
plt.rcParams['font.sans-serif'] = ['SimHei']  # 'SimHei' 是黑体的意思
plt.rcParams['axes.unicode_minus'] = False  # 正确显示负号

def hyperbolic_function(x, x_min, x_max, lam=0.001, tau=0):
    term1 = lam * (x - x_min)
    term2 = math.sqrt((lam ** 2) * ((x - x_min) ** 2) + (tau ** 2))
    term3 = lam * (x_max - x)
    term4 = math.sqrt((lam ** 2) * ((x_max - x) ** 2) + (tau ** 2))
    return term1 - term2 + term3 - term4

# 参数设置
x_min = -50
x_max = 50
lam = 0.01
tau = 0.1

x = np.linspace(-100, 100, 1000)
y = [hyperbolic_function(xi, x_min, x_max, lam, tau) for xi in x]

plt.figure(figsize=(10, 5))
plt.plot(x, y, linewidth=2, label='惩罚函数值')
plt.axvline(x=x_min, color='r', linestyle='--', label='x_min 左边界')
plt.axvline(x=x_max, color='r', linestyle='--', label='x_max 右边界')
plt.axhline(y=0, color='k', linestyle=':', alpha=0.5)
plt.xlabel('x')
plt.ylabel('惩罚值(越小惩罚越重)')
plt.title('双曲区间惩罚函数曲线')
plt.grid(True, alpha=0.3)
plt.legend()
plt.tight_layout()
plt.show()




posted on 2026-06-24 19:47  Angry_Panda  阅读(10)  评论(0)    收藏  举报

导航