Trace Sampling

Trace sampling performs the following steps:

  1. Draw a trace from the historical traces conditional on the summary.
  2. Rescale the time to match the duration specified by the summary.
  3. Interpolate the trace back to the original time resolution.
  4. Rescale the trace based on the rescale rules.

Use samplesingletrace to perform this process for one trace.

HistoricalStormTraceSimulation.samplesingletraceFunction
samplesingletrace(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 type TraceSampler.
  • rescalemethod: see docstring for sampletraces.
  • interpolation_method: see docstring for sampletraces.
source

Sometimes, it is useful to fix which trace is chosen in step 1. Use samplesinglefixedtrace to do this.

Sampling from the historical traces

The sampling depends on the chosen distribution and the chosen distance used to measure the similarity between summaries.

Trace samplers

The method for trace sampling is specified by a TraceSampler.

HistoricalStormTraceSimulation.TraceSamplerType
TraceSampler(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 closest m points. Defaults to 1:50. Could also be a Distribution.
  • 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.

source
HistoricalStormTraceSimulation.computedistances!Function
computedistances!(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.

source

Rescaling time

Time rescaling of a trace can be done with adjusttracetime, which in turn calls rescaletime and then repacks as a StormTrace.

HistoricalStormTraceSimulation.rescaletimeFunction
rescaletime(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\}$.

source

Interpolating the trace

Interpolation is performed with

HistoricalStormTraceSimulation.interpolatetraceFunction
interpolatetrace(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 for sampletraces.
source

Rescaling the trace

Trace rescaling is performed by

HistoricalStormTraceSimulation.rescaletrace!Function
rescaletrace!(trace::StormTrace,summary,rescalemethod::NTuple{N,RescaleMethod}) where {N}

Rescale a trace to match a summary.

Arguments

  • trace: The StormTrace to be adjusted.
  • summary: The summary to simulate a trace for.
  • rescalemethod: see docstring for sampletraces.
source

See Rescale methods for details of the available rescale methods.