1

fminsearch特定のパラメーターを摂動させることにより、粗いスケールでの共分散と細かいスケールでの共分散の平均との間の誤差を最小化するために使用しています。これらは、私が混乱させようとしている3つの引数を使用fminsearchして目的関数を呼び出している2行のコード行です。minimize_me

opts = optimset('display', 'iter');
[x,fval,exitflag] = fminsearch( @(x) minimize_me(x(1), x(2), x(3)), [2, 5, 90], opts);

この関数minimize_meは次のように示され、本体内でさらにいくつかの関数を使用します。

function diff = minimize_me(a_minor, a_major, theta)

%# Grid and model parameters
nModel=50;
nModel_want=1;
nI_grid1=5;
Nth=1;
nRow.Scale1=5;
nCol.Scale1=5;
nRow.Scale2=5^2;
nCol.Scale2=5^2;
nCell.Scale1=nRow.Scale1*nCol.Scale1;

%% Covariance computation, averaging and difference of coarse and fine scale averaged covariances

% Reading files by using the function 'general_gslib_file_to_mat.mat'
[Deff_matrix_NthModel,~,~]=general_gslib_file_to_mat(nModel,nCell.Scale1,nModel_want,nI_grid1,Nth,'effective_dispersivity_coarsegrid5x5_gslib_format');

%# Maximum value of covariance/variogram at coarse scale
sill = var(reshape(Deff_matrix_NthModel,nCell.Scale1,1)); % variance of the coarse data matrix of size (nRow.Scale1 X nCol.Scale1)

%% Compute the covariance at different lags using the function general_CovModel.m

for ihRow = 1:nRow.Scale1
    for ihCol = 1:nCol.Scale1
        [cov.Scale1(ihRow,ihCol),heff.Scale1(ihRow,ihCol)] = general_CovModel(theta, ihCol, ihRow, a_minor, a_major, sill, 'Exp');
    end
end

for ihRow = 1:nRow.Scale2
    for ihCol = 1:nCol.Scale2
        [cov.Scale2(ihRow,ihCol),heff.Scale2(ihRow,ihCol)] = general_CovModel(theta, ihCol/(nCol.Scale2/nCol.Scale1), ihRow/(nRow.Scale2/nRow.Scale1), a_minor, a_major,...
            sill/(nRow.Scale2*nCol.Scale2), 'Exp');
    end
end

%# Scale-up of fine scale values by averaging which is done using the function general_AverageProperty.m
[covAvg.Scale2,var_covAvg.Scale2,varNorm_covAvg.Scale2] = general_AverageProperty(nRow.Scale2/nRow.Scale1,nCol.Scale2/nCol.Scale1,1,nRow.Scale1,nCol.Scale1,1,cov.Scale2,1);

%# Difference between the coarse scaled covariance and average of fine scale covariance
diff = (covAvg.Scale2 - cov.Scale1)^2;
end

ただし、前に示したコードの最初の2行を実行すると、次のエラーが発生します。

??? Subscripted assignment dimension mismatch.

Error in ==> fminsearch at 195
fv(:,1) = funfcn(x,varargin{:});

誰かが何が悪いのか指摘できますか?ありがとう!

4

1 に答える 1

3

問題は、誰かがあなたのコードをテストするのに十分なものを提供していないということです。

だからあなたは...

  • デバッガーの使い方を学びましょう!どんな状況でも良い考えです。これは、あなたが間違ったことを発見するのに役立ちますが、貴重なツールを使用することも教えてくれます。

  • 開始値を使用して関数を1回テストします。それは何を返しますか?これを試しましたか?常にこのテストを行ってください。目的が期待どおりに機能することを確認します。

Fminsearchは、最小化するためにスカラー出力を必要とします。あなたの関数はそれを与えますか?

ちなみに、diffという名前の変数、またはMATLABの便利なツールとしてすでに存在するものを定義するのはひどい考えです。それ以外の場合は、コード内で見つけにくいバグを作成することを主張しているだけです。

于 2012-11-18T16:33:54.600 に答える