scatseisnet.network#
Scattering network graph definition.
This module contains the ScatteringNetwork class that implements the
scattering network graph. The network is composed of a series of wavelet filter
banks (so far limited to ComplexMorletBank instances) and pooling
operations.
The ScatteringNetwork class is a container for the filter banks and
the pooling operations. It is used to transform time samples (waveforms with an
artibtrary number of channels) with the scattering network graph. The
ScatteringNetwork class is also used to compute the scattering
network graph properties, such as the number of output channels, the number of
output bins, etc.
Terms of use
Copyright (C) 2023 Léonard Seydoux.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/>.
Attributes#
Classes#
Scattering network graph. |
Module Contents#
- class scatseisnet.network.ScatteringNetwork(*layer_kwargs: dict, bins: int = 128, sampling_rate: float = 1.0, verbose: bool = False)[source]#
Scattering network graph.
- Parameters:
layer_kwargs (
dict) – The keyword argiments of each filter bank keyword arguments, in the form of a :series ofdictobjects with the keyword arguments forComplexMorletBank. The number of network layers is defined by the number of arguments. Please see theComplexMorletBankdocumentation for more information about the keyword arguments themselves.bins (
int, optional) – Number of time samples per signal windows. By default, this value is 128. Note that once set, the value cannot be changed.sampling_rate (
float, optional) – Input data sampling rate in Hertz. This is useful to keep track of physical frequencies in the filterbanks properties. The default value is 1.0 (reduced frequency).
- transform_segment(segment: numpy.ndarray, reduce_type: Callable | None = None) list[source]#
Scattering network transformation.
This function transforms a single segment with the scattering network. The reduce_type parameter defines the pooling operation. It can be either max, avg, or med.
Note
If the
reduce_typeparameter is not defined, the function returns the scalogram of each layer of the scattering network (i.e. the continuous wavelet transform of the input segment at each layer) without any pooling operation.- Parameters:
segment (
numpy.ndarray) – The input segment time series to calculate the scattering coefficients from. The shape of the array must be(bins, n_channels), wherebinsis the number of time samples per segment andn_channelsis the number of channels. The number of channels can be 1 or more.reduce_type (callable, optional) – The reduction function (e.g.
numpy.mean()). If not defined, the function returns the scalogram of each layer of the scattering network, without any pooling operation.
- Returns:
scattering_coefficients – The scattering coefficients per layer of the scattering network.
- Return type:
listof array-like
Examples
>>> import numpy as np >>> from scatseisnet import ScatteringNetwork >>> layer_kwargs = [ ... {"octaves": 8, "resolution": 8}, ... {"octaves": 12, "resolution": 1}, ... ] >>> network = ScatteringNetwork(*layer_kwargs) >>> segment = np.random.randn(128) >>> scattering_coefficients = network.transform_segment(segment, reduce_type=np.max) >>> len(scattering_coefficients) 2 >>> scattering_coefficients[0].shape (64,) >>> scattering_coefficients[1].shape (64, 12)
- transform(segments: numpy.ndarray, taper_alpha=None, reduce_type: Callable | None = None) list[source]#
Transform a set of segments.
This function is a wrapper to loop over a series of segments with the
transform_segment()method. Please refer to this method for more information.- Parameters:
segments (
numpy.ndarray) – The input segment time series to calculate the scattering coefficients from. The shape of the array must be(n_segments, bins, n_channels), wherebinsis the number of time samples per segment andn_channelsis the number of channels. The number of channels can be 1 or more.taper_alpha (float, optional) – Tapering factor for the time domain. If None, no tapering is applied (default None).
reduce_type (callable, optional) – The reduction function (e.g.
numpy.mean()). If not defined, the function returns the scalogram of each layer of the scattering network, without any pooling operation.
- Returns:
scattering_coefficients – The scattering coefficients per layer of the scattering network.
- Return type:
listof array-like
Examples
>>> import numpy as np >>> from scatseisnet import ScatteringNetwork >>> layer_kwargs = [ ... {"octaves": 8, "resolution": 8}, ... {"octaves": 12, "resolution": 1}, ... ] >>> network = ScatteringNetwork(*layer_kwargs) >>> segments = np.random.randn(10, 128) >>> scattering_coefficients = network.transform(segments, np.max) >>> len(scattering_coefficients) 2 >>> scattering_coefficients[0].shape (10, 64) >>> scattering_coefficients[1].shape (10, 64, 12)