FlowChange.FlowChangeLikely#
Baseline.FlowChangeLikely.py
- compute_yscale(x, y)#
Compute the y-scale for likelihood computation.
- Parameters:
x (array-like) – The x-values of the curve.
y (array-like) – The y-values of the curve.
- Returns:
The y-scale value.
- Return type:
float
- get_safeslice(lb, ub, start, stop)#
Get a safe slice within the bounds [lb, ub).
- Parameters:
lb (int) – The lower bound (inclusive).
ub (int) – The upper bound (exclusive).
start (int) – The start index of the slice.
stop (int) – The stop index of the slice.
- Returns:
The safe slice object.
- Return type:
slice
- find_nearest_point(px, py, i, x, y, yscale)#
Find the nearest point to (px, py) around index i.
- Parameters:
px (float) – The x-coordinate of the point.
py (float) – The y-coordinate of the point.
i (int) – The index around which to search.
x (array-like) – The x-values of the curve.
y (array-like) – The y-values of the curve.
yscale (float) – The y-scale for distance computation.
- Returns:
The index of the nearest point.
- Return type:
int
- compute_flowchange_likelihoods(x, y, points, segments, yscale=None, return_neighbours=False)#
Compute the flow change likelihoods at the given points.
- Parameters:
x (array-like) – The x-values of the curve.
y (array-like) – The y-values of the curve.
points (list of int) – The breakpoints of the segments.
segments (list of Linesegment) – The list of line segments.
yscale (float, optional) – The y-scale for likelihood computation. If None, it will be computed from the data.
return_neighbours (bool, optional) – If True, also return the neighbouring point indices for each breakpoint. Defaults to False.
- Returns:
likelihoods (array-like) – The normalized likelihoods for each breakpoint.
neighbours (list of tuples, optional) – If return_neighbours is True, a list of (j, k) tuples where j and k are the indices of the nearest points on either side of each breakpoint.
- flowchange_likelihood(x, y, i, seg1, seg2, yscale, neighbours=None, debug=False)#
Compute the flow change likelihood at the given index.
- Parameters:
x (array-like) – The x-values of the curve.
y (array-like) – The y-values of the curve.
i (int) – The index of the breakpoint.
seg1 (Linesegment) – The segment before the breakpoint.
seg2 (Linesegment) – The segment after the breakpoint.
yscale (float) – The y-scale for likelihood computation.
neighbours (list of tuples, optional) – If provided, the function will append the (j, k) indices of the nearest points on either side of the breakpoint to this list.
debug (bool, optional) – If True, print debug information.
- Returns:
The likelihood value for the breakpoint.
- Return type:
float