Exemple #1
0
        /* convert a list of symbols to an action, false on failure */
        bool symsToAction(symbol_list_t symlist, action_t action)
        {
            action = 0;

            //symbol_list_t::const_reverse_iterator it = symlist.rbegin();
            //for (UInt64 c = 0; it != symlist.rend(); ++it, c++) {
            //    if (*it == On) action |= (1 << c);
            //}
            UInt16 c = 0;

            foreach (bool bit in  symlist.reverseIterator())
            {
                if (bit == true)
                {
                    action = action | ((UInt64)1 << c);
                }
                c++;
            }

            return(isActionOk(action));
        }
Exemple #2
0
        /* interprets a list of symbols as a reward */
        public reward_t  rewardFromPercept(symbol_list_t percept)
        {
            // assert(percept.size() == m_obs_bits_c + m_rew_bits_c);

            // symbol_list_t::const_reverse_iterator it = percept.rbegin();
            //int it = 0;
            IEnumerator it = percept.reverseIterator().GetEnumerator();

            if (m_base2_reward_encoding)
            {     // base2 reward encoding
                int r = 0;
                for (int c = 0; c < m_rew_bits; it.MoveNext())
                {
                    //assert(it != percept.rend());
                    if ((bool)it.Current == true)
                    {
                        r |= (1 << c);
                    }
                    c++;
                }
                return((double)(r));
            }

            // assume the reward is the number of on bits
            double reward = 0.0;

            it.MoveNext();
            for (int c = 0; c < m_rew_bits; it.MoveNext())
            {
                //assert(it != percept.rend());
                if ((bool)it.Current == true)
                {
                    reward += 1.0;
                }
                c++;
            }

            return(reward);
        }