congrads 1.0.7__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- congrads/__init__.py +2 -3
- congrads/checkpoints.py +73 -127
- congrads/constraints.py +804 -454
- congrads/core.py +521 -345
- congrads/datasets.py +491 -191
- congrads/descriptor.py +118 -82
- congrads/metrics.py +55 -127
- congrads/networks.py +35 -81
- congrads/py.typed +0 -0
- congrads/transformations.py +65 -88
- congrads/utils.py +499 -131
- {congrads-1.0.7.dist-info → congrads-1.1.0.dist-info}/METADATA +48 -41
- congrads-1.1.0.dist-info/RECORD +14 -0
- congrads-1.1.0.dist-info/WHEEL +4 -0
- congrads-1.0.7.dist-info/LICENSE +0 -26
- congrads-1.0.7.dist-info/RECORD +0 -15
- congrads-1.0.7.dist-info/WHEEL +0 -5
- congrads-1.0.7.dist-info/top_level.txt +0 -1
congrads/transformations.py
CHANGED
|
@@ -1,139 +1,116 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This module defines the abstract base class `Transformation` and two
|
|
3
|
-
specific transformations: `IdentityTransformation` and `DenormalizeMinMax`.
|
|
4
|
-
These transformations are used to apply operations to neuron data.
|
|
5
|
-
|
|
6
|
-
Classes:
|
|
7
|
-
|
|
8
|
-
- Transformation: An abstract base class for transformations that
|
|
9
|
-
can be applied to neuron data. Subclasses must implement the
|
|
10
|
-
`__call__` method to apply the transformation.
|
|
11
|
-
- IdentityTransformation: A subclass of `Transformation` that
|
|
12
|
-
returns the input data unchanged.
|
|
13
|
-
- DenormalizeMinMax: A subclass of `Transformation` that denormalizes
|
|
14
|
-
input data based on specified minimum and maximum values.
|
|
15
|
-
|
|
16
|
-
Key Methods:
|
|
17
|
-
|
|
18
|
-
- `__call__(data: Tensor) -> Tensor`: Abstract method in the
|
|
19
|
-
`Transformation` class that must be implemented by subclasses to apply
|
|
20
|
-
a transformation to the input data.
|
|
21
|
-
- `__init__(neuron_name: str)`: Initializes the transformation with the
|
|
22
|
-
associated neuron name.
|
|
23
|
-
- `IdentityTransformation.__call__(data: Tensor) -> Tensor`: Returns
|
|
24
|
-
the input data without applying any transformation.
|
|
25
|
-
- `DenormalizeMinMax.__call__(data: Tensor) -> Tensor`: Denormalizes
|
|
26
|
-
the input data by scaling it based on the specified min and max values.
|
|
27
|
-
|
|
28
|
-
The `Transformation` class is intended as a base class for creating
|
|
29
|
-
custom transformations for neuron data, while the `IdentityTransformation`
|
|
30
|
-
is used when no transformation is desired, and `DenormalizeMinMax` is used
|
|
31
|
-
for reversing the normalization process by using a min-max scaling approach.
|
|
32
|
-
"""
|
|
1
|
+
"""Module defining transformations and components."""
|
|
33
2
|
|
|
34
3
|
from abc import ABC, abstractmethod
|
|
35
4
|
from numbers import Number
|
|
36
5
|
|
|
37
6
|
from torch import Tensor
|
|
38
7
|
|
|
39
|
-
from .utils import validate_type
|
|
8
|
+
from .utils import validate_callable, validate_type
|
|
40
9
|
|
|
41
10
|
|
|
42
11
|
class Transformation(ABC):
|
|
43
|
-
"""
|
|
44
|
-
Abstract base class for transformations applied to neuron data.
|
|
12
|
+
"""Abstract base class for tag data transformations."""
|
|
45
13
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
the transformation.
|
|
14
|
+
def __init__(self, tag: str):
|
|
15
|
+
"""Initialize a Transformation.
|
|
49
16
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"""
|
|
55
|
-
|
|
56
|
-
def __init__(self, neuron_name: str):
|
|
57
|
-
validate_type("neuron_name", neuron_name, str)
|
|
17
|
+
Args:
|
|
18
|
+
tag (str): Tag this transformation applies to.
|
|
19
|
+
"""
|
|
20
|
+
validate_type("tag", tag, str)
|
|
58
21
|
|
|
59
22
|
super().__init__()
|
|
60
|
-
self.
|
|
23
|
+
self.tag = tag
|
|
61
24
|
|
|
62
25
|
@abstractmethod
|
|
63
26
|
def __call__(self, data: Tensor) -> Tensor:
|
|
64
|
-
"""
|
|
65
|
-
Abstract method to apply the transformation to the given data.
|
|
27
|
+
"""Apply the transformation to the input tensor.
|
|
66
28
|
|
|
67
29
|
Args:
|
|
68
|
-
data (Tensor):
|
|
30
|
+
data (Tensor): Input tensor representing network data.
|
|
69
31
|
|
|
70
32
|
Returns:
|
|
71
|
-
Tensor:
|
|
33
|
+
Tensor: Transformed tensor.
|
|
72
34
|
|
|
73
|
-
|
|
35
|
+
Raises:
|
|
36
|
+
NotImplementedError: Must be implemented by subclasses.
|
|
74
37
|
"""
|
|
75
38
|
raise NotImplementedError
|
|
76
39
|
|
|
77
40
|
|
|
78
41
|
class IdentityTransformation(Transformation):
|
|
79
|
-
"""
|
|
80
|
-
A transformation that returns the data unchanged (identity transformation).
|
|
81
|
-
|
|
82
|
-
Inherits from the Transformation class and implements the
|
|
83
|
-
__call__ method to return the input data as is.
|
|
84
|
-
"""
|
|
42
|
+
"""A transformation that returns the input unchanged."""
|
|
85
43
|
|
|
86
44
|
def __call__(self, data: Tensor) -> Tensor:
|
|
87
|
-
"""
|
|
88
|
-
Returns the input data without any transformation.
|
|
45
|
+
"""Return the input tensor without any modification.
|
|
89
46
|
|
|
90
47
|
Args:
|
|
91
|
-
data (Tensor):
|
|
48
|
+
data (Tensor): Input tensor.
|
|
92
49
|
|
|
93
50
|
Returns:
|
|
94
|
-
Tensor: The
|
|
51
|
+
Tensor: The same input tensor.
|
|
95
52
|
"""
|
|
96
53
|
return data
|
|
97
54
|
|
|
98
55
|
|
|
99
56
|
class DenormalizeMinMax(Transformation):
|
|
100
|
-
"""
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
min (Number): The minimum value to scale the data.
|
|
111
|
-
max (Number): The maximum value to scale the data.
|
|
112
|
-
|
|
113
|
-
Methods:
|
|
114
|
-
__call__(data: Tensor) -> Tensor:
|
|
115
|
-
Applies the denormalization to the given data by scaling it
|
|
116
|
-
with the min and max values.
|
|
117
|
-
"""
|
|
118
|
-
|
|
119
|
-
# pylint: disable-next=redefined-builtin
|
|
120
|
-
def __init__(self, neuron_name: str, min: Number, max: Number):
|
|
57
|
+
"""A transformation that denormalizes data using min-max scaling."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, tag: str, min: Number, max: Number):
|
|
60
|
+
"""Initialize a min-max denormalization transformation.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
tag (str): Tag this transformation applies to.
|
|
64
|
+
min (Number): Minimum value used for denormalization.
|
|
65
|
+
max (Number): Maximum value used for denormalization.
|
|
66
|
+
"""
|
|
121
67
|
validate_type("min", min, Number)
|
|
122
68
|
validate_type("max", max, Number)
|
|
123
69
|
|
|
124
|
-
super().__init__(
|
|
70
|
+
super().__init__(tag)
|
|
125
71
|
|
|
126
72
|
self.min = min
|
|
127
73
|
self.max = max
|
|
128
74
|
|
|
129
75
|
def __call__(self, data: Tensor) -> Tensor:
|
|
130
|
-
"""
|
|
131
|
-
Denormalizes the input data based on the min and max values.
|
|
76
|
+
"""Denormalize the input tensor using the min-max range.
|
|
132
77
|
|
|
133
78
|
Args:
|
|
134
|
-
data (Tensor):
|
|
79
|
+
data (Tensor): Normalized input tensor (typically in range [0, 1]).
|
|
135
80
|
|
|
136
81
|
Returns:
|
|
137
|
-
Tensor:
|
|
82
|
+
Tensor: Denormalized tensor in the range [min, max].
|
|
138
83
|
"""
|
|
139
84
|
return data * (self.max - self.min) + self.min
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ApplyOperator(Transformation):
|
|
88
|
+
"""A transformation that applies a binary operator to the input tensor."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, tag: str, operator: callable, value: Number):
|
|
91
|
+
"""Initialize an operator-based transformation.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
tag (str): Tag this transformation applies to.
|
|
95
|
+
operator (callable): A callable that takes two arguments (tensor, value)
|
|
96
|
+
and returns a tensor.
|
|
97
|
+
value (Number): The value to use as the second argument in the operator.
|
|
98
|
+
"""
|
|
99
|
+
validate_callable("operator", operator)
|
|
100
|
+
validate_type("value", value, Number)
|
|
101
|
+
|
|
102
|
+
super().__init__(tag)
|
|
103
|
+
|
|
104
|
+
self.operator = operator
|
|
105
|
+
self.value = value
|
|
106
|
+
|
|
107
|
+
def __call__(self, data: Tensor) -> Tensor:
|
|
108
|
+
"""Apply the operator to the input tensor and the specified value.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
data (Tensor): Input tensor.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Tensor: Result of applying `operator(data, value)`.
|
|
115
|
+
"""
|
|
116
|
+
return self.operator(data, self.value)
|