用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill rl-model-based命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | rl-model-based |
| description | 模型-based 强化学习技能 - World Models、MPC、PlaNet、MuZero 实现 |
| argument-hint | World Models OR MPC OR PlaNet OR 模型学习 OR model based RL |
| user-invocable | true |
学习环境模型的强化学习方法 - 数据效率高的机器人学习
当需要以下帮助时使用此技能:
import torch
import torch.nn as nn
class WorldModel:
def __init__(self, state_dim, action_dim, hidden_dim=256):
# 编码器
self.encoder = nn.Sequential(
nn.Linear(state_dim + action_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, state_dim) # 潜在空间
)
# 奖励预测器
self.reward_predictor = nn.Sequential(
nn.Linear(state_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, 1)
)
# 判别器 (用于 VAE)
self.discriminator = nn.Sequential(
nn.Linear(state_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, 1),
nn.Sigmoid()
)
def forward(self, state, action):
# 预测下一个潜在状态
next_latent = self.encoder(torch.cat([state, action], dim=-1))
reward = self.reward_predictor(next_latent)
return next_latent, reward
def imagine_rollout(self, initial_state, policy, horizon=50):
"""想象轨迹展开"""
states = [initial_state]
rewards = []
for _ in range(horizon):
action = policy(states[-1])
next_state, reward = self.forward(states[-1], action)
states.append(next_state)
rewards.append(reward)
return states, rewards
class MPCController:
def __init__(self, world_model, action_dim, horizon=10, num_samples=100):
self.world_model = world_model
self.action_dim = action_dim
self.horizon = horizon
self.num_samples = num_samples
def get_action(self, state, policy_net=None):
best_action = None
best_reward = float('-inf')
for _ in range(self.num_samples):
# 随机采样动作序列
actions = torch.randn(self.horizon, self.action_dim)
# 模拟轨迹
current_state = state
total_reward = 0
for t in range(self.horizon):
next_state, reward = self.world_model(current_state, actions[t])
total_reward += reward
if total_reward > best_reward:
best_reward = total_reward
best_action = actions[0]
return best_action.unsqueeze(0)