MDP的curriculums部分

article/2025/7/14 15:49:36

文章目录

  • 1. isaaclab中的curriculums
    • 1.1 modify_reward_weight
      • 1.1.1 函数功能
      • 1.1.2 参数详解
      • 1.1.3 函数逻辑
      • 1.1.4 如何使用
  • 2. isaaclab_task中的curriculums
    • 2.1 terrain_levels_vel
      • 2.1 功能概述
      • 2.2 函数参数
      • 2.3 函数逻辑
  • 3. robot_lab中的curriculums
    • 3.1 command_levels_vel

1. isaaclab中的curriculums

路径:IsaacLab/source/isaaclab/isaaclab/envs/mdp/curriculums.py

1.1 modify_reward_weight

# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause"""Common functions that can be used to create curriculum for the learning environment.The functions can be passed to the :class:`isaaclab.managers.CurriculumTermCfg` object to enable
the curriculum introduced by the function.
"""from __future__ import annotationsfrom collections.abc import Sequence
from typing import TYPE_CHECKINGif TYPE_CHECKING:from isaaclab.envs import ManagerBasedRLEnvdef modify_reward_weight(env: ManagerBasedRLEnv, env_ids: Sequence[int], term_name: str, weight: float, num_steps: int):"""Curriculum that modifies a reward weight a given number of steps.Args:env: The learning environment.env_ids: Not used since all environments are affected.term_name: The name of the reward term.weight: The weight of the reward term.num_steps: The number of steps after which the change should be applied."""if env.common_step_counter > num_steps: # 检查当前全局步数是否超过设定的阈值# obtain term settings 通过环境中的奖励管理器获取特定奖励项的配置对象term_cfg = env.reward_manager.get_term_cfg(term_name) # update term settingsterm_cfg.weight = weight # 直接修改配置对象的权重属性env.reward_manager.set_term_cfg(term_name, term_cfg) #将修改后的配置重新设置到奖励管理器中

1.1.1 函数功能

这是一个用于动态调整强化学习环境中特定奖励项权重的课程学习函数。该函数允许在训练过程中根据训练进度(步数)动态修改奖励函数中特定奖励项的权重值。

1.1.2 参数详解

env: ManagerBasedRLEnv当前的强化学习环境对象实例提供对奖励管理器和其他环境状态的访问env_ids: Sequence[int]需要应用此修改的环境ID序列当前实现中此参数未被使用,修改会应用到所有环境term_name: str​​关键参数​​:需要调整权重的奖励项的名称必须与奖励管理器配置中的项名匹配weight: float​​关键参数​​:要设置的新权重值可以是任何浮点数(正数表示奖励,负数表示惩罚)num_steps: int​​关键参数​​:触发此权重修改的步数阈值当环境的全局步数超过此值时应用修改

1.1.3 函数逻辑

在这里插入图片描述

1.1.4 如何使用

  1. 在环境配置中定义课程
    你需要在环境配置文件中创建一个 CurriculumCfg 类,并使用 CurriculumTermCfg(别名为 CurrTerm)来配置课程项:
from isaaclab.managers import CurriculumTermCfg as CurrTerm
import isaaclab.envs.mdp as mdp@configclass
class CurriculumCfg:"""Curriculum terms for the MDP."""# 示例:在4500步后将action_rate奖励权重从-0.0001改为-0.005action_rate = CurrTerm(func=mdp.modify_reward_weight, params={"term_name": "action_rate",    # 要修改的奖励项名称"weight": -0.005,             # 新的权重值"num_steps": 4500             # 在第4500步后生效})# 另一个示例:修改关节速度惩罚joint_vel = CurrTerm(func=mdp.modify_reward_weight, params={"term_name": "joint_vel", "weight": -0.001, "num_steps": 4500})
  1. 在主环境配置中包含课程配置
@configclass
class MyEnvCfg(ManagerBasedRLEnvCfg):"""你的环境配置"""# 其他配置...rewards: RewardsCfg = RewardsCfg()curriculum: CurriculumCfg = CurriculumCfg()  # 添加课程配置
  1. 确保奖励项存在
@configclass
class RewardsCfg:"""Reward terms for the MDP."""# 这些奖励项必须存在,才能被课程修改action_rate = RewTerm(func=mdp.action_rate_l2, weight=-0.0001)joint_vel = RewTerm(func=mdp.joint_vel_l2,weight=-0.0001,params={"asset_cfg": SceneEntityCfg("robot")},)

2. isaaclab_task中的curriculums

2.1 terrain_levels_vel

路径:IsaacLab/source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/mdp/curriculums.py

# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause"""Common functions that can be used to create curriculum for the learning environment.The functions can be passed to the :class:`isaaclab.managers.CurriculumTermCfg` object to enable
the curriculum introduced by the function.
"""from __future__ import annotationsimport torch
from collections.abc import Sequence
from typing import TYPE_CHECKINGfrom isaaclab.assets import Articulation
from isaaclab.managers import SceneEntityCfg
from isaaclab.terrains import TerrainImporterif TYPE_CHECKING:from isaaclab.envs import ManagerBasedRLEnvdef terrain_levels_vel(env: ManagerBasedRLEnv, env_ids: Sequence[int], asset_cfg: SceneEntityCfg = SceneEntityCfg("robot")
) -> torch.Tensor:"""Curriculum based on the distance the robot walked when commanded to move at a desired velocity.This term is used to increase the difficulty of the terrain when the robot walks far enough and decrease thedifficulty when the robot walks less than half of the distance required by the commanded velocity... note::It is only possible to use this term with the terrain type ``generator``. For further informationon different terrain types, check the :class:`isaaclab.terrains.TerrainImporter` class.Returns:The mean terrain level for the given environment ids."""# extract the used quantities (to enable type-hinting)asset: Articulation = env.scene[asset_cfg.name] # 机器人对象terrain: TerrainImporter = env.scene.terrain # 地形对象command = env.command_manager.get_command("base_velocity") # 速度命令# compute the distance the robot walked# 从环境初始位置到当前位置的水平距离 (X-Y平面)distance = torch.norm(asset.data.root_pos_w[env_ids, :2] - env.scene.env_origins[env_ids, :2], dim=1)# robots that walked far enough progress to harder terrainsmove_up = distance > terrain.cfg.terrain_generator.size[0] / 2# robots that walked less than half of their required distance go to simpler terrainsmove_down = distance < torch.norm(command[env_ids, :2], dim=1) * env.max_episode_length_s * 0.5move_down *= ~move_up# update terrain levelsterrain.update_env_origins(env_ids, move_up, move_down)# return the mean terrain levelreturn torch.mean(terrain.terrain_levels.float())

2.1 功能概述

这是一个基于机器人行走距离的地形难度自适应课程学习策略函数。它根据机器人在给定速度命令下实际行走的距离,自动调整训练环境中的地形难度级别。

2.2 函数参数

env: ManagerBasedRLEnv强化学习环境实例提供访问场景对象、命令系统和其他环境状态env_ids: Sequence[int]需要处理的环境ID序列允许针对特定子集环境应用课程学习asset_cfg: SceneEntityCfg = SceneEntityCfg("robot")场景实体配置(默认为"robot")指定课程学习作用的机器人对象

2.3 函数逻辑

在这里插入图片描述

3. robot_lab中的curriculums

3.1 command_levels_vel

# Copyright (c) 2024-2025 Ziqi Fan
# SPDX-License-Identifier: Apache-2.0"""
机器人学习环境课程学习模块该模块包含了用于创建课程学习的通用函数。课程学习是一种渐进式训练方法,
通过逐步增加任务难度来提高机器人的学习效率和最终性能。主要功能:
1. 基于奖励的自适应课程调整
2. 速度命令范围的动态扩展
3. 任务难度的渐进式增加这些函数可以传递给 :class:`isaaclab.managers.CurriculumTermCfg` 对象,
以启用相应的课程学习功能。
"""from __future__ import annotationsimport torch
from collections.abc import Sequence
from typing import TYPE_CHECKINGif TYPE_CHECKING:from isaaclab.envs import ManagerBasedRLEnvdef command_levels_vel(env: ManagerBasedRLEnv, env_ids: Sequence[int], reward_term_name: str, max_curriculum: float = 1.0
) -> None:"""基于机器人速度跟踪奖励的课程学习函数该函数根据机器人在执行指定速度命令时的跟踪奖励来调整课程难度。当机器人的跟踪奖励超过最大值的80%时,会增加命令的范围,从而逐步提高任务的难度。Args:env: 强化学习环境对象env_ids: 需要更新课程的环境ID序列reward_term_name: 用于评估的奖励项名称max_curriculum: 课程学习的最大难度值,默认为1.0Returns:float: 线性速度命令范围的累积增量工作原理:1. 获取指定奖励项的累积值2. 计算平均奖励与最大奖励的比值3. 如果比值超过80%,则扩展速度命令范围4. 返回当前的速度增量值课程策略:- 初始阶段:较小的速度命令范围,便于机器人学习基础运动- 进阶阶段:随着性能提升,逐步扩大命令范围- 最终阶段:达到最大课程难度,测试机器人的极限性能"""# 获取指定奖励项的累积值episode_sums = env.reward_manager._episode_sums[reward_term_name]# 获取奖励项的配置信息reward_term_cfg = env.reward_manager.get_term_cfg(reward_term_name)# 获取基础速度命令的范围配置base_velocity_ranges = env.command_manager.get_term("base_velocity").cfg.ranges# 定义速度范围的增量值(对称增加)delta_range = torch.tensor([-0.1, 0.1], device=env.device)# 初始化线性速度增量(如果不存在)if not hasattr(env, "delta_lin_vel"):env.delta_lin_vel = torch.tensor(0.0, device=env.device)# 判断是否需要增加课程难度# 条件:平均奖励超过最大奖励的80%if torch.mean(episode_sums[env_ids]) / env.max_episode_length > 0.8 * reward_term_cfg.weight:# 获取当前的线性速度范围lin_vel_x = torch.tensor(base_velocity_ranges.lin_vel_x, device=env.device)lin_vel_y = torch.tensor(base_velocity_ranges.lin_vel_y, device=env.device)# 扩展X方向线性速度范围,并限制在最大课程范围内base_velocity_ranges.lin_vel_x = torch.clamp(lin_vel_x + delta_range, -max_curriculum, max_curriculum).tolist()# 扩展Y方向线性速度范围,并限制在最大课程范围内base_velocity_ranges.lin_vel_y = torch.clamp(lin_vel_y + delta_range, -max_curriculum, max_curriculum).tolist()# 更新累积的线性速度增量env.delta_lin_vel = torch.clamp(env.delta_lin_vel + delta_range[1], 0.0, max_curriculum)# 返回当前的速度增量值,用于监控课程进度return env.delta_lin_vel

http://www.hkcw.cn/article/gyKrigLHpG.shtml

相关文章

【AUTOSAR OS】事件机制解析:定义、实现与应用

文章目录 一、Event的定义与作用二、核心数据结构三、重要函数实现与原理1. **事件初始化 Os_InitEvent()**2. **设置事件 SetEvent()/Os_SetEvent()**3. **等待事件 WaitEvent()/Os_WaitEvent()**4. **清除事件 ClearEvent()**5. **获取事件状态 GetEvent()** 四、应用示例&am…

单元测试-断言常见注解

目录 1.断言 2.常见注解 3.依赖范围 1.断言 断言练习 package com.gdcp;import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;//测试类 public class UserServiceTest {Testpublic void testGetGender(){UserService userService new UserService…

5.3.1_1二叉树的先中后序遍历

知识总览&#xff1a; 什么是遍历&#xff1a; 按照某种次序把所有节点都访问一遍 二叉树的遍历-分支节点逐层展开法(会这个就行)&#xff1a; 先序(根)遍历&#xff1a;根左右 中序(根)遍历&#xff1a;左根右 后序(根)遍历&#xff1a;左右根 分支节点逐层展开法&am…

SpringMVC的注解

1. SpringMVC:Spring Web MVC 2. RequestMapping 既是类注解&#xff0c;又是方法注解 3. 访问的URL路径&#xff1a;类路径方法路径 4.后端开发人员测试接口&#xff0c;通常使用postman或其他类似工具来发起请求 对于后端而言&#xff0c;使用postman或form表单&#xff0…

ipfs下载和安装(windows)

关于ipfs介绍&#xff0c;网上一大堆&#xff0c;这里就不讲了。 zip安装包下载衔接&#xff1a;https://github.com/ipfs/kubo/releases/download/v0.35.0/kubo_v0.35.0_windows-amd64.zip 下载之后解压&#xff0c;将文件放到一个合适的目录。 配置系统环境变量&#xff08…

World of Warcraft Hunter [Grandel] [Ancient Petrified Leaf]

World of Warcraft Hunter [Grandel] [Ancient Petrified Leaf] 猎人史诗弓任务 [远古石叶][罗克迪洛尔&#xff0c;上古守护者的手杖][伦鲁迪洛尔&#xff0c;上古守护者的长弓] 最伟大的猎手 Grandel&#xff0c;很多年前的图片。史诗弓流程。

【LeetCode 题解】两数之和(C++/Python 双解法):从语法到算法的全面解析

【LeetCode题解】两数之和&#xff08;C/Python双解法&#xff09;&#xff1a;从语法到算法的全面解析 一、题目描述 题目链接&#xff1a;1. 两数之和 难度&#xff1a;简单 要求&#xff1a;给定一个整数数组 nums 和一个整数目标值 target&#xff0c;在数组中找出两个数…

《AI Agent项目开发实战》DeepSeek R1模型蒸馏入门实战

一、模型蒸馏环境部署 注&#xff1a;本次实验仍然采用Ubuntu操作系统&#xff0c;基本配置如下&#xff1a; 需要注意的是&#xff0c;本次公开课以Qwen 1.5-instruct模型为例进行蒸馏&#xff0c;从而能省略冷启动SFT过程&#xff0c;并且 由于Qwen系列模型本身性能较强&…

17.进程间通信(三)

一、System V 消息队列基本结构与理解 消息队列是全双工通信&#xff0c;可以同时收发消息。 结论1&#xff1a;消息队列提供了一种&#xff0c;一个进程给另一个进程发送有类型数据块的方式&#xff01; 结论2&#xff1a;OS中消息队列可能有多个&#xff0c;要对消息队列进行…

【汽车电子入门】一文了解LIN总线

前言&#xff1a;LIN&#xff08;Local Interconnect Network&#xff09;总线&#xff0c;也就是局域互联网的意思&#xff0c;它的出现晚于CAN总线&#xff0c;于20世纪90年代末被摩托罗拉、宝马、奥迪、戴姆勒、大众以及沃尔沃等多家公司联合开发&#xff0c;其目的是提供一…

BayesFlow:基于神经网络的摊销贝叶斯推断框架

贝叶斯推断为不确定性条件下的推理、复杂系统建模以及基于观测数据的预测提供了严谨且功能强大的理论框架。尽管贝叶斯建模在理论上具有优雅性&#xff0c;但在实际应用中经常面临显著的计算挑战&#xff1a;后验分布通常缺乏解析解&#xff0c;模型验证和比较需要进行重复的推…

高压电绝缘子破损目标检测数据集简介与应用

在电力系统中&#xff0c;高压电绝缘子起着关键的绝缘与机械支撑作用。一旦发生破损&#xff0c;不仅影响输电线路的安全运行&#xff0c;还可能引发电力事故。因此&#xff0c;利用目标检测技术对高压绝缘子的破损情况进行智能识别&#xff0c;已成为当前电力巡检中的重要研究…

深度学习与神经网络 前馈神经网络

1.神经网络特征 无需人去告知神经网络具体的特征是什么&#xff0c;神经网络可以自主学习 2.激活函数性质 &#xff08;1&#xff09;连续并可导&#xff08;允许少数点不可导&#xff09;的非线性函数 &#xff08;2&#xff09;单调递增 &#xff08;3&#xff09;函数本…

paoxiaomo的XCPC算法竞赛训练经验

楼主作为一个普通二本的ICPC选手&#xff0c;在0基础的情况下凭借自学&#xff0c;获得过南昌邀请赛金牌&#xff0c;杭州区域赛银牌&#xff0c;一路上经历过不少的跌宕起伏&#xff0c;如今将曾经摸索出来的学习路线分享给大家 一&#xff0c;语言基础 学习C语言基础语法&a…

电力系统时间同步系统

电力系统中&#xff0c;电压、电流、功率变化等特征量测量都是时间相关函数[1]&#xff0c;统一精准的时间源对于电网安全稳定运行至关重要&#xff0c;因此&#xff0c;电力系统运行规程[2]中明确要求继电保护装置、自动化装置、安全稳定控制系统、能量管理系统和生产信息管理…

Codeforces Round 1028 (Div. 2)(A-D)

题面链接&#xff1a;Dashboard - Codeforces Round 1028 (Div. 2) - Codeforces A. Gellyfish and Tricolor Pansy 思路 要知道骑士如果没了那么这个人就失去了攻击手段&#xff0c;贪心的来说我们只需要攻击血量少的即可&#xff0c;那么取min比较一下即可 代码 void so…

金属材料资料

一、金属材料 1. 黑色金属材料&#xff08;钢铁材料&#xff09; 铸铁&#xff08;含碳量&#xff1e;2.11%&#xff09; 分类&#xff1a; 按碳存在形式&#xff1a;白口铸铁&#xff08;硬脆&#xff0c;炼钢原料&#xff09;、灰口铸铁&#xff08;应用最广&#xff09;、…

mysql专题上

连接服务器 mysql -h 127.0.0.1 -P 3306 -u root -p -h后接的是要连接的部署了mysql的主机&#xff0c;127.0.0.1指的是单机访问&#xff0c;如果没有指令则直接连接本地 -P后接的是端口号 一般是3306 -u后接的是要登入的用户 -p指要登陆密码 如果要退出可以直接quit mysql…

DAY43打卡

浙大疏锦行 kaggle找到一个图像数据集&#xff0c;用cnn网络进行训练并且用grad-cam做可视化 进阶&#xff1a;并拆分成多个文件 fruit_cnn_project/ ├─ data/ # 存放数据集&#xff08;需手动创建&#xff0c;后续放入图片&#xff09; │ ├─ train/ …