{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using TensorFlow backend.\n" ] } ], "source": [ "import numpy as np\n", "from keras import activations\n", "from keras import backend as K" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def format_decimal(arr):\n", " return [round(x * 1e6) / 1e6 for x in arr]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### softmax" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softmax.0] 1D**" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softmax(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softmax.1] 2D**" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965, 0.107768, 0.149902, 0.11105, 0.247147, 0.082268, 0.301865]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softmax(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### softplus" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softplus.0] 1D**" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softplus(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softplus.1] 2D**" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928, 0.67826, 0.854355, 0.693147, 1.171101, 0.554355, 1.313262]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softplus(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softplus.2] 3D**" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.693147, 0.798139, 0.474077, 0.644397, 1.313262, 2.126928, 0.67826, 2.395545, 0.693147, 1.171101, 0.554355, 1.313262]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softplus(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### softsign" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softsign.0] 1D**" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softsign(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softsign.1] 2D**" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.230769, 0.0, 0.444444, -0.230769, 0.5]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softsign(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.softsign.2] 3D**" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.0, 0.166667, -0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.69697, 0.0, 0.444444, -0.230769, 0.5]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.softsign(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### ReLU" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.relu.0] 1D**" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.0, 0.2, 0.5, 0.0, 1.0, 2.0]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.relu(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.relu.1] 2D**" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.0, 0.2, 0.5, 0.0, 1.0, 2.0, 0.0, 0.3, 0.0, 0.8, 0.0, 1.0]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.relu(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.relu.2] 3D**" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.0, 0.2, 0.0, 0.0, 1.0, 2.0, 0.0, 2.3, 0.0, 0.8, 0.0, 1.0]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.relu(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.relu.3] 3D, max_value=0.5**" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.0, 0.2, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.relu(K.variable(np.array([arr_in])), max_value=0.5)\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.relu.4] 3D, alpha=0.3**" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.0, 0.2, -0.15, -0.03, 1.0, 2.0, -0.009, 2.3, 0.0, 0.8, -0.09, 1.0]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.relu(K.variable(np.array([arr_in])), alpha=0.3)\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### tanh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.tanh.0] 1D**" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.tanh(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.tanh.1] 2D**" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.291313, 0.0, 0.664037, -0.291313, 0.761594]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.tanh(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.tanh.2] 3D**" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.0, 0.197375, -0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.980096, 0.0, 0.664037, -0.291313, 0.761594]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.tanh(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### sigmoid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.sigmoid.0] 1D**" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.sigmoid(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.sigmoid.1] 2D**" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797, 0.492501, 0.574443, 0.5, 0.689974, 0.425557, 0.731059]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.sigmoid(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.sigmoid.2] 3D**" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.5, 0.549834, 0.377541, 0.475021, 0.731059, 0.880797, 0.492501, 0.908877, 0.5, 0.689974, 0.425557, 0.731059]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.sigmoid(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### hardSigmoid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.hardSigmoid.0] 1D**" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.5, 0.54, 0.6, 0.48, 0.7, 0.9]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.hard_sigmoid(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.hardSigmoid.1] 2D**" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.5, 0.54, 0.6, 0.48, 0.7, 0.9, 0.494, 0.56, 0.5, 0.66, 0.44, 0.7]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.hard_sigmoid(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.hardSigmoid.2] 3D**" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.5, 0.54, 0.4, 0.48, 0.7, 0.9, 0.494, 0.96, 0.5, 0.66, 0.44, 0.7]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.hard_sigmoid(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### linear" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.linear.0] 1D**" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (6,)\n", "out: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.linear(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.linear.1] 2D**" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 6)\n", "out shape: (2, 6)\n", "out: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, -0.03, 0.3, 0.0, 0.8, -0.3, 1.0]\n" ] } ], "source": [ "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 6)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.linear(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[activations.linear.2] 3D**" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "in shape: (2, 2, 3)\n", "out shape: (2, 2, 3)\n", "out: [0.0, 0.2, -0.5, -0.1, 1.0, 2.0, -0.03, 2.3, 0.0, 0.8, -0.3, 1.0]\n" ] } ], "source": [ "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n", "data_in_shape = (2, 2, 3)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "\n", "result = activations.linear(K.variable(np.array([arr_in])))\n", "\n", "arr_out = K.eval(result)[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }