gradient_aware_harmonisation.utils#
Utility functions
Classes:
| Name | Description |
|---|---|
Timeseries |
Timeseries class |
Functions:
| Name | Description |
|---|---|
cosine_decay |
Compute cosine decay function |
decay_weights |
Compute a sequence of decaying weights according to specified decay method. |
harmonise_constant_offset |
Harmonise timeseries using a constant offset |
harmonise_splines |
Harmonises two splines by matching a harmonisee to a target spline |
interpolate_harmoniser |
Compute an interpolated timeseries |
interpolate_timeseries |
Compute interpolated timeseries |
polynomial_decay |
Compute polynomial decay function |
timeseries_to_spline |
Estimates splines from timeseries arrays. |
Timeseries #
Timeseries class
Methods:
| Name | Description |
|---|---|
values_validator |
Validate the values |
Source code in src/gradient_aware_harmonisation/utils.py
values_validator #
Validate the values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attribute
|
Any
|
Attribute to validate |
required |
value
|
Any
|
Value to validate |
required |
Source code in src/gradient_aware_harmonisation/utils.py
cosine_decay #
Compute cosine decay function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decay_steps
|
int
|
number of steps to decay over |
required |
initial_weight
|
float
|
starting weight with default = 1. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
weight_seq |
NDArray[Any]
|
weight sequence |
Reference
cosine decay as implemented in tensorflow.keras <https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/CosineDecay>_
Source code in src/gradient_aware_harmonisation/utils.py
decay_weights #
decay_weights(
timeseries_harmonisee: Timeseries,
harmonisation_time: Union[int, float],
convergence_time: Optional[Union[int, float]],
decay_method: str,
**kwargs: Any,
) -> NDArray[Any]
Compute a sequence of decaying weights according to specified decay method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeseries_harmonisee
|
Timeseries
|
timeseries of harmonised spline |
required |
harmonisation_time
|
Union[int, float]
|
point in time_axis at which harmonise should be matched to target |
required |
convergence_time
|
Optional[Union[int, float]]
|
time point at which harmonisee should match target function |
required |
decay_method
|
str
|
decay method to use If decay_method="polynomial" power of the polynmials (arg: 'pow') is required; 'pow' is expected to be greater or equal to 1. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
weight_sequence |
NDArray[Any]
|
sequence of weights for interpolation |
Raises:
| Type | Description |
|---|---|
ValueError
|
Currently supported values for |
Source code in src/gradient_aware_harmonisation/utils.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
harmonise_constant_offset #
harmonise_constant_offset(
target: Spline,
harmonisee: Spline,
harmonisation_time: Union[int, float],
) -> Spline
Harmonise timeseries using a constant offset
In other words, the timeseries are harmonised by simply adding a constant to the harmonisee such that its value matches the value of the target at the harmonisation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Spline
|
Target for harmonisation |
required |
harmonisee
|
Spline
|
Function/spline to harmonisation |
required |
harmonisation_time
|
Union[int, float]
|
Time at which |
required |
Returns:
| Type | Description |
|---|---|
Spline
|
Harmonised spline |
Source code in src/gradient_aware_harmonisation/utils.py
harmonise_splines #
harmonise_splines(
target: Spline,
harmonisee: Spline,
harmonisation_time: Union[int, float],
**kwargs: Any,
) -> Spline
Harmonises two splines by matching a harmonisee to a target spline
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Spline
|
target spline |
required |
harmonisee
|
Spline
|
harmonisee spline |
required |
harmonisation_time
|
Union[int, float]
|
time point at which harmonisee should be matched to the target |
required |
**kwargs
|
Any
|
keyword arguments passed to make_interp_spline or polynomial_decay function |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
harmonised_spline |
Spline
|
harmonised spline (harmonised spline and target have same zero-and first-order derivative at harmonisation time) |
Source code in src/gradient_aware_harmonisation/utils.py
interpolate_harmoniser #
interpolate_harmoniser(
interpolation_target: Spline,
harmonised_spline: Spline,
harmonisee_timeseries: Timeseries,
convergence_time: Optional[Union[int, float]],
harmonisation_time: Union[int, float],
decay_method: str = "cosine",
**kwargs: Any,
) -> Timeseries
Compute an interpolated timeseries
The interpolated timeseries is generated by interpolating from the harmonised_spline to the interpolation target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpolation_target
|
Spline
|
interpolation target, i.e., the target with which predicitons the interpolation spline match after the convergence time? Usually this will be either the original harmonisee or the biased-corrected harmonisee |
required |
harmonised_spline
|
Spline
|
harmonised spline that matches with target wrt zero-and first-order derivative |
required |
harmonisee_timeseries
|
Timeseries
|
harmonisee timeseries |
required |
convergence_time
|
Optional[Union[int, float]]
|
time point where interpolation_target and harmonised spline should match |
required |
harmonisation_time
|
Union[int, float]
|
time point where harmonised spline should match the original target |
required |
decay_method
|
str
|
decay method used for computing weights that interpolate the spline, currently supported methods are 'cosine'. |
'cosine'
|
Returns:
| Name | Type | Description |
|---|---|---|
interpolated_timeseries |
Timeseries
|
interpolated values |
Source code in src/gradient_aware_harmonisation/utils.py
interpolate_timeseries #
interpolate_timeseries(
harmonisee: Spline,
harmonised: Spline,
harmonisation_time: Union[int, float],
timeseries_harmonisee: Timeseries,
decay_weights: NDArray[Any],
) -> Timeseries
Compute interpolated timeseries
The interpolated timeseries is generated by interpolating between the harmonised spline at harmonisation time and the target spline at either the last date of the harmonisee or the specified convergence time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
harmonisee
|
Spline
|
harmonisee spline |
required |
harmonised
|
Spline
|
harmonised (adjusted) spline |
required |
harmonisation_time
|
Union[int, float]
|
time point at which harmonisee and target should match |
required |
timeseries_harmonisee
|
Timeseries
|
timeseries of the harmonisee |
required |
decay_weights
|
NDArray[Any]
|
sequence of weights decaying from 1 to 0 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
timeseries_interpolated |
Timeseries
|
timeseries that interpolate between harmonised spline and harmonisee |
Source code in src/gradient_aware_harmonisation/utils.py
polynomial_decay #
polynomial_decay(
decay_steps: int,
pow: Union[float, int],
initial_weight: float = 1.0,
) -> NDArray[Any]
Compute polynomial decay function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decay_steps
|
int
|
number of steps to decay over |
required |
pow
|
Union[float, int]
|
power of polynomial expected to be greater or equal to 1. |
required |
initial_weight
|
float
|
starting weight, default is 1. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
weight_seq |
NDArray[Any]
|
weight sequence |
Raises:
| Type | Description |
|---|---|
ValueError
|
Power of polynomial is expected to be greater or equal to 1. |
Source code in src/gradient_aware_harmonisation/utils.py
timeseries_to_spline #
timeseries_to_spline(
timeseries: Timeseries, **kwargs: Any
) -> SplineScipy
Estimates splines from timeseries arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeseries
|
Timeseries
|
timeseries of format dict(time_axis = np.array, values = np.array) |
required |
**kwargs
|
Any
|
additional arguments to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
spline |
SplineScipy
|
compute spline from timeseries data |
Raises:
| Type | Description |
|---|---|
ValueError
|
Spline degree ( |