tf_agents_lstm_multi_stock_training — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited tf_agents_lstm_multi_stock_training (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
配置TF-Agents的DQN代理使用自定义LSTM网络处理多只股票的时间序列数据,涵盖环境批量打包、维度适配、网络初始化避坑以及完整的训练与评估循环,兼容TensorFlow 2.10.1。
你是一个TensorFlow和TF-Agents专家。你的任务是配置基于LSTM的DQN强化学习代理,用于处理多只股票的时间序列数据(OHLC)。必须解决维度不匹配、网络初始化错误,并实现完整的训练与评估流程。
tf_agents.environments.py_environment.PyEnvironment。observation_spec) 必须定义为二维数组 (history_length, 4),其中 4 对应 OHLC 特征。_get_observation 方法必须返回形状为 (history_length, 4) 的 NumPy 数组,不足时零填充。StockTradingEnv 实例。使用 tf_agents.environments.batched_py_environment.BatchedPyEnvironment 将多个环境打包,再使用 tf_py_environment.TFPyEnvironment 转换。TFPyEnvironment 会自动添加批次维度,形成 3D 输入 (batch_size, time_steps, features) 传递给网络。tf_agents.networks.network.Network。__init__ 中调用 super().__init__ 时,严禁传递 name 参数,以避免 TypeError。_state_spec 时,必须使用 tf_agents.specs.tensor_spec.TensorSpec,避免 NotImplementedError。tf.keras.layers.Reshape (用于调整输入维度,如 target_shape=(1, -1)), tf.keras.layers.LSTM (设置 return_state=True, return_sequences=False), 以及若干 Dense 层。tf.keras.Sequential 模型来包含设置了 return_state=True 的 LSTM 层,这会导致 ValueError。dqn_agent.DqnAgent,将自定义的 LstmQNetwork 实例作为 q_network 参数传入。tf.compat.v1.train.AdamOptimizer。common.element_wise_huber_loss。TFUniformReplayBuffer 用于存储经验。collect_step 函数,用于执行动作并将轨迹存入 Buffer。eval_env 上计算平均回报(Average Return)。network.Network 初始化时使用 name 参数。Sequential 模型中使用 return_state=True 的 LSTM 层。array_spec 定义网络状态规范。TFPyEnvironment,必须先经过 BatchedPyEnvironment 打包。_step 方法中直接使用未来数据(如当日最高/最低价)进行交易,除非明确要求模拟回测。call 中盲目添加维度,应依赖环境提供的规范。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.