

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# アセット間でセンサーの異常検出を有効にする
<a name="anom-detection-sensors-across-asset"></a>

## 計算モデルを作成する (AWS CLI)
<a name="create-computation-model-across-assets"></a>

計算モデルを作成するには、 コマンドラインインターフェイス () AWS を使用しますAWS CLI。計算モデルを定義したら、モデルをトレーニングし、推論をスケジュールして、 のアセット間で異常検出を実行します AWS IoT SiteWise。

次の手順では、このプロセスについて説明します。

1. 異常検出を設定するには、[UpdateAssetModel (AWS CLI)](https://docs.aws.amazon.com/cli/latest/reference/iotsitewise/update-asset-model.html) を使用し、次の要件を満たします。

   1. または `DOUBLE` `INTEGER` データ型のいずれかである少なくとも 1 つの入力プロパティ。これは測定プロパティまたは変換プロパティのいずれかであり、モデルのトレーニングに使用されます。

   1. `STRING` データ型の結果プロパティ。これは測定プロパティでなければならず、異常検出結果を保存します。

1. 次の内容`anomaly-detection-computation-model-payload.json`のファイルを作成します。
**注記**  
をデータソース`assetProperty`として直接指定して計算モデルを作成します。

   ```
   {
       "computationModelName": "name of ComputationModel",
       "computationModelConfiguration": {
           "anomalyDetection": {
               "inputProperties": "${properties}",
               "resultProperty": "${p3}"
           }
       },
       "computationModelDataBinding": {
           "properties": {
               "list": [
                   {
                       "assetProperty": { 
                           "assetId": "asset-id",
                           "propertyId": "input-property-id-1"
                       }
                   },
                   {
                       "assetProperty": { 
                           "assetId": "asset-id",
                           "propertyId": "input-property-id-2"
                       }
                   }
               ]
           },
           "p3": {
               "assetProperty": { 
                   "assetId": "asset-id",
                   "propertyId": "results-property-id"
               }
           }
       }
   }
   ```

1. 次のコマンドを実行して、計算モデルを作成します。

   ```
   aws iotsitewise create-computation-model \
       --cli-input-json file://anomaly-detection-computation-model-payload.json
   ```

## ExecuteAction API ペイロードの準備
<a name="create-action-payload-across-assets"></a>

 トレーニングと推論を実行する次のステップは、[ExecuteAction](https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_ExecuteAction.html) API を使用して実行されます。トレーニングと推論の両方が JSON アクションペイロード設定で設定されます。[ExecuteAction](https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_ExecuteAction.html) API を呼び出すときは、アクションペイロードを`stringValue`ペイロードの値として指定する必要があります。

 ペイロードは API 要件に厳密に従う必要があります。具体的には、値は**制御文字** (改行、タブ、キャリッジリターンなど) のない**フラット文字列**である必要があります。以下のオプションは、有効なアクションペイロードを提供する 2 つの信頼できる方法を提供します。

### オプション 1: クリーンペイロードファイルを使用する
<a name="clean-payload-file-across-assets"></a>

次の手順では、クリーンペイロードファイルのステップについて説明します。

1. ファイルをクリーンアップして、コントロール文字を削除します。

   ```
   tr -d '\n\r\t' < original-action-payload.json > training-or-inference-action-payload.json
   ```

1. ファイル を使用して アクションを実行します`@=file://...`。

   ```
   aws iotsitewise execute-action \
       --target-resource computationModelId=<MODEL_ID> \
       --action-definition-id <ACTION_DEFINITION_ID> \
       --action-payload stringValue@=file://training-or-inference-action-payload.json
   ```

### オプション 2: エスケープされた引用符を含むインライン文字列
<a name="inline-string-quotes-across-assets"></a>

次の手順では、ペイロードをインラインで提供し、中間ファイルを回避する手順について説明します。
+ JSON 文字列内でエスケープされた二重引用符 (`\"`) を使用します。
+ `StringValue=..` 式全体を二重引用符で囲みます。

**Example エスケープされたアクションペイロードの :**  

```
aws iotsitewise execute-action \
    --target-resource computationModelId=<MODEL_ID> \
    --action-definition-id <ACTION_DEFINITION_ID> \
    --action-payload "stringValue={\"exportDataStartTime\":1717225200,\"exportDataEndTime\":1722789360,\"targetSamplingRate\":\"PT1M\"}"
```

## モデルのトレーニング (AWS CLI)
<a name="start-training-cli-across-assets"></a>

1. 次のコマンドを実行して、`AWS/ANOMALY_DETECTION_TRAINING` アクションの `actionDefinitionId` を検索します。を前のステップで返された ID `computation-model-id`に置き換えます。

   ```
   aws iotsitewise describe-computation-model \
       --computation-model-id computation-model-id
   ```

1. という名前のファイルを作成し`anomaly-detection-training-payload.json`、次の値を追加します。
**注記**  
 ペイロードは に準拠している必要があります[オプション 1: クリーンペイロードファイルを使用する](#clean-payload-file-across-assets)。

   1. `StartTime` エポック秒で提供されるトレーニングデータの開始。

   1. `EndTime` エポック秒で提供されるトレーニングデータの終了。

   1. オプションで を設定できます[高度な推論設定](advanced-inference-configurations.md)。

      1. (オプション) `TargetSamplingRate`データのサンプリングレート。

      1. (オプション) モデルトレーニングを改善するために異常な動作が発生した期間`LabelInputConfiguration`を指定します。

      1. (オプション) `ModelEvaluationConfiguration` トレーニングの完了後に指定された時間範囲で推論を実行してモデルのパフォーマンスを評価する。

   ```
   {
     "exportDataStartTime": StartTime,
     "exportDataEndTime": EndTime
   }
   ```  
**Example トレーニングペイロードの例:**  

   ```
   {
     "exportDataStartTime": 1717225200,
     "exportDataEndTime": 1722789360
   }
   ```

1. 次のコマンドを実行してトレーニングを開始します (アセットをターゲットリソースとして指定しません）。コマンド内の以下のパラメータを置き換えてください。

   ```
   aws iotsitewise execute-action \
       --target-resource computationModelId=computation-model-id \
       --action-definition-id training-action-definition-id \
       --action-payload stringValue@=file://anomaly-detection-training-payload.json
   ```

1. 次のコマンドを実行して、モデルトレーニングプロセスのステータスを確認します。最新の実行概要には、実行ステータス (`RUNNING`/`COMPLETED`/) が表示されます`FAILED`。

   ```
   aws iotsitewise list-executions \
       --target-resource-type COMPUTATION_MODEL \
       --target-resource-id computation-model-id
   ```

1. 次のコマンドを実行して、最新のトレーニング済みモデルの設定を確認します。このコマンドは、少なくとも 1 つのモデルが正常にトレーニングを完了した場合にのみ出力を生成します。

   ```
   aws iotsitewise describe-computation-model-execution-summary \
       --computation-model-id computation-model-id
   ```

## モデルの再トレーニングを開始および停止する (AWS CLI)
<a name="start-stop-retraining-cli-model"></a>

 初期モデルトレーニングの後、データドリフトに対処し、時間の経過とともにモデルの精度を維持するように自動再トレーニングを設定できます。再トレーニングスケジューラを使用すると、設定可能な昇格モードで定期的なモデル更新を設定できます。

### スケジューラの再トレーニングを開始する
<a name="start-retraining-scheduler-model"></a>

1. 「」で説明されているのと同じペイロードを準備します[スケジューラの再トレーニングを開始する](anom-detection-sensors-asset.md#start-retraining-scheduler)。

1. トレーニングアクションを実行する (アセットをターゲットリソースとして指定しない）。コマンド内の以下のパラメータを置き換えてください。

   1. `computation-model-id` ターゲット計算モデルの ID を指定します。

   1. `training-action-definition-id` `AWS/ANOMALY_DETECTION_TRAINING`アクションの ID を指定します。

   ```
   aws iotsitewise execute-action \
       --target-resource computationModelId=computation-model-id \
       --action-definition-id training-action-definition-id \
       --action-payload stringValue@=file://anomaly-detection-start-retraining-payload.json
   ```

1. 次のコマンドを実行して、再トレーニングの開始スケジューラプロセスのステータスを確認します。最新の実行概要には、実行ステータス (`RUNNING`/`COMPLETED`/) が表示されます`FAILED`。

   ```
   aws iotsitewise list-executions \
       --target-resource-type COMPUTATION_MODEL \
       --target-resource-id computation-model-id
   ```

### スケジューラの再トレーニングを停止する
<a name="stop-retraining-scheduler-model"></a>

1. 「」で説明されているのと同じペイロードを準備します[スケジューラの再トレーニングを停止する](anom-detection-sensors-asset.md#stop-retraining-scheduler)。

1. トレーニングアクションを実行する (アセットをターゲットリソースとして指定しない）。コマンド内の以下のパラメータを置き換えてください。

   1. `computation-model-id` ターゲット計算モデルの ID を指定します。

   1. `training-action-definition-id` `AWS/ANOMALY_DETECTION_TRAINING`アクションの ID を指定します。

   ```
   aws iotsitewise execute-action \
       --target-resource computationModelId=computation-model-id \
       --action-definition-id training-action-definition-id \
       --action-payload stringValue@=file://anomaly-detection-stop-retraining-payload.json
   ```

1. 次のコマンドを実行して、再トレーニングのスケジューラプロセスの停止ステータスを確認します。最新の実行概要には、実行ステータス (`RUNNING`/`COMPLETED`/) が表示されます`FAILED`。

   ```
   aws iotsitewise list-executions \
       --target-resource-type COMPUTATION_MODEL \
       --target-resource-id computation-model-id
   ```

## 推論の開始と停止 (AWS CLI)
<a name="start-stop-inference-across-assets"></a>

モデルをトレーニングしたら、推論を開始します。推論は、 に産業用アセットの異常のモニタリングを開始する AWS IoT SiteWise よう指示します。

### 推論を開始する
<a name="start-inference-across-assets"></a>

1. 次のコマンドを実行して、`AWS/ANOMALY_DETECTION_INFERENCE` アクションの `actionDefinitionId` を検索します。を、前に作成した計算モデルの実際の ID `computation-model-id`に置き換えます。

   ```
   aws iotsitewise describe-computation-model \
       --computation-model-id computation-model-id
   ```

1. ファイルを作成し`anomaly-detection-start-inference-payload.json`、次のコードを追加します。説明に従って、次のパラメータを置き換えます。
**注記**  
 ペイロードは に準拠している必要があります[オプション 1: クリーンペイロードファイルを使用する](#clean-payload-file-across-assets)。

   1. `DataUploadFrequency`: 異常検出を実行するために推論スケジュールを実行する頻度を設定します。許可される値は `PT5M, PT10M, PT15M, PT30M, PT1H, PT2H..PT12H, PT1D` です。

      ```
      "inferenceMode": "START",
      "dataUploadFrequency": "DataUploadFrequency"
      ```

   1. (オプション) 遅延オフセット`DataDelayOffsetInMinutes`を分単位で指定します。この値を 0～60 分に設定します。

   1. (オプション) アクティブ化`TargetModelVersion`するモデルバージョン。

   1. (オプション) シフト設定`weeklyOperatingWindow`で を設定します。

   1. オプションで を設定できます[高度な推論設定](advanced-inference-configurations.md)。

      1. [高頻度推論 (5 分～1 時間)](advanced-inference-configurations.md#high-frequency-inferencing).

      1. [低頻度推論 (2 時間～1 日)](advanced-inference-configurations.md#low-frequency-inferencing).

      1. [柔軟なスケジューリング](advanced-inference-configurations.md#flexible-scheduling).

1. 推論を開始するには、次のコマンドを実行します。ペイロードファイルの次のパラメータを置き換えます。

   1. `computation-model-id` ターゲット計算モデルの ID を指定します。

   1. `inference-action-definition-id` ステップ 1 の`AWS/ANOMALY_DETECTION_INFERENCE`アクションの ID を持つ 。

   ```
   aws iotsitewise execute-action \
       --target-resource computationModelId=computation-model-id \
       --action-definition-id inference-action-definition-id \
       --action-payload stringValue@=file://anomaly-detection-inference-payload.json
   ```

1. 次のコマンドを実行して、推論がまだ実行されているかどうかを確認します。推論がアクティブな`TRUE`場合、 `inferenceTimerActive`フィールドは に設定されます。

   ```
   aws iotsitewise describe-computation-model-execution-summary \
       --computation-model-id computation-model-id
   ```

1. 次のコマンドは、すべての推論実行を一覧表示します。

   ```
   aws iotsitewise list-executions \
       --target-resource-type COMPUTATION_MODEL \
       --target-resource-id computation-model-id
   ```

1. 次のコマンドを実行して、個々の実行を記述します。を前のステップ 5 の ID `execution-id`に置き換えます。

   ```
   aws iotsitewise describe-execution \
       --execution-id execution-id
   ```

### 推論を停止する
<a name="stop-inference-across-assets"></a>

1. 次のコマンドを実行して、`AWS/ANOMALY_DETECTION_INFERENCE` アクションの `actionDefinitionId` を検索します。を、前に作成した計算モデルの実際の ID `computation-model-id`に置き換えます。

   ```
   aws iotsitewise describe-computation-model \
       --computation-model-id computation-model-id
   ```

1. ファイルを作成し`anomaly-detection-stop-inference-payload.json`、次のコードを追加します。

   ```
   {
       "inferenceMode": "STOP"
   }
   ```
**注記**  
 ペイロードは に準拠している必要があります[オプション 1: クリーンペイロードファイルを使用する](anom-detection-sensors-asset.md#clean-payload-file)。

1. 推論を停止するには、次のコマンドを実行します。ペイロードファイルの次のパラメータを置き換えます。

   1. `computation-model-id` ターゲット計算モデルの ID を指定します。

   1. `inference-action-definition-id` ステップ 1 の`AWS/ANOMALY_DETECTION_INFERENCE`アクションの ID を持つ 。  
**Example stop inference コマンドの :**  

   ```
   aws iotsitewise execute-action \
   --target-resource computationModelId=computation-model-id \
   --action-definition-id inference-action-definition-id \
   --action-payload stringValue@=file://anomaly-detection-stop-inference-payload.json
   ```