{ "cells": [ { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "import tensorflow as tf\n", "import numpy as np\n", "\n", "sess = tf.Session()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def variable_init(size):\n", " in_dim = size[0]\n", "\n", " #计算随机生成变量所服从的正态分布标准差\n", " w_stddev = 1. / tf.sqrt(in_dim / 2.)\n", " return tf.random_normal(shape=size, stddev=w_stddev)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "def variable_init(size):\n", " # He initialization: sqrt(2./dim of the previous layer)\n", " # np.random.randn(layers_dims[l], layers_dims[l-1]) * np.sqrt(2./layers_dims[l-1])\n", " in_dim = size[0]\n", " out_dim = size[1]\n", " return np.random.randn(in_dim, out_dim) * np.sqrt(2./in_dim)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[-1.8757054 , -1.1076592 , 0.70838064],\n", " [-0.5223602 , -0.5380756 , 0.47503483]], dtype=float32)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sess.run(variable_init([2,3]))" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[-1.2229257 , 0.60203326, -1.1791672 ],\n", " [ 2.1850308 , 0.15628994, 1.35896603]])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "variable_init([2,3])" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.00633705, 0.94050111, 0.04682479, 0.00633705])" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sess.run(tf.nn.softmax(np.array([-2.,3., 0., -2])))" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "tf.nn.sigmoid?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" }, "toc": { "colors": { "hover_highlight": "#DAA520", "running_highlight": "#FF0000", "selected_highlight": "#FFD700" }, "moveMenuLeft": true, "nav_menu": { "height": "12px", "width": "252px" }, "navigate_menu": true, "number_sections": true, "sideBar": true, "threshold": 4, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }