Mathematics - Matrix and Vector Transformation

Mathematics - Matrix and Vector Transformation



1. When to Transform?

在一些神经网络的一些优化算法中,要求传入的是向量来进行优化。但是权值却是矩阵,所以需要进行转换,在处理之后再转回来。
所以我们需要学习如何进行Matrix 和 Vector 的转换



2. How to Transform?

1) Octave Implement

在Octave 中我们需要用的 “[]” 把矩阵转成向量;再通过 Reshape 函数把向量转换回数组

1.分别使用 ones()函数产生2个等大的矩阵,作为输入层,隐藏层。

theta1 = ones(3,4)

> Output:
theta1 =

  1   1   1   1
  1   1   1   1
  1   1   1   1



theta2 = 3*ones(3,4)

> Output:
theta2 =
  3   3   3   3
  3   3   3   3
  3   3   3   3
  1. 同样使用ones()函数,产生输出层的theta
theta3 = 4*ones(1,4)

> Output:
theta3 =
  4   4   4   4

3.通过 “[]” 来合成矩阵,注意括号里面要加上 : 符号代码把当前矩阵变成向量输出–>就可以得到我们需要的向量了

thetaVec = [theta1(:); theta2(:); theta3(:)]

> Output:
thetaVec =

  1
  1
  1
  1
  1
  1
  1
  1
  1
  1
  1
  1
  3
  3
  3
  3
  3
  3
  3
  3
  3
  3
  3
  3
  4
  4
  4
  4

4.再通过Reshape函数把向量转换回矩阵:要注意向量的index。

newTheta1 = reshape(thetaVec(1:12),3,4)

> Output:
newTheta1 =
  1   1   1   1
  1   1   1   1
  1   1   1   1




newTheta2 = reshape(thetaVec(13:24),3,4)

> Output:
newTheta2 =

  3   3   3   3
  3   3   3   3
  3   3   3   3



newTheta3 = reshape(thetaVec(25:28),1,4)

> Output:
newTheta3 =
  4   4   4   4

2) Python Implement

@TODO



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值