MCPcopy
hub / github.com/ddbourgin/numpy-ml / Affine

Class Affine

numpy_ml/neural_nets/activations/activations.py:342–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340
341
342class 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
395class Identity(Affine):

Callers 15

plot_activationsFunction · 0.90
test_FullyConnectedFunction · 0.90
test_MultiplyLayerFunction · 0.90
test_AddLayerFunction · 0.90
test_Conv2DFunction · 0.90
test_Conv1DFunction · 0.90
test_Deconv2DFunction · 0.90
init_from_strMethod · 0.85
set_paramsMethod · 0.85
_init_paramsMethod · 0.85

Calls

no outgoing calls

Tested by 8

test_FullyConnectedFunction · 0.72
test_MultiplyLayerFunction · 0.72
test_AddLayerFunction · 0.72
test_Conv2DFunction · 0.72
test_Conv1DFunction · 0.72
test_Deconv2DFunction · 0.72