我正在研究多层感知器,一种神经网络。当我读到反向传播算法时,我看到一些作者建议在计算特定层的所有错误后立即更新权重,但另一位作者解释说我们需要在获得所有层的所有错误后更新权重。正确的做法有哪些?
第一种方法:
function void BackPropagate(){
ComputeErrorsForOutputLayer();
UpdateWeightsOutputLayer();
ComputeErrorsForHiddenLayer();
UpdateWeightsHiddenLayer();
}
Run Code Online (Sandbox Code Playgroud)
第二种方法:
function void BackPropagate(){
ComputeErrorsForOutputLayer();
ComputeErrorsForHiddenLayer();
UpdateWeightsOutputLayer();
UpdateWeightsHiddenLayer();
}
Run Code Online (Sandbox Code Playgroud)
感谢一切。
我想弄清楚整个机器学习的事情,所以我做了一些测试。我想让它学习正弦函数(带有弧度角)。神经网络是:
1 个输入(弧度角)/2 个隐藏层/1 个输出(正弦预测)
对于挤压激活,我使用的是:RELU,值得注意的是,当我使用 Logistic 函数而不是 RELU 时,脚本正在运行。
为此,我创建了一个从 0 开始到 180 结束的循环,它将以弧度转换数字(弧度 = Loop_index*Math.PI/180),然后它基本上会执行该弧度的正弦运算角度并存储弧度和正弦结果。
所以我的表看起来像这样的条目:{输入:[RADIAN ANGLE],输出:[sin(radian)]}
for(var i = 0; i <= 180; i++) {
radian = (i*(Math.PI / 180));
train_table.push({input:[radian],output:[Math.sin(radian)]})
}
Run Code Online (Sandbox Code Playgroud)
我使用此表使用交叉熵和 0.3 的学习率以及 20000 次迭代来训练我的神经网络。
问题是它失败了,当我尝试预测任何内容时它返回“NaN”
我正在使用 Synaptic 框架(https://github.com/cazala/synaptic),这是我的代码的 JSfiddle: https: //jsfiddle.net/my7xe9ks/2/
我尝试在 Keras 中制作自定义损失函数。
我想做这个损失函数
输出的维度为80。批量大小为5000。
所以我在下面构建了这个损失函数。但这行不通。
def normalize_activation(y_true, y_pred):
nb_divide = K.reshape(K.sqrt(K.sum(K.square(y_pred), axis=1)),(5000, 1))
nb_divide=numpy.tile(nb_divide,80)
predicted=numpy.divide(y_pred,nb_divide)
return K.sum(K.square(y_true-predicted))
Run Code Online (Sandbox Code Playgroud)
ValueError:使用序列设置数组元素。
出现此错误。我认为y_true,y_pred的形状是(5000,80)。
我应该在哪里修复它?
我试图对深度强化学习有一个直观的理解。在深度 Q 网络(DQN)中,我们将所有动作/环境/奖励存储在内存数组中,并在剧集结束时通过我们的神经网络“重播”它们。这是有道理的,因为我们正在尝试构建我们的奖励矩阵,看看我们的情节是否以奖励结束,然后通过我们的矩阵缩减奖励。
我认为导致奖励状态的动作序列是需要捕获的重要内容 - 这个动作序列(而不是独立的动作)是导致我们进入奖励状态的原因。
在Mnih 的 Atari-DQN 论文和许多教程中,我们看到了从内存阵列中随机采样和训练的实践。所以如果我们有这样的记忆:
(动作a,状态1)-->(动作b,状态2)-->(动作c,状态3)-->(动作d,状态4)-->奖励!
我们可以训练一小批:
[(动作c状态3),(动作b,状态2),奖励!]
给出的理由是:
其次,由于样本之间的相关性很强,直接从连续样本中学习效率很低;随机化样本会破坏这些相关性,从而减少更新的方差。
或者来自这个pytorch 教程:
通过随机采样,构建批次的转换是去相关的。事实证明,这极大地稳定并改进了 DQN 训练过程。
我的直觉告诉我,序列是强化学习中最重要的。大多数剧集都有延迟奖励,因此大多数行动/状态没有奖励(并且没有“强化”)。将部分奖励带到这些先前状态的唯一方法是追溯地将奖励分解到整个序列中(通过奖励 + 奖励 *learning_rate(future_reward)的 Q 算法中的 future_reward )
内存库的随机采样打破了我们的序列,当您尝试回填 Q(奖励)矩阵时,这有什么帮助?
也许这更类似于马尔可夫模型,每个状态都应该被认为是独立的?我的直觉哪里出了问题?
谢谢你!
reinforcement-learning neural-network q-learning deep-learning
我正在尝试运行来自 GitHub 的动作识别代码。原始代码使用 4 个 GPU 的批处理大小 128。我只有两个 GPU,所以我无法匹配它们的 bacth 大小。无论如何,我可以批量补偿这种差异吗?我在某处看到 iter_size 可能会根据公式进行补偿effective_batchsize= batch_size*iter_size*n_gpu。这个公式中的 iter_size 是多少?我使用 PYthorch 而不是 Caffe。
artificial-intelligence neural-network deep-learning pytorch
在训练时,最好初始化隐藏状态而不是将其设置为 0。但我想知道在验证和测试时初始化隐藏状态是好是坏。谢谢
在构建简单的感知器神经网络时,我们通常将格式输入的二维矩阵传递给二维权(batch_size,features)重矩阵,类似于numpy 中的这个简单神经网络。我一直假设神经网络的感知器/密集/线性层只接受 2D 格式的输入并输出另一个 2D 输出。但是最近我遇到了这个 pytorch 模型,其中一个 Linear 层接受一个 3D 输入张量并输出另一个 3D 张量 ( o1 = self.a1(x))。
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
class Net(nn.Module):
def __init__(self):
super().__init__()
self.a1 = nn.Linear(4,4)
self.a2 = nn.Linear(4,4)
self.a3 = nn.Linear(9,1)
def forward(self,x):
o1 = self.a1(x)
o2 = self.a2(x).transpose(1,2)
output = torch.bmm(o1,o2)
output = output.view(len(x),9)
output = self.a3(output)
return output
x = torch.randn(10,3,4)
y = torch.ones(10,1)
net = Net()
criterion …Run Code Online (Sandbox Code Playgroud) 我最近在 iris 数据集上实现了概率神经网络。我试图使用 YellowBrick 分类器打印分类报告,但是当我运行此代码时出现错误。如下所示。
from neupy import algorithms
model = algorithms.PNN(std=0.1, verbose=True, batch_size = 500)
model.train(X_train, Y_train)
predictions = model.predict(X_test)
from yellowbrick.classifier import ClassificationReport
visualizer = ClassificationReport(model, support=True)
visualizer.fit(X_train, Y_train) # Fit the visualizer and the model
visualizer.score(X_test, Y_test) # Evaluate the model on the test data
visualizer.show()
Run Code Online (Sandbox Code Playgroud)
此代码返回此错误。
YellowbrickTypeError: This estimator is not a classifier; try a regression or clustering score visualizer instead!
Run Code Online (Sandbox Code Playgroud)
当我为其他分类模型尝试相同的分类报告代码时,它起作用了。我不知道。为什么会这样?谁能帮我解决这个问题?
我正在使用带有新功能 API 的 Keras 神经网络的 one-hot 编码。我遇到了如下所示的错误:
Failed to find data adapter that can handle input: (<class 'list'> containing values of types {'(<class \'list\'> containing values of types {\'(<class \\\'list\\\'> containing values of types {\\\'(<class \\\\\\\'list\\\\\\\'> containing values of types {"<class \\\\\\\'int\\\\\\\'>"})\\\'})\'})'}), (<class 'dict'> containing {"<class 'str'>"} keys and {'(<class \'list\'> containing values of types {\'(<class \\\'list\\\'> containing values of types {"<class \\\'int\\\'>"})\'})'} values)
Run Code Online (Sandbox Code Playgroud)
如果我没有记错的话,我相信网络不接受一种热编码作为合适的输出。有谁知道这个错误的解决方法?
代码片段:
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras …Run Code Online (Sandbox Code Playgroud) 如何处理错误ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous-multioutput' instead?
我尝试过一些东西from sklearn.utils.multiclass import type_of_target或x[0],y[0],但没有成功......
X.shape, Y.shape
Run Code Online (Sandbox Code Playgroud)
((336, 10), (336, 5))
for train, test in kfold.split(X, Y):
model = Sequential()
model.add(Dense(10, input_dim=20,
kernel_regularizer=l2(0.001),
kernel_initializer=VarianceScaling(),
activation='sigmoid'))
model.add(Dense(5,
kernel_regularizer=l2(0.01),
kernel_initializer=VarianceScaling(),
activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam',
metrics=['acc'])
model.fit(X[train], Y[train], epochs=50, batch_size=25, verbose = 0,
validation_data=(X[test], Y[test]))
scores = model.evaluate(X[test], Y[test], verbose=0)
print("%s: %.2f%%" % (model.metrics_names[2], scores[2]*100))
cvscores.append(scores[2] * 100)
Run Code Online (Sandbox Code Playgroud)
---------------------------------------------------------------------------
ValueError: Supported target types are: …Run Code Online (Sandbox Code Playgroud) neural-network ×10
keras ×3
python ×3
pytorch ×3
lstm ×1
perceptron ×1
q-learning ×1
scikit-learn ×1
sequential ×1
tensorflow ×1
yellowbrick ×1