franc.evaluation.filter_interface
Shared functionality and interface for all filtering techniques
Attributes
Classes
common interface definition for Filter implementations |
Functions
add a dimension to 1D arrays and leave 2D arrays as they are |
|
|
A decorator for the init functions of classes derived from FitlerInterface |
Module Contents
- franc.evaluation.filter_interface.FilterTypeT
- franc.evaluation.filter_interface.make_2d_array(A)
add a dimension to 1D arrays and leave 2D arrays as they are This is intended to allow 1D array input for single channel application
- Parameters:
A (collections.abc.Sequence | collections.abc.Sequence[collections.abc.Sequence] | numpy.typing.NDArray) – input array
- Returns:
extended array
- Raises:
ValueError if the input shape is not compatible
- Return type:
numpy.typing.NDArray
>>> import franc as fnc >>> fnc.evaluation.make_2d_array([1, 2]) array([[1, 2]])
>>> import franc as fnc >>> fnc.evaluation.make_2d_array([[1, 2], [3, 4]]) array([[1, 2], [3, 4]])
- franc.evaluation.filter_interface.handle_from_dict(init_func)
A decorator for the init functions of classes derived from FitlerInterface
If the _from_dict keyword argument is passed, the __init__() function is ignored and the class is initialized based on the passed dictionary. Otherwise, the constructor is called the usual way.
- Parameters:
init_func (collections.abc.Callable) –
- class franc.evaluation.filter_interface.FilterInterface(n_channel, _from_dict=None)
Bases:
abc.ABCcommon interface definition for Filter implementations
- Parameters:
n_channel (int) – Number of witness sensor channels
- requires_apply_target: bool
- n_channel: int
- method_hash_value: bytes
- supports_multi_sequence = True
- filter_name = 'FilterInterface'
- default_args = [None]
- static supports_saving_loading()
Indicates whether saving and loading is supported Due to the way dataclasses work with inheritance, class values with default values don’t work in the parent dataclass. Thus, this is a function
- Return type:
bool
- condition(witness, target)
Use an input dataset to condition the filter
- Parameters:
witness (collections.abc.Sequence | collections.abc.Sequence[collections.abc.Sequence] | numpy.typing.NDArray) – Witness sensor data
target (collections.abc.Sequence | numpy.typing.NDArray) – Target sensor data
- abstract condition_multi_sequence(witness, target)
Similar to condition(), but expects multiple sequences
First index to the given data objects indicates the sequence. The last index indicates the time within a single sequence. Sequences must not have the same length.
- Parameters:
witness (collections.abc.Sequence | collections.abc.Sequence[collections.abc.Sequence] | numpy.typing.NDArray) –
target (collections.abc.Sequence | numpy.typing.NDArray) –
- Return type:
Any
- apply(witness, target=None, pad=True, update_state=False)
Apply the filter to a single sequence of input data
- Parameters:
witness (collections.abc.Sequence | numpy.typing.NDArray) – Witness sensor data (1D or 2D array)
target (collections.abc.Sequence | numpy.typing.NDArray | None) – Target sensor data (1D array)
pad (bool) – if True, apply padding zeros so that the length matches the target signal
update_state (bool) – if True, the filter state will be changed. If false, the filter state will remain
- Returns:
prediction
- Return type:
numpy.typing.NDArray
- abstract apply_multi_sequence(witness, target, pad=True, update_state=False)
Apply the filter to multiple sequences of input data.
Similar to apply() but expects multiple sequences. First index to the given data objects indicates the sequence. The last index indicates the time within a single sequence. Sequences must not have the same length.
- Parameters:
witness (collections.abc.Sequence | numpy.typing.NDArray) –
target (collections.abc.Sequence | numpy.typing.NDArray | None) –
pad (bool) –
update_state (bool) –
- Return type:
collections.abc.Sequence[numpy.typing.NDArray]
- check_data_dimensions(witness, target=None)
Check the dimensions of the provided input data and apply make_2d_array()
- Parameters:
witness (collections.abc.Sequence | numpy.typing.NDArray) – Witness sensor data
target (collections.abc.Sequence | numpy.typing.NDArray | None) – Target sensor data
- Returns:
data as (target, witness)
- Raises:
AssertionError
- Return type:
tuple[numpy.typing.NDArray, numpy.typing.NDArray]
- check_data_dimensions_multi_sequence(witness: collections.abc.Sequence | numpy.typing.NDArray, target: None) tuple[list[numpy.typing.NDArray], None]
- check_data_dimensions_multi_sequence(witness: collections.abc.Sequence | numpy.typing.NDArray, target: collections.abc.Sequence | numpy.typing.NDArray) tuple[list[numpy.typing.NDArray], list[numpy.typing.NDArray]]
Check the dimensions of the provided input data and apply make_2d_array()
- Parameters:
witness – Witness sensor data
target – Target sensor data
- Returns:
data as (target, witness)
- Raises:
AssertionError
- as_dict()
Returns a dictionary that represents the state of this filter.
- Return type:
dict[str, Any]
- classmethod from_dict(input_dict)
Create a filter instance from a dictionary that was created from as_dict()
- Parameters:
input_dict (dict[str, Any]) –
- Return type:
FilterTypeT
- classmethod make_filename(filename)
Append the file type of save files for this class to the given filename, if it is not already present
- Parameters:
filename (str | pathlib.Path) –
- save(filename, warn_incompatible=False)
Save the filter state as a numpy file
The given filename will be autocompleted with a “.<filter_name>.npz” filename extension, unless a matching extension is detected.
- warn_incompatible: set to True to warn for object types might not
compatible with np.save(allow_pickle=False) during development
- Parameters:
filename (str | pathlib.Path) –
warn_incompatible (bool) –
- classmethod load(filename)
Load a filter state from the supplied filename.
The given filename will be autocompleted with a “.<filter_name>.npz” filename extension, unless a matching extension is detected.
- Return type:
FilterTypeT
- classmethod file_hash()
Calculates a hash value based on the file in which this method was defined.
- Return type:
bytes
- property method_hash: bytes
A hash of the method and parameters NOTE: This is not a hash of the conditioned filter! Thus, the same filter configuration applied to a different dataset will result in the same hash!
- Return type:
bytes
- property method_filename_part: str
string that can be used in a file name
- Return type:
str