简体   繁体   English

可以将scipy.optimize.minimize用于Python中的神经网络

[英]Can scipy.optimize.minimize be used for Neural network in Python

I created a Neural Network with one hidden layer. 我创建了一个具有一层隐藏层的神经网络。 Can I use the minimize function? 我可以使用最小化功能吗? What is the approach to pass two Theta matrix to mimimize. 通过两个Theta矩阵进行最小化的方法是什么。 I am trying by using flatten on both the Theta and then concatenate them using 我正在尝试在两个Theta上都使用flatten,然后使用

np.concatenate.
thetaFlat = np.concatenate((initial_Theta1.flatten(),initial_Theta2.flatten()),axis=0)

In my Cost and gradient function I am retrieving the thetas based on index and then reshaping them. 在我的成本和梯度函数中,我基于索引检索theta,然后对其进行重塑。

theta1=(thetaFlat[0:(hiddenLayerSize*(inputLayerSize+1))]).reshape(hiddenLayerSize,(inputLayerSize+1))

theta2=(thetaFlat[(hiddenLayerSize*(inputLayerSize+1)):len(thetaFlat)]).reshape(num_labels,(hiddenLayerSize+1))

Is this approach correct? 这种方法正确吗? This approach is however used in Octave, but the flattening there is columnwise and in Python its rowise. 但是,此方法在Octave中使用,但此处的展平是按列的,而在Python中则为rowise。

The performance on training set is around 80% in Python. 在Python上,训练集的性能约为80%。 While in Octave its 96%.So I am a bit skeptical on the approach. 虽然在Octave中达到了96%,所以我对该方法有些怀疑。 Please also suggest any better option if available for Neural Network on Python.Or any other optimizaton function 如果适用于Python上的神经网络,请也建议任何更好的选择或其他优化功能

regards Souvik Saha Bhowmik 关于Souvik Saha Bhowmik

This is a valid, and pretty much only approach. 这是有效且几乎唯一的方法。 Remember to double check that your flattening and unflattening operations are each others inverses though (just define them as two functions, flat and unflat and check whether x == unflat(flat(x)) for many random x's). 记住要仔细检查一下,扁平化和非扁平化操作是否彼此相反(只需将它们定义为两个函数,flat和unflat,并检查许多随机x的x == unflat(flat(x)))。 There are many possible reasons for differences in the final model, but flattening is not one of them. 最终模型的差异可能有很多原因,但展平并不是其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM