{ "metadata": {}, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "# from http://pythonprogramming.net/3d-bar-charts-python-matplotlib/\n", "from mpl_toolkits.mplot3d import Axes3D\n", "import matplotlib.pyplot as plt\n", "import matplotlib.patches as mpatches\n", "from matplotlib import animation\n", "import numpy as np\n", "import pylab as pylab\n", "import math as math\n", "from decimal import *\n", "from savedWeights import *\n", " \n", "fig = plt.figure()\n", "ax1 = fig.add_subplot(111, projection='3d')\n", "colorNumber = -1\n", "ypos = []\n", "yposNeuronOrder = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]\n", "weights = retreiveTestW()\n", "colors = []\n", "neurons = [None]*len(weights)\n", "numberOfWeights = len(weights)\n", "numberOfPixels = 15\n", "xpos = np.ones(numberOfPixels*numberOfWeights)\n", "num_elements = len(xpos)\n", "zpos = np.zeros(numberOfPixels*numberOfWeights)\n", "dx = np.ones(numberOfPixels*numberOfWeights)*.9\n", "dy = np.ones(numberOfPixels*numberOfWeights)*.5\n", "timeDelay = 24#3\n", "\n", "for weightIndex in range(numberOfWeights):\n", "\tcolorNumber += 1\n", "\tif colorNumber == 4: colorNumber = 0\n", "\tif colorNumber == 0: colors = np.append(colors, ['r']*15); neurons[weightIndex] = plt.Rectangle((0, 0), 0.1, 0.1,fc='r');\n", "\tif colorNumber == 1: colors = np.append(colors, ['g']*15); neurons[weightIndex] = plt.Rectangle((0, 0), 0.1, 0.1,fc='g');\n", "\tif colorNumber == 2: colors = np.append(colors, ['b']*15); neurons[weightIndex] = plt.Rectangle((0, 0), 0.1, 0.1,fc='b');\n", "\tif colorNumber == 3: colors = np.append(colors, ['y']*15); neurons[weightIndex] = plt.Rectangle((0, 0), 0.1, 0.1,fc='y');\n", "\typos = np.append(ypos, yposNeuronOrder)\n", "\txpos[(15*weightIndex):(15*(weightIndex+1))] *= (weightIndex+1)\n", "\n", "colors = colors.tolist();ypos = ypos.tolist();xpos = xpos.tolist();" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
generateGraph
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def generateGraph(timePoint):\n", "\ttimePointScaled = math.floor(Decimal(format((timePoint), '.1f'))/Decimal(format(timeDelay, '.1f')))\n", "\tax1.clear()\n", "\tax1.grid(b=False)\t\n", "\tax1.set_axisbelow(True)\n", "\tdz = []\n", "\tfor weightIndex in range(numberOfWeights):\n", "\t\tif weightIndex == timePointScaled: dz = np.append(dz, weights[weightIndex])\n", "\t\telse: dz = np.append(dz, [0]*numberOfPixels)\n", "\tdz = dz.tolist()\n", "\txLabel = ax1.set_xlabel('\\nOutput Neuron', linespacing=1.2)\n", "\tyLabel = ax1.set_ylabel('\\nInput Neuron', linespacing=1.2)\n", "\tzLabel = ax1.set_zlabel('\\nWeight', linespacing=1.2)\n", "\tax1.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colors, alpha=0.95)\n", "\tif timePointScaled==5 or timePointScaled==10 or timePointScaled==15 or timePointScaled==20 or timePointScaled==25: print 'processing timepoint:\\t',timePointScaled\n", "\n", "ax1.view_init(elev=30.0, azim=40)\n", "\n", "line_ani = animation.FuncAnimation(fig, generateGraph, frames=(numberOfWeights*timeDelay), interval=1, blit=False) \n", "ext = 'mp4'\n", "fps = 30\n", "codec = {'mp4': 'libx264', 'webm': 'libvpx'}.get(ext, 'mpeg4')\n", "line_ani.save('26CharTrainedWeights.mp4', fps=30, extra_args=['-vcodec', 'libx264'])\n", "print 'Completed saving the video'\n", "\n", "#plt.show()" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }