Example #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;
            }
        }
Example #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;
                    }
                }
            }
        }
Example #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];
        }
Example #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;
                        }
                    }
                }
            }
        }
Example #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);
             }
         }
     }
 }
Example #6
0
 public virtual void AddReward(float v, RewardFunc from = null)
 {
     if (from != null && from.causeEpisodeToEnd)
     {
         this.RequestDoneFrom(from);
     }
     reward += v;
 }
Example #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;
        }
Example #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);
         }
     }
 }
Example #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;
         }
     }
 }
Example #11
0
        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);
                }
            }
        }
Example #12
0
 public virtual void AddReward(float v, RewardFunc from = null)
 {
     reward += v;
 }
Example #13
0
 public override void RequestDoneFrom(RewardFunc rf)
 {
     Done = true;
 }
Example #14
0
 public virtual void SubReward(float v, RewardFunc from = null)
 {
     reward -= v;
 }
Example #15
0
 public virtual void RequestDoneFrom(RewardFunc rf)
 {
 }
Example #16
0
 public void Unsubscribe(RewardFunc rf)
 {
     notificationList.Remove(rf);
 }
Example #17
0
 public void Subscribe(RewardFunc rf)
 {
     notificationList.Add(rf);
 }
Example #18
0
 public virtual void OnNotificationFrom(RewardFunc notifier, float reward)
 {
 }