用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill rl-hyperparameter-tuning命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | rl-hyperparameter-tuning |
| description | 强化学习超参数自动调优技能 - Optuna、Ray Tune、Population-Based Training |
| argument-hint | 超参数调优 OR Optuna OR Ray Tune OR PBT OR hyperparameter |
| user-invocable | true |
自动优化 RL 算法超参数的技能
当需要以下帮助时使用此技能:
import optuna
import torch
import numpy as np
def objective(trial):
# 采样超参数
lr = trial.suggest_float('lr', 1e-5, 1e-2, log=True)
gamma = trial.suggest_float('gamma', 0.9, 0.999)
hidden_dim = trial.suggest_categorical('hidden_dim', [64, 128, 256, 512])
entropy_coef = trial.suggest_float('entropy_coef', 1e-4, 1e-1, log=True)
# 创建 Agent
agent = PPOLearner(
state_dim=STATE_DIM,
action_dim=ACTION_DIM,
lr=lr,
gamma=gamma,
hidden_dim=hidden_dim,
entropy_coef=entropy_coef
)
# 训练
for episode in range(MAX_EPISODES):
state = env.reset()
episode_reward = 0
while not done:
action = agent.select_action(state)
next_state, reward, done, _ = env.step(action)
agent.update(state, action, reward, next_state, done)
state = next_state
episode_reward += reward
trial.report(episode_reward, episode)
if trial.should_prune():
raise optuna.TrialPruned()
return episode_reward
# 运行优化
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100, timeout=3600)
class PBTTrainer:
def __init__(self, population_size=10):
self.population_size = population_size
self.population = []
def evolve(self):
# 选择最佳的一半
sorted_pop = sorted(self.population, key=lambda x: x.fitness, reverse=True)
survivors = sorted_pop[:self.population_size // 2]
new_population = survivors.copy()
for _ in range(self.population_size // 2):
# 克隆并变异
parent = np.random.choice(survivors)
child = self.mutate(parent)
new_population.append(child)
self.population = new_population
def mutate(self, parent):
child = {
'lr': parent['lr'] * np.random.uniform(0.8, 1.2),
'gamma': parent['gamma'] * np.random.uniform(0.99, 1.01),
'hidden_dim': parent['hidden_dim'],
'noise_std': parent['noise_std'] * np.random.uniform(0.9, 1.1)
}
return child