Trace Sampling
Trace sampling performs the following steps:
- Draw a trace from the historical traces conditional on the summary.
- Rescale the time to match the duration specified by the summary.
- Interpolate the trace back to the original time resolution.
- Rescale the trace based on the rescale rules.
Use samplesingletrace to perform this process for one trace.
HistoricalStormTraceSimulation.samplesingletrace — Functionsamplesingletrace(summary,history,sampler,rescalemethod,interpolation_method=LinearInterpolation)Function to sample a trace given a summary and history.
Arguments
summary: The summary to simulate a trace for.history: The StormHistory to match to.sampler: Sampler of typeTraceSampler.rescalemethod: see docstring forsampletraces.interpolation_method: see docstring forsampletraces.
Sometimes, it is useful to fix which trace is chosen in step 1. Use samplesinglefixedtrace to do this.
HistoricalStormTraceSimulation.samplesinglefixedtrace — Functionsamplesinglefixedtrace()Method to simulate a fixed trace based on rescaling the ith historical trace.
Sampling from the historical traces
The sampling depends on the chosen distribution and the chosen distance used to measure the similarity between summaries.
HistoricalStormTraceSimulation.samplehistoricaltrace — Functionsamplehistoricaltrace(summary,history,sampler::TraceSampler)Sample a historical trace from a history given a summary.
See samplesingletrace for argument details.
Trace samplers
The method for trace sampling is specified by a TraceSampler.
HistoricalStormTraceSimulation.TraceSampler — TypeTraceSampler(d,samplemethod,n::Int)Arguments
summarymetric: A metric for determining closeness of storm summaries (must be subtype of Metric). Default is Euclidean().samplemethod: Method for sampling from closest points. Passing 1:m will sample uniformly from the closestmpoints. Defaults to 1:50. Could also be aDistribution.n: The number of storms.
Note
There is an alternate constructor TraceSampler(summarymetric,samplemethod,distance_store,distance_index) this is an internal feature, distance_store and distance_index are constructed based on n in the other constructor. Their purpose is to preallocate distance storage and improve performance.
HistoricalStormTraceSimulation.computedistances! — Functioncomputedistances!(summary,history,sampler::TraceSampler)Compute the distances for a given summary to all historical summaries.
Note: This overwrites memory in sampler and returns nothing. See samplesingletrace for argument details.
Rescaling time
Time rescaling of a trace can be done with adjusttracetime, which in turn calls rescaletime and then repacks as a StormTrace.
HistoricalStormTraceSimulation.adjusttracetime — Functionadjusttracetime(trace, summary)Adjust the time of a trace based on a summary (just calls rescaletime and then repacks in a StormTrace).
HistoricalStormTraceSimulation.rescaletime — Functionrescaletime(time,duration)Rescale the time to match the duration $(d)$ and start at 0. The formula is, $\forall t \in T_y$
$\tilde{t}_t = (t-\min T_y) \frac{d}{\max T_y - \min T_y}.$
Then the time vector of $\tilde y$ is $T_{\tilde{y}} = \{\tilde{t}_t \mid t \in T_y\}$.
Interpolating the trace
Interpolation is performed with
HistoricalStormTraceSimulation.interpolatetrace — Functioninterpolatetrace(trace,Δ,interpolation_method=LinearInterpolation)Interpolate a trace to a new resolution Δ.
Arguments
trace: The trace to be interpolated.Δ: The new time resolution.interpolation_method: see docstring forsampletraces.
Rescaling the trace
Trace rescaling is performed by
HistoricalStormTraceSimulation.rescaletrace! — Functionrescaletrace!(trace::StormTrace,summary,rescalemethod::NTuple{N,RescaleMethod}) where {N}Rescale a trace to match a summary.
Arguments
trace: TheStormTraceto be adjusted.summary: The summary to simulate a trace for.rescalemethod: see docstring forsampletraces.
See Rescale methods for details of the available rescale methods.