qewton.data.data_processing package¶
Module contents¶
Submodules¶
qewton.data.data_processing.normalization module¶
- class qewton.data.data_processing.normalization.StdNormalizationNode(data_source_node: DataNode, eps: float = 1e-06, name: str = 'Normalization Node', backend: type[ComputingBackend[TensorType]] = <class 'qewton.backends.base.DeepLearningBackend'>)[source]¶
Bases:
GraphNode[TensorType],DataProcessingNode[TensorType]Applies a normalization of the input data by a mean shift and afterwards a normalization with the standard derivation.
- Parameters:
data_source_node (DataNode) – The original source of data. Does not have to be node which is directly to this node, only the original data loader providing the original data set.
eps (float, optional) – A small tolerance added to the standard derivation, to avoid dividing by 0. Defaults to 1.0e-6.
name (str, optional) – Defaults to “Normalization Node”.
backend (type[ComputingBackend[TensorType]], optional) – Defaults to DEFAULT_DL_BACKEND.
- data_axes = <qewton.config.axes.EllipsisAxes object>¶
- batch_axes = <qewton.config.axes.BatchAxes object>¶
- build(graph: Graph) None[source]¶
Create what the node computes with, e.g. the weights or the inner graph of a network, from the current hyperparameter values.
Called by
setup()for a node that is not built yet; a tuner makes a node unbuilt again (reset()) before trying other hyperparameter values. Does nothing by default.
- fit(data_batch)[source]¶
The main fitting behavior of the node. This method is called in the setup phase or can also be called manually to fit the node to a batch of data. The batch is expected to be a list of tensors, where each entry corresponds to a batch of data from the data source node.
- Parameters:
data_batch (list[TensorType]) – The batch of data to fit the node to.
- to(device)[source]¶
Moves all nodes within the encapsulated graph to a specified device (e.g., GPU, CPU).
- Parameters:
device – The target device.
- property memory_consumption: int¶
- forward(x: Annotated[TensorType, BatchAxes([None]), ...]) Annotated[TensorType, BatchAxes([None]), ...][source]¶
Evaluate the inner graph on the inputs.
Subclasses override this method only to declare the data configurations of their ports with
typing.Annotated; the body staysreturn super().forward(...). Inside a graph, the steps of the inner graph run in place of this node instead.- Parameters:
*args – The values of the input ports, in order.
**kwargs – The values of input ports by name.
- Returns:
The value of the output port, or a tuple for several.
- Return type:
Any
- Raises:
RuntimeError – If the node is not built and waits for sizes to be inferred from connected data.
- class qewton.data.data_processing.normalization.InverseStdNormalizationNode(std_node: StdNormalizationNode[TensorType], name: str = 'Inverse Std. Norm. Node')[source]¶
Bases:
GraphNode[TensorType],DataProcessingNode[TensorType]Inverts a normalization.
- Parameters:
std_node (StdNormalizationNode[TensorType]) – The node that applies the initial normalization we want to invert.
name (str, optional) – Defaults to “Inverse Std. Norm. Node”.
- data_axes = <qewton.config.axes.EllipsisAxes object>¶
- batch_axes = <qewton.config.axes.BatchAxes object>¶
- data_source_node: StdNormalizationNode¶
- build(graph: Graph) None[source]¶
Create what the node computes with, e.g. the weights or the inner graph of a network, from the current hyperparameter values.
Called by
setup()for a node that is not built yet; a tuner makes a node unbuilt again (reset()) before trying other hyperparameter values. Does nothing by default.
- to(device)[source]¶
Moves all nodes within the encapsulated graph to a specified device (e.g., GPU, CPU).
- Parameters:
device – The target device.
- forward(x: Annotated[TensorType, BatchAxes([None]), ...]) Annotated[TensorType, BatchAxes([None]), ...][source]¶
Evaluate the inner graph on the inputs.
Subclasses override this method only to declare the data configurations of their ports with
typing.Annotated; the body staysreturn super().forward(...). Inside a graph, the steps of the inner graph run in place of this node instead.- Parameters:
*args – The values of the input ports, in order.
**kwargs – The values of input ports by name.
- Returns:
The value of the output port, or a tuple for several.
- Return type:
Any
- Raises:
RuntimeError – If the node is not built and waits for sizes to be inferred from connected data.
qewton.data.data_processing.pca module¶
- class qewton.data.data_processing.pca.PCANode(n: int | HyperParameter, data_source_node: DataNode, scale: bool | HyperParameter = True, name: str | None = 'PCA Node', backend: type[ComputingBackend[TensorType]] = <class 'qewton.backends.base.DeepLearningBackend'>)[source]¶
Bases:
DataProcessingNode[TensorType]A node that performs a principal component analysis (PCA) on its input data. To construct the PCA, in the setup phase all training data is collect by (partially) evaluating the graph it belongs to.
- Parameters:
n (int | HyperParameter) – The number of principal components to keep.
data_source_node (DataNode) – The original source of data. Does not have to be node which is directly connected to this PCANode, only the original data loader providing the original data set.
scale (bool | HyperParameter, optional) – If the input data after the representation in the PCA-basis should be scaled by the principal components. Defaults to True.
name (str | None, optional) – Defaults to “PCA Node”.
backend (type[ComputingBackend[TensorType]], optional) – Defaults to DEFAULT_DL_BACKEND.
- refresh_port_data_configurations() None[source]¶
Refresh static data configurations that depend on hyperparameters.
- reset()[source]¶
Make the node unbuilt, so that the next
setup()builds it again (e.g. for other hyperparameter values); a FIXED node stays as it is.
- build(graph: Graph) None[source]¶
Build the node from the data of the graph it belongs to: run the graph up to this node to collect its input data, then fit to it.
- Parameters:
graph (Graph) – The graph this node belongs to.
- fit(data_batch)[source]¶
The main fitting behavior of the node. This method is called in the setup phase or can also be called manually to fit the node to a batch of data. The batch is expected to be a list of tensors, where each entry corresponds to a batch of data from the data source node.
- Parameters:
data_batch (list[TensorType]) – The batch of data to fit the node to.
- to(device)[source]¶
Move the data stored in this node to device.
Does nothing by default.
- Parameters:
device (Device or str) – The target device, e.g. a CPU or GPU.
- property memory_consumption: int¶
- forward(x: ~typing.Annotated[~qewton.backends.base.TensorType, <function PCANode.x_data_config at 0x7c052e6c6200>]) tuple[~typing.Annotated[~qewton.backends.base.TensorType, <function PCANode.out_data_config at 0x7c052e6c62a0>], ~typing.Annotated[~qewton.backends.base.TensorType, <function PCANode.out_u_config at 0x7c052e6c6340>], ~typing.Annotated[~qewton.backends.base.TensorType, <function PCANode.out_s_config at 0x7c052e6c63e0>], ~typing.Annotated[~qewton.backends.base.TensorType, <function PCANode.out_v_config at 0x7c052e6c6480>]][source]¶
Compute the outputs of this node from its inputs.
The signature and type hints define the ports of the node.
- Raises:
NotImplementedError – Always; subclasses must implement this method.
- class qewton.data.data_processing.pca.InversePCANode(pca_node: PCANode[TensorType], name: str | None = 'Inverse PCA Node')[source]¶
Bases:
DataProcessingNode[TensorType]Applies a inverse PCA, given some coefficients it uses the PCA-basis to map back to the original one.
- Parameters:
pca_node (PCANode[TensorType]) – The PCANode that yields the PCA basis that is required for the inverse transformation.
name (str | None, optional) – Defaults to “Inverse PCA Node”
- refresh_port_data_configurations() None[source]¶
Refresh static data configurations that depend on the wrapped PCA node.
- build(graph: Graph) None[source]¶
Build the node from the data of the graph it belongs to: run the graph up to this node to collect its input data, then fit to it.
- Parameters:
graph (Graph) – The graph this node belongs to.
- forward(pca_coefficients: ~typing.Annotated[~qewton.backends.base.TensorType, <function InversePCANode.x_data_config at 0x7c052e6c6840>]) out_data_config at 0x7c052e6c68e0>][source]¶
Compute the outputs of this node from its inputs.
The signature and type hints define the ports of the node.
- Raises:
NotImplementedError – Always; subclasses must implement this method.