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.
@@ -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
- Args:
47
- neuron_name (str): The name of the neuron associated with
48
- the transformation.
14
+ def __init__(self, tag: str):
15
+ """Initialize a Transformation.
49
16
 
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)
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.neuron_name = neuron_name
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): The input data to be transformed.
30
+ data (Tensor): Input tensor representing network data.
69
31
 
70
32
  Returns:
71
- Tensor: The transformed data.
33
+ Tensor: Transformed tensor.
72
34
 
73
- Must be implemented by subclasses.
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): The input data to be returned as is.
48
+ data (Tensor): Input tensor.
92
49
 
93
50
  Returns:
94
- Tensor: The unchanged input data.
51
+ Tensor: The same input tensor.
95
52
  """
96
53
  return data
97
54
 
98
55
 
99
56
  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):
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__(neuron_name)
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): The normalized input data to be denormalized.
79
+ data (Tensor): Normalized input tensor (typically in range [0, 1]).
135
80
 
136
81
  Returns:
137
- Tensor: The denormalized data.
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)