result_type result(Args const &args) const
        {
            float_type threshold = sum_of_weights(args)
                             * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );

            std::size_t n = 0;
            Weight sum = Weight(0);

            while (sum < threshold)
            {
                if (n < static_cast<std::size_t>(tail_weights(args).size()))
                {
                    sum += *(tail_weights(args).begin() + n);
                    n++;
                }
                else
                {
                    if (std::numeric_limits<float_type>::has_quiet_NaN)
                    {
                        std::fill(
                            this->tail_means_.begin()
                          , this->tail_means_.end()
                          , std::numeric_limits<float_type>::quiet_NaN()
                        );
                    }
                    else
                    {
                        std::ostringstream msg;
                        msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
                        boost::throw_exception(std::runtime_error(msg.str()));
                    }
                }
            }

            std::size_t num_variates = tail_variate(args).begin()->size();

            this->tail_means_.clear();
            this->tail_means_.resize(num_variates, Sample(0));

            this->tail_means_ = std::inner_product(
                tail_variate(args).begin()
              , tail_variate(args).begin() + n
              , tail_weights(args).begin()
              , this->tail_means_
              , numeric::functional::plus<array_type const, array_type const>()
              , numeric::functional::multiply_and_promote_to_double<VariateType const, Weight const>()
            );

            float_type factor = sum * ( (is_same<Impl, relative>::value) ? non_coherent_weighted_tail_mean(args) : 1. );

            std::transform(
                this->tail_means_.begin()
              , this->tail_means_.end()
              , this->tail_means_.begin()
              , std::bind2nd(numeric::functional::divides<typename array_type::value_type const, float_type const>(), factor)
            );

            return make_iterator_range(this->tail_means_);
        }
예제 #2
0
파일: append.hpp 프로젝트: TyRoXx/silicium
 typename boost::disable_if<
     std::is_same<typename std::decay<Sink>::type::element_type,
                  boost::container::basic_string<Element>>,
     typename error_type<Sink>::type>::type
 append(Sink &&out, boost::container::basic_string<Element> const &str)
 {
     return out.append(
         make_iterator_range(str.data(), str.data() + str.size()));
 }
예제 #3
0
파일: append.hpp 프로젝트: TyRoXx/silicium
 typename std::enable_if<
     std::is_same<Element,
                  typename std::decay<Sink>::type::element_type>::value,
     typename error_type<Sink>::type>::type
 append(Sink &&out, Element const *c_str)
 {
     return out.append(make_iterator_range(
         c_str, c_str + std::char_traits<Element>::length(c_str)));
 }
예제 #4
0
        result_type result(Args const &args) const
        {
            std::size_t cnt = count(args);

            std::size_t n = static_cast<std::size_t>(
                std::ceil(
                    cnt * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] )
                )
            );

            std::size_t num_variates = tail_variate(args).begin()->size();

            this->tail_means_.clear();
            this->tail_means_.resize(num_variates, Sample(0));

            // If n is in a valid range, return result, otherwise return NaN or throw exception
            if (n < static_cast<std::size_t>(tail(args).size()))
            {
                this->tail_means_ = std::accumulate(
                    tail_variate(args).begin()
                  , tail_variate(args).begin() + n
                  , this->tail_means_
                  , numeric::plus
                );

                float_type factor = n * ( (is_same<Impl, relative>::value) ? non_coherent_tail_mean(args) : 1. );

                std::transform(
                    this->tail_means_.begin()
                  , this->tail_means_.end()
                  , this->tail_means_.begin()
#ifdef BOOST_NO_CXX98_BINDERS
                  , std::bind(std::divides<float_type>(), std::placeholders::_1, factor)
#else
                  , std::bind2nd(std::divides<float_type>(), factor)
#endif
                );
            }
            else
            {
                if (std::numeric_limits<float_type>::has_quiet_NaN)
                {
                    std::fill(
                        this->tail_means_.begin()
                      , this->tail_means_.end()
                      , std::numeric_limits<float_type>::quiet_NaN()
                    );
                }
                else
                {
                    std::ostringstream msg;
                    msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
                    boost::throw_exception(std::runtime_error(msg.str()));
                }
            }
            return make_iterator_range(this->tail_means_);
        }
예제 #5
0
            find_iterator(
                    RangeT& Col,
                    FinderT Finder ) :
                detail::find_iterator_base<IteratorT>(Finder,0)
            {
                iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_col(as_literal(Col));
                m_Match=make_iterator_range(::boost::begin(lit_col), ::boost::begin(lit_col));
                m_End=::boost::end(lit_col);

                increment();
            }
예제 #6
0
            split_iterator(
                    RangeT& Col,
                    FinderT Finder ) :
                detail::find_iterator_base<IteratorT>(Finder,0),
                m_bEof(false)
            {
                iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_col(::boost::as_literal(Col));
                m_Match=make_iterator_range(::boost::begin(lit_col), ::boost::begin(lit_col));
                m_Next=::boost::begin(lit_col);
                m_End=::boost::end(lit_col);

                // force the correct behavior for empty sequences and yield at least one token
                if(m_Next!=m_End)
                {
                    increment();
                }
            }
        result_type result(Args const &args) const
        {
            if (this->is_dirty)
            {
                this->is_dirty = false;

                // creates a vector of std::pair where each pair i holds
                // the values heights[i] (x-axis of histogram) and
                // actual_positions[i] / sum_of_weights (y-axis of histogram)

                for (std::size_t i = 0; i < this->histogram.size(); ++i)
                {
                    this->histogram[i] = std::make_pair(this->heights[i], numeric::fdiv(this->actual_positions[i], sum_of_weights(args)));
                }
            }

            return make_iterator_range(this->histogram);
        }
예제 #8
0
        result_type result(Args const &args) const
        {
            if (this->is_dirty)
            {
                this->is_dirty = false;

                // creates a vector of std::pair where each pair i holds
                // the values bin_positions[i] (x-axis of histogram) and
                // samples_in_bin[i] / cnt (y-axis of histogram).

                for (std::size_t i = 0; i < this->num_bins + 2; ++i)
                {
                    this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::average(this->samples_in_bin[i], count(args)));
                }
            }
            // returns a range of pairs
            return make_iterator_range(this->histogram);
        }
            inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
            make_range_impl( Range& r,
                             BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
                             BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
            {
                //
                // Not worth the effort
                //
                //if( advance_begin == 0 && advance_end == 0 )
                //    return make_iterator_range( r );
                //

                BOOST_DEDUCED_TYPENAME range_iterator<Range>::type
                    new_begin = lslboost::begin( r ),
                    new_end   = lslboost::end( r );
                std::advance( new_begin, advance_begin );
                std::advance( new_end, advance_end );
                return make_iterator_range( new_begin, new_end );
            }
예제 #10
0
    void GameStateManager::draw()
    {
        auto findStart = [&]
        {
            for (auto riter = std::rbegin(states), eriter = std::rend(states); riter != eriter; ++riter)
            {
                auto iter = next(riter).base();
                auto halts = iter->haltsDraw();
                if (halts) return iter;
            }
            return begin(states);
        };

        auto start = findStart();
        for (auto& state : make_iterator_range(start, end(states)))
        {
            state.draw();
        }
    }
예제 #11
0
            inline bool ends_with_iter_select( 
                ForwardIterator1T Begin, 
                ForwardIterator1T End, 
                ForwardIterator2T SubBegin,
                ForwardIterator2T SubEnd,
                PredicateT Comp,
                std::forward_iterator_tag)
            {
                if ( SubBegin==SubEnd )
                {
                    // empty subsequence check
                    return true;
                }

                iterator_range<ForwardIterator1T> Result
                    =last_finder( 
                        make_iterator_range(SubBegin, SubEnd),
                        Comp)(Begin, End);

                return !Result.empty() && Result.end()==End;
            }
예제 #12
0
 iterator_range<value_type *> to_range() const
 {
     return make_iterator_range(begin(), end());
 }
예제 #13
0
 ArcRange  arcs () const {   return make_iterator_range( arcBegin (), arcEnd () );   }
예제 #14
0
 IncEdgeRange incEdges( BaseNode const & n ) const {
   return make_iterator_range( incEdgeBegin( n ), incEdgeEnd( n ) );
 }
 bool dispatch_attribute_element(Component const& component, mpl::true_) const
 {
     return f(component, make_iterator_range(iter, end));
 }
예제 #16
0
bool TrackList::Contains(const Track * t) const
{
   return make_iterator_range( *this ).contains( t );
}
예제 #17
0
 memory_source<Element> make_c_str_source(Element const *c_str)
 {
     return memory_source<Element>(make_iterator_range(
         c_str, c_str + std::char_traits<Element>::length(c_str)));
 }
예제 #18
0
 memory_source<Element>
 make_container_source(std::basic_string<Element> const &container)
 {
     return memory_source<Element>(make_iterator_range(
         container.data(), container.data() + container.size()));
 }
예제 #19
0
 InArcRange   inArcs  ( BaseNode const & n ) const {
   return make_iterator_range( inArcBegin  ( n ), inArcEnd  ( n ) );
 }
예제 #20
0
iterator_range<typename range_access_iterator<Container>::type>
range(Container& cont)
{ return make_iterator_range(cont); }
예제 #21
0
 operator range_type () {
     return make_iterator_range(message_.headers().begin(), message_.headers().end());
 }
예제 #22
0
 operator range_type () {
     return make_iterator_range(headers_wrapper<Tag>::_message.headers().begin(), headers_wrapper<Tag>::_message.headers().end());
 };
예제 #23
0
 NodeRange nodes() const {   return make_iterator_range( nodeBegin(), nodeEnd() );   }
 bool dispatch_main(Component const& component, mpl::true_) const
 {
     return f(component, make_iterator_range(iter, end));
 }
예제 #25
0
 EdgeRange edges() const {   return make_iterator_range( edgeBegin(), edgeEnd() );   }
예제 #26
0
 mutable_memory_source<Element>
 make_container_source(std::array<Element, N> &&container)
 {
     return mutable_memory_source<Element>(make_iterator_range(
         container.data(), container.data() + container.size()));
 }
예제 #27
0
 OutArcRange  outArcs ( BaseNode const & n ) const {
   return make_iterator_range( outArcBegin ( n ), outArcEnd ( n ) );
 }