




























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
双曲惩罚函数曲线图

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()
本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注处,如有侵权请与博主联系。 如果未特殊标注则为原创,遵循 CC 4.0 BY-SA 版权协议。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。