lab 4
This commit is contained in:
parent
faaa6cb172
commit
9e22b43205
@ -78,7 +78,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@ -146,39 +146,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load -s Sigmoid mlp/layers.py\n",
|
||||
"class Sigmoid(Linear):\n",
|
||||
" def __init__(self, idim, odim,\n",
|
||||
" rng=None,\n",
|
||||
" irange=0.1):\n",
|
||||
"\n",
|
||||
" super(Sigmoid, self).__init__(idim, odim, rng, irange)\n",
|
||||
" \n",
|
||||
" def fprop(self, inputs):\n",
|
||||
" a = super(Sigmoid, self).fprop(inputs)\n",
|
||||
" h = 1.0/(1 + numpy.exp(-a))\n",
|
||||
" return h\n",
|
||||
" \n",
|
||||
" def bprop(self, h, igrads):\n",
|
||||
" dsigm = h*(1.0 - h)\n",
|
||||
" deltas = igrads*dsigm\n",
|
||||
" ___, ograds = super(Sigmoid, self).bprop(h=None, igrads=deltas)\n",
|
||||
" return deltas, ograds\n",
|
||||
"\n",
|
||||
" def cost_bprop(self, h, igrads, cost):\n",
|
||||
" if cost is None or cost.get_name() == 'bce':\n",
|
||||
" return super(Sigmoid, self).bprop(h=h, igrads=igrads)\n",
|
||||
" else:\n",
|
||||
" raise NotImplementedError('Sigmoid.bprop_cost method not implemented '\n",
|
||||
" 'for the %s cost' % cost.get_name())\n",
|
||||
"\n",
|
||||
" def pgrads(self, inputs, deltas):\n",
|
||||
" \"Return list of gradients w.r.t parameters\"\n",
|
||||
" gparams = super(Sigmoid, self).pgrads(inputs, deltas)\n",
|
||||
" return gparams\n",
|
||||
"\n",
|
||||
" def get_name(self):\n",
|
||||
" return 'sigmoid'\n"
|
||||
"%load -s Sigmoid mlp/layers.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -194,26 +162,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1.0\n",
|
||||
"0.0\n",
|
||||
"0.0744177068753\n",
|
||||
"[ 4.571e-05 1.697e-03 9.877e-01 6.631e-04 1.194e-04 8.880e-04\n",
|
||||
" 1.977e-04 8.671e-03]\n",
|
||||
"[ 4.571e-05 1.697e-03 9.877e-01 6.631e-04 1.194e-04 8.880e-04\n",
|
||||
" 1.977e-04 -9.913e-01]\n",
|
||||
"[-0.089 0.03 0.079 0.011 0.017 0.027]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from mlp.layers import Softmax\n",
|
||||
"\n",
|
||||
@ -251,15 +204,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%load -s Softmax mlp/layers.py\n",
|
||||
"1.0\n",
|
||||
"-1.11022302463e-16\n",
|
||||
"0.0744177068753\n",
|
||||
"[ 4.571e-05 1.697e-03 9.877e-01 6.631e-04 1.194e-04 8.880e-04\n",
|
||||
" 1.977e-04 8.671e-03]\n",
|
||||
"[ 4.571e-05 1.697e-03 9.877e-01 6.631e-04 1.194e-04 8.880e-04\n",
|
||||
" 1.977e-04 -9.913e-01]\n",
|
||||
"[-0.089 0.03 0.079 0.011 0.017 0.027]"
|
||||
"%load -s Softmax mlp/layers.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user