Neural Network used to transform a space into another. This class uses a PyTorch backend.
Parameters: |
-
name
(str )
–
Name of the model to be saved with. Expected a .torch extension.
-
input_size
(int )
–
Number of neurons in the input layer.
-
shape
(Tuple[int] )
–
Tuple with the number of cells per layer.
-
output_size
(int )
–
Number of neurons in the output layer.
-
scale
(bool , default:
True
)
–
Includes scaler step before prediction. Defaults to True.
|
Raises:
ValueError: Raises if any attribute is not valid.
Source code in digneapy/transformers/neural.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 | def __init__(
self,
name: str,
input_size: int,
shape: Sequence[int],
output_size: int,
scale: bool = True,
):
"""Neural Network used to transform a space into another. This class uses a PyTorch backend.
Args:
name (str): Name of the model to be saved with. Expected a .torch extension.
input_size (int): Number of neurons in the input layer.
shape (Tuple[int]): Tuple with the number of cells per layer.
output_size (int): Number of neurons in the output layer.
scale (bool, optional): Includes scaler step before prediction. Defaults to True.
Raises:
ValueError: Raises if any attribute is not valid.
"""
if not name.endswith(".torch"):
name = name + ".torch"
Transformer.__init__(self, name)
torch.nn.Module.__init__(self)
self._scaler = StandardScaler() if scale else None
self._model = torch.nn.ModuleList([torch.nn.Linear(input_size, shape[0])])
self._model.append(torch.nn.ReLU())
for i in range(len(shape[1:-1])):
self._model.append(torch.nn.Linear(shape[i], shape[i + 1]))
self._model.append(torch.nn.ReLU())
self._model.append(torch.nn.Linear(shape[-1], output_size))
|