congrads 0.1.0__py3-none-any.whl → 1.0.1__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 +21 -13
- congrads/checkpoints.py +232 -0
- congrads/constraints.py +728 -316
- congrads/core.py +525 -139
- congrads/datasets.py +273 -516
- congrads/descriptor.py +95 -30
- congrads/metrics.py +185 -38
- congrads/networks.py +51 -28
- congrads/requirements.txt +6 -0
- congrads/transformations.py +139 -0
- congrads/utils.py +710 -0
- congrads-1.0.1.dist-info/LICENSE +26 -0
- congrads-1.0.1.dist-info/METADATA +208 -0
- congrads-1.0.1.dist-info/RECORD +16 -0
- {congrads-0.1.0.dist-info → congrads-1.0.1.dist-info}/WHEEL +1 -1
- congrads/learners.py +0 -233
- congrads-0.1.0.dist-info/LICENSE +0 -34
- congrads-0.1.0.dist-info/METADATA +0 -196
- congrads-0.1.0.dist-info/RECORD +0 -13
- {congrads-0.1.0.dist-info → congrads-1.0.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
"""
|
|
33
|
+
|
|
34
|
+
from abc import ABC, abstractmethod
|
|
35
|
+
from numbers import Number
|
|
36
|
+
|
|
37
|
+
from torch import Tensor
|
|
38
|
+
|
|
39
|
+
from .utils import validate_type
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Transformation(ABC):
|
|
43
|
+
"""
|
|
44
|
+
Abstract base class for transformations applied to neuron data.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
neuron_name (str): The name of the neuron associated with
|
|
48
|
+
the transformation.
|
|
49
|
+
|
|
50
|
+
Methods:
|
|
51
|
+
__call__(data: Tensor) -> Tensor:
|
|
52
|
+
Applies the transformation to the provided data.
|
|
53
|
+
Must be implemented by subclasses.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def __init__(self, neuron_name: str):
|
|
57
|
+
validate_type("neuron_name", neuron_name, str)
|
|
58
|
+
|
|
59
|
+
super().__init__()
|
|
60
|
+
self.neuron_name = neuron_name
|
|
61
|
+
|
|
62
|
+
@abstractmethod
|
|
63
|
+
def __call__(self, data: Tensor) -> Tensor:
|
|
64
|
+
"""
|
|
65
|
+
Abstract method to apply the transformation to the given data.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
data (Tensor): The input data to be transformed.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Tensor: The transformed data.
|
|
72
|
+
|
|
73
|
+
Must be implemented by subclasses.
|
|
74
|
+
"""
|
|
75
|
+
raise NotImplementedError
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
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
|
+
"""
|
|
85
|
+
|
|
86
|
+
def __call__(self, data: Tensor) -> Tensor:
|
|
87
|
+
"""
|
|
88
|
+
Returns the input data without any transformation.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
data (Tensor): The input data to be returned as is.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
Tensor: The unchanged input data.
|
|
95
|
+
"""
|
|
96
|
+
return data
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class DenormalizeMinMax(Transformation):
|
|
100
|
+
"""
|
|
101
|
+
A transformation that denormalizes data based on a
|
|
102
|
+
specified min and max value.
|
|
103
|
+
|
|
104
|
+
This transformation scales the data by the range of the min and max values,
|
|
105
|
+
then adds the min value to denormalize it back to the original scale.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
neuron_name (str): The name of the neuron associated with
|
|
109
|
+
the transformation.
|
|
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):
|
|
121
|
+
validate_type("min", min, Number)
|
|
122
|
+
validate_type("max", max, Number)
|
|
123
|
+
|
|
124
|
+
super().__init__(neuron_name)
|
|
125
|
+
|
|
126
|
+
self.min = min
|
|
127
|
+
self.max = max
|
|
128
|
+
|
|
129
|
+
def __call__(self, data: Tensor) -> Tensor:
|
|
130
|
+
"""
|
|
131
|
+
Denormalizes the input data based on the min and max values.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
data (Tensor): The normalized input data to be denormalized.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
Tensor: The denormalized data.
|
|
138
|
+
"""
|
|
139
|
+
return data * (self.max - self.min) + self.min
|