| 340 | |
| 341 | |
| 342 | class Affine(ActivationBase): |
| 343 | def __init__(self, slope=1, intercept=0): |
| 344 | """ |
| 345 | An affine activation function. |
| 346 | |
| 347 | Parameters |
| 348 | ---------- |
| 349 | slope: float |
| 350 | Activation slope. Default is 1. |
| 351 | intercept: float |
| 352 | Intercept/offset term. Default is 0. |
| 353 | """ |
| 354 | self.slope = slope |
| 355 | self.intercept = intercept |
| 356 | super().__init__() |
| 357 | |
| 358 | def __str__(self): |
| 359 | """Return a string representation of the activation function""" |
| 360 | return "Affine(slope={}, intercept={})".format(self.slope, self.intercept) |
| 361 | |
| 362 | def fn(self, z): |
| 363 | r""" |
| 364 | Evaluate the Affine activation on the elements of input `z`. |
| 365 | |
| 366 | .. math:: |
| 367 | |
| 368 | \text{Affine}(z_i) = \text{slope} \times z_i + \text{intercept} |
| 369 | """ |
| 370 | return self.slope * z + self.intercept |
| 371 | |
| 372 | def grad(self, x): |
| 373 | r""" |
| 374 | Evaluate the first derivative of the Affine activation on the elements |
| 375 | of input `x`. |
| 376 | |
| 377 | .. math:: |
| 378 | |
| 379 | \frac{\partial \text{Affine}}{\partial x_i} = \text{slope} |
| 380 | """ |
| 381 | return self.slope * np.ones_like(x) |
| 382 | |
| 383 | def grad2(self, x): |
| 384 | r""" |
| 385 | Evaluate the second derivative of the Affine activation on the elements |
| 386 | of input `x`. |
| 387 | |
| 388 | .. math:: |
| 389 | |
| 390 | \frac{\partial^2 \text{Affine}}{\partial x_i^2} = 0 |
| 391 | """ |
| 392 | return np.zeros_like(x) |
| 393 | |
| 394 | |
| 395 | class Identity(Affine): |
no outgoing calls