zoukankan      html  css  js  c++  java
  • Sigmoid And Tanh

    Sigmoid

    • The value is [0,1]

    import math
    import numpy as np
    import matplotlib.pyplot as plt
    def sigmoid(x):
        a = []
        for item in x:
            a.append(1/(1+math.exp(-item)))
        return a
        
    ##这个函数返回sigmoid的函数值。
    
    x = np.arange(-10., 10., 0.2)
    sig = sigmoid(x)
    plt.plot(x,sig)
    plt.show()
    
    

    Tanh Function

    • the value is [-1,1]

    #!/usr/bin/python #encoding:utf-8
    import math
    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib as mpl
    mpl.rcParams['axes.unicode_minus']=False
     
     
    def  sigmoid(x):
        return 1.0 / (1.0 + np.exp(-x))
     
    fig = plt.figure(figsize=(6,4))
    ax = fig.add_subplot(111)
     
    x = np.linspace(-10, 10)
    y = sigmoid(x)
    tanh = 2*sigmoid(2*x) - 1
     
    plt.xlim(-11,11)
    plt.ylim(-1.1,1.1)
     
    ax.spines['top'].set_color('none')
    ax.spines['right'].set_color('none')
     
    ax.xaxis.set_ticks_position('bottom')
    ax.spines['bottom'].set_position(('data',0))
    ax.set_xticks([-10,-5,0,5,10])
    ax.yaxis.set_ticks_position('left')
    ax.spines['left'].set_position(('data',0))
    ax.set_yticks([-1,-0.5,0.5,1])
     
    plt.plot(x,y,label="Sigmoid",color = "blue")
    plt.plot(2*x,tanh,label="Tanh", color = "red")
    plt.legend()
    plt.show()
    
    

    The Unknow Word

    The First Column The Second Column
    tanh hyperbolic tan [haiper ' bolik] 双曲线正切
  • 相关阅读:
    Map集合
    Collection的另外一个子类LinkedList&Set集合
    多项式牛顿迭代 学习笔记
    《混凝土数学》第二章 和式 学习笔记
    洛谷P5039 最小生成树 题解
    gdfzoj#236 | 提高组练习题16 Set
    CF979E 题解
    CF1039D 题解
    CF886E 题解
    CF1061C 题解
  • 原文地址:https://www.cnblogs.com/hugeng007/p/9501225.html
Copyright © 2011-2022 走看看