komanawa.BASE.generators.uniform_path_generator#

created matt_dumont on: 12/05/24

Classes#

ParentPathChange

A base class for the path change generators which defines the KS test for the path change generator.

UniformPathGenerator

A base class for the path change generators which defines the KS test for the path change generator.

Module Contents#

class ParentPathChange#

A base class for the path change generators which defines the KS test for the path change generator.

comptest(sample, test=kstest, n_gen=None, random_state=None, **kwargs)#

Calculate the scipy test for the path change generator. The test is calculated for each time step in the path. The first time step is the starting point of the path, the second time step is the difference between the first and second points in the path, the third time step is the difference between the second and third points in the path, etc.

The test can be any of the scipy tests like kstest, Mann-Whitney U test, wasserstein_distance_nd, etc.

Parameters:
  • sample – sample to test shape=(nsims, self.n)

  • n_gen – Number of samples to generate for the KS test, if None use the length of the sample

  • kwargs – other keyword arguments to pass to scipy.stats test

Returns:

[estResult, …] for each time step in the path (see scipy function)

plot_test(test_results, ax, x=None, plot_stats=('statistic', 'pvalue'), plot_on_twinx=True, colors=None, **kwargs)#

Plot the results of the KS test for the path change generator.

Parameters:
  • ktest_results – [testResult, …] for each time step in the path

  • ax – axis to plot on or None (if None a new figure is created)

  • plot_stats – tuple subset of result values to plot or None (assumes results are float)

  • plot_on_twinx – if True plot the first of plot_stats on the ax and then each subsequent statistic on individual twinx axes

  • colors – dictionary of colors for each statistic or None (if None use default colors)

  • kwargs – other keyword arguments to pass to the ax.plot

Returns:

fig, ax, (handles, labels)

class UniformPathGenerator(low, up, n)#

Bases: komanawa.BASE.generators.parent_path_change.ParentPathChange

Inheritance diagram of komanawa.BASE.generators.uniform_path_generator.UniformPathGenerator

A base class for the path change generators which defines the KS test for the path change generator.

Generate a random path of length n, within the bounds of low and up. The path is generated by picking a value out of the uniform distribution (low[i]-up[i]) for each point in the path.

parameters low and up can be scalars or lists of length n. If they are scalars the value is used for all points in the path. If they are iterable the value is used for the corresponding point in the path.

Parameters:
  • low

  • up

  • n

comptest(sample, test=kstest, n_gen=None, random_state=None, **kwargs)#

Calculate the scipy test for the path change generator. The test is calculated for each time step in the path. The first time step is the starting point of the path, the second time step is the difference between the first and second points in the path, the third time step is the difference between the second and third points in the path, etc.

The test can be any of the scipy tests like kstest, Mann-Whitney U test, wasserstein_distance_nd, etc.

Parameters:
  • sample – sample to test shape=(nsims, self.n)

  • n_gen – Number of samples to generate for the KS test, if None use the length of the sample

  • kwargs – other keyword arguments to pass to scipy.stats test

Returns:

[estResult, …] for each time step in the path (see scipy function)

logpdf(q0)#

Calculate the log probability of the path (q0) given the parameters of the generator.

Parameters:

q0

Returns:

plot_path(x=None, ax=None, round_lab=2, lab_rotation=0, xlab=None)#

Plot the path with the bounds.

Parameters:
  • x – None or an array of length n to use as the x axis, if None the x axis will be the integers from 0 to n

  • ax – None or an axis to plot on

  • round_lab – the number of decimal places to round the labels to

  • lab_rotation – rotation of the x axis labels

  • xlab – None or a strings to use as the xtick label

Returns:

plot_test(test_results, ax, x=None, plot_stats=('statistic', 'pvalue'), plot_on_twinx=True, colors=None, **kwargs)#

Plot the results of the KS test for the path change generator.

Parameters:
  • ktest_results – [testResult, …] for each time step in the path

  • ax – axis to plot on or None (if None a new figure is created)

  • plot_stats – tuple subset of result values to plot or None (assumes results are float)

  • plot_on_twinx – if True plot the first of plot_stats on the ax and then each subsequent statistic on individual twinx axes

  • colors – dictionary of colors for each statistic or None (if None use default colors)

  • kwargs – other keyword arguments to pass to the ax.plot

Returns:

fig, ax, (handles, labels)

rvs(random_state=None)#

Generate a random path of length n, with a starting point in the interval start_bounds process is first pick a value out of the uniform distribution (”*start_bounds”), then for each additional point in the series pick a value from a normal distribution centered on the previous value with a scale of scale. If the picked value is outside the interval set to the upper and lower bounds then the value is truncated to the bounds value.

Parameters:

random_state – None, use the global random state, or an integer to seed the random state. As this is a markov chain process the random state is used to generate a suite of integer seeds to make each delta deterministic.

Returns: