From: Eric Niebler (eric_at_[hidden])
Date: 2006-12-14 15:37:59
Zach Laine wrote:
> I use time series in the signal processing domain. I think there are
> a couple of valid use cases there that may not apply in the financial
> domain, and so got left out.
> The Hello, World! example says: "iterators ... traverse both the zeros
> and the non-zeros, even if the storage is sparse". What if I want to
> iterate over only the actual sparse elements? This is actually a very
> common use case for me. I'd like to be able to do both full and
> sparse iteration.
You can. Only the clip() view provides STL-style iterators that make the
storage appear sparse. But if you look deeper, you can see that all the
TimeSeries types export cursors (sequence::begin(series) and
sequence::end(series)) that traverse only the non-zeros. For instance,
given a TimeSeries, range_run_storage::for_each() will call a
user-specified predicate, passing the value, offset and end-offset of
every non-zero run in the series. Most of the time series algorithms are
implemented in terms of this lower-level interface to deal efficiently
with sparse data.
> Commonly in signal processing, you have uniformly spaced sample times,
> but they are a multiple of some non-integral time increment. This
> seems to be impossible to specify using Boost.Time_series as-is. From
> my understanding of the docs, it seems that you cannot have
> uniformly-spaced floating-point offsets without resorting to
> dense_series<std::pair<TimeType, ValueType> >. Specifically, this
> note: "Some of the numeric algorithms do not work with series that
> have floating-point offsets. For instance, partial_sum() assumes
> integral offsets; in fact, the discrete nature of the algorithm
> prohibits its use with any series with floating-point offsets."
> bothers me. What if I have a time interval that is 3.7367ms, but it
> is completely regular? My alternatives appear to be a time series and
> an extrinsic timestep value, which I must multiply by the time series
> index to get back the actual timestamp of a series element, or the
> pair I mentioned above.
Not a problem. You can have a series with a floating point
discretization and an integral offset type. Consider the following program:
using namespace boost;
using namespace time_series;
sparse_series< double, double > s1(discretization = 3.7367);
sparse_series< double, double > s2(discretization = 3.7367);
sparse_series< double, double > s3 = s1 + s2;
std::cout << s3 << std::endl;
The series type "sparse_series<double, double>" has a value type of
double, a discretization of double, and an offset type which defaults to
int. The discretization of both series is initialized to 3.7367. When
you add the series, the discretizations are compared at runtime (it
would assert if they were not the same), and the resulting series has
the same discretization value.
The integral offsets into such a series represent integral multiples of
the floating point discretization.
> Typo: In http://boost-sandbox.sourceforge.net/libs/time_series/doc/html/time_series/user_s_guide/extensibility.html
> "container" is misspelled "contaier".
> These issues aside, I really like the formalisms introduced by the
> library, and think it will be very useful.
Thanks for your feedback.
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk