はじめに
人工知能のアルゴリズムでは、シグモイド関数とシグモイド関数の微分が大切みたいです。
コードをメモっておきます。
なお、以下のコードで、でグラフの見出しを作成することが可能です。 複数のデータ例がある場合に、便利です。
plt.plot(x, y_sig, label="sigmoid") plt.plot(x, dy_sig, label="d_sigmoid") plt.legend()
コード
import matplotlib.pyplot as plt import numpy as np import math # シグモイド関数 # y = 1 / (1 * + e^(-x)) def sigmoid(a): s = 1 / (1 + e**-a) return s # シグモイド関数の微分 # dy_sig = sigmoid(x) * (1 - sigmoid(x)) def d_sigmoid(a): s = sigmoid(a) * (1 - sigmoid(a)) return s e = math.e dx = 0.1 x = np.arange(-10, 10, dx) y_sig = sigmoid(x) dy_sig = d_sigmoid(x) plt.plot(x, y_sig, label="sigmoid") plt.plot(x, dy_sig, label="d_sigmoid") plt.legend() plt.show()
イメージ