gradient_aware_harmonisation.add_cubic#
Harmonisation by adding a cubic
Functions:
| Name | Description |
|---|---|
harmonise_splines_add_cubic |
Generate cubic spline |
taylor_shift |
Compute Taylor shift according to Shaw and Traub (1974) |
harmonise_splines_add_cubic #
harmonise_splines_add_cubic(
diverge_from: Spline,
harmonisee: Spline,
harmonisation_time: float | int,
convergence_time: float | int,
) -> Spline
Generate cubic spline
The cubic spline interpolates between harmonised spline and harmonisee
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diverge_from
|
Spline
|
Spline whose value and first derivative at the harmonization time match the target spline values. |
required |
harmonisee
|
Spline
|
Spline that the cubic spline should converge to and match at and after the convergence time. |
required |
harmonisation_time
|
float | int
|
Time point at which cubic spline should be matched to the target. |
required |
convergence_time
|
float | int
|
Time point at which the cubic spline should converge to harmonisee. |
required |
Returns:
| Type | Description |
|---|---|
Spline
|
cubic spline |
Examples:
>>> from gradient_aware_harmonisation.timeseries import Timeseries
>>> from gradient_aware_harmonisation.add_cubic import harmonise_splines_add_cubic
>>> import numpy as np
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> harmonised = Timeseries(time_axis=time, values=-0.5 * time + 1)
>>> harmonisee = Timeseries(time_axis=time, values=0.2 * time**3 - 5)
>>> cubic_spline = harmonise_splines_add_cubic(
... diverge_from=harmonised.to_spline(),
... harmonisee=harmonisee.to_spline(),
... harmonisation_time=harmonisation_time,
... convergence_time=convergence_time,
... )
>>> _, ax = plt.subplots(figsize=(6, 3))
>>> for y, name in zip(
... [harmonised.values, harmonisee.values, cubic_spline(time)],
... ["diverge_from", "harmonisee", "cubic_spline"],
... ):
... ax.plot(time, y, label=name)
>>> ax.axvline(harmonisation_time, color="black", linestyle="--")
>>> ax.axvline(convergence_time, color="black", linestyle="--")
>>> ax.legend()
>>> plt.show()

Source code in src/gradient_aware_harmonisation/add_cubic.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
taylor_shift #
taylor_shift(
coeffs: NP_ARRAY_OF_FLOAT_OR_INT, shift: float
) -> NP_ARRAY_OF_FLOAT_OR_INT
Compute Taylor shift according to Shaw and Traub (1974)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
NP_ARRAY_OF_FLOAT_OR_INT
|
polynomial coefficients |
required |
shift
|
float
|
Taylor shift |
required |
Returns:
| Type | Description |
|---|---|
NP_ARRAY_OF_FLOAT_OR_INT
|
new polynomial coefficients by Taylor shift |
References
Shaw, M., & Traub, J. F. (1974). On the number of multiplications for the evaluation of a polynomial and some of its derivatives. Journal of the ACM, 21(1), 161-167.