Skip to main content

基于张量图的网络的简单试验...

项目描述

Leo/need

基于张量图的网络的简单试验...

要求

确保NumPyNumPy在 GitHub 上)和MatplotlibMatplotlib在 GitHub 上)在安装之前已经安装Leo/need

安装它们的最简单方法之一是安装它conda

$ conda install numpy matplotlib

安装

目前最新版本的Leo/need可以安装pip如下:

$ pip install leoneed --upgrade

或像其他软件包一样来自源代码。

输入

要访问Leo/need及其函数,请将其导入您的 Python 代码中,如下所示:

>>> import leoneed as ln
どうだっていい存在じゃない簡単に愛は終わらないよ

成分

needle: 张量图中的节点

>>> mulmat = ln.needle.Mul_Matrix(( 3 , 4 ))
>>> mulmat.tensor
matrix([[ 1.40483957,  0.22112104, -0.14532731,  0.12319917],
        [ 0.60602697,  2.42277001, -1.91660854, -2.42252709],
        [ 0.64629422,  0.20150064, -0.15671318,  0.77204576]])

stella: 损失函数的实例

它返回指定损失函数的值和梯度。

>>> simploss = ln.stella.Loss_Simple(3) # Loss Function: (y_pred - y_true)^2 / 2
>>> simploss([ 1, 3, 4 ], [ 5, 7, 1 ])
(matrix([[8. , 8. , 4.5]]), matrix([[-4, -4,  3]]))

stage: 模特的容器

BATCH_SIZE = 128
NUM_EPOCHES = 39
MINI_BATCH = 5
ae = ln.stage.Auto_Encoder(3, 2)
print("W_Encoder(pre-training):", ae[0].tensor, sep="\n")
print("b_Encoder(pre-training):", ae[1].tensor, sep="\n")
print("W_Decoder(pre-training):", ae[3].tensor, sep="\n")
print("b_Decoder(pre-training):", ae[4].tensor, sep="\n")
randdata = np.random.randn(BATCH_SIZE)
randdata /= np.abs(randdata).max() * 1.28
traindata = np.zeros(( BATCH_SIZE , 3 )) # Constructing a Dataset Filled with Sample Vectors like (+a, 0, -a) Manually.
traindata[ : , 0 ] += randdata
traindata[ : , 2 ] -= randdata
ae_history = []
for idx_epoch in range(NUM_EPOCHES):
    for k in range(BATCH_SIZE):
        ae, ae_loss = ae.fit_sample(traindata[ k : (k + 1) , : ], traindata[ k : (k + 1) , : ])
        ae_history.append(ae_loss)
print("W_Encoder(pst-training):", ae[0].tensor, sep="\n")
print("b_Encoder(pst-training):", ae[1].tensor, sep="\n")
print("W_Decoder(pst-training):", ae[3].tensor, sep="\n")
print("b_Decoder(pst-training):", ae[4].tensor, sep="\n")
with plt.rc_context({}):
    plt.plot(ae_history, label="Loss")
    plt.legend()
    plt.xlabel("Iterations")
    plt.title("Gradient Descend, on the same Batch of %d Samples." % BATCH_SIZE)
    plt.savefig("./gradloss-ae.jpeg")
    plt.show()

输出:

W_Encoder(pre-training):
[[ 1.40483957  0.22112104]
 [-0.14532731  0.12319917]
 [ 0.60602697  2.42277001]]
b_Encoder(pre-training):
[[0. 0.]]
W_Decoder(pre-training):
[[-1.91660854 -2.42252709  0.64629422]
 [ 0.20150064 -0.15671318  0.77204576]]
b_Decoder(pre-training):
[[0. 0. 0.]]
W_Encoder(pst-training):
[[ 0.87722083  0.77930038]
 [-0.14532731  0.12319917]
 [ 1.13364571  1.86459068]]
b_Encoder(pst-training):
[[-0.00498058  0.00632017]]
W_Decoder(pst-training):
[[-1.88554672 -2.21171336  0.71931055]
 [-0.56403606  0.55549326  0.85221518]]
b_Decoder(pst-training):
[[ 0.00564453 -0.01603693 -0.01378995]]

变更日志

版本0.0.3

  • 完成矩阵乘法后的梯度实现;

  • 添加了生成AE(自动编码器)的API .stage.Auto_Encoder(numvisible, numhidden, w1=None, w2=None):;

版本0.0.2

  • 添加了子模块needle(张量图的节点)、stella(损失函数)和stage

参考

[^extra-1]: Harry-P (针原翼), Issenkou , 2017, av17632876;

额外的

息吹く炎、君の鼓动の中
。火炎般的守护神,绽放于你跳动的心脏。
---- Harry-P in "Issenkou"[^extra-1]

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

leoneed-0.0.3.tar.gz (17.3 kB 查看哈希)

已上传 source

内置分布

leoneed-0.0.3-py3-none-any.whl (18.0 kB 查看哈希

已上传 py3