Normalize sequences and targets Args: sequences: Input sequences targets: Target values fit: Whether to fit normalization parameters Returns: Normalized sequences and targets
(
self,
sequences: np.ndarray,
targets: np.ndarray,
fit: bool = True
)
| 181 | return np.array(sequences), np.array(targets) |
| 182 | |
| 183 | def normalize_data( |
| 184 | self, |
| 185 | sequences: np.ndarray, |
| 186 | targets: np.ndarray, |
| 187 | fit: bool = True |
| 188 | ) -> Tuple[np.ndarray, np.ndarray]: |
| 189 | """ |
| 190 | Normalize sequences and targets |
| 191 | |
| 192 | Args: |
| 193 | sequences: Input sequences |
| 194 | targets: Target values |
| 195 | fit: Whether to fit normalization parameters |
| 196 | |
| 197 | Returns: |
| 198 | Normalized sequences and targets |
| 199 | """ |
| 200 | if fit: |
| 201 | # Calculate normalization parameters |
| 202 | self.feature_mean = sequences.mean(axis=(0, 1)) |
| 203 | self.feature_std = sequences.std(axis=(0, 1)) + 1e-8 |
| 204 | self.target_mean = targets.mean() |
| 205 | self.target_std = targets.std() + 1e-8 |
| 206 | |
| 207 | # Normalize |
| 208 | sequences_norm = (sequences - self.feature_mean) / self.feature_std |
| 209 | targets_norm = (targets - self.target_mean) / self.target_std |
| 210 | |
| 211 | return sequences_norm, targets_norm |
| 212 | |
| 213 | def train( |
| 214 | self, |