> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ionworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 配列データフィット

> Fit the same model separately at each value of an independent variable (e.g. temperature, pulse SOC) and return the fitted parameter as a 2xN array.

`ArrayDataFit` は、**独立変数** の各値について同じフィットを独立に実行し、フィット結果のパラメータを 2xN 配列として返します。1 行に独立変数の値、もう 1 行に対応するフィット値が格納されます。

これは、フィットするパラメータが状態変数に *依存する* と想定され、単一のスカラーではなくサンプリングされた関数を得たい場合に適したツールです。よくある例は次のとおりです。

* **化学量論に対する拡散係数** — GITT またはパルス実験から得られ、各パルスの中間点の化学量論を鍵としてパルスごとに 1 回フィットします。
* **温度に対する交換電流密度または拡散係数** — チャンバー温度ごとに 1 回フィットします。
* **SOC に対する OCP 由来のパラメータ** — SOC 設定値ごとに 1 回フィットします。

## 通常の `DataFit` との違い

通常の `DataFit` は、すべての目的関数に対して *まとめて* 1 回の最適化を実行し、パラメータごとに単一のベストフィット値を生成します。一方 `ArrayDataFit` は、`objectives` の各キーについて *個別に* 最適化を実行し、キーごとにフィット値を生成します。キー自体が独立変数の値となります。

|               | `DataFit`      | `ArrayDataFit`                                    |
| ------------- | -------------- | ------------------------------------------------- |
| 最適化の回数        | 1 回            | `objectives` のキーごとに 1 回                           |
| パラメータごとの結果の形状 | スカラー           | 2xN 配列（`[independent_var_values, fitted_values]`） |
| 使う場面          | パラメータが単一の数値の場合 | パラメータが独立変数のサンプリングされた関数の場合                         |

## Python での使用方法

```python theme={null}
import ionworkspipeline as iwp

# objectives keyed by the independent-variable value (here: midpoint
# stoichiometry of each pulse)
objectives = {
    0.25: iwp.objectives.Pulse(data_pulse_25, options={"model": model}),
    0.50: iwp.objectives.Pulse(data_pulse_50, options={"model": model}),
    0.75: iwp.objectives.Pulse(data_pulse_75, options={"model": model}),
}

array_fit = iwp.ArrayDataFit(
    objectives,
    parameters={
        "Positive particle diffusivity [m2.s-1]": iwp.Parameter(
            "D_p", initial_value=1e-14, bounds=(1e-15, 1e-13)
        ),
    },
)

result = array_fit.run(parameter_values)

# result.parameter_values["Positive particle diffusivity [m2.s-1]"]
# is a 2x3 array: row 0 = [0.25, 0.50, 0.75], row 1 = fitted D_p values
```

## API での使用方法

パイプライン API は、`data_fit` と同じトップレベルのフィールドを持つ `array_data_fit` 要素を受け付けます。`objectives` のキーは独立変数の値です。

```python theme={null}
pipeline_config = {
    "elements": {
        "known values": {"element_type": "entry", "values": parameter_values},
        "fit diffusivity vs sto": {
            "element_type": "array_data_fit",
            "objectives": {
                0.25: {"objective": "Pulse", "data": "db:meas-pulse-25", ...},
                0.50: {"objective": "Pulse", "data": "db:meas-pulse-50", ...},
                0.75: {"objective": "Pulse", "data": "db:meas-pulse-75", ...},
            },
            "parameters": {
                "Positive particle diffusivity [m2.s-1]": {
                    "bounds": [1e-15, 1e-13],
                    "initial_value": 1e-14,
                },
            },
        },
    },
}

pipeline = client.pipeline.create(pipeline_config)
```

`DataFit` と共有するオプション一式（cost、optimizer、multistarts、prior など）の詳細は、[SimplePipeline ガイド](/ja/simulate/api#シンプルパイプラインの実行)
と [API リファレンス](https://pipeline.docs.ionworks.com/source/api/index.html) を参照してください。

## 関連

<CardGroup cols={2}>
  <Card title="データフィッティング入門" icon="chart-line" href="/ja/guide/data-fitting/overview">
    Background on objectives, parameters, and optimizers
  </Card>

  <Card title="目的関数" icon="bullseye" href="/ja/guide/data-fitting/objective-functions">
    Choose the right objective for your data
  </Card>
</CardGroup>
