
I'm interested in 2nd order stats for complex numbers. typedef std::complex<double> complex_t; typedef accumulator_set<complex_t, stats<tag::mean, tag::moment<2> > > acc_t; 2 issues: 1) Need template<typename flt_t> inline std::complex<flt_t> operator/ (std::complex<flt_t> const& a, unsigned long int b) { return std::complex<flt_t> (real (a)/b, imag (a)/b); } 2) What do I get for moment<2> in the case of complex (and does this match the usual mathematical definition?)

Neal Becker wrote:
I'm interested in 2nd order stats for complex numbers.
typedef std::complex<double> complex_t; typedef accumulator_set<complex_t, stats<tag::mean, tag::moment<2> > > acc_t;
2 issues:
1) Need template<typename flt_t> inline std::complex<flt_t> operator/ (std::complex<flt_t> const& a, unsigned long int b) { return std::complex<flt_t> (real (a)/b, imag (a)/b); }
2) What do I get for moment<2> in the case of complex (and does this match the usual mathematical definition?)
I believe what I want to is mean, and \sum |x- mean(x)|**2 Can I do this with accumlators framework?

Neal Becker wrote:
Neal Becker wrote:
I'm interested in 2nd order stats for complex numbers.
typedef std::complex<double> complex_t; typedef accumulator_set<complex_t, stats<tag::mean, tag::moment<2> > > acc_t;
2 issues:
1) Need template<typename flt_t> inline std::complex<flt_t> operator/ (std::complex<flt_t> const& a, unsigned long int b) { return std::complex<flt_t> (real (a)/b, imag (a)/b); }
This should work if you #include <boost/accumulators/numeric/functional/complex.hpp>, or better, compile with BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT defined.
2) What do I get for moment<2> in the case of complex (and does this match the usual mathematical definition?)
I believe what I want to is mean, and \sum |x- mean(x)|**2
Can I do this with accumlators framework?
Yes, I believe so. -- Eric Niebler BoostPro Computing http://www.boostpro.com

This seems to work: namespace boost { namespace accumulators { namespace impl { template<typename Sample> struct abs_sqr_accumulator : accumulator_base { typedef typename Sample::value_type result_type; template<typename Args> abs_sqr_accumulator (Args const& args) {} template<typename Args> void operator () (Args const& args) { this->sum += real (args[sample] * conj (args[sample])); } template<typename Args> result_type result (Args const& args) const { return boost::numeric::average (this->sum, count (args)); } result_type sum; }; }}} namespace boost { namespace accumulators { namespace tag { struct abs_sqr : depends_on< count > // depends_on<> to specify dependencies { // Define a nested typedef called 'impl' that specifies which // accumulator implements this feature. typedef accumulators::impl::abs_sqr_accumulator< mpl::_1 > impl; }; }}} namespace boost { namespace accumulators { namespace extract { extractor< tag::abs_sqr> const abs_sqr = {}; } using extract::abs_sqr; } }
participants (2)
-
Eric Niebler
-
Neal Becker