Main Content

fitoptions

近似オプション オブジェクトを作成または変更する

説明

fitOptions = fitoptions は既定の近似オプション オブジェクト fitOptions を作成します。

fitOptions = fitoptions(libraryModelName) はライブラリ モデルの既定の近似オプション オブジェクトを作成します。

fitOptions = fitoptions(libraryModelName,Name,Value) は 1 つ以上の Name,Value ペア引数で指定された追加オプションを使用して、指定されたライブラリ モデルの近似オプションを作成します。

fitOptions = fitoptions(fitType) は指定された fitType の近似オプション オブジェクトを取得します。カスタム モデルの近似オプションを操作するには、この構文を使用します。

fitOptions = fitoptions(Name,Value) は 1 つ以上の Name,Value ペア引数で指定された追加オプションを使用して、近似オプションを作成します。

newOptions = fitoptions(fitOptions,Name,Value) は 1 つ以上の Name,Value ペア引数で指定された新しいオプションを使用して、既存の近似オプション オブジェクト fitOptions を変更し、更新された近似オプションを newOptions に返します。

newOptions = fitoptions(options1,options2) は既存の近似オプション オブジェクト options1options2 を結合して newOptions に返します。

  • Method が一致する場合、options2 内のプロパティの空でない値によって newOptions にある options1 内の対応する値がオーバーライドされます。

  • Method が異なる場合、newOptions には Methodoptions1 の値と NormalizeExclude および Weightsoptions2 の値が含まれます。

すべて折りたたむ

既定の近似オプション オブジェクトを作成し、近似する前にデータをセンタリングおよびスケーリングするオプションを設定します。

options = fitoptions;
options.Normal = 'on'
options = 
  basefitoptions with properties:

    Normalize: 'on'
      Exclude: [1x0 double]
      Weights: [1x0 double]
       Method: 'None'

options = fitoptions('gauss2')
options = 
  nlsqoptions with properties:

       StartPoint: []
            Lower: [-Inf -Inf 0 -Inf -Inf 0]
            Upper: [1x0 double]
        Algorithm: 'Trust-Region'
    DiffMinChange: 1.0000e-08
    DiffMaxChange: 0.1000
          Display: 'Notify'
      MaxFunEvals: 600
          MaxIter: 400
           TolFun: 1.0000e-06
             TolX: 1.0000e-06
           Robust: 'Off'
        Normalize: 'off'
          Exclude: [1x0 double]
          Weights: [1x0 double]
           Method: 'NonlinearLeastSquares'

3 次多項式の近似オプションを作成し、データのセンタリングとスケーリングおよびロバスト近似オプションを設定します。

options = fitoptions('poly3', 'Normalize', 'on', 'Robust', 'Bisquare')
options = 
  llsqoptions with properties:

        Lower: [1x0 double]
        Upper: [1x0 double]
       Robust: 'Bisquare'
    Normalize: 'on'
      Exclude: [1x0 double]
      Weights: [1x0 double]
       Method: 'LinearLeastSquares'

options = fitoptions('Method', 'LinearLeastSquares')
options = 
  llsqoptions with properties:

        Lower: [1x0 double]
        Upper: [1x0 double]
       Robust: 'Off'
    Normalize: 'off'
      Exclude: [1x0 double]
      Weights: [1x0 double]
       Method: 'LinearLeastSquares'

最近傍外挿を用いる線形内挿近似用に fitoptions オブジェクトを作成します。

linearoptions = fitoptions("linearinterp",ExtrapolationMethod="nearest")
linearoptions = 
  linearinterpoptions with properties:

    ExtrapolationMethod: 'nearest'
              Normalize: 'off'
                Exclude: [1x0 double]
                Weights: [1x0 double]
                 Method: 'LinearInterpolant'

最近傍外挿を用いる 3 次内挿近似用に 2 つ目の fitoptions オブジェクトを作成します。

cubicoptions = fitoptions("cubicinterp",ExtrapolationMethod="nearest")
cubicoptions = 
  cubicsplineinterpoptions with properties:

    ExtrapolationMethod: 'nearest'
              Normalize: 'off'
                Exclude: [1x0 double]
                Weights: [1x0 double]
                 Method: 'CubicSplineInterpolant'

関数fitを使用すると、linearoptions 内の近似オプションを使って linearinterp 近似オブジェクトを作成できます。cubicoptions を使用して cubicinterp 近似を作成します。

NormalizeExclude または Weights プロパティを設定してから、さまざまな近似法で同じオプションを使用してデータを近似する場合、既定の近似オプション オブジェクトを変更すると便利です。次の例では、同じ近似オプションを使用して異なるライブラリ モデル タイプで近似しています。

load census
options = fitoptions;
options.Normalize = 'on';
f1 = fit(cdate,pop,'poly3',options);
f2 = fit(cdate,pop,'exp1',options);
f3 = fit(cdate,pop,'cubicspline',options)
f3 = 
     Cubic interpolating spline:
       f3(x) = piecewise polynomial computed from p
       with cubic extrapolation
       where x is normalized by mean 1890 and std 62.05
     Coefficients:
       p = coefficient structure

平滑化パラメーターを確認します。smooth パラメーターなどのデータ依存の近似オプションは、関数 fit の 3 番目の出力引数として返されます。

load census
[f,gof,out] = fit(cdate,pop,'SmoothingSpline');
smoothparam = out.p
smoothparam = 0.0089

新しい近似用に既定の平滑化パラメーターを変更します。

options = fitoptions('Method','SmoothingSpline',...
                     'SmoothingParam',0.0098);
[f,gof,out] = fit(cdate,pop,'SmoothingSpline',options);

ガウス近似を作成し、信頼区間を調べます。アルゴリズムを支援するために、下限の近似オプションを指定します。

幅の狭いガウス ピークと幅の広いガウス ピークからノイズを含む和を作成します。

a1 = 1; b1 = -1; c1 = 0.05;
a2 = 1; b2 = 1; c2 = 50;
x = (-10:0.02:10)';
gdata = a1*exp(-((x-b1)/c1).^2) + ...
        a2*exp(-((x-b2)/c2).^2) + ...
        0.1*(rand(size(x))-.5);
plot(x,gdata)

Figure contains an axes object. The axes object contains an object of type line.

2 項ガウス ライブラリ モデルを使用してデータに当てはめます。

gfit = fit(x,gdata,'gauss2') 
gfit = 
     General model Gauss2:
     gfit(x) =  a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)
     Coefficients (with 95% confidence bounds):
       a1 =     -0.1451  (-1.485, 1.195)
       b1 =       9.725  (-14.7, 34.15)
       c1 =       7.117  (-15.84, 30.07)
       a2 =       14.08  (-1.962e+04, 1.965e+04)
       b2 =       607.4  (-3.197e+05, 3.209e+05)
       c2 =         376  (-9.745e+04, 9.82e+04)
plot(gfit,x,gdata)

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent data, fitted curve.

いくつかの係数の信頼区間が広いことからわかるように、このアルゴリズムはうまく機能していません。

アルゴリズムを支援するために、非負の振幅 a1 および a2、幅 c1c2 に下限を指定します。

options = fitoptions('gauss2', 'Lower', [0 -Inf 0 0 -Inf 0]);

または、options.Property = NewPropertyValue の形式を使用して近似オプションのプロパティを設定することができます。

options = fitoptions('gauss2');
options.Lower = [0 -Inf 0 0 -Inf 0];

係数の範囲制約を使用して近似を再計算します。

gfit = fit(x,gdata,'gauss2',options) 
gfit = 
     General model Gauss2:
     gfit(x) =  a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)
     Coefficients (with 95% confidence bounds):
       a1 =       1.005  (0.966, 1.044)
       b1 =          -1  (-1.002, -0.9988)
       c1 =      0.0491  (0.0469, 0.0513)
       a2 =      0.9985  (0.9958, 1.001)
       b2 =      0.8059  (0.3879, 1.224)
       c2 =        50.6  (46.68, 54.52)
plot(gfit,x,gdata)

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent data, fitted curve.

大幅に改善された近似が得られました。近似オプション オブジェクトの他のプロパティに妥当な値を代入することで、近似をさらに改善できます。

近似オプションを作成し、下限を設定します。

options = fitoptions('gauss2', 'Lower', [0 -Inf 0 0 -Inf 0])
options = 
  nlsqoptions with properties:

       StartPoint: []
            Lower: [0 -Inf 0 0 -Inf 0]
            Upper: [1x0 double]
        Algorithm: 'Trust-Region'
    DiffMinChange: 1.0000e-08
    DiffMaxChange: 0.1000
          Display: 'Notify'
      MaxFunEvals: 600
          MaxIter: 400
           TolFun: 1.0000e-06
             TolX: 1.0000e-06
           Robust: 'Off'
        Normalize: 'off'
          Exclude: [1x0 double]
          Weights: [1x0 double]
           Method: 'NonlinearLeastSquares'

近似オプションの新しいコピーを作成し、ロバスト パラメーターを変更します。

newoptions = fitoptions(options, 'Robust','Bisquare')
newoptions = 
  nlsqoptions with properties:

       StartPoint: []
            Lower: [0 -Inf 0 0 -Inf 0]
            Upper: [1x0 double]
        Algorithm: 'Trust-Region'
    DiffMinChange: 1.0000e-08
    DiffMaxChange: 0.1000
          Display: 'Notify'
      MaxFunEvals: 600
          MaxIter: 400
           TolFun: 1.0000e-06
             TolX: 1.0000e-06
           Robust: 'Bisquare'
        Normalize: 'off'
          Exclude: [1x0 double]
          Weights: [1x0 double]
           Method: 'NonlinearLeastSquares'

近似オプションを結合します。

options2 = fitoptions(options, newoptions)
options2 = 
  nlsqoptions with properties:

       StartPoint: []
            Lower: [0 -Inf 0 0 -Inf 0]
            Upper: [1x0 double]
        Algorithm: 'Trust-Region'
    DiffMinChange: 1.0000e-08
    DiffMaxChange: 0.1000
          Display: 'Notify'
      MaxFunEvals: 600
          MaxIter: 400
           TolFun: 1.0000e-06
             TolX: 1.0000e-06
           Robust: 'Bisquare'
        Normalize: 'off'
          Exclude: [1x0 double]
          Weights: [1x0 double]
           Method: 'NonlinearLeastSquares'

線形モデル近似タイプを作成します。

lft = fittype({'x','sin(x)','1'})
lft = 
     Linear model:
     lft(a,b,c,x) = a*x + b*sin(x) + c

近似タイプ lft の近似オプションを取得します。

fo = fitoptions(lft)
fo = 
  llsqoptions with properties:

        Lower: [1x0 double]
        Upper: [1x0 double]
       Robust: 'Off'
    Normalize: 'off'
      Exclude: [1x0 double]
      Weights: [1x0 double]
       Method: 'LinearLeastSquares'

正規化近似オプションを設定します。

fo.Normalize = 'on'
fo = 
  llsqoptions with properties:

        Lower: [1x0 double]
        Upper: [1x0 double]
       Robust: 'Off'
    Normalize: 'on'
      Exclude: [1x0 double]
      Weights: [1x0 double]
       Method: 'LinearLeastSquares'

入力引数

すべて折りたたむ

近似に使用するライブラリ モデル。文字ベクトルまたは string スカラーとして指定します。次の表にいくつかの一般的な例を示します。

ライブラリ モデル名

説明

'poly1'

線形多項式曲線

'poly11'

線形多項式曲面

'poly2'

2 次多項式曲線

'linearinterp'

区分的線形内挿

'cubicinterp'

区分的 3 次内挿

'smoothingspline'

平滑化スプライン (曲線)

'lowess'

局所線形回帰 (曲面)

ライブラリ モデル名の一覧については、モデルの名前と方程式を参照してください。

例: 'poly2'

データ型: char | string

近似に使用するモデル タイプ。関数 fittype で構成された fittype として指定します。カスタム モデルの近似オプションを操作するには、これを使用します。

アルゴリズム オプション。関数 fitoptions を使用して作成された fitoptions オブジェクトとして指定します。

結合対象のアルゴリズム オプション。関数 fitoptions を使用して構成します。

結合対象のアルゴリズム オプション。関数 fitoptions を使用して構成します。

名前と値の引数

引数の任意のペアを Name1=Value1,...,NameN=ValueN のように指定します。Name は引数名、Value は対応する値です。名前と値の引数は、他の引数より後に指定されている必要があります。ただし、各ペアの順序は任意です。

R2021a 以前では、それぞれの名前と値をコンマで区切り、Name を引用符で囲みます。

例: 'Method','NonlinearLeastSquares','Lower',[0,0],'Upper',[Inf,max(x)],'Startpoint',[1 1] は近似法、範囲および開始点を指定します。

すべての近似法のオプション

すべて折りたたむ

データのセンタリングとスケーリングを行うオプション。'Normalize''on' または 'off' で構成されるコンマ区切りのペアとして指定します。

データ型: char

近似から排除する点。'Exclude' と次のいずれかで構成されるコンマ区切りのペアとして指定します。

  • logical ベクトルを記述する式。たとえば、x > 10

  • 排除する点にインデックス付けする整数のベクトル。たとえば、[1 10 25]

  • excludedata によって作成され、true が外れ値を表す、すべてのデータ点についての logical ベクトル。

例については、fit を参照してください。

近似の重み。'Weights' と、データ点の数と同じサイズのベクトルで構成されるコンマ区切りのペアとして指定します。

データ型: double

近似法。'Method' と、次の表のいずれかの近似法で構成されるコンマ区切りペアとして指定します。

近似法

説明

'NearestInterpolant'

最近傍内挿

'LinearInterpolant'

線形内挿

'PchipInterpolant'

区分的 3 次エルミート内挿 (曲線のみ)

'CubicSplineInterpolant'

3 次スプライン内挿

'BiharmonicInterpolant'

重調和曲面内挿

'SmoothingSpline'

平滑化スプライン

'LowessFit'

Lowess 平滑化 (曲面のみ)

'LinearLeastSquares'

線形最小二乗法

'NonlinearLeastSquares'

非線形最小二乗法

データ型: char | string

内挿オプション

すべて折りたたむ

内挿近似の外挿法。以下の値のいずれかとして指定します。

説明サポートされる近似
"auto"

すべてのタイプの内挿近似に対する既定値。ExtrapolationMethod"auto" に設定すると、関数 fit を使用するときに自動的に外挿法が近似オブジェクトに割り当てられます。

すべてのタイプの内挿近似、cubicspline 近似

"none"

外挿なし。関数 fitfitOptions を使用して凸包の外側のクエリ点を評価すると、fitNaN を返します。

linearinterp 曲面近似、nearestinterp 曲面近似、cubicinterp 曲面近似

"linear"

境界勾配に基づく線形外挿

linearinterp 近似、nearestinterp 曲面近似、cubicinterp 曲面近似

"nearest"

最近傍外挿。この外挿法は、近似データの凸包境界上の最近傍の値に評価します。

linearinterp 曲面近似、nearestinterp 近似、cubicinterp 近似

"thinplate"

薄板スプライン外挿。この外挿法は、近似データの凸包の外側に薄板内挿スプラインを拡張します。詳細については、tpaps を参照してください。

thinplateinterp 近似

"biharmonic"

重調和スプライン外挿。この外挿法は、近似データの凸包の外側に重調和内挿スプラインを拡張します。

biharmonicinterp 近似

"pchip"

区分的 3 次エルミート内挿多項式 (PCHIP) 外挿。この外挿法は、近似データの凸包の外側に形状維持 PCHIP を拡張します。詳細については、pchip を参照してください。

pchipinterp 近似

"cubic"

3 次スプライン外挿。この外挿法は、近似データの凸包の外側に 3 次内挿スプラインを拡張します。

cubicspline 近似、cubicinterp 曲線近似

データ型: char | string

平滑化オプション

すべて折りたたむ

平滑化パラメーター。'SmoothingParam' と、0 と 1 の間のスカラー値で構成されるコンマ区切りペアとして指定します。既定値はデータセットによって異なります。MethodSmoothingSpline の場合のみ使用できます。

データ型: double

局所回帰で使用するデータ点の割合。'Span' と、0 と 1 の間のスカラー値で構成されるコンマ区切りペアとして指定します。MethodLowessFit の場合のみ使用できます。

データ型: double

線形および非線形最小二乗法のオプション

すべて折りたたむ

ロバスト線形最小二乗近似法。'Robust' と次のいずれかの値で構成されるコンマ区切りのペアとして指定します。

  • 'LAR' — 最小絶対残差法を指定する。

  • 'Bisquare' — 二重平方重み法を指定する。

MethodLinearLeastSquares または NonlinearLeastSquares のときに使用できます。

データ型: char

近似される係数の下限。'Lower' とベクトルで構成されるコンマ区切りのペアとして指定します。既定値は空のベクトルであり、近似が下限によって制約されないことを示します。範囲を指定する場合、ベクトルの長さは係数の数と等しくなければなりません。ベクトル値の係数のエントリ順序を確認するには、関数 coeffnames を使用します。例については、fit を参照してください。個々の制約なしの下限は -Inf によって指定できます。

MethodLinearLeastSquares または NonlinearLeastSquares のときに使用できます。

データ型: double

近似される係数の上限。'Upper' とベクトルで構成されるコンマ区切りのペアとして指定します。既定値は空のベクトルであり、近似が上限によって制約されないことを示します。範囲を指定する場合、ベクトルの長さは係数の数と等しくなければなりません。ベクトル値の係数のエントリ順序を確認するには、関数 coeffnames を使用します。例については、fit を参照してください。個々の制約なしの上限は +Inf によって指定できます。

MethodLinearLeastSquares または NonlinearLeastSquares のときに使用できます。

データ型: logical

非線形最小二乗法のオプション

すべて折りたたむ

係数の初期値。'StartPoint' とベクトルから構成されるコンマ区切りのペアとして指定します。ベクトル値の係数のエントリ順序を確認するには、関数 coeffnames を使用します。例については、fit を参照してください。

開始点 (既定値は空のベクトル) を関数 fit に渡さない場合、一部のライブラリ モデルの開始点は経験則的に決定されます。有理モデル、ワイブル モデルおよびすべてのカスタム非線形モデルでは、係数の既定の初期値が区間 (0,1) からランダムかつ一様に選択されます。その結果、同じデータとモデルを使用する複数の近似から異なる近似係数が得られる可能性があります。これを回避するには、StartPoint プロパティのベクトル値を使用して係数の初期値を指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

近似手順で使用するアルゴリズム。'Algorithm' と、'Levenberg-Marquardt' または 'Trust-Region' で構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: char

有限差分勾配の係数の最大変化量。'DiffMaxChange' とスカラーで構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

有限差分勾配の係数の最小変化量。'DiffMinChange' とスカラーで構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

コマンド ウィンドウの表示オプション。'Display' と次のいずれかのオプションで構成されるコンマ区切りのペアとして指定します。

  • 'notify' — 近似が収束しない場合にのみ出力を表示する。

  • 'final' — 最終出力のみを表示する。

  • 'iter' — 各反復の出力を表示する。

  • 'off' — 出力を表示しない。

MethodNonlinearLeastSquares のときに使用できます。

データ型: char

許容されるモデルの最大評価回数。'MaxFunEvals' とスカラーで構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

近似の許容される最大反復回数。'MaxIter' とスカラーで構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

モデル値の終了許容誤差。'TolFun' とスカラーで構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

係数値の終了許容誤差。'TolX' とスカラーで構成されるコンマ区切りのペアとして指定します。

MethodNonlinearLeastSquares のときに使用できます。

データ型: double

出力引数

すべて折りたたむ

アルゴリズム オプション。options オブジェクトとして返されます。

新しいアルゴリズム オプション。options オブジェクトとして返されます。

バージョン履歴

R2006a より前に導入

すべて展開する