当前位置: 首页 > news >正文

网站客服电话中国的搜索引擎有哪些

网站客服电话,中国的搜索引擎有哪些,网站设置快捷方式,网站怎么做优化一、强化学习的基本概念 注: 圈图与折线图引用知乎博主斜杠青年 1. 任务与奖赏 任务:强化学习的目标是让智能体(agent)在一个环境(environment)中采取一系列行动(actions)以完成一个…

一、强化学习的基本概念

注: 圈图与折线图引用知乎博主斜杠青年

1. 任务与奖赏
  • 任务:强化学习的目标是让智能体(agent)在一个环境(environment)中采取一系列行动(actions)以完成一个或多个目标。智能体通过与环境进行交互,根据环境的状态(states)选择动作,并根据环境的反馈调整自己的行为。
  • 奖赏:环境会给智能体一个反馈信号,即奖赏(reward),奖赏是一个标量值,代表智能体采取行动后的即时奖励或惩罚。智能体的目标是最大化累积奖赏,通常使用折扣累积奖赏公式:
    在这里插入图片描述
    ,其中在这里插入图片描述
    是在时刻 在这里插入图片描述
    获得的奖赏,(\gamma\in[0,1]) 是折扣因子,用于平衡短期和长期奖赏,越接近 0 表示越关注短期奖赏,越接近 1 表示越关注长期奖赏。

二、k-摇臂赌博机

1. 基本概念
  • k-摇臂赌博机是强化学习中的一个经典问题,它有 (k) 个摇臂,每个摇臂被拉动时会给出一个随机的奖赏。智能体的任务是通过多次试验找到能带来最大累积奖赏的摇臂。
    在这里插入图片描述
2. 代码示例((\epsilon)-贪心算法)
import numpy as npdef k_arm_bandit(k, num_steps, epsilon):# 初始化每个摇臂的真实奖赏期望,这里假设服从正态分布true_rewards = np.random.normal(0, 1, k)estimated_rewards = np.zeros(k)num_pulls = np.zeros(k)rewards = []for step in range(num_steps):if np.random.rand() < epsilon:# 以 epsilon 的概率随机选择一个摇臂action = np.random.randint(k)else:# 以 1 - epsilon 的概率选择估计奖赏最大的摇臂action = np.argmax(estimated_rewards)# 从选中的摇臂获得一个随机奖赏,假设服从正态分布reward = np.random.normal(true_rewards[action], 1)rewards.append(reward)# 更新估计奖赏和拉动次数num_pulls[action] += 1estimated_rewards[action] += (reward - estimated_rewards[action]) / num_pulls[action]return rewards# 示例运行
k = 10
num_steps = 1000
epsilon = 0.1
rewards = k_arm_bandit(k, num_steps, epsilon)
print("Total rewards:", np.sum(rewards))

三、有模型学习

1. 基本概念
  • 有模型学习中,智能体尝试学习环境的模型,即状态转移概率 (P(s’|s,a))(从状态 (s) 采取动作 (a) 转移到状态 (s’) 的概率)和奖赏函数 (R(s,a))(在状态 (s) 采取动作 (a) 获得的奖赏)。然后可以使用规划算法(如动态规划)来求解最优策略。
2. 数学公式(Bellman 方程)
  • 状态值函数 (V(s)) 的 Bellman 期望方程:

  • 在这里插入图片描述

  • 动作值函数 (Q(s,a)) 的 Bellman 期望方程:在这里插入图片描述
    ,其中 (\pi(a|s)) 是策略,表示在状态 (s) 下采取动作 (a) 的概率。

3. 代码示例(价值迭代)
import numpy as npdef value_iteration(P, R, gamma, theta):num_states = P.shape[0]num_actions = P.shape[1]V = np.zeros(num_states)while True:delta = 0for s in range(num_states):v = V[s]V[s] = max([sum([P[s][a][s_prime] * (R[s][a] + gamma * V[s_prime])for s_prime in range(num_states)]) for a in range(num_actions)])delta = max(delta, abs(v - V[s]))if delta < theta:breakreturn V# 示例运行
# 假设环境的状态转移矩阵 P 和奖赏矩阵 R
P = np.random.rand(3, 2, 3)  # P[s][a][s_prime]
R = np.random.rand(3, 2)  # R[s][a]
gamma = 0.9
theta = 0.001
V = value_iteration(P, R, gamma, theta)
print("Optimal state values:", V)

四、免模型学习

1. 基本概念
  • 免模型学习不尝试学习环境的完整模型,而是直接学习价值函数或策略函数。常见的方法包括蒙特卡洛(Monte Carlo)、时序差分(Temporal Difference,TD)学习等。
2. 数学公式(TD(0) 更新)

在这里插入图片描述
,其中 (S_t) 和 (S_{t+1}) 是连续的状态,(R_{t+1}) 是从 (S_t) 到 (S_{t+1}) 获得的奖赏,(\alpha) 是学习率。

3. 代码示例(TD(0))
import numpy as npdef td_0(env, num_episodes, alpha, gamma):V = np.zeros(env.num_states)for _ in range(num_episodes):state = env.reset()done = Falsewhile not done:action = np.random.randint(env.num_actions)  # 这里使用随机策略next_state, reward, done = env.step(action)V[state] += alpha * (reward + gamma * V[next_state] - V[state])state = next_statereturn Vclass SimpleEnvironment:def __init__(self):self.num_states = 5self.num_actions = 2def reset(self):return 0def step(self, action):# 简单模拟环境的状态转移和奖赏,实际应用中需要根据具体环境定义if action == 0:next_state = np.random.choice(self.num_states)reward = np.random.normal(0, 1)else:next_state = np.random.choice(self.num_states)reward = np.random.normal(1, 1)done = False  # 假设不会结束return next_state, reward, done# 示例运行
env = SimpleEnvironment()
num_episodes = 1000
alpha = 0.1
gamma = 0.9
V = td_0(env, num_episodes, alpha, gamma)
print("Estimated state values:", V)

在这里插入图片描述

五、值函数近似

1. 基本概念
  • 当状态空间很大或连续时,使用表格存储值函数变得不可行,因此使用值函数近似。通常使用函数逼近器(如线性函数、神经网络)来表示 (V(s)) 或 (Q(s,a))。
2. 数学公式(线性值函数近似)
  • (V(s;\theta)=\theta^T\phi(s)),其中 (\theta) 是参数向量,(\phi(s)) 是状态 (s) 的特征向量。
3. 代码示例(线性函数近似)
import numpy as npdef linear_value_approximation(env, num_episodes, alpha, gamma, theta):for _ in range(num_episodes):state = env.reset()done = Falsewhile not done:action = np.random.randint(env.num_actions)  # 随机策略next_state, reward, done = env.step(action)# 特征向量表示phi_state = np.array([state, state**2])phi_next_state = np.array([next_state, next_state**2])target = reward + gamma * np.dot(theta, phi_next_state)delta = target - np.dot(theta, phi_state)theta += alpha * delta * phi_statestate = next_statereturn thetaclass SimpleEnvironment:def __init__(self):self.num_states = 5self.num_actions = 2def reset(self):return 0def step(self, action):# 简单模拟环境的状态转移和奖赏if action == 0:next_state = np.random.choice(self.num_states)reward = np.random.normal(0, 1)else:next_state = np.random.choice(self.num_states)reward = np.random.normal(1, 1)done = False  # 假设不会结束return next_state, reward, done# 示例运行
env = SimpleEnvironment()
num_episodes = 1000
alpha = 0.1
gamma = 0.9
theta = np.random.rand(2)
theta = linear_value_approximation(env, num_episodes, alpha, gamma, theta)
print("Estimated theta:", theta)

六、模仿学习

1. 基本概念
  • 模仿学习旨在让智能体通过模仿专家的行为来学习策略,通常用于解决难以通过奖赏函数定义的任务。包括行为克隆(Behavior Cloning)、逆强化学习(Inverse Reinforcement Learning)等方法。
2. 代码示例(行为克隆)
import numpy as np
from sklearn.linear_model import LogisticRegressiondef behavior_cloning(expert_states, expert_actions):# 假设专家状态和动作是已知的model = LogisticRegression()model.fit(expert_states, expert_actions)return model# 示例运行
expert_states = np.random.rand(100, 2)  # 假设专家状态是二维的
expert_actions = np.random.randint(0, 2, 100)  # 专家动作是 0 或 1
model = behavior_cloning(expert_states, expert_actions)
print("Trained model:", model)

在这里插入图片描述

代码解释

k-摇臂赌博机代码解释:
  • k_arm_bandit 函数:
    • true_rewards:每个摇臂的真实期望奖赏。
    • estimated_rewards:对每个摇臂奖赏的估计。
    • num_pulls:每个摇臂被拉动的次数。
    • 使用 (\epsilon)-贪心算法,以概率 (\epsilon) 随机选择摇臂,以概率 (1 - \epsilon) 选择估计奖赏最高的摇臂。
有模型学习代码解释:
  • value_iteration 函数:
    • P:状态转移矩阵。
    • R:奖赏矩阵。
    • 通过迭代更新状态值函数 (V(s)),直到收敛((\Delta < \theta))。
免模型学习代码解释:
  • td_0 函数:
    • V:状态值函数。
    • 通过 TD(0) 更新规则 (V(S_t)\leftarrow V(S_t)+\alpha(R_{t+1}+\gamma V(S_{t+1})-V(S_t))) 来更新值函数。
值函数近似代码解释:
  • linear_value_approximation 函数:
    • 使用线性函数 (V(s;\theta)=\theta^T\phi(s)) 来近似值函数。
    • 通过更新参数 (\theta) 来学习。
模仿学习代码解释:
  • behavior_cloning 函数:
    • 使用逻辑回归模型来学习专家的状态 - 动作映射。

算法比对

在这里插入图片描述

请注意,上述代码仅为简单示例,在实际应用中可能需要更复杂的环境和算法调整。同时,对于使用的库,如 numpysklearn,你可以使用 pip 安装:

pip install numpy sklearn

在这里插入图片描述

http://www.hkea.cn/news/450490/

相关文章:

  • 旅游网站 建设平台分析百度seo一本通
  • 怎么用dw做网站app开发网站
  • 昆山做网站的公司有哪些seo整站优化推广
  • 网站建设谈单情景对话青岛seo百科
  • 网站做自适应好不好网页分析报告案例
  • 大连手机自适应网站建设公司seo诊断站长
  • 有哪些好的网站十大电商代运营公司
  • 个人网页设计欣赏网站整站优化快速排名
  • 多少钱立案seo 公司
  • 医学类的网站做Google百度怎么优化排名
  • 手机网站怎样做枸橼酸西地那非片的功效与作用
  • 邯郸做wap网站的公司六六seo基础运营第三讲
  • 六安市建设银行网站seo编辑的工作内容
  • seo外包平台福州百度快照优化
  • 橙子建站广告怎么投放竞价网络推广
  • 中国公司查询网站网络公司起名
  • wordpress邮箱内容更改一键关键词优化
  • 楼市最新消息2022年房价走势seo网络推广经理
  • wordpress免费中文企业主题seo权重优化软件
  • 周口网站建设哪家好济南专业seo推广公司
  • 济南网站忧化怎么把抖音关键词做上去
  • 网站建设与维护的题目网站点击软件排名
  • 网站收录服务企业网络的组网方案
  • nba排名灰色词seo排名
  • 如何建自己的个人网站深圳市seo上词多少钱
  • 迎访问中国建设银行网站_永久免费的电销外呼系统
  • 类似AG网站建设网络营销的十大特点
  • 河北盘古做的网站用的什么服务器品牌策划与推广
  • 做网站开发的是不是程序员品牌营销与推广
  • 安卓android软件seo搜索引擎优化方式