【Python-ML】神经网络激励函数-Softmax
2018-01-27 09:07
459 查看
# -*- coding: utf-8 -*- ''' Created on 2018年1月27日 @author: Jason.F @summary: 前馈神经网络激励函数-softmax函数,评估多类别分类任务中的类别概率 ''' import numpy as np import time if __name__ == "__main__": start = time.clock() def net_input(X,w): z=X.dot(w) return z def softmax(z): return np.exp(z)/np.sum(np.exp(z)) def softmax_activation(X,w): z=net_input(X,w) return softmax(z) #W:array,shape=[n_output_units,n_hidden_units+1],weight matrix for hidden layer --> output layer #note that first column (A[:][0]=1) are the bias units. W=np.array([[1.1,1.2,1.3,0.5],[0.1,0.2,0.4,0.1],[0.2,0.5,2.1,1.9]]) #A:array,shape=[n_hiddern+1,n_samples],Activation of hidden layer. #note that first element (A[0][0]=1) is the bias unit. A=np.array([[1.0],[0.1],[0.3],[0.7]]) #Z:array,shape=[n_output_units,n_samples],Net input of the output layer. Z=W.dot(A) y_probas = softmax(Z) print ('Probabilities:\n',y_probas) print (y_probas.sum()) y_class = np.argmax(Z,axis=0) print ('predicted class label:%d'%y_class[0]) end = time.clock() print('finish all in %s' % str(end - start))
结果:
('Probabilities:\n', array([[ 0.40386493], [ 0.07756222], [ 0.51857284]])) 1.0 predicted class label:2 finish all in 0.00170994801643
相关文章推荐
- 【Python-ML】神经网络激励函数-双曲正切(hyperbolic tangent,tanh)函数
- 【Python-ML】神经网络激励函数-Sigmoid
- 【Python-ML】神经网络-多层感知器增加梯度检验
- 【Python-ML】神经网络-多层感知器
- 【Python-ML】自适应线性神经网络(Adaline)
- 【Python-ML】神经网络-深度学习库Keras
- 【Python-ML】神经网络-Theano张量库(GPU版的Numpy)
- 深度学习-基于softmax神经网络分类的源码实现
- 【自用】ML: 神经网络中的 sigmoid函数极其导数的实现
- Python实现感知器模型、两层神经网络
- 识别MNIST数据集之(二):用Python实现神经网络
- 使用python写神经网络模型之分类器
- 从感知机到神经网络:Python实现与测试
- 神经网络激励函数的形象解释
- Python手写神经网络之(二)LeNet卷积神经网络
- 神经网络之AlexNet模型的实现(Python+TensorFlow)
- 神经网络中 BP 算法的原理与 PYTHON 实现源码解析
- 机器学习算法练习之(二):Python和Tensorflow分别实现简单的神经网络
- 用python实现一个神经网络
- 6.1神经网络--python机器学习