function [J grad] = nnCostFunction(nn_params, ...
input_layer_size, ...
hidden_layer_size, ...
num_labels, ...
X, y, lambda)
%NNCOSTFUNCTION Implements the neural network cost function for a two layer
%neural network which performs classification
% [J grad] = NNCOSTFUNCTON(nn_params, hidden_layer_size, num_labels, ...
% X, y, lambda) computes the cost and gradient of the neural network. The
% parameters for the neural network are "unrolled" into the vector
% nn_params and need to be converted back into the weight matrices.
%
% The returned parameter grad should be a "unrolled" vector of the
% partial derivatives of the neural network.
%
% Reshape nn_params back into the parameters Theta1 and Theta2, the weight matrices
% for our 2 layer neural network
Theta1 = reshape(nn_params(1:hidden_layer_size *
吴恩达的机器学习编程作业11:nnCostFunction 求解神经网络的代价函数(含BP算法)
最新推荐文章于 2024-02-27 19:10:21 发布
这段代码实现了吴恩达机器学习课程中,针对两层神经网络的代价函数nnCostFunction。该函数通过展开的参数nn_params重构权重矩阵Theta1和Theta2,然后进行前向传播计算成本,并使用反向传播算法求得梯度。代码中包括了正则化的成本计算,以及对Theta1和Theta2的梯度更新。

最低0.47元/天 解锁文章
37万+

被折叠的 条评论
为什么被折叠?



