矩阵乘法是各种数值方法中的基础运算之一。例如,在神经网络层中实施前向和后向传播方法时经常用到。
各种卷积也可归因于矩阵乘积的类别。MQL5 中的此类函数组类似于:
为给出关于如何管理这些方法的一个总体概念,我们将给出他们的原型(按以下顺序:从矩阵开始,经过混合矩阵-向量,到向量)。
matrix<T> matrix<T>::MatMul(const matrix<T> &m)
matrix<T> matrix<T>::Power(const int power)
matrix<T> matrix<T>::Inner(const matrix<T> &m)
matrix<T> matrix<T>::Outer(const matrix<T> &m)
matrix<T> matrix<T>::Kron(const matrix<T> &m)
matrix<T> matrix<T>::Kron(const vector<T> &v)
matrix<T> matrix<T>::CorrCoef(const bool rows = true)
matrix<T> matrix<T>::Cov(const bool rows = true)
matrix<T> vector<T>::Cov(const vector<T> &v)
T vector<T>::CorrCoef(const vector<T> &v)
vector<T> vector<T>::Correlate(const vector<T> &v, ENUM_VECTOR_CONVOLVE mode)
vector<T> vector<T>::Convolve(const vector<T> &v, ENUM_VECTOR_CONVOLVE mode)
matrix<T> vector<T>::Outer(const vector<T> &v)
matrix<T> vector<T>::Kron(const matrix<T> &m)
matrix<T> vector<T>::Kron(const vector<T> &v)
T vector<T>::Dot(const vector<T> &v)
下面的简单示例演示了如何使用 MatMul 方法计算两个矩阵的矩阵乘积:
matrix a = {{1, 0, 0},
|
A[M,N] * B[N,K] = C[M,K] 形式的矩阵可以相乘,即,第一矩阵中的列数必须等于第二矩阵中的行数。如果维数不一致,则结果为空矩阵。
当矩阵和向量相乘时,允许两个选项:
向量也可以彼此相乘。在 MatMul 中,这始终等效于一个行向量乘以一个列向量的点积(Dot 法),并且“当一个列向量乘以一个行向量并得到一个矩阵”这一选择由另一个方法支持:Outer。
我们演示向量 v5 乘以向量 v3 的Outer积,并以相反顺序演示。在两种情况下,列向量指示在左边,行向量指示在右边。
vector v3 = {1, 2, 3};
|