Group Abstract Group Abstract

Message Boards Message Boards

1
|
5K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:

Can I set the ""ExtrapolationHandler" -> Indeterminate in a TimeSeries?

Posted 11 years ago

Hi,

I like the new time-series, but I wanted to be able to set the extrapolation handler, like I can do with interpolating functions. How do I do this?

Thanks!

Sam

Posted 11 years ago

Good question!

I also faced this problem and was not able to find a way to control the extrapolation handler in TimeSeries. It should be ResamplingMethod but it does not work! I ended up reimplementing this functionality on the base of Interpolation what gave me huge speed-up as compared to TimeSeries. The basic idea is to construct InterpolatingFunctions for the datasets and then use these InterpolatingFunctions for upsampling the datasets in order to line them up:

ts1 = {{1, 10}, {2, 20}, {5, 50}};
ts2 = {{2, -20}, {3, -30}, {6, -60}};

datasets = {ts1, ts2};
interpFs = Interpolation[#, InterpolationOrder -> 1, 
     "ExtrapolationHandler" -> {Indeterminate &, "WarningMessage" -> False}] & /@ datasets;
abscissas = Union[Flatten@datasets[[;; , ;; , 1]]];
upsampledDatasets = Transpose[{abscissas, #}] & /@ Through[interpFs@abscissas]

{{{1, 10}, {2, 20}, {3, 30}, {5, 50}, {6, Indeterminate}}, {{1, Indeterminate}, {2, -20}, {3, -30}, {5, -50}, {6, -60}}}

Now we can perform arithmetic operations on the lined up datasets, for example summing them up:

Transpose[{abscissas, Total[upsampledDatasets[[;; , ;; , 2]], 1]}]

{{1, Indeterminate}, {2, 0}, {3, 0}, {5, 0}, {6, Indeterminate}}

Here is what we obtain using TimeSeries by default in version 10.2:

(TimeSeries[ts1] + TimeSeries[ts2])["Path"]

{{2, 0}, {3, 0}, {5, 0}}

Of course if would be much nicer to have the "ExtrapolationHandler" available from within of TimeSeries.

POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard