RE: [boost] Statistics code example -usingcycliciterator/buffer/array
Thanks for this, which I have just got round to trying out.Sadly, MSVC 7.0 now gags on it as below. Is there something I need to #define? (I assume that the previous config.h is replaced by the boost config). Is the warning C4253 a worry? Is remains at warning level 3 (and I like things to be warning free at level 4 if possible). Thanks Paul Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK +44 1539 561830 Mobile +44 7714 33 02 04 Mobile mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] : test_cyclic_buffer.cpp j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(324) : warning C4253: 'boost::AssignableConcept::constraints' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(831) : see reference to class template instantiation 'boost::cyclic_buffer' being compiled j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(388) : error C2977: 'std::reverse_iterator' : too many template arguments C:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(723) : see declaration of 'std::reverse_iterator' j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(391) : error C2977: 'std::reverse_iterator' : too many template arguments C:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(723) : see declaration of 'std::reverse_iterator' j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(324) : warning C4253: 'boost::AssignableConcept::constraints' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name with [ TT=int ] test_cyclic_buffer.cpp(45) : see reference to class template instantiation 'boost::cyclic_buffer' being compiled with [ T=int, Alloc=std::vector>::allocator_type ] j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(388) : error C2977: 'std::reverse_iterator' : too many template arguments C:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(723) : see declaration of 'std::reverse_iterator' j:\Cpp\cyclic_buffer\cyclic_buffer.hpp(391) : error C2977: 'std::reverse_iterator' : too many template arguments C:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(723) : see declaration of 'std::reverse_iterator' | -Original Message- | From: [EMAIL PROTECTED] | [mailto:[EMAIL PROTECTED] Behalf Of Jan Gaspar | Sent: Thursday, April 10, 2003 4:07 PM | To: Boost mailing list | Subject: Re: [boost] Statistics code example - | usingcycliciterator/buffer/array | | | Hi all! | | I have refactored my implelentation of the cyclic buffer. Its | underlaying container is now vector | (previosly it was deque). There is still one problem - iterator | invalidation. If you add or remove an | element from the end of the buffer, the iterators becomes invalidated. | | Jan | | -- | Jan Gaspar | [EMAIL PROTECTED] | Whitestein Technologies | www.whitestein.com | Panenska 28 | SK-81103 Bratislava | Slovak Republic | Tel +421(2)5930-0721 | Fax +421(2)5443-5512 | | ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Statistics code example
Neal D. Becker wrote: My purpose was only to demonstrate a generic class to do stats for both scalar and complex types. I don't know if I have time or will-power to turn it into a real boost submission. I hope you don't mind, but I have taken your statistics class and vamped it up. I have made it more boost/standard library-like and fixed the portability problems (although I have only tested it on MSVC7). I have also added basic iterator and container support so it can make use of STL facilities. This will still require work, but the basics are there. Paul A. Bristow wrote: Sadly (but perhaps not too surpringly) this does not seem to work for MSVC 7.0 with complex. (OK without) I have got it working for complex and real numbers, but I don't know if the results are correct for the complex number test, because I don't know complex-based statistics; also, is it valid to use complex numbers with imaginary values in these statistics? To make it work I made 4 modifications: [1] wrapped the template partial specialization for compilers that don't support it; [2] the MSVC library does not overload std::abs for the different floating point types - this lead to conversion errors and an incorrect stddev/variance calculation; [3] the MSVC compiler complained that it could not divide a complex number by count, so I added conversions to the base type; [4] if template partial specialization is available, there will be complaints on the statistical functions about complex -> real number conversions - this is what stat_t< T >::convert is for. This has not been tested on any other compiler, so I don't know exactly how compatible it is. A full working example with at least a few comments might sell this better? I have created a basic test program with a few examples. This is not an extensive test, but will give a basic idea of how to use it. -rhd- mailto:[EMAIL PROTECTED] _ Surf together with new Shared Browsing http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059 statistics.zip Description: Zip compressed data ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Statistics code example
On Thursday 03 April 2003 03:54 pm, Paul A. Bristow wrote: > I believe this conjecture is correct, but I am still eagerly awaiting 7.1 > :-) > > This is quite interesting (though it needs Industrial Strengthening of > course), and could usefully generate the higher moments and other > statistical thingys too. My purpose was only to demonstrate a generic class to do stats for both scalar and complex types. I don't know if I have time or will-power to turn it into a real boost submission. > > And it makes me wonder if one could use a container like a circular buffer. > I can think of applications where one would like new data to pour in > continuously and to look back for mean (weighted Kalmanesque?), perhaps > only a limited distance. Using a vector or valarray would imply it would > grow for ever and run out of space eventually. (I think someone else > suggested something of this sort?) > Is the STL queue suitable? > We have actually seen some nice code for circular buffer, about 6months to 1 year back. I have brought the subject up here a couple of times. The most promising IMHO is cycle_iterator, which is an adaptor submitted by Gennadiy Rozental. I believe this is almost ready for a real boost submission. Last we left it, there were some questions of the semantics of the "distance" between iterators. In any case, the "distance" between iterators in a cyclic buffer is fuzzy. I think the semantics in cyclic_buffer are the ones I prefer. That is, the distance from A -> B is always interpreted as positive. ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RE: [boost] Statistics code example
I believe this conjecture is correct, but I am still eagerly awaiting 7.1 :-) This is quite interesting (though it needs Industrial Strengthening of course), and could usefully generate the higher moments and other statistical thingys too. And it makes me wonder if one could use a container like a circular buffer. I can think of applications where one would like new data to pour in continuously and to look back for mean (weighted Kalmanesque?), perhaps only a limited distance. Using a vector or valarray would imply it would grow for ever and run out of space eventually. (I think someone else suggested something of this sort?) Is the STL queue suitable? Paul Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK +44 1539 561830 Mobile +44 7714 33 02 04 Mobile mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Reece Dunn > Sent: Thursday, April 03, 2003 3:33 PM > To: [EMAIL PROTECTED] > Subject: Re: [boost] Statistics code example > > > MSVC 7 does not handle partial template specialization, so it will not > compile (you'll need to remove the above specialization). It should work for > MSVC 7.1 final beta, but I do not have a copy of it to verify. > > The solution would be to wrap the above in a guard statement similar to: > > #if !defined(BOOST_NO_PARTIAL_SPECIALIZATION) > template > struct Stat_t< std::complex > { > typedef typename std::complex::value_type value_t; > }; > #endif ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Statistics code example
Neal D. Becker wrote: Could you elaborate? What didn't work? Any ideas how to fix? I don't use MSVC. Looking at the code, I think the problem is this (although I have not yet tried it): template struct Stat_t< std::complex > { typedef typename std::complex::value_type value_t; }; MSVC 7 does not handle partial template specialization, so it will not compile (you'll need to remove the above specialization). It should work for MSVC 7.1 final beta, but I do not have a copy of it to verify. The solution would be to wrap the above in a guard statement similar to: #if !defined(BOOST_NO_PARTIAL_SPECIALIZATION) template struct Stat_t< std::complex > { typedef typename std::complex::value_type value_t; }; #endif NOTE: I'm not sure if the BOOST_NO_PARTIAL_SPECIALIZATION name is correct, but you get the idea. Then, if there is partial specialization support the program will work as indented. Compilers (like MSVC 7) that do not have partial specialization support will then be able to use the program and it will still work because the imaginary component is not used in sumXsqr so the complex number is in essence a real number. There are several concerns with this: * there is no automatic conversion of a complex number to a real number, so this is not a complete solution * output to a stream would probably result in a display of the form: (x, y) I do not how how to get around these problems. -rhd- mailto:[EMAIL PROTECTED] _ Hotmail messages direct to your mobile phone http://www.msn.co.uk/mobile ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Statistics code example
On Wednesday 02 April 2003 02:57 pm, Paul A. Bristow wrote: > Sadly (but perhaps not too surpringly) this does not seem to work for MSVC > 7.0 with complex. (OK without) > Could you elaborate? What didn't work? Any ideas how to fix? I don't use MSVC. > A full working example with at least a few comments might sell this better? > > Paul > > Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK > +44 1539 561830 Mobile +44 7714 33 02 04 > Mobile mailto:[EMAIL PROTECTED] > mailto:[EMAIL PROTECTED] > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] Behalf Of Neal D. Becker > > Sent: Tuesday, April 01, 2003 2:26 PM > > To: [EMAIL PROTECTED] > > Subject: [boost] Statistics code example > > > > > > Here is an example of a class that can compute 2nd order stats that will > > work for either scalar or complex types. > > > > It could be made slightly more efficient. It uses abs(), relying on the > > "trick" that abs() is defined for both scalar float and complex. It > > could be improved by defining our own "norm" function for both scalar > > float and complex. (Unfortunately for efficiency, complex norm is > > defined in terms of abs, which uses sqrt, on at least some systems > > (libstdc++)). > > ___ > Unsubscribe & other changes: > http://lists.boost.org/mailman/listinfo.cgi/boost ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RE: [boost] Statistics code example
Sadly (but perhaps not too surpringly) this does not seem to work for MSVC 7.0 with complex. (OK without) A full working example with at least a few comments might sell this better? Paul Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK +44 1539 561830 Mobile +44 7714 33 02 04 Mobile mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Neal D. Becker > Sent: Tuesday, April 01, 2003 2:26 PM > To: [EMAIL PROTECTED] > Subject: [boost] Statistics code example > > > Here is an example of a class that can compute 2nd order stats that will work > for either scalar or complex types. > > It could be made slightly more efficient. It uses abs(), relying on the > "trick" that abs() is defined for both scalar float and complex. It could be > improved by defining our own "norm" function for both scalar float and > complex. (Unfortunately for efficiency, complex norm is defined in terms of > abs, which uses sqrt, on at least some systems (libstdc++)). > > ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Statistics code example
Here is an example of a class that can compute 2nd order stats that will work for either scalar or complex types. It could be made slightly more efficient. It uses abs(), relying on the "trick" that abs() is defined for both scalar float and complex. It could be improved by defining our own "norm" function for both scalar float and complex. (Unfortunately for efficiency, complex norm is defined in terms of abs, which uses sqrt, on at least some systems (libstdc++)). #ifndef _Stat_H #define _Stat_H //! $Id: Stat.H,v 1.1 2003/03/17 13:51:03 nbecker Exp $ #include template struct Stat_t { typedef T value_t; }; template struct Stat_t< std::complex > { typedef typename std::complex::value_type value_t; }; template class Stat { typedef typename Stat_t::value_t value_t; T sumX; value_t sumXsqr; cnt_t count; public: Stat() : sumX (0), sumXsqr (0), count (0) {} void Reset() { sumX = 0; sumXsqr = 0; count = 0; } template void Compute (in_t in, in_t inend) { for (; in != inend; in++) Compute (*in); } void Compute (T x) { operator += (x); } void operator += (T x) { count++; sumX += x; sumXsqr += (abs(x) * abs(x)); } void operator() (T x) { operator += (x); } value_t Mean() const { if ( count > 0) return (sumX / count); else return ( 0.0 ); } value_t Var() const { if (count > 1) return (sumXsqr - ((abs(sumX) * abs (sumX)) / count)) / (count - 1); else return 0.0; } value_t StdDev() const { if (count <= 0) return 0; else return sqrt (Var()); } value_t RMS() const { return StdDev(); } cnt_t Cnt() const { return count; } value_t XsqrBar() const { return (sumXsqr / count); } }; #endif ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost