1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | using System.Collections.Generic; using UnityEngine; using MLAgents; public class RollerAgent : Agent { Rigidbody rBody; void Start () { rBody = GetComponent<Rigidbody>(); } public Transform Target; public override void AgentReset() { if (this.transform.position.y < 0) { // If the Agent fell, zero its momentum this.rBody.angularVelocity = Vector3.zero; this.rBody.velocity = Vector3.zero; this.transform.position = new Vector3( 0, 0.5f, 0); } // Move the target to a new spot Target.position = new Vector3(Random.value * 8 - 4, 0.5f, Random.value * 8 - 4); } public override void CollectObservations() { // 相対座標を計算(Calculate relative position) Vector3 relativePosition = Target.position - this.transform.position; // 相対座標を正規化して設定(Relative position) AddVectorObs(relativePosition.x/5); AddVectorObs(relativePosition.z/5); // 床の隅からの距離を正規化した値を設定(Distance to edges of platform) AddVectorObs((this.transform.position.x + 5)/5); AddVectorObs((this.transform.position.x - 5)/5); AddVectorObs((this.transform.position.z + 5)/5); AddVectorObs((this.transform.position.z - 5)/5); // エージェントの速度(Agent velocity) AddVectorObs(rBody.velocity.x/5); AddVectorObs(rBody.velocity.z/5); } public float speed = 10; public override void AgentAction(float[] vectorAction, string textAction) { // Targetとの距離 float distanceToTarget = Vector3.Distance( this.transform.position, Target.position); // Targetに接触したか if (distanceToTarget < 1.42f) { AddReward(1); Done(); } // 近づいたサブリワード if (distanceToTarget < previousDistance) { previousDistance = distanceToTarget; AddReward(0.03f); } // 近づかなかったペナルティ AddReward(-0.05f); // プラットフォームから転落 if (this.transform.position.y < -1.0) { AddReward(-1); Done(); } // 動作の設定。sizeが2なのでvectorActionは2つ Vector3 controlSignal = Vector3.zero; controlSignal.x = vectorAction[0]; controlSignal.z = vectorAction[1]; rBody.AddForce(controlSignal * speed); } } |
12月27日
動いたと思った日
https://twitter.com/Yuki1111117/status/1078107218283646976
今
動かん・・・
中身2
手順3
タイトル3
中身3
手順4
タイトル4
中身4
手順5
タイトル5
中身5
コメントを残す