示例1:我们学习出一个恒同变换
1 | import numpy as np |
Pyfunc grad <function custom_matmul_grad at 0x7f60181d1158>
step 0
[[ 0.9000001 0.90000117 0.90000004]
[ 0.90000004 0.90000075 0.90000004]
[ 0.9000001 0.90000176 0.9000001 ]]
step 100
[[ 1.00945520e+00 -8.40856228e-05 -1.38531029e-02]
[ -9.42480564e-03 1.00150728e+00 -5.25715109e-03]
[ -1.19535998e-03 1.63702958e-03 1.01351130e+00]]
step 200
[[ 9.99940336e-01 7.62419877e-05 -4.71634121e-06]
[ -3.78266304e-06 1.00004244e+00 -4.32819579e-05]
[ -8.31601501e-05 -3.92800757e-05 1.00019753e+00]]
step 300
[[ 9.99999821e-01 4.15331755e-07 7.49084165e-07]
[ -5.45732973e-07 1.00000012e+00 -3.67430317e-07]
[ 3.99243845e-07 -2.52412678e-06 1.00000083e+00]]
step 400
[[ 9.99999940e-01 7.07783840e-08 -2.49022083e-08]
[ 5.56420900e-08 1.00000000e+00 1.32440938e-08]
[ 6.04069683e-10 -1.87024824e-07 1.00000012e+00]]
step 500
[[ 1.00000000e+00 3.02750269e-09 -4.36058212e-09]
[ -1.26462696e-09 1.00000000e+00 1.13272758e-09]
[ -4.88804694e-08 1.90021368e-08 1.00000012e+00]]
step 600
[[ 1.00000000e+00 4.74864503e-09 -1.23212629e-09]
[ -1.27859068e-09 1.00000000e+00 1.08854614e-09]
[ 1.83422522e-08 -5.04616526e-09 1.00000000e+00]]
step 700
[[ 1.00000000e+00 1.54621693e-09 4.64706537e-11]
[ -6.52278231e-10 1.00000000e+00 1.07698872e-09]
[ 3.22814344e-08 3.30813066e-08 1.00000000e+00]]
step 800
[[ 1.00000000e+00 1.14085366e-10 -2.25349095e-09]
[ 5.05051445e-10 1.00000000e+00 1.66086556e-09]
[ -1.02083888e-08 2.51823873e-09 1.00000000e+00]]
step 900
[[ 1.00000000e+00 6.23920082e-10 9.54518131e-10]
[ 5.08392162e-10 1.00000000e+00 1.66382574e-09]
[ -4.58602969e-08 1.36057530e-08 1.00000000e+00]]
示例2-用自定义的矩阵乘法和log实现MNIST
1 | #%% MNIST graph building: single-layer neural network |
Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
elapsed time: 4.2179083824157715
test accuracy: 0.9211