view tvii/sigmoid.py @ 85:d705f6384e8b

i hate namespace conflicts
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 14:03:02 -0800
parents 38aa9098bf2d
children
line wrap: on
line source

"""
sigmoid function: 1/(1 + e^-z)
"""

import numpy as np
from .iterable import isiterable

def sigmoid(z):
    """https://en.wikipedia.org/wiki/Sigmoid_function"""
    if not isinstance(z, np.ndarray) and isiterable(z):
        z = np.array(z)
    return 1./(1. + np.exp(-z))


def sigmoidprime(z):
    """"derivative of sigmoid"""
    return sigmoid(z)*(1-sigmoid(z))