{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "if(window['d3'] === undefined ||\n", " window['Nyaplot'] === undefined){\n", " var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n", "\n", "\n", "\n", " var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n", "\n", " require.config({paths: path, shim:shim});\n", "\n", "\n", "require(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n", "\n", "\tvar script = d3.select(\"head\")\n", "\t .append(\"script\")\n", "\t .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n", "\t .attr(\"async\", true);\n", "\n", "\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n", "\n", "\n", "\t var event = document.createEvent(\"HTMLEvents\");\n", "\t event.initEvent(\"load_nyaplot\",false,false);\n", "\t window.dispatchEvent(event);\n", "\t console.log('Finished loading Nyaplotjs');\n", "\n", "\t};\n", "\n", "\n", "});});\n", "}\n" ], "text/plain": [ "\"if(window['d3'] === undefined ||\\n window['Nyaplot'] === undefined){\\n var path = {\\\"d3\\\":\\\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\\\",\\\"downloadable\\\":\\\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\\\"};\\n\\n\\n\\n var shim = {\\\"d3\\\":{\\\"exports\\\":\\\"d3\\\"},\\\"downloadable\\\":{\\\"exports\\\":\\\"downloadable\\\"}};\\n\\n require.config({paths: path, shim:shim});\\n\\n\\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\\n\\n\\tvar script = d3.select(\\\"head\\\")\\n\\t .append(\\\"script\\\")\\n\\t .attr(\\\"src\\\", \\\"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\\\")\\n\\t .attr(\\\"async\\\", true);\\n\\n\\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\\n\\n\\n\\t var event = document.createEvent(\\\"HTMLEvents\\\");\\n\\t event.initEvent(\\\"load_nyaplot\\\",false,false);\\n\\t window.dispatchEvent(event);\\n\\t console.log('Finished loading Nyaplotjs');\\n\\n\\t};\\n\\n\\n});});\\n}\\n\"" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "#" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'ruby_brain'\n", "require 'nyaplot'\n", "org_stderr = $stderr\n", "$stderr = File.open(File::NULL, \"w\")\n", "org_stdout = $stdout\n", "$stdout = File.open(File::NULL, \"w\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we tray to make a network which imitate a wave form.\n", "\n", "Currently RubyBrain has shigmoid as the activation function.\n", "Output layer also can has only sigmoid. \n", "In the result, the network can only treat 0~1 outpus.\n", "\n", "So, we prepare a function which produces values whithin 0~1 for this example." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define `X` is range $0 .. (2*\\pi)$ with step $0.1$" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35000000000000003, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41000000000000003, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47000000000000003, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.5700000000000001, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.6900000000000001, 0.7000000000000001, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.8200000000000001, 0.8300000000000001, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.9400000000000001, 0.9500000000000001, 0.96, 0.97, 0.98, 0.99, 1.0]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X = (0..1).step(0.01).to_a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set\n", "\n", "$(0.75 * sin(x*2*\\pi) + 0.15 * cos(5*\\pi – 0.023) + 1) / 2$\n", "\n", "to `Y_IDEAL`\n", "\n", "and use `Y_IDEAL + (random noise)` for `Y`" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[0.40552972386823233, 0.4774905499906632, 0.46219024504515543, 0.49408772854706584, 0.5511014641648844, 0.5830607265235062, 0.6290909985528079, 0.7188366408926009, 0.7464502651167544, 0.7570660940515662, 0.8487802767323701, 0.8048638528562673, 0.8781999845775225, 0.8350774438331358, 0.8231075782014501, 0.8205059962114565, 0.7620703948059987, 0.7592930665178563, 0.7564538805783714, 0.7718808660785458, 0.7939093724782238, 0.7241579038424741, 0.7556405318869907, 0.783810615332835, 0.8146499203453131, 0.9079803254799771, 0.8609454155246148, 0.963374223298478, 0.953686722421743, 0.9423887091039158, 0.9586439428093037, 0.9007886717482598, 0.8955021053214614, 0.9019821644047896, 0.8086460470276943, 0.8185435115568951, 0.7927944294792918, 0.7413519001413804, 0.6947676161553855, 0.6612751665879212, 0.6504900333096678, 0.5568179391111076, 0.6171380642298777, 0.5603384907700707, 0.5760947029063451, 0.5844655117589066, 0.6711066378344058, 0.5841094333299761, 0.5794228773540913, 0.5832987506533194, 0.5501273323962572, 0.6012162864215608, 0.5261450973336963, 0.4587469523684175, 0.4553581842601778, 0.37634597984408674, 0.31052441243765166, 0.2690342620110815, 0.2536487272472072, 0.24769930022299474, 0.17983166212931287, 0.12805859422706325, 0.11537112023884277, 0.21125790572283304, 0.16186838744714038, 0.16132579127049282, 0.2444294667072354, 0.19538817632744343, 0.24132425605822755, 0.22265883054824356, 0.2636831443649561, 0.26362289739592015, 0.2222927083908854, 0.17811329085234903, 0.12732948899046037, 0.16354600102188116, 0.13097407719532192, 0.06720693291100473, 0.05812709756878874, 0.01542796780553005, 0.07579910093602107, 0.07597297165054914, 0.057527311423150096, 0.08270797348892969, 0.10655437450419285, 0.23844271322818672, 0.2668974483956788, 0.2526080180629122, 0.36733263194408383, 0.3199785178151612, 0.3481489425022125, 0.4350143793173079, 0.37639065262225435, 0.3603462039844907, 0.34573400064588994, 0.4343252944140983, 0.3526295334202674, 0.3255975274840675, 0.3246599727949182, 0.3813989077499905, 0.36205386878698165]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Y_IDEAL = X.map {|x| (0.75 * Math.sin(x*2*Math::PI) - 0.2 * Math.cos(5*x*2*Math::PI - 0.023) + 1) / 2} \n", "Y = [Y_IDEAL, Array.new(X.size) {rand(-0.05..0.05)}].transpose.map {|e| e.inject(:+)}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Following graph shows `X`, `Y_IDEAL` and `Y`" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#[#[#:line, :options=>{:x=>\"data0\", :y=>\"data1\", :title=>\"Y_IDEAL\"}, :data=>\"96a106dd-1c42-4b8b-8de2-96edfab422e7\"}, @xrange=[0.0, 1.0], @yrange=[0.042411493708411296, 0.9575885062915888]>, #:scatter, :options=>{:x=>\"data0\", :y=>\"data1\", :title=>\"Y\", :color=>\"rgb(43,140,190)\"}, :data=>\"ec5ac005-4e2a-418a-b0b5-c5a8b481741c\"}, @xrange=[0.0, 1.0], @yrange=[0.01542796780553005, 0.963374223298478]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[0.0, 1.0], :yrange=>[0.01542796780553005, 0.963374223298478]}}>], :data=>{\"96a106dd-1c42-4b8b-8de2-96edfab422e7\"=>#0.0, :data1=>0.4000264488340164}, {:data0=>0.01, :data1=>0.42775527110469325}, {:data0=>0.02, :data1=>0.46476787381494744}, {:data0=>0.03, :data1=>0.5096444389387358}, {:data0=>0.04, :data1=>0.560177944254349}, {:data0=>0.05, :data1=>0.6135815756685751}, {:data0=>0.06, :data1=>0.6667529964208871}, {:data0=>0.07, :data1=>0.7165696382953357}, {:data0=>0.08, :data1=>0.7601861427790648}, {:data0=>0.09, :data1=>0.7953048689854758}, {:data0=>0.1, :data1=>0.820393020775661}, {:data0=>0.11, :data1=>0.8348251698745579}, {:data0=>0.12, :data1=>0.8389372534949249}, {:data0=>0.13, :data1=>0.8339867893139402}, {:data0=>0.14, :data1=>0.8220232294733926}, {:data0=>0.15, :data1=>0.8056811701126355}, {:data0=>0.16, :data1=>0.7879166828991226}, {:data0=>0.17, :data1=>0.7717126010580154}, {:data0=>0.18, :data1=>0.7597816296838359}, {:data0=>0.19, :data1=>0.7542963613397422}, {:data0=>0.2, :data1=>0.756672642444699}, {:data0=>0.21, :data1=>0.7674275117044373}, {:data0=>0.22, :data1=>0.7861256302515915}, {:data0=>0.23, :data1=>0.8114194589620184}, {:data0=>0.24, :data1=>0.8411792597281302}, {:data0=>0.25, :data1=>0.8727002027779698}, {:data0=>0.26, :data1=>0.9029663123247347}, {:data0=>0.27, :data1=>0.9289454169513626}, {:data0=>0.28, :data1=>0.9478862340141797}, {:data0=>0.29, :data1=>0.9575885062915888}, {:data0=>0.3, :data1=>0.9566197447766662}, {:data0=>0.31, :data1=>0.9444573559268936}, {:data0=>0.32, :data1=>0.9215422334464239}, {:data0=>0.33, :data1=>0.8892385590473597}, {:data0=>0.34, :data1=>0.8497037354957271}, {:data0=>0.35000000000000003, :data1=>0.8056811701126354}, {:data0=>0.36, :data1=>0.7602361768767882}, {:data0=>0.37, :data1=>0.7164608313245959}, {:data0=>0.38, :data1=>0.6771766497323368}, {:data0=>0.39, :data1=>0.6446641752874066}, {:data0=>0.4, :data1=>0.6204459184436939}, {:data0=>0.41000000000000003, :data1=>0.6051438743983245}, {:data0=>0.42, :data1=>0.5984255390164767}, {:data0=>0.43, :data1=>0.5990436803059914}, {:data0=>0.44, :data1=>0.6049659438242828}, {:data0=>0.45, :data1=>0.6135815756685751}, {:data0=>0.46, :data1=>0.6219649968509536}, {:data0=>0.47000000000000003, :data1=>0.6271703969280801}, {:data0=>0.48, :data1=>0.6265284775775357}, {:data0=>0.49, :data1=>0.6179162656918447}, {:data0=>0.5, :data1=>0.5999735511659836}, {:data0=>0.51, :data1=>0.5722447288953069}, {:data0=>0.52, :data1=>0.5352321261850526}, {:data0=>0.53, :data1=>0.490355561061264}, {:data0=>0.54, :data1=>0.43982205574565103}, {:data0=>0.55, :data1=>0.38641842433142504}, {:data0=>0.56, :data1=>0.33324700357911274}, {:data0=>0.5700000000000001, :data1=>0.28343036170466424}, {:data0=>0.58, :data1=>0.2398138572209354}, {:data0=>0.59, :data1=>0.2046951310145244}, {:data0=>0.6, :data1=>0.179606979224339}, {:data0=>0.61, :data1=>0.16517483012544204}, {:data0=>0.62, :data1=>0.16106274650507507}, {:data0=>0.63, :data1=>0.16601321068605968}, {:data0=>0.64, :data1=>0.17797677052660738}, {:data0=>0.65, :data1=>0.19431882988736465}, {:data0=>0.66, :data1=>0.21208331710087713}, {:data0=>0.67, :data1=>0.2282873989419847}, {:data0=>0.68, :data1=>0.24021837031616433}, {:data0=>0.6900000000000001, :data1=>0.24570363866025774}, {:data0=>0.7000000000000001, :data1=>0.24332735755530105}, {:data0=>0.71, :data1=>0.23257248829556276}, {:data0=>0.72, :data1=>0.21387436974840862}, {:data0=>0.73, :data1=>0.18858054103798189}, {:data0=>0.74, :data1=>0.15882074027186988}, {:data0=>0.75, :data1=>0.12729979722203044}, {:data0=>0.76, :data1=>0.09703368767526532}, {:data0=>0.77, :data1=>0.07105458304863732}, {:data0=>0.78, :data1=>0.05211376598582007}, {:data0=>0.79, :data1=>0.042411493708411296}, {:data0=>0.8, :data1=>0.043380255223333775}, {:data0=>0.81, :data1=>0.055542644073106606}, {:data0=>0.8200000000000001, :data1=>0.07845776655357617}, {:data0=>0.8300000000000001, :data1=>0.11076144095264046}, {:data0=>0.84, :data1=>0.15029626450427247}, {:data0=>0.85, :data1=>0.19431882988736454}, {:data0=>0.86, :data1=>0.23976382312321176}, {:data0=>0.87, :data1=>0.2835391686754039}, {:data0=>0.88, :data1=>0.32282335026766334}, {:data0=>0.89, :data1=>0.35533582471259345}, {:data0=>0.9, :data1=>0.3795540815563061}, {:data0=>0.91, :data1=>0.3948561256016757}, {:data0=>0.92, :data1=>0.40157446098352323}, {:data0=>0.93, :data1=>0.40095631969400874}, {:data0=>0.9400000000000001, :data1=>0.3950340561757175}, {:data0=>0.9500000000000001, :data1=>0.38641842433142515}, {:data0=>0.96, :data1=>0.37803500314904637}, {:data0=>0.97, :data1=>0.37282960307192003}, {:data0=>0.98, :data1=>0.37347152242246406}, {:data0=>0.99, :data1=>0.38208373430815545}, {:data0=>1.0, :data1=>0.4000264488340163}]>, \"ec5ac005-4e2a-418a-b0b5-c5a8b481741c\"=>#0.0, :data1=>0.40552972386823233}, {:data0=>0.01, :data1=>0.4774905499906632}, {:data0=>0.02, :data1=>0.46219024504515543}, {:data0=>0.03, :data1=>0.49408772854706584}, {:data0=>0.04, :data1=>0.5511014641648844}, {:data0=>0.05, :data1=>0.5830607265235062}, {:data0=>0.06, :data1=>0.6290909985528079}, {:data0=>0.07, :data1=>0.7188366408926009}, {:data0=>0.08, :data1=>0.7464502651167544}, {:data0=>0.09, :data1=>0.7570660940515662}, {:data0=>0.1, :data1=>0.8487802767323701}, {:data0=>0.11, :data1=>0.8048638528562673}, {:data0=>0.12, :data1=>0.8781999845775225}, {:data0=>0.13, :data1=>0.8350774438331358}, {:data0=>0.14, :data1=>0.8231075782014501}, {:data0=>0.15, :data1=>0.8205059962114565}, {:data0=>0.16, :data1=>0.7620703948059987}, {:data0=>0.17, :data1=>0.7592930665178563}, {:data0=>0.18, :data1=>0.7564538805783714}, {:data0=>0.19, :data1=>0.7718808660785458}, {:data0=>0.2, :data1=>0.7939093724782238}, {:data0=>0.21, :data1=>0.7241579038424741}, {:data0=>0.22, :data1=>0.7556405318869907}, {:data0=>0.23, :data1=>0.783810615332835}, {:data0=>0.24, :data1=>0.8146499203453131}, {:data0=>0.25, :data1=>0.9079803254799771}, {:data0=>0.26, :data1=>0.8609454155246148}, {:data0=>0.27, :data1=>0.963374223298478}, {:data0=>0.28, :data1=>0.953686722421743}, {:data0=>0.29, :data1=>0.9423887091039158}, {:data0=>0.3, :data1=>0.9586439428093037}, {:data0=>0.31, :data1=>0.9007886717482598}, {:data0=>0.32, :data1=>0.8955021053214614}, {:data0=>0.33, :data1=>0.9019821644047896}, {:data0=>0.34, :data1=>0.8086460470276943}, {:data0=>0.35000000000000003, :data1=>0.8185435115568951}, {:data0=>0.36, :data1=>0.7927944294792918}, {:data0=>0.37, :data1=>0.7413519001413804}, {:data0=>0.38, :data1=>0.6947676161553855}, {:data0=>0.39, :data1=>0.6612751665879212}, {:data0=>0.4, :data1=>0.6504900333096678}, {:data0=>0.41000000000000003, :data1=>0.5568179391111076}, {:data0=>0.42, :data1=>0.6171380642298777}, {:data0=>0.43, :data1=>0.5603384907700707}, {:data0=>0.44, :data1=>0.5760947029063451}, {:data0=>0.45, :data1=>0.5844655117589066}, {:data0=>0.46, :data1=>0.6711066378344058}, {:data0=>0.47000000000000003, :data1=>0.5841094333299761}, {:data0=>0.48, :data1=>0.5794228773540913}, {:data0=>0.49, :data1=>0.5832987506533194}, {:data0=>0.5, :data1=>0.5501273323962572}, {:data0=>0.51, :data1=>0.6012162864215608}, {:data0=>0.52, :data1=>0.5261450973336963}, {:data0=>0.53, :data1=>0.4587469523684175}, {:data0=>0.54, :data1=>0.4553581842601778}, {:data0=>0.55, :data1=>0.37634597984408674}, {:data0=>0.56, :data1=>0.31052441243765166}, {:data0=>0.5700000000000001, :data1=>0.2690342620110815}, {:data0=>0.58, :data1=>0.2536487272472072}, {:data0=>0.59, :data1=>0.24769930022299474}, {:data0=>0.6, :data1=>0.17983166212931287}, {:data0=>0.61, :data1=>0.12805859422706325}, {:data0=>0.62, :data1=>0.11537112023884277}, {:data0=>0.63, :data1=>0.21125790572283304}, {:data0=>0.64, :data1=>0.16186838744714038}, {:data0=>0.65, :data1=>0.16132579127049282}, {:data0=>0.66, :data1=>0.2444294667072354}, {:data0=>0.67, :data1=>0.19538817632744343}, {:data0=>0.68, :data1=>0.24132425605822755}, {:data0=>0.6900000000000001, :data1=>0.22265883054824356}, {:data0=>0.7000000000000001, :data1=>0.2636831443649561}, {:data0=>0.71, :data1=>0.26362289739592015}, {:data0=>0.72, :data1=>0.2222927083908854}, {:data0=>0.73, :data1=>0.17811329085234903}, {:data0=>0.74, :data1=>0.12732948899046037}, {:data0=>0.75, :data1=>0.16354600102188116}, {:data0=>0.76, :data1=>0.13097407719532192}, {:data0=>0.77, :data1=>0.06720693291100473}, {:data0=>0.78, :data1=>0.05812709756878874}, {:data0=>0.79, :data1=>0.01542796780553005}, {:data0=>0.8, :data1=>0.07579910093602107}, {:data0=>0.81, :data1=>0.07597297165054914}, {:data0=>0.8200000000000001, :data1=>0.057527311423150096}, {:data0=>0.8300000000000001, :data1=>0.08270797348892969}, {:data0=>0.84, :data1=>0.10655437450419285}, {:data0=>0.85, :data1=>0.23844271322818672}, {:data0=>0.86, :data1=>0.2668974483956788}, {:data0=>0.87, :data1=>0.2526080180629122}, {:data0=>0.88, :data1=>0.36733263194408383}, {:data0=>0.89, :data1=>0.3199785178151612}, {:data0=>0.9, :data1=>0.3481489425022125}, {:data0=>0.91, :data1=>0.4350143793173079}, {:data0=>0.92, :data1=>0.37639065262225435}, {:data0=>0.93, :data1=>0.3603462039844907}, {:data0=>0.9400000000000001, :data1=>0.34573400064588994}, {:data0=>0.9500000000000001, :data1=>0.4343252944140983}, {:data0=>0.96, :data1=>0.3526295334202674}, {:data0=>0.97, :data1=>0.3255975274840675}, {:data0=>0.98, :data1=>0.3246599727949182}, {:data0=>0.99, :data1=>0.3813989077499905}, {:data0=>1.0, :data1=>0.36205386878698165}]>}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot1 = Nyaplot::Plot.new\n", "y_ideal_line = plot1.add(:line, X, Y_IDEAL)\n", "y_ideal_line.title('Y_IDEAL')\n", "y_scatter = plot1.add(:scatter, X, Y)\n", "y_scatter.title('Y')\n", "y_scatter.color('rgb(43,140,190)')\n", "plot1.legend(true)\n", "plot1.show" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use this `X` for input and `Y` for output for the training of the network.\n", "The structure of the network is `[1, 13, 6, 1]`." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "#" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a_network = RubyBrain::Network.new([1, 13, 6, 1])\n", "a_network.init_network\n", "a_network.learning_rate = 0.5\n", "a_network.learn(X.map{|e| [e]}, Y.map{|e| [e]}, max_tra2ining_count=40000, tolerance=0.0004, monitoring_channels=[:best_params_training])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can review the trained network `a_network` with following code.\n", "`Y_PREDICATED` is the output corresponding to `X`" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "[0.3737866292325307, 0.4155508699326962, 0.4612227994051432, 0.510046222316126, 0.5607734887723744, 0.6116963934435019, 0.6608041726195469, 0.7060561912063408, 0.7456936081165836, 0.7784771369914162, 0.8037633916292516, 0.821410822089631, 0.831586492584581, 0.8345823617111626, 0.8307413200241917, 0.8205601443542602, 0.8049833967331003, 0.7858084350432145, 0.7659928349479052, 0.749589830496322, 0.7411587691845486, 0.7447336675059035, 0.7625310220377353, 0.7935930796595669, 0.8330121525085872, 0.873067538056558, 0.9065953289122177, 0.9300075375974213, 0.9432493802227251, 0.9475817667632656, 0.9436455216754961, 0.9308388250593038, 0.9080063638789239, 0.8751177181219204, 0.8346966936121065, 0.791409829361061, 0.7500728594939753, 0.7139692559515088, 0.6844888844303758, 0.6616316360791809, 0.6446489620789511, 0.6324921879080175, 0.6240459705698431, 0.6182210197904666, 0.6139740134240194, 0.6102956793165908, 0.6061871336344701, 0.6006329967575015, 0.5925754751648203, 0.5808950235422582, 0.5644105663702081, 0.5419267127836488, 0.5123759457604228, 0.4751183746737355, 0.43043144025293156, 0.38008020925535185, 0.32759650799188295, 0.2777575913555481, 0.2351886300617187, 0.20288571825862314, 0.1816714242970304, 0.17069750793984778, 0.16828296262253334, 0.17249611104525836, 0.18140743063906747, 0.19317928271401796, 0.20610461796094728, 0.2186044213693785, 0.22916435709398889, 0.23622278351873238, 0.23808013473390544, 0.23296469703376121, 0.2194239008812383, 0.1971133324075873, 0.1677002148212329, 0.13509396366268775, 0.10427568291398343, 0.07924563358074717, 0.06177808250062096, 0.05186721200466839, 0.04910661008352084, 0.05398370820118536, 0.06866668050121455, 0.09667948867577882, 0.14010814455355214, 0.19507285296341761, 0.2514040310494902, 0.2990186192456708, 0.3333385333302497, 0.354951345988609, 0.366768019225795, 0.3719392889242799, 0.3730100268641807, 0.37177787567756004, 0.36941386972406837, 0.36663471156418753, 0.3638523036599009, 0.3612843115758146, 0.35902970509799054, 0.35711797443189763, 0.3555401330418815]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Y_PREDICATE = X.map{|e| [e]}.map {|a| a_network.get_forward_outputs(a).first}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following graph shows `X`, `Y_IDEAL`, `Y` and `Y_PREDICATED`.\n", "\n", "Looks good." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#[#[#:line, :options=>{:x=>\"data0\", :y=>\"data1\", :title=>\"Y_IDEAL\"}, :data=>\"88ccb1e7-4aff-4ee1-9c3a-4e16027ebcd7\"}, @xrange=[0.0, 1.0], @yrange=[0.042411493708411296, 0.9575885062915888]>, #:scatter, :options=>{:x=>\"data0\", :y=>\"data1\", :title=>\"Y\", :color=>\"rgb(43,140,190)\"}, :data=>\"75730182-ed89-4d92-976c-09544249ee7d\"}, @xrange=[0.0, 1.0], @yrange=[0.01542796780553005, 0.963374223298478]>, #:line, :options=>{:x=>\"data0\", :y=>\"data1\", :title=>\"Y_PREDICATED\", :color=>\"#f85\"}, :data=>\"cc397a57-ec2f-4cf3-a43a-1d8f5ec20fb8\"}, @xrange=[0.0, 1.0], @yrange=[0.04910661008352084, 0.9475817667632656]>], :options=>{:legend=>true, :zoom=>true, :width=>800, :xrange=>[0.0, 1.0], :yrange=>[0.01542796780553005, 0.963374223298478]}}>], :data=>{\"88ccb1e7-4aff-4ee1-9c3a-4e16027ebcd7\"=>#0.0, :data1=>0.4000264488340164}, {:data0=>0.01, :data1=>0.42775527110469325}, {:data0=>0.02, :data1=>0.46476787381494744}, {:data0=>0.03, :data1=>0.5096444389387358}, {:data0=>0.04, :data1=>0.560177944254349}, {:data0=>0.05, :data1=>0.6135815756685751}, {:data0=>0.06, :data1=>0.6667529964208871}, {:data0=>0.07, :data1=>0.7165696382953357}, {:data0=>0.08, :data1=>0.7601861427790648}, {:data0=>0.09, :data1=>0.7953048689854758}, {:data0=>0.1, :data1=>0.820393020775661}, {:data0=>0.11, :data1=>0.8348251698745579}, {:data0=>0.12, :data1=>0.8389372534949249}, {:data0=>0.13, :data1=>0.8339867893139402}, {:data0=>0.14, :data1=>0.8220232294733926}, {:data0=>0.15, :data1=>0.8056811701126355}, {:data0=>0.16, :data1=>0.7879166828991226}, {:data0=>0.17, :data1=>0.7717126010580154}, {:data0=>0.18, :data1=>0.7597816296838359}, {:data0=>0.19, :data1=>0.7542963613397422}, {:data0=>0.2, :data1=>0.756672642444699}, {:data0=>0.21, :data1=>0.7674275117044373}, {:data0=>0.22, :data1=>0.7861256302515915}, {:data0=>0.23, :data1=>0.8114194589620184}, {:data0=>0.24, :data1=>0.8411792597281302}, {:data0=>0.25, :data1=>0.8727002027779698}, {:data0=>0.26, :data1=>0.9029663123247347}, {:data0=>0.27, :data1=>0.9289454169513626}, {:data0=>0.28, :data1=>0.9478862340141797}, {:data0=>0.29, :data1=>0.9575885062915888}, {:data0=>0.3, :data1=>0.9566197447766662}, {:data0=>0.31, :data1=>0.9444573559268936}, {:data0=>0.32, :data1=>0.9215422334464239}, {:data0=>0.33, :data1=>0.8892385590473597}, {:data0=>0.34, :data1=>0.8497037354957271}, {:data0=>0.35000000000000003, :data1=>0.8056811701126354}, {:data0=>0.36, :data1=>0.7602361768767882}, {:data0=>0.37, :data1=>0.7164608313245959}, {:data0=>0.38, :data1=>0.6771766497323368}, {:data0=>0.39, :data1=>0.6446641752874066}, {:data0=>0.4, :data1=>0.6204459184436939}, {:data0=>0.41000000000000003, :data1=>0.6051438743983245}, {:data0=>0.42, :data1=>0.5984255390164767}, {:data0=>0.43, :data1=>0.5990436803059914}, {:data0=>0.44, :data1=>0.6049659438242828}, {:data0=>0.45, :data1=>0.6135815756685751}, {:data0=>0.46, :data1=>0.6219649968509536}, {:data0=>0.47000000000000003, :data1=>0.6271703969280801}, {:data0=>0.48, :data1=>0.6265284775775357}, {:data0=>0.49, :data1=>0.6179162656918447}, {:data0=>0.5, :data1=>0.5999735511659836}, {:data0=>0.51, :data1=>0.5722447288953069}, {:data0=>0.52, :data1=>0.5352321261850526}, {:data0=>0.53, :data1=>0.490355561061264}, {:data0=>0.54, :data1=>0.43982205574565103}, {:data0=>0.55, :data1=>0.38641842433142504}, {:data0=>0.56, :data1=>0.33324700357911274}, {:data0=>0.5700000000000001, :data1=>0.28343036170466424}, {:data0=>0.58, :data1=>0.2398138572209354}, {:data0=>0.59, :data1=>0.2046951310145244}, {:data0=>0.6, :data1=>0.179606979224339}, {:data0=>0.61, :data1=>0.16517483012544204}, {:data0=>0.62, :data1=>0.16106274650507507}, {:data0=>0.63, :data1=>0.16601321068605968}, {:data0=>0.64, :data1=>0.17797677052660738}, {:data0=>0.65, :data1=>0.19431882988736465}, {:data0=>0.66, :data1=>0.21208331710087713}, {:data0=>0.67, :data1=>0.2282873989419847}, {:data0=>0.68, :data1=>0.24021837031616433}, {:data0=>0.6900000000000001, :data1=>0.24570363866025774}, {:data0=>0.7000000000000001, :data1=>0.24332735755530105}, {:data0=>0.71, :data1=>0.23257248829556276}, {:data0=>0.72, :data1=>0.21387436974840862}, {:data0=>0.73, :data1=>0.18858054103798189}, {:data0=>0.74, :data1=>0.15882074027186988}, {:data0=>0.75, :data1=>0.12729979722203044}, {:data0=>0.76, :data1=>0.09703368767526532}, {:data0=>0.77, :data1=>0.07105458304863732}, {:data0=>0.78, :data1=>0.05211376598582007}, {:data0=>0.79, :data1=>0.042411493708411296}, {:data0=>0.8, :data1=>0.043380255223333775}, {:data0=>0.81, :data1=>0.055542644073106606}, {:data0=>0.8200000000000001, :data1=>0.07845776655357617}, {:data0=>0.8300000000000001, :data1=>0.11076144095264046}, {:data0=>0.84, :data1=>0.15029626450427247}, {:data0=>0.85, :data1=>0.19431882988736454}, {:data0=>0.86, :data1=>0.23976382312321176}, {:data0=>0.87, :data1=>0.2835391686754039}, {:data0=>0.88, :data1=>0.32282335026766334}, {:data0=>0.89, :data1=>0.35533582471259345}, {:data0=>0.9, :data1=>0.3795540815563061}, {:data0=>0.91, :data1=>0.3948561256016757}, {:data0=>0.92, :data1=>0.40157446098352323}, {:data0=>0.93, :data1=>0.40095631969400874}, {:data0=>0.9400000000000001, :data1=>0.3950340561757175}, {:data0=>0.9500000000000001, :data1=>0.38641842433142515}, {:data0=>0.96, :data1=>0.37803500314904637}, {:data0=>0.97, :data1=>0.37282960307192003}, {:data0=>0.98, :data1=>0.37347152242246406}, {:data0=>0.99, :data1=>0.38208373430815545}, {:data0=>1.0, :data1=>0.4000264488340163}]>, \"75730182-ed89-4d92-976c-09544249ee7d\"=>#0.0, :data1=>0.40552972386823233}, {:data0=>0.01, :data1=>0.4774905499906632}, {:data0=>0.02, :data1=>0.46219024504515543}, {:data0=>0.03, :data1=>0.49408772854706584}, {:data0=>0.04, :data1=>0.5511014641648844}, {:data0=>0.05, :data1=>0.5830607265235062}, {:data0=>0.06, :data1=>0.6290909985528079}, {:data0=>0.07, :data1=>0.7188366408926009}, {:data0=>0.08, :data1=>0.7464502651167544}, {:data0=>0.09, :data1=>0.7570660940515662}, {:data0=>0.1, :data1=>0.8487802767323701}, {:data0=>0.11, :data1=>0.8048638528562673}, {:data0=>0.12, :data1=>0.8781999845775225}, {:data0=>0.13, :data1=>0.8350774438331358}, {:data0=>0.14, :data1=>0.8231075782014501}, {:data0=>0.15, :data1=>0.8205059962114565}, {:data0=>0.16, :data1=>0.7620703948059987}, {:data0=>0.17, :data1=>0.7592930665178563}, {:data0=>0.18, :data1=>0.7564538805783714}, {:data0=>0.19, :data1=>0.7718808660785458}, {:data0=>0.2, :data1=>0.7939093724782238}, {:data0=>0.21, :data1=>0.7241579038424741}, {:data0=>0.22, :data1=>0.7556405318869907}, {:data0=>0.23, :data1=>0.783810615332835}, {:data0=>0.24, :data1=>0.8146499203453131}, {:data0=>0.25, :data1=>0.9079803254799771}, {:data0=>0.26, :data1=>0.8609454155246148}, {:data0=>0.27, :data1=>0.963374223298478}, {:data0=>0.28, :data1=>0.953686722421743}, {:data0=>0.29, :data1=>0.9423887091039158}, {:data0=>0.3, :data1=>0.9586439428093037}, {:data0=>0.31, :data1=>0.9007886717482598}, {:data0=>0.32, :data1=>0.8955021053214614}, {:data0=>0.33, :data1=>0.9019821644047896}, {:data0=>0.34, :data1=>0.8086460470276943}, {:data0=>0.35000000000000003, :data1=>0.8185435115568951}, {:data0=>0.36, :data1=>0.7927944294792918}, {:data0=>0.37, :data1=>0.7413519001413804}, {:data0=>0.38, :data1=>0.6947676161553855}, {:data0=>0.39, :data1=>0.6612751665879212}, {:data0=>0.4, :data1=>0.6504900333096678}, {:data0=>0.41000000000000003, :data1=>0.5568179391111076}, {:data0=>0.42, :data1=>0.6171380642298777}, {:data0=>0.43, :data1=>0.5603384907700707}, {:data0=>0.44, :data1=>0.5760947029063451}, {:data0=>0.45, :data1=>0.5844655117589066}, {:data0=>0.46, :data1=>0.6711066378344058}, {:data0=>0.47000000000000003, :data1=>0.5841094333299761}, {:data0=>0.48, :data1=>0.5794228773540913}, {:data0=>0.49, :data1=>0.5832987506533194}, {:data0=>0.5, :data1=>0.5501273323962572}, {:data0=>0.51, :data1=>0.6012162864215608}, {:data0=>0.52, :data1=>0.5261450973336963}, {:data0=>0.53, :data1=>0.4587469523684175}, {:data0=>0.54, :data1=>0.4553581842601778}, {:data0=>0.55, :data1=>0.37634597984408674}, {:data0=>0.56, :data1=>0.31052441243765166}, {:data0=>0.5700000000000001, :data1=>0.2690342620110815}, {:data0=>0.58, :data1=>0.2536487272472072}, {:data0=>0.59, :data1=>0.24769930022299474}, {:data0=>0.6, :data1=>0.17983166212931287}, {:data0=>0.61, :data1=>0.12805859422706325}, {:data0=>0.62, :data1=>0.11537112023884277}, {:data0=>0.63, :data1=>0.21125790572283304}, {:data0=>0.64, :data1=>0.16186838744714038}, {:data0=>0.65, :data1=>0.16132579127049282}, {:data0=>0.66, :data1=>0.2444294667072354}, {:data0=>0.67, :data1=>0.19538817632744343}, {:data0=>0.68, :data1=>0.24132425605822755}, {:data0=>0.6900000000000001, :data1=>0.22265883054824356}, {:data0=>0.7000000000000001, :data1=>0.2636831443649561}, {:data0=>0.71, :data1=>0.26362289739592015}, {:data0=>0.72, :data1=>0.2222927083908854}, {:data0=>0.73, :data1=>0.17811329085234903}, {:data0=>0.74, :data1=>0.12732948899046037}, {:data0=>0.75, :data1=>0.16354600102188116}, {:data0=>0.76, :data1=>0.13097407719532192}, {:data0=>0.77, :data1=>0.06720693291100473}, {:data0=>0.78, :data1=>0.05812709756878874}, {:data0=>0.79, :data1=>0.01542796780553005}, {:data0=>0.8, :data1=>0.07579910093602107}, {:data0=>0.81, :data1=>0.07597297165054914}, {:data0=>0.8200000000000001, :data1=>0.057527311423150096}, {:data0=>0.8300000000000001, :data1=>0.08270797348892969}, {:data0=>0.84, :data1=>0.10655437450419285}, {:data0=>0.85, :data1=>0.23844271322818672}, {:data0=>0.86, :data1=>0.2668974483956788}, {:data0=>0.87, :data1=>0.2526080180629122}, {:data0=>0.88, :data1=>0.36733263194408383}, {:data0=>0.89, :data1=>0.3199785178151612}, {:data0=>0.9, :data1=>0.3481489425022125}, {:data0=>0.91, :data1=>0.4350143793173079}, {:data0=>0.92, :data1=>0.37639065262225435}, {:data0=>0.93, :data1=>0.3603462039844907}, {:data0=>0.9400000000000001, :data1=>0.34573400064588994}, {:data0=>0.9500000000000001, :data1=>0.4343252944140983}, {:data0=>0.96, :data1=>0.3526295334202674}, {:data0=>0.97, :data1=>0.3255975274840675}, {:data0=>0.98, :data1=>0.3246599727949182}, {:data0=>0.99, :data1=>0.3813989077499905}, {:data0=>1.0, :data1=>0.36205386878698165}]>, \"cc397a57-ec2f-4cf3-a43a-1d8f5ec20fb8\"=>#0.0, :data1=>0.3737866292325307}, {:data0=>0.01, :data1=>0.4155508699326962}, {:data0=>0.02, :data1=>0.4612227994051432}, {:data0=>0.03, :data1=>0.510046222316126}, {:data0=>0.04, :data1=>0.5607734887723744}, {:data0=>0.05, :data1=>0.6116963934435019}, {:data0=>0.06, :data1=>0.6608041726195469}, {:data0=>0.07, :data1=>0.7060561912063408}, {:data0=>0.08, :data1=>0.7456936081165836}, {:data0=>0.09, :data1=>0.7784771369914162}, {:data0=>0.1, :data1=>0.8037633916292516}, {:data0=>0.11, :data1=>0.821410822089631}, {:data0=>0.12, :data1=>0.831586492584581}, {:data0=>0.13, :data1=>0.8345823617111626}, {:data0=>0.14, :data1=>0.8307413200241917}, {:data0=>0.15, :data1=>0.8205601443542602}, {:data0=>0.16, :data1=>0.8049833967331003}, {:data0=>0.17, :data1=>0.7858084350432145}, {:data0=>0.18, :data1=>0.7659928349479052}, {:data0=>0.19, :data1=>0.749589830496322}, {:data0=>0.2, :data1=>0.7411587691845486}, {:data0=>0.21, :data1=>0.7447336675059035}, {:data0=>0.22, :data1=>0.7625310220377353}, {:data0=>0.23, :data1=>0.7935930796595669}, {:data0=>0.24, :data1=>0.8330121525085872}, {:data0=>0.25, :data1=>0.873067538056558}, {:data0=>0.26, :data1=>0.9065953289122177}, {:data0=>0.27, :data1=>0.9300075375974213}, {:data0=>0.28, :data1=>0.9432493802227251}, {:data0=>0.29, :data1=>0.9475817667632656}, {:data0=>0.3, :data1=>0.9436455216754961}, {:data0=>0.31, :data1=>0.9308388250593038}, {:data0=>0.32, :data1=>0.9080063638789239}, {:data0=>0.33, :data1=>0.8751177181219204}, {:data0=>0.34, :data1=>0.8346966936121065}, {:data0=>0.35000000000000003, :data1=>0.791409829361061}, {:data0=>0.36, :data1=>0.7500728594939753}, {:data0=>0.37, :data1=>0.7139692559515088}, {:data0=>0.38, :data1=>0.6844888844303758}, {:data0=>0.39, :data1=>0.6616316360791809}, {:data0=>0.4, :data1=>0.6446489620789511}, {:data0=>0.41000000000000003, :data1=>0.6324921879080175}, {:data0=>0.42, :data1=>0.6240459705698431}, {:data0=>0.43, :data1=>0.6182210197904666}, {:data0=>0.44, :data1=>0.6139740134240194}, {:data0=>0.45, :data1=>0.6102956793165908}, {:data0=>0.46, :data1=>0.6061871336344701}, {:data0=>0.47000000000000003, :data1=>0.6006329967575015}, {:data0=>0.48, :data1=>0.5925754751648203}, {:data0=>0.49, :data1=>0.5808950235422582}, {:data0=>0.5, :data1=>0.5644105663702081}, {:data0=>0.51, :data1=>0.5419267127836488}, {:data0=>0.52, :data1=>0.5123759457604228}, {:data0=>0.53, :data1=>0.4751183746737355}, {:data0=>0.54, :data1=>0.43043144025293156}, {:data0=>0.55, :data1=>0.38008020925535185}, {:data0=>0.56, :data1=>0.32759650799188295}, {:data0=>0.5700000000000001, :data1=>0.2777575913555481}, {:data0=>0.58, :data1=>0.2351886300617187}, {:data0=>0.59, :data1=>0.20288571825862314}, {:data0=>0.6, :data1=>0.1816714242970304}, {:data0=>0.61, :data1=>0.17069750793984778}, {:data0=>0.62, :data1=>0.16828296262253334}, {:data0=>0.63, :data1=>0.17249611104525836}, {:data0=>0.64, :data1=>0.18140743063906747}, {:data0=>0.65, :data1=>0.19317928271401796}, {:data0=>0.66, :data1=>0.20610461796094728}, {:data0=>0.67, :data1=>0.2186044213693785}, {:data0=>0.68, :data1=>0.22916435709398889}, {:data0=>0.6900000000000001, :data1=>0.23622278351873238}, {:data0=>0.7000000000000001, :data1=>0.23808013473390544}, {:data0=>0.71, :data1=>0.23296469703376121}, {:data0=>0.72, :data1=>0.2194239008812383}, {:data0=>0.73, :data1=>0.1971133324075873}, {:data0=>0.74, :data1=>0.1677002148212329}, {:data0=>0.75, :data1=>0.13509396366268775}, {:data0=>0.76, :data1=>0.10427568291398343}, {:data0=>0.77, :data1=>0.07924563358074717}, {:data0=>0.78, :data1=>0.06177808250062096}, {:data0=>0.79, :data1=>0.05186721200466839}, {:data0=>0.8, :data1=>0.04910661008352084}, {:data0=>0.81, :data1=>0.05398370820118536}, {:data0=>0.8200000000000001, :data1=>0.06866668050121455}, {:data0=>0.8300000000000001, :data1=>0.09667948867577882}, {:data0=>0.84, :data1=>0.14010814455355214}, {:data0=>0.85, :data1=>0.19507285296341761}, {:data0=>0.86, :data1=>0.2514040310494902}, {:data0=>0.87, :data1=>0.2990186192456708}, {:data0=>0.88, :data1=>0.3333385333302497}, {:data0=>0.89, :data1=>0.354951345988609}, {:data0=>0.9, :data1=>0.366768019225795}, {:data0=>0.91, :data1=>0.3719392889242799}, {:data0=>0.92, :data1=>0.3730100268641807}, {:data0=>0.93, :data1=>0.37177787567756004}, {:data0=>0.9400000000000001, :data1=>0.36941386972406837}, {:data0=>0.9500000000000001, :data1=>0.36663471156418753}, {:data0=>0.96, :data1=>0.3638523036599009}, {:data0=>0.97, :data1=>0.3612843115758146}, {:data0=>0.98, :data1=>0.35902970509799054}, {:data0=>0.99, :data1=>0.35711797443189763}, {:data0=>1.0, :data1=>0.3555401330418815}]>}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot1 = Nyaplot::Plot.new\n", "ideal_line = plot1.add(:line, X, Y_IDEAL)\n", "ideal_line.title('Y_IDEAL')\n", "training_scatter = plot1.add(:scatter, X, Y)\n", "training_scatter.title('Y')\n", "training_scatter.color('rgb(43,140,190)')\n", "predicated_line = plot1.add(:line, X, Y_PREDICATE)\n", "predicated_line.title(\"Y_PREDICATED\")\n", "predicated_line.color('#f85')\n", "plot1.legend(true)\n", "plot1.show" ] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.3.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.3.1" } }, "nbformat": 4, "nbformat_minor": 0 }