-4

重複の可能性:
MATLAB: ベクトルを範囲 [-1;1] に正規化/非正規化する方法

こんにちは、Matlab を使い始めたばかりで、マトリックス内のデータを再スケーリングする方法を知りたいです。N 行 x M 列の行列があり、列のデータを -1 から 1 の間に再スケーリングしたいと考えています。

各列には、たとえば 0 ~ 10,000 から 0 ~ 1 の間のスケールで変化する値が含まれます。これらの値はニューラル ネットワークで変換の入力値として使用されるため、-1 ~ 1 の間で正規化する必要があります。サインベースの関数。

4

3 に答える 3

5

前の答えはどちらも正しくありません。これはあなたがする必要があることです:

[rows,~]=size(A);%# A is your matrix
colMax=max(abs(A),[],1);%# take max absolute value to account for negative numbers
normalizedA=A./repmat(colMax,rows,1);

マトリックスnormalizedAは と の間の値を持ち-1ます1

例:

A=randn(4)

A =

   -1.0689    0.3252   -0.1022   -0.8649
   -0.8095   -0.7549   -0.2414   -0.0301
   -2.9443    1.3703    0.3192   -0.1649
    1.4384   -1.7115    0.3129    0.6277

normalizedA = 

   -0.3630    0.1900   -0.3203   -1.0000
   -0.2749   -0.4411   -0.7564   -0.0347
   -1.0000    0.8006    1.0000   -0.1906
    0.4885   -1.0000    0.9801    0.7258
于 2011-04-12T21:20:33.127 に答える
1

A simple solution would use simple logic. Assuming that you mean to scale EACH column independently, do this:

  1. Subtract off the column minimum for each column.
  2. Scale the column maximum to be 2.
  3. Subtract 1.

Clearly this will result in the min for each column to be -1, the max will be 1. Code to do so is simple enough.

A = randn(5,4)   % some random example data
A =
    0.70127      0.20378       0.4085      0.83125
    0.64984     -0.90414      0.67386       1.2022
     1.6843      -1.6584     -0.31735      -1.8981
    -1.3898     -0.89092     -0.23122      -1.2075
    0.72904    -0.095776      0.67517      0.28613

Now, perform the steps above to A.

A = bsxfun(@minus,A,min(A,[],1));
A = bsxfun(@times,A,2./max(A,[],1));
A = A - 1

A =
    0.36043            1      0.46264      0.76071
    0.32697     -0.18989      0.99735            1
          1           -1           -1           -1
         -1      -0.1757     -0.82646     -0.55446
     0.3785      0.67828            1      0.40905
于 2011-04-12T22:40:20.127 に答える
0
[m, n] = size(normalizedMatrix)
normalizedMatrix*2-ones(m,n)
于 2011-04-12T20:32:31.880 に答える