예제 #1
0
        public override void OnNotificationFrom(RewardFunc notifier, float reward)
        {
            if (applied && !repeatable)
            {
                return;
            }

            if (notifier.Name == arguments[0].Name)
            {
                r   += reward;
                arg1 = true;
            }

            if (notifier.Name == arguments[1].Name)
            {
                r   += reward;
                arg2 = true;
            }

            if (arg1 && arg2)
            {
                float mixed = (1 - alfa) * successReward + alfa * r;
                NotifyAll(mixed);
                agent.AddReward(mixed, this, endEpisodeInSuccess);
                if (repeatable)
                {
                    arg1 = arg2 = false;
                }
                else
                {
                    applied = true;
                }
                r = 0.0f;
            }
        }
예제 #2
0
        public override void OnNotificationFrom(RewardFunc notifier, float reward)
        {
            var idx = events.IndexOf(notifier);

            if (idx != currentPos)
            {
                NotifyAll(failReward);
                agent.AddReward(failReward, this, endEpisodeInFail);
                if (resetAfterFail)
                {
                    currentPos = 0;
                }
            }
            else
            {
                currentPos++;
                if (currentPos >= events.Count)
                {
                    NotifyAll(successReward);
                    agent.AddReward(successReward, this, endEpisodeInSuccess);
                    if (resetAfterSuccess)
                    {
                        currentPos = 0;
                    }
                }
            }
        }
예제 #3
0
        public override void OnCreate()
        {
            r    = 0.0f;
            arg1 = arg2 = false;
            RewardFunc[] funcs = new RewardFunc[NB_OF_ARGS];

            if (negativeRewardFuncPath != null && positiveRewardFuncPath != null)
            {
                funcs[0] = GetNode(positiveRewardFuncPath) as RewardFunc;
                funcs[1] = GetNode(negativeRewardFuncPath) as RewardFunc;
                funcs[0].Subscribe(this);
                funcs[1].Subscribe(this);
            }
            else
            {
                var count = 0;
                foreach (Node node in GetChildren())
                {
                    if (node.GetType().IsSubclassOf(typeof(RewardFunc)))
                    {
                        RewardFunc r = node as RewardFunc;
                        funcs[count++] = r;
                        r.Subscribe(this);
                        if (count >= NB_OF_ARGS)
                        {
                            break;
                        }
                    }
                }
            }
            positiveRewardFunc = funcs[0];
            negativeRewardFunc = funcs[1];
        }
예제 #4
0
        public override void OnCreate()
        {
            arguments = new RewardFunc[NB_OF_ARGS];

            if (argOneRewardFuncPath != null && argTwoRewardFuncPath != null)
            {
                arguments[0] = GetNode(argOneRewardFuncPath) as RewardFunc;
                arguments[1] = GetNode(argTwoRewardFuncPath) as RewardFunc;
                arguments[0].Subscribe(this);
                arguments[1].Subscribe(this);
            }
            else
            {
                var count = 0;
                foreach (Node node in GetChildren())
                {
                    if (node.GetType().IsSubclassOf(typeof(RewardFunc)))
                    {
                        RewardFunc r = node as RewardFunc;
                        arguments[count++] = r;
                        r.Subscribe(this);
                        if (count >= NB_OF_ARGS)
                        {
                            break;
                        }
                    }
                }
            }
        }
예제 #5
0
 public override void OnCreate()
 {
     events = new List <RewardFunc>();
     if (eventsPath != null)
     {
         for (int i = 0; i < eventsPath.Count; i++)
         {
             RewardFunc rf = GetNode(eventsPath[i]) as RewardFunc;
             events.Add(rf);
             rf.Subscribe(this);
         }
     }
     else
     {
         foreach (Node node in GetChildren())
         {
             if (node.GetType().IsSubclassOf(typeof(RewardFunc)))
             {
                 RewardFunc r = node as RewardFunc;
                 events.Add(r);
                 r.Subscribe(this);
             }
         }
     }
 }
예제 #6
0
 public virtual void AddReward(float v, RewardFunc from = null)
 {
     if (from != null && from.causeEpisodeToEnd)
     {
         this.RequestDoneFrom(from);
     }
     reward += v;
 }
예제 #7
0
        public override void AddReward(float v, RewardFunc from = null)
        {
            if (doneAtNegativeReward && v < 0)
            {
                Done = true;
            }

            if (doneAtPositiveReward && v > 0)
            {
                Done = true;
            }
            base.AddReward(v, from);
        }
        public override void AddReward(float v, RewardFunc from = null)
        {
            if (doneAtNegativeReward && v < 0)
            {
                done = true;
            }

            if (doneAtPositiveReward && v > 0)
            {
                done = true;
            }
            reward += v;
        }
예제 #9
0
 public virtual void PreconditionFailListener(RewardFunc func, RewardFunc precondiction)
 {
     if (Done)
     {
         return;
     }
     if (func is TouchRewardFunc)
     {
         if (!checkFirstTouch(func.gameObject.tag) && !((TouchRewardFunc)func).allowNext)
         {
             this.RequestDoneFrom(func);
         }
     }
 }
예제 #10
0
 public override void OnNotificationFrom(RewardFunc notifier, float reward)
 {
     if (!test.ContainsKey(notifier.ID))
     {
         size++;
         test[notifier.ID] = true;
     }
     if (size > 0)
     {
         NotifyAll(successReward);
         agent.AddReward(successReward, this, endEpisodeInSuccess);
         if (resetAfterSuccess)
         {
             test = new Dictionary <string, bool>();
             size = 0;
         }
     }
 }
예제 #11
0
파일: RLAgent.cs 프로젝트: gilcoder/AI4U
        public virtual void AddReward(float v, RewardFunc from = null, bool causeEpisodeToEnd = false)
        {
            if (from.isJustAnEvent)
            {
                return;
            }
            RewardInfo info = new RewardInfo(null, v, nSteps, null);

            reward += v;
            if (from != null)
            {
                info.name     = from.Name;
                info.nodePath = from.GetPath();
                if (!rewardRegistry.ContainsKey(from.Name))
                {
                    rewardOcurrence.Add(info);
                    rewardRegistry[from.Name] = true;
                }
                if (causeEpisodeToEnd)
                {
                    this.RequestDoneFrom(from);
                }
            }
        }
예제 #12
0
 public virtual void AddReward(float v, RewardFunc from = null)
 {
     reward += v;
 }
예제 #13
0
 public override void RequestDoneFrom(RewardFunc rf)
 {
     Done = true;
 }
예제 #14
0
 public virtual void SubReward(float v, RewardFunc from = null)
 {
     reward -= v;
 }
예제 #15
0
 public virtual void RequestDoneFrom(RewardFunc rf)
 {
 }
예제 #16
0
파일: RewardFunc.cs 프로젝트: gilcoder/AI4U
 public void Unsubscribe(RewardFunc rf)
 {
     notificationList.Remove(rf);
 }
예제 #17
0
파일: RewardFunc.cs 프로젝트: gilcoder/AI4U
 public void Subscribe(RewardFunc rf)
 {
     notificationList.Add(rf);
 }
예제 #18
0
파일: RewardFunc.cs 프로젝트: gilcoder/AI4U
 public virtual void OnNotificationFrom(RewardFunc notifier, float reward)
 {
 }