【Machine Learning】【Andrew Ng】- notes(Week 4: Neural Network: Representation)

Model Representation I

Let’s examine how we will represent a hypothesis function using neural networks. At a very simple level, neurons are basically computational units that take inputs (dendrites) as electrical inputs (called “spikes”) that are channeled to outputs (axons). In our model, our dendrites are like the input features x1xn x 1 ⋯ x n , and the output is the result of our hypothesis function. In this model our x0 x 0 input node is sometimes called the “bias unit.” It is always equal to 1. In neural networks, we use the same logistic function as in classification, 11+eθTx 1 1 + e − θ T x , yet we sometimes call it a sigmoid (logistic) activation function. In this situation, our “theta” parameters are sometimes called “weights”.
Visually, a simplistic representation looks like:
这里写图片描述
Our input nodes (layer 1), also known as the “input layer”, go into another node (layer 2), which finally outputs the hypothesis function, known as the “output layer”.
We can have intermediate layers of nodes between the input and output layers called the “hidden layers.”
In this example, we label these intermediate or “hidden” layer nodes a20a2n a 0 2 ⋯ a n 2 and call them “activation units.”
Our input nodes (layer 1), also known as the “input layer”, go into another node (layer 2), which finally outputs the hypothesis function, known as the “output layer”.
We can have intermediate layers of nodes between the input and output layers called the “hidden layers.”
In this example, we label these intermediate or “hidden” layer nodes a20a2n a 0 2 ⋯ a n 2 and call them “activation units.”
这里写图片描述
If we had one hidden layer, it would look like:
这里写图片描述
The values for each of the “activation” nodes is obtained as follows:
这里写图片描述
This is saying that we compute our activation nodes by using a 3×4 matrix of parameters. We apply each row of the parameters to our inputs to obtain the value for one activation node. Our hypothesis output is the logistic function applied to the sum of the values of our activation nodes, which have been multiplied by yet another parameter matrix Θ(2) Θ ( 2 ) containing the weights for our second layer of nodes.
Each layer gets its own matrix of weights, Θ(j) Θ ( j ) .
The dimensions of these matrices of weights is determined as follows:
If network has sj s j units in layer j and sj+1 s j + 1 units in layer j+1, then Θ(j) Θ ( j ) will be of dimension sj+1×(sj+1) s j + 1 × ( s j + 1 ) .
The +1 comes from the addition in Θ(j) Θ ( j ) of the “bias nodes,” x0 x 0 and Θ(j)0 Θ 0 ( j ) . In other words the output nodes will not include the bias nodes while the inputs will. The following image summarizes our model representation:
这里写图片描述
Example: If layer 1 has 2 input nodes and layer 2 has 4 activation nodes. Dimension of Θ(1) Θ ( 1 ) is going to be 4×3 4 × 3 where sj=2 s j = 2 and sj+1=4 s j + 1 = 4 , so sj+1=4×3 s j + 1 = 4 × 3 .

Model Representation II

To re-iterate, the following is an example of a neural network:
这里写图片描述
In this section we’ll do a vectorized implementation of the above functions. We’re going to define a new variable z(j)k z k ( j ) that encompasses the parameters inside our g function. In our previous example if we replaced by the variable z for all the parameters we would get:
这里写图片描述
In other words, for layer j=2 and node k, the variable z will be:
这里写图片描述
The vector representation of x and zj z j is:
这里写图片描述
Setting x=a(1) x = a ( 1 ) , we can rewrite the equation as:
这里写图片描述
We are multiplying our matrix Θ(j1) Θ ( j − 1 ) with dimensions sj×(n+1) s j × ( n + 1 ) (where sj s j is the number of our activation nodes) by our vector a(j1) a ( j − 1 ) with height (n+1). This gives us our vector z(j) z ( j ) with height sj s j . Now we can get a vector of our activation nodes for layer j as follows:
a(j)=g(z(j)) a ( j ) = g ( z ( j ) )
Where our function g can be applied element-wise to our vector z(j) z ( j ) .
We can then add a bias unit (equal to 1) to layer j after we have computed a(j) a ( j ) . This will be element a(j)0 a 0 ( j ) and will be equal to 1. To compute our final hypothesis, let’s first compute another z vector:
z(j+1)=Θ(j)a(j) z ( j + 1 ) = Θ ( j ) a ( j )
We get this final z vector by multiplying the next theta matrix after Θ(j1) Θ ( j − 1 ) with the values of all the activation nodes we just got. This last theta matrix Θ(j) Θ ( j ) will have only one row which is multiplied by one column a(j) a ( j ) so that our result is a single number. We then get our final result with:
hΘ(x)=a(j+1)=g(z(j+1)) h Θ ( x ) = a ( j + 1 ) = g ( z ( j + 1 ) )
Notice that in this last step, between layer j and layer j+1, we are doing exactly the same thing as we did in logistic regression. Adding all these intermediate layers in neural networks allows us to more elegantly produce interesting and more complex non-linear hypotheses.

Multiclass Classification

To classify data into multiple classes, we let our hypothesis function return a vector of values. Say we wanted to classify our data into one of four categories. We will use the following example to see how this classification is done. This algorithm takes as input an image and classifies it accordingly:
这里写图片描述
We can define our set of resulting classes as y:
这里写图片描述
Each y(i) y ( i ) represents a different image corresponding to either a car, pedestrian, truck, or motorcycle. The inner layers, each provide us with some new information which leads to our final hypothesis function. The setup looks like:
这里写图片描述
Our resulting hypothesis for one set of inputs may look like:
这里写图片描述
In which case our resulting class is the third one down, or hΘ(x)3 h Θ ( x ) 3 , which represents the motorcycle.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值