Search code examples
pythonmachine-learningneural-networkpybrain

Pybrain neural network step transfer function


can someone show me how to implement a step activation function in pybrain ?

eg.

def stepActivationFunction(n):
    if n > 0.5: return 1.
    else: return 0.

I can't seem to find any implementation in pybrain.structure.modules ?

Thanks

EDIT

I now understand that you can extend pybrain and create your own layers. However, i'm still not sure how to do this based on the documentation. Can someone possibly show me an example of how to create a layer that implements a step activation function ?


Solution

  • If you want to use this in a multilayer network trained with backpropagation, then this is impossible. The step function is not (sub)differentiable, which is a requirement for the backprop algorithm.

    The closest that you can come to a step function would be a function like

    f(x) = max(-1, min(x, 1))
    

    which clips the value of x to produce a value between 1 and -1 (you can change this to 0 and 1 if you like). This function has a subderivative of

    f'(x) = 1 if -1 < x < 1
            0 otherwise