行列とベクトル

タイプベクトルは、MQL5の特別なデータ型であり、ベクトル演算を可能にします。ベクトルは、 double型の1次元配列です。これは線形代数の基本的な概念の1つであり、物理学、幾何学など、多くの科学分野で使用されています。ベクトルは、3Dグラフィックスやその他のアプリケーション分野で、連立一次方程式を解くために使用されます。ベクトルは加算および乗算できます。ベクトル間の長さまたは距離は、ノルムを介して取得できます。プログラミングでは、ベクトルは通常、同種の要素の配列で表されます。これには、通常のベクトル演算がない(配列を追加または乗算できず、ノルムがない)場合があります。

行列を操作する場合、ベクトルは行ベクトルおよび文字列ベクトルとして表すことができます。また、線形代数ではベクトルの共変性と反変性の概念を使用します。ベクトル型の各オブジェクトが何であるかを決定するのはプログラマーだけなので、これらの概念はMQL5コードを書くときに何の違いももたらしません。たとえば、3Dグラフィックスの回転、変位、または圧縮ベクトルにすることができます。

一般的に言えば、線形代数の観点からは、数もベクトルですが、1次元のベクトル空間にあります。ベクトル自体は、行列の特殊なケースと見なすことができます。

タイプ行列は、あと1つのMQL5の特別なデータ型であり、行列を表します。行列は、実際にはdouble型の2次元配列です。ベクトルと行列は、特定のタイプのデータセットでの操作を容易にするためにMQL5に導入されました。それらを使用すると、開発者は、単純で数学のような形式で線形代数の可能性から利益を得ることができます。行列を使用すれば、線形方程式系または微分方程式系をコンパクトに記述できます。行列の行の数は方程式の数に対応し、列の数は未知数の数に等しくなります。その結果、線形方程式系は行列演算によって解くことができます。

行列には、次の代数演算が定義されています。

  • 同じサイズの行列の追加
  • 適切なサイズの行列の乗算:左側の行列の列の数は、右側の行列の行の数と等しくなければなりません
  • 列ベクトルによる行列の乗算。行列乗算規則に従った行列による行ベクトルの乗算。この意味で、ベクトルは行列の特殊なケースです
  • 数値(スカラー)による行列の乗算

数学では多くの異なる行列タイプを考慮します。単位行列、対称行列、歪対称行列、上三角行列と下三角行列、およびその他のタイプが例です。 行列理論では、さまざまな正規形が重要な役割を果たします。それらは、特定の変換によって取得できる、特定の標準形の行列を表します。実際には、安定性などの追加のプロパティを持つ正規形が使用されます。

ベクトルと行列、またはむしろ関連するタイプの特別なメソッドを使用すると、数学表記に近い、より単純かつ簡潔でより明確なコードの作成が可能になります。これらのメソッドを使用すると、ネストされたループを作成したり、計算で配列の正しいインデックスを作成したりする必要がなくなります。したがって、これらのメソッドを使用すると、複雑なプログラムの開発における信頼性と速度が向上します。

 

行列とベクトルのメソッドのリスト

タイプ行列およびベクトルには、関連するNumPyライブラリメソッドに対応するメソッドが含まれます。これらのメソッドを使用すると、最小限の労力でアルゴリズムとコードをPythonからMQL5に変換できます。多くのデータ処理タスク、数式、ニューラルネットワーク、機械学習タスクは、既製のPythonメソッドとライブラリを使用して解決できます。

メソッド行列/ベクトル

NumPyの類似の方法

説明

void matrix.Eye(const int rows, const int cols, const int ndiag=0)

eye

対角線上に1があって他の場所に0がある行列を作成します

void matrix.Identity(const int rows)

identity

主対角線上に正方行列を作成します

void matrix.Ones(const int rows, const int cols)

ones

与えられた行と列の新しい行列を作成し、1で埋めます

void matrix.Zeros(const int rows, const int cols)

zeros

ゼロで埋められた、指定された行と列の新しい行列を作成します

void matrix.Full(const int rows, const int cols, const scalar value)

full

スカラー値で満たされた、指定された行と列の新しい行列を作成します

void matrix.Copy(const matrix a)

copy

与えられた行列のコピーを作成します

void matrix.FromBuffer(const int rows, const int cols, const scalar array[], const int count=-1, const int offset=0)

frombuffer

1次元配列から作成された行列を作成します

void matrix.FromFile(const int rows, condt int cols, const int file_handle, const int count=-1, const int offset=0)

fromfile

テキストまたはバイナリファイルのデータから行列を作成します

void vector.FromString(const string source, const string sep=" ")

fromstring

文字列内のテキストデータから初期化されたベクトルを作成します

void vector.Arange(const scalar start, const scalar stop, const scalar step=1)

arange

指定された間隔内で等間隔の値を作成します

void matrix.Diag(const vector v, const int ndiag=0)

diag

対角線を抽出するか、対角行列を作成します

void matrix.Tri(const int rows, const int cols, const int ndiag=0)

tri

指定された対角線以下に1があり、他の場所に0がある行列を作成します

void matrix.Tril(const int rows, const int cols, const scalar array[], const int ndiag=0)

tril

k番目の対角線がゼロより上にある要素を含む行列のコピーを返します

void matrix.Triu(const int rows, const int cols, const scalar array[], const int ndiag=0)

triu

k番目の対角線がゼロになっている下の要素を含む行列のコピーを返します

void matrix.Vander(const vector v, const int cols=-1, const bool increasing=false)

vander

ヴァンデルモンドの行列を生成します

vector matrix.Row(const unsigned nrow)

 

行ベクトルを返します

vector matrix.Col(const unsigned ncol)

 

列ベクトルを返します

unsigned matrix.Rows()

 

行列の行数を返します

unsigned matrix.Cols()

 

行列の列数を返します

void matrix.Init()

 

行列を初期化します

matrix matrix.Transpose()

transpose

行列の軸を反転または並べ替えます。 変更された行列を返します

matrix matrix.Dot(const matrix b)

dot

2つの行列の内積

matrix matrix.Inner(const matrix b)

inner

2つの行列の内積

matrix matrix.Outer(const matrix b)

outer

2つの行列の外積を計算します

matrix matrix.MatMul(const matrix b)

matmul

2つの行列の行列積

matrix matrix.MatrixPower(const int power)

matrix_power

正方行列のn(整数)乗

matrix matrix.Kron(const matrix b)

kron

2つの行列のクロネッカー積を返します

bool matrix.Cholesky(matrix& L)

cholesky

コレスキー分解を返します

bool matrix.QR(matrix& Q, matrix& R)

qr

行列のQR分解を計算します

bool matrix.SVD(matrix& U, matrix& V, vector& singular_values)

svd

特異値分解

bool matrix.Eig(matrix& eigen_vectors, vector& eigen_values)

eig

正方行列の固有値と右固有ベクトルを計算します

bool matrix.EigH(matrix& eigen_vectors, vector& eigen_values)

eigh

エルミート行列の固有値と固有ベクトルを返します

bool matrix.EigVals(vector& eigen_values)

eigvals

一般的な行列の固有値を計算します

bool matrix.EigValsH(vector& eigen_values)

eigvalsh

エルミート行列の固有値を計算します

bool matrix.LU(matrix& L, matrix& U)

 

下三角行列と上三角行列の積としての行列のLU分解

bool matrix.LUP(matrix& L, matrix& U, matrix& P)

 

部分的なピボットを使用したLUP分解。これは、行の順列のみを使用したLU分解を指します。PA= LU

double matrix.Norm(const norm)

norm

行列またはベクトルのノルムを返します

double matrix.Cond(const norm)

cond

行列の条件数を計算します

vector matrix.Spectrum()

 

行列のスペクトルを、積AT*Aからの固有値のセットとして計算します

double matrix.Det()

det

配列の行列式を計算します

int matrix.Rank()

matrix_rank

ガウスの方法を使用して配列の行列階数を返します

int matrix.SLogDet(int& sign)

slogdet

配列の行列式の符号と対数を計算します

double matrix.Trace()

trace

行列の対角線に沿って合計を返します

vector matrix.Solve(const vector b)

solve

線形行列方程式系または線形代数方程式系を解きます

vector matrix.LstSq(const vector b)

lstsq

線形代数方程式の最小二乗解を返します(非二乗行列または縮退行列の場合)

matrix matrix.Inv()

inv

行列の(乗法)逆数を計算します

matrix matrix.PInv()

pinv

ムーア・ペンローズ法により、行列の疑似逆行列を計算します

int matrix.Compare(const matrix matrix_c, const double epsilon)

int matrix.Compare(const matrix matrix_c, const int digits)

int vector.Compare(const vector vector_c, const double epsilon)

int vector.Compare(const vector vector_c, const int digits)

 

指定された精度で2つの行列/ベクトルの要素を比較します

double matrix.Flat(const ulong index)

bool matrix.Flat(const ulong index,const double value)

flat

2つではなく1つのインデックスを介して行列要素をアドレス指定できます

double vector.ArgMax()

double matrix.ArgMax()

vector matrix.ArgMax(const int axis)

argmax

最大値のインデックスを返します

double vector.ArgMin()

double matrix.ArgMin()

vector matrix.ArgMin(const int axis)

argmin

最小値のインデックスを返します

double vector.Max()

double matrix.Max()

vector matrix.Max(const int axis)

max

行列/ベクトルの最大値を返します

double vector.Mean()

double matrix.Mean()

vector matrix.Mean(const int axis)

mean

要素値の算術平均を計算します

double vector.Min()

double matrix.Min()

vector matrix.Min(const int axis)

min

行列/ベクトルの最小値を返します

double vector.Sum()

double matrix.Sum()

vector matrix.Sum(const int axis)

sum

指定された軸に対しても実行できる行列/ベクトル要素の合計を返します

void vector.Clip(const double min_value,const double max_value)

void matrix.Clip(const double min_value,const double max_value)

clip

行列/ベクトルの要素を有効な値の指定された範囲に制限します

vector vector.CumProd()

vector matrix.CumProd()

matrix matrix.CumProd(const int axis)

cumprod

指定された軸に沿ったものを含む、行列/ベクトル要素の累積積を返します

vector vector.CumSum()

vector matrix.CumSum()

matrix matrix.CumSum(const int axis)

cumsum

指定された軸に沿ったものを含む、行列/ベクトル要素の累積和を返します

double vector.Prod(const double initial=1)

double matrix.Prod(const double initial=1)

vector matrix.Prod(const int axis,const double initial=1)

prod

指定された軸に対しても実行できる行列/ベクトル要素の積を返します

void matrix.Reshape(const ulong rows, const ulong cols)

reshape

データを変更せずに行列の形状を変更します

void matrix.Resize(const ulong rows,const ulong cols)

resize

形状とサイズが変更された新しい行列を返します

bool matrix.SwapRows(const ulong row1, const ulong row2)

 

行列の行を入れ替えます

bool matrix.SwapCols(const ulong col1, const ulong col2)

 

行列の列を入れ替えます

double vector.Ptp()

double matrix.Ptp()

vector matrix.Ptp(const int axis)

ptp

Max() - Min()と同等の、行列/ベクトルまたは指定された行列軸の値の範囲を返します

double vector.Percentile(const int percent)

double matrix.Percentile(const int percent)

vector matrix.Percentile(const int percent,const int axis)

percentile

行列/ベクトル要素または指定された軸に沿った要素の値の指定されたパーセンタイルを返します。percentパラメータの有効な値は[0, 100]の範囲です

double vector.Quantile(const int percent)

double matrix.Quantile(const int percent)

vector matrix.Quantile(const int percent,const int axis)

quantile

行列/ベクトル要素または指定された軸に沿った要素の値の指定された分位数を返します。percentパラメータの値は[0, 100]の範囲です

double vector.Median()

double matrix.Median()

vector matrix.Median(const int axis)

median

行列/ベクトル要素の中央値を計算します。中央値とは、配列/ベクトル要素の上位半分を要素の下位半分から分離する真ん中の値です

double vector.Average()

double matrix.Average()

vector matrix.Average(const int axis)

average

行列/ベクトル値の算術平均を計算します。分母の重みの合計を0に等しくすることはできませんが、一部の重みは0にすることができます

double vector.Std()

double matrix.Std()

vector matrix.Std(const int axis)

std

行列/ベクトル要素または指定された軸に沿った要素の値の標準偏差を返します

double vector.Var()

double matrix.Var()

vector matrix.Var(const int axis)

var

行列/ベクトル要素の値の分散を計算します

double vector.CorrCoef(const vector& v)

matrix matrix.CorrCoef()

corrcoef

ピアソン相関係数(線形相関係数)を計算します。相関係数は[-1, 1]の範囲にあります

vector vector.Correlate(const vector& v,enum mode)

correlate

2つのベクトルの相互相関を計算します。modeパラメータは、線形畳み込み計算モードを決定します

vector vector.Convolve(const vector& v, enum mode)

convolve

2つのベクトルの離散線形畳み込みを返します。modeパラメータは、線形畳み込み計算モードを決定します

matrix matrix.Cov()

matrix vector.Cov(const vector& v); (resulting matrix 2 x 2)

cov

共分散行列を計算します。2つの標本(2つの確率変数)の共分散は、それらの線形依存性の尺度です