質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
強化学習

強化学習とは、ある環境下のエージェントが現状を推測し行動を決定することで報酬を獲得するという見解から、その報酬を最大限に得る方策を学ぶ機械学習のことを指します。問題解決時に得る報酬が選択結果によって変化することで、より良い行動を選択しようと学習する点が特徴です。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

1469閲覧

Unity強化学習のQiitaチュートリアルでScriptを取り付けることが出来ず困っています。

aguroshou

総合スコア22

強化学習

強化学習とは、ある環境下のエージェントが現状を推測し行動を決定することで報酬を獲得するという見解から、その報酬を最大限に得る方策を学ぶ機械学習のことを指します。問題解決時に得る報酬が選択結果によって変化することで、より良い行動を選択しようと学習する点が特徴です。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/04/28 12:13

編集2019/04/28 12:19

前提・実現したいこと

【Unity強化学習】自作ゲームで強化学習
https://qiita.com/God_KonaBanana/items/7aebdb411c99b059cc6f
こちらのサイトを見ながらチュートリアルを進めています。

発生している問題・エラーメッセージ

チュートリアルの途中で
「ML-Agents>ScriptsにBrainがあるのでこれをCartPoleBrain(オブジェクト)に取り付けます。」
とあるのですが、

The associated script can not be loaded. Please fix any compile errors and assign a valid script.

となってしまい、うまく取り付けることが出来ていないようです。

該当のソースコード

C#

1using System.Collections.Generic; 2using UnityEngine; 3 4namespace MLAgents 5{ 6 /// <summary> 7 /// Brain receive data from Agents through calls to SendState. The brain then updates the 8 /// actions of the agents at each FixedUpdate. 9 /// The Brain encapsulates the decision making process. Every Agent must be assigned a Brain, 10 /// but you can use the same Brain with more than one Agent. You can also create several 11 /// Brains, attach each of the Brain to one or more than one Agent. 12 /// Brain assets has several important properties that you can set using the Inspector window. 13 /// These properties must be appropriate for the Agents using the Brain. For example, the 14 /// Vector Observation Space Size property must match the length of the feature 15 /// vector created by an Agent exactly. 16 /// </summary> 17 public abstract class Brain : ScriptableObject 18 { 19 [SerializeField] public BrainParameters brainParameters; 20 21 protected Dictionary<Agent, AgentInfo> agentInfos = 22 new Dictionary<Agent, AgentInfo>(1024); 23 24 protected Batcher brainBatcher; 25 26 [System.NonSerialized] 27 private bool _isInitialized; 28 29 /// <summary> 30 /// Sets the Batcher of the Brain. The brain will call the batcher at every step and give 31 /// it the agent's data using SendBrainInfo at each DecideAction call. 32 /// </summary> 33 /// <param name="batcher"> The Batcher the brain will use for the current session</param> 34 public void SetBatcher(Batcher batcher) 35 { 36 if (batcher == null) 37 { 38 brainBatcher = null; 39 } 40 else 41 { 42 brainBatcher = batcher; 43 brainBatcher.SubscribeBrain(name); 44 } 45 LazyInitialize(); 46 } 47 48 /// <summary> 49 /// Adds the data of an agent to the current batch so it will be processed in DecideAction. 50 /// </summary> 51 /// <param name="agent"></param> 52 /// <param name="info"></param> 53 public void SendState(Agent agent, AgentInfo info) 54 { 55 LazyInitialize(); 56 agentInfos.Add(agent, info); 57 58 } 59 60 /// <summary> 61 /// If the Brain is not initialized, it subscribes to the Academy's DecideAction Event and 62 /// calls the Initialize method to be implemented by child classes. 63 /// </summary> 64 private void LazyInitialize() 65 { 66 if (!_isInitialized) 67 { 68 var academy = FindObjectOfType<Academy>(); 69 if (academy) 70 { 71 academy.BrainDecideAction += BrainDecideAction; 72 academy.DestroyAction += Shutdown; 73 Initialize(); 74 _isInitialized = true; 75 } 76 } 77 } 78 79 /// <summary> 80 /// Called by the Academy when it shuts down. This ensures that the Brain cleans up properly 81 /// after scene changes. 82 /// </summary> 83 private void Shutdown() 84 { 85 if (_isInitialized) 86 { 87 agentInfos.Clear(); 88 89 _isInitialized = false; 90 } 91 } 92 93 /// <summary> 94 /// Calls the DecideAction method that the concrete brain implements. 95 /// </summary> 96 private void BrainDecideAction() 97 { 98 brainBatcher?.SendBrainInfo(name, agentInfos); 99 DecideAction(); 100 } 101 102 /// <summary> 103 /// Is called only once at the begening of the training or inference session. 104 /// </summary> 105 protected abstract void Initialize(); 106 107 /// <summary> 108 /// Is called once per Environment Step after the Brain has been initialized. 109 /// </summary> 110 protected abstract void DecideAction(); 111 } 112}

試したこと

namespace MLAgents、public abstract classの意味を調べてみたのですが、正直どうすればいいのか分かりませんでした。
私が適当にプログラムを書き換えて一時的にエラーが出なくなったとしても、別のプログラムに影響する可能性があるのでプログラムの書き換えはしていません。

補足情報(FW/ツールのバージョンなど)

Qiitaの記事が1年ほど前なので、その間に
https://github.com/Unity-Technologies/ml-agents
こちらのサイトのデータが変更され、その影響でうまく実行できていない可能性があります。
その場合には諦めて別のチュートリアルを参考にUnityの強化学習を進めていく事も考えています。
私は強化学習のチュートリアルを手順通りに行う程度の知識しか無く、自分で0から強化学習を制作していく能力はありません。
イメージ説明

初めてUnityで強化学習を体験したい私へアドバイスをするだけでも構わないので、ご回答よろしくお願いします。
ここまで質問内容をお読みいただきありがとうございます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

すみません。ML-Agentsのバージョンをv0.4ではなく最新のものを使用していました。
もう一度v0.4で試してから再度質問したいと思います。
もし解決方法を考えて下さった方がいたら申し訳ございません。

投稿2019/04/28 12:34

aguroshou

総合スコア22

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問