各測定値に既知の公式を適用して予測を計算します。 例えば、weight = 2 * speed + 0.5 * temperature + 173は速度が20で温度が203のとき、重さが10になると予測します。 計算は組み込みのマップ変換で行われます。
この例はあらかじめ定義された式と合成値を用いています。
関連する独立したパターンは、更新のフィッティングと承認、MQTTを通じた承認済み係数の提供を含みます。
Prerequisites
共有された例の前提条件を完了してください。defaultプロファイルとfactory-mqttエンドポイントを含めてください。 デバッグにはYAMLを使い、本番管理にはAzure CLIまたはBicepを使いましょう。
既存の default レジストリエンドポイントを組み込みの変換に使います。 CLI デプロイでは、AIO_INSTANCE_NAME には既存のインスタンス名を、RESOURCE_GROUP にはリソース グループ名を設定してください。 Bicep展開の場合は、CUSTOM_LOCATION_NAMEをインスタンスの既存のカスタムロケーションに設定してください。 デプロイタブはこれらの共有リソースを参照しています。作成するわけではありません。
係数の取得元を選択
| 係数ソース |
処理経路 |
次の場合に使用します。 |
| 各メッセージに含まれています |
係数を含む読み取り値 → マップ → 予測 |
提供元はすでにモデルとそのバージョンを提供しています |
| 資産ごとに別々に保存 |
読み取り → エンリッチメント → マップ → 予測 |
アプリケーションは承認済み係数をセンサーメッセージとは独立して維持します |
どちらかの完全なグラフを選択してください。 Enrichmentは格納されたパラメータを提供します。mapは式を評価します。 どちらのパスもピースID、特徴、モデルバージョンを保持します。
メッセージで指定された係数を評価してください
1 つのレコードに入力と係数が含まれている場合は、マップ変換で speed * speedCoefficient + temperature * temperatureCoefficient + intercept が評価されます。
以下の例のワイルドカードルールは元のフィールドを保持します。 入力が別々に届く場合は、コンテキストルックアップやコリレーションを使ってレコードを組み立てます。
式言語の範囲を超えるランタイムまたはアルゴリズムを必要とするモデルには、カスタム WASM または外部サービスが必要です。
以下のいずれかの方法を使ってこのグラフをデプロイします。
factory/predicted-valuesを購読し、次の入力をfactory/features-with-modelに公開してください。
操作エクスペリエンスでインスタンスを開き、[データ フロー グラフ]>[データ フロー グラフの作成] を選択します。
グラフにpredict-with-coefficientsという名前を付け、defaultプロファイルを選択します。
ソースfactory-mqttを、エンドポイントfactory/features-with-modelおよびトピックsourceとともに追加します。
マップ変換defaultを追加します。レジストリエンドポイントpredictのazureiotoperations/graph-dataflow-map:1.0.0を使います。 以下のルールを順番に設定してください:
| 入力 (順番に) |
Output |
Expression |
* |
* |
空のままにします |
speed、temperature、speedCoefficient、temperatureCoefficient、intercept |
predictedWeight |
$1 * $3 + $2 * $4 + $5 |
宛先factory-mqttをエンドポイントfactory/predicted-valuesとトピックdestinationで追加します。
source の接続 → predict → destination および 保存 の選択。
グラフのすべてのプロパティを graph.json として保存してください。 トランスフォームルールは configuration.value のエスケープされたJSON文字列です。
{
"mode": "Enabled",
"nodes": [
{
"name": "source",
"nodeType": "Source",
"sourceSettings": {
"endpointRef": "factory-mqtt",
"dataSources": ["factory/features-with-model"]
}
},
{
"name": "predict",
"nodeType": "Graph",
"graphSettings": {
"registryEndpointRef": "default",
"artifact": "azureiotoperations/graph-dataflow-map:1.0.0",
"configuration": [
{
"key": "rules",
"value": "{\"map\":[{\"inputs\":[\"*\"],\"output\":\"*\"},{\"inputs\":[\"speed\",\"temperature\",\"speedCoefficient\",\"temperatureCoefficient\",\"intercept\"],\"output\":\"predictedWeight\",\"expression\":\"$1 * $3 + $2 * $4 + $5\"}]}"
}
]
}
},
{
"name": "destination",
"nodeType": "Destination",
"destinationSettings": {
"endpointRef": "factory-mqtt",
"dataDestination": "factory/predicted-values"
}
}
],
"nodeConnections": [
{"from": {"name": "source"}, "to": {"name": "predict"}},
{"from": {"name": "predict"}, "to": {"name": "destination"}}
]
}
グラフを既存のインスタンスの default プロファイルに適用します:
az iot ops dataflowgraph apply \
--name predict-with-coefficients \
--instance $AIO_INSTANCE_NAME \
--resource-group $RESOURCE_GROUP \
--config-file graph.json
main.bicepとして保存します。 すべての親リソースはすでにリソースグループ内に存在しています。
param aioInstanceName string
param customLocationName string
resource aioInstance 'Microsoft.IoTOperations/instances@2026-07-01' existing = {
name: aioInstanceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource defaultDataflowProfile 'Microsoft.IoTOperations/instances/dataflowProfiles@2026-07-01' existing = {
parent: aioInstance
name: 'default'
}
resource dataflowGraph 'Microsoft.IoTOperations/instances/dataflowProfiles/dataflowGraphs@2026-07-01' = {
parent: defaultDataflowProfile
name: 'predict-with-coefficients'
extendedLocation: {
name: customLocation.id
type: 'CustomLocation'
}
properties: {
mode: 'Enabled'
nodes: [
{
name: 'source'
nodeType: 'Source'
sourceSettings: {
endpointRef: 'factory-mqtt'
dataSources: ['factory/features-with-model']
}
}
{
name: 'predict'
nodeType: 'Graph'
graphSettings: {
registryEndpointRef: 'default'
artifact: 'azureiotoperations/graph-dataflow-map:1.0.0'
configuration: [
{
key: 'rules'
value: '{"map":[{"inputs":["*"],"output":"*"},{"inputs":["speed","temperature","speedCoefficient","temperatureCoefficient","intercept"],"output":"predictedWeight","expression":"$1 * $3 + $2 * $4 + $5"}]}'
}
]
}
}
{
name: 'destination'
nodeType: 'Destination'
destinationSettings: {
endpointRef: 'factory-mqtt'
dataDestination: 'factory/predicted-values'
}
}
]
nodeConnections: [
{ from: { name: 'source' }, to: { name: 'predict' } }
{ from: { name: 'predict' }, to: { name: 'destination' } }
]
}
}
az deployment group create \
--resource-group $RESOURCE_GROUP \
--template-file main.bicep \
--parameters aioInstanceName="$AIO_INSTANCE_NAME" customLocationName="$CUSTOM_LOCATION_NAME"
Important
Kubernetes 配置マニフェストの使用は運用環境ではサポートされていないため、デバッグとテストにのみ使用する必要があります。
predict-with-coefficients.yamlとして保存します。
apiVersion: connectivity.iotoperations.azure.com/v1
kind: DataflowGraph
metadata:
name: predict-with-coefficients
namespace: azure-iot-operations
spec:
profileRef: default
mode: Enabled
nodes:
- name: source
nodeType: Source
sourceSettings:
endpointRef: factory-mqtt
dataSources: [factory/features-with-model]
- name: predict
nodeType: Graph
graphSettings:
registryEndpointRef: default
artifact: azureiotoperations/graph-dataflow-map:1.0.0
configuration:
- key: rules
value: |
{
"map": [
{"inputs":["*"],"output":"*"},
{
"inputs":["speed","temperature","speedCoefficient","temperatureCoefficient","intercept"],
"output":"predictedWeight",
"expression":"$1 * $3 + $2 * $4 + $5"
}
]
}
- name: destination
nodeType: Destination
destinationSettings:
endpointRef: factory-mqtt
dataDestination: factory/predicted-values
nodeConnections:
- from: { name: source }
to: { name: predict }
- from: { name: predict }
to: { name: destination }
kubectl apply -f predict-with-coefficients.yaml
factory/features-with-model への入力:
{"assetId":"line-1","pieceId":"part-42","modelVersion":8,"speed":10,"temperature":20,"speedCoefficient":2,"temperatureCoefficient":0.5,"intercept":173}
factory/predicted-valuesの出力は入力フィールドを保持し、predictedWeightを加えます:
{"assetId":"line-1","pieceId":"part-42","modelVersion":8,"speed":10,"temperature":20,"speedCoefficient":2,"temperatureCoefficient":0.5,"intercept":173,"predictedWeight":203}
状態ストアから係数を読み取る
エンリッチメントを使用してキー factory-active-models のアクティブ モデル レコード全体を読み取ってから、マップ変換で数式を評価します。
スタンドアロンのデモの場合は、state-store writer を使って v8 レコードを初期化します。フィッティングの手順は不要です。 ライタークロックとブローカークロックは同期しなければなりません。 リーディングを公開する前に、一致する +OK レスポンスを待ちましょう。
このグラフを、以下のいずれかの方法を使用してデプロイします。
factory/predictions をサブスクライブしてから、この入力を factory/features に発行します。
{"assetId":"line-1","pieceId":"part-43","speed":10,"temperature":20}
シードされたv8モデルでは、出力は predictedWeight: 203 と modelVersion: 8です。
グラフは各予測について承認済みのレコードを読み取ります。
操作エクスペリエンスでインスタンスを開き、[データ フロー グラフ]>[データ フロー グラフの作成] を選択します。
グラフ predict-with-approved-model に名前を付け、default プロファイルを選択します。
ソースfactory-mqttをエンドポイントfactory/featuresおよびトピックsourceで追加します。
azureiotoperations/graph-dataflow-map:1.0.0 を使ってレジストリエンドポイントread-modelからマップ変換defaultを追加します。 データセット構成では、状態ストアキー factory-active-models as model、一致入力 $source.assetId、$context.assetId、および一致式 $1 == $2を設定します。 これらのマップ ルールを順番に構成します。式は空のままにします。
| Input |
Output |
* |
* |
$context(model).modelVersion |
modelVersion |
$context(model).speedCoefficient |
speedCoefficient |
$context(model).temperatureCoefficient |
temperatureCoefficient |
$context(model).intercept |
intercept |
同じアーティファクトとレジストリエンドポイントを使って、マップ変換 predictを追加します。 以下のルールを順番に設定してください:
| 入力 (順に) |
Output |
Expression |
* |
* |
空のままにします |
assetId |
kind |
"prediction" |
speed、temperature、speedCoefficient、temperatureCoefficient、intercept |
predictedWeight |
$1 * $3 + $2 * $4 + $5 |
宛先 destination をエンドポイント factory-mqtt とトピック factory/predictions と共に追加します。
source → read-model → predict → destination接続して「保存」を選択します。
完全なグラフ プロパティを graph.json として保存します。
{
"mode": "Enabled",
"nodes": [
{
"name": "source",
"nodeType": "Source",
"sourceSettings": {
"endpointRef": "factory-mqtt",
"dataSources": ["factory/features"]
}
},
{
"name": "read-model",
"nodeType": "Graph",
"graphSettings": {
"registryEndpointRef": "default",
"artifact": "azureiotoperations/graph-dataflow-map:1.0.0",
"configuration": [
{
"key": "rules",
"value": "{\"datasets\":[{\"key\":\"factory-active-models as model\",\"inputs\":[\"$source.assetId\",\"$context.assetId\"],\"expression\":\"$1 == $2\"}],\"map\":[{\"inputs\":[\"*\"],\"output\":\"*\"},{\"inputs\":[\"$context(model).modelVersion\"],\"output\":\"modelVersion\"},{\"inputs\":[\"$context(model).speedCoefficient\"],\"output\":\"speedCoefficient\"},{\"inputs\":[\"$context(model).temperatureCoefficient\"],\"output\":\"temperatureCoefficient\"},{\"inputs\":[\"$context(model).intercept\"],\"output\":\"intercept\"}]}"
}
]
}
},
{
"name": "predict",
"nodeType": "Graph",
"graphSettings": {
"registryEndpointRef": "default",
"artifact": "azureiotoperations/graph-dataflow-map:1.0.0",
"configuration": [
{
"key": "rules",
"value": "{\"map\":[{\"inputs\":[\"*\"],\"output\":\"*\"},{\"inputs\":[\"assetId\"],\"output\":\"kind\",\"expression\":\"\\\"prediction\\\"\"},{\"inputs\":[\"speed\",\"temperature\",\"speedCoefficient\",\"temperatureCoefficient\",\"intercept\"],\"output\":\"predictedWeight\",\"expression\":\"$1 * $3 + $2 * $4 + $5\"}]}"
}
]
}
},
{
"name": "destination",
"nodeType": "Destination",
"destinationSettings": {
"endpointRef": "factory-mqtt",
"dataDestination": "factory/predictions"
}
}
],
"nodeConnections": [
{"from": {"name": "source"}, "to": {"name": "read-model"}},
{"from": {"name": "read-model"}, "to": {"name": "predict"}},
{"from": {"name": "predict"}, "to": {"name": "destination"}}
]
}
az iot ops dataflowgraph apply \
--name predict-with-approved-model \
--instance $AIO_INSTANCE_NAME \
--resource-group $RESOURCE_GROUP \
--config-file graph.json
main.bicepとして保存します。
param aioInstanceName string
param customLocationName string
resource aioInstance 'Microsoft.IoTOperations/instances@2026-07-01' existing = {
name: aioInstanceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource defaultDataflowProfile 'Microsoft.IoTOperations/instances/dataflowProfiles@2026-07-01' existing = {
parent: aioInstance
name: 'default'
}
resource dataflowGraph 'Microsoft.IoTOperations/instances/dataflowProfiles/dataflowGraphs@2026-07-01' = {
parent: defaultDataflowProfile
name: 'predict-with-approved-model'
extendedLocation: {
name: customLocation.id
type: 'CustomLocation'
}
properties: {
mode: 'Enabled'
nodes: [
{
name: 'source'
nodeType: 'Source'
sourceSettings: {
endpointRef: 'factory-mqtt'
dataSources: ['factory/features']
}
}
{
name: 'read-model'
nodeType: 'Graph'
graphSettings: {
registryEndpointRef: 'default'
artifact: 'azureiotoperations/graph-dataflow-map:1.0.0'
configuration: [
{
key: 'rules'
value: '{"datasets":[{"key":"factory-active-models as model","inputs":["$source.assetId","$context.assetId"],"expression":"$1 == $2"}],"map":[{"inputs":["*"],"output":"*"},{"inputs":["$context(model).modelVersion"],"output":"modelVersion"},{"inputs":["$context(model).speedCoefficient"],"output":"speedCoefficient"},{"inputs":["$context(model).temperatureCoefficient"],"output":"temperatureCoefficient"},{"inputs":["$context(model).intercept"],"output":"intercept"}]}'
}
]
}
}
{
name: 'predict'
nodeType: 'Graph'
graphSettings: {
registryEndpointRef: 'default'
artifact: 'azureiotoperations/graph-dataflow-map:1.0.0'
configuration: [
{
key: 'rules'
value: '{"map":[{"inputs":["*"],"output":"*"},{"inputs":["assetId"],"output":"kind","expression":"\\"prediction\\""},{"inputs":["speed","temperature","speedCoefficient","temperatureCoefficient","intercept"],"output":"predictedWeight","expression":"$1 * $3 + $2 * $4 + $5"}]}'
}
]
}
}
{
name: 'destination'
nodeType: 'Destination'
destinationSettings: {
endpointRef: 'factory-mqtt'
dataDestination: 'factory/predictions'
}
}
]
nodeConnections: [
{ from: { name: 'source' }, to: { name: 'read-model' } }
{ from: { name: 'read-model' }, to: { name: 'predict' } }
{ from: { name: 'predict' }, to: { name: 'destination' } }
]
}
}
az deployment group create \
--resource-group $RESOURCE_GROUP \
--template-file main.bicep \
--parameters aioInstanceName="$AIO_INSTANCE_NAME" customLocationName="$CUSTOM_LOCATION_NAME"
Important
Kubernetes 配置マニフェストの使用は運用環境ではサポートされていないため、デバッグとテストにのみ使用する必要があります。
predict-with-approved-model.yamlとして保存します。
apiVersion: connectivity.iotoperations.azure.com/v1
kind: DataflowGraph
metadata:
name: predict-with-approved-model
namespace: azure-iot-operations
spec:
profileRef: default
mode: Enabled
nodes:
- name: source
nodeType: Source
sourceSettings:
endpointRef: factory-mqtt
dataSources: [factory/features]
- name: read-model
nodeType: Graph
graphSettings:
registryEndpointRef: default
artifact: azureiotoperations/graph-dataflow-map:1.0.0
configuration:
- key: rules
value: |
{
"datasets": [
{
"key":"factory-active-models as model",
"inputs":["$source.assetId","$context.assetId"],
"expression":"$1 == $2"
}
],
"map": [
{"inputs":["*"],"output":"*"},
{"inputs":["$context(model).modelVersion"],"output":"modelVersion"},
{"inputs":["$context(model).speedCoefficient"],"output":"speedCoefficient"},
{"inputs":["$context(model).temperatureCoefficient"],"output":"temperatureCoefficient"},
{"inputs":["$context(model).intercept"],"output":"intercept"}
]
}
- name: predict
nodeType: Graph
graphSettings:
registryEndpointRef: default
artifact: azureiotoperations/graph-dataflow-map:1.0.0
configuration:
- key: rules
value: |
{
"map": [
{"inputs":["*"],"output":"*"},
{"inputs":["assetId"],"output":"kind","expression":"\"prediction\""},
{
"inputs":["speed","temperature","speedCoefficient","temperatureCoefficient","intercept"],
"output":"predictedWeight",
"expression":"$1 * $3 + $2 * $4 + $5"
}
]
}
- name: destination
nodeType: Destination
destinationSettings:
endpointRef: factory-mqtt
dataDestination: factory/predictions
nodeConnections:
- from: { name: source }
to: { name: read-model }
- from: { name: read-model }
to: { name: predict }
- from: { name: predict }
to: { name: destination }
kubectl apply -f predict-with-approved-model.yaml
最初のマップは、選択したモデルとバージョンをレコードにコピーします。
後者はそれらのフィールドから計算を行います。 マップルールは変換の入力を読み取ります。
また、アップデート前後の予測を比較するために、まず、ライターの modelVersion を 7 に、intercept を 175 に変更して v7 をシードします。 読み取り値を発行し、v8 を書き込んだ後、新たな対象の読み取り値を発行します。
| 保存済みモデル |
速度10、温度20の計算 |
予測される重量 |
| v7 |
10 * 2 + 20 * 0.5 + 175 |
205 |
| v8 |
10 * 2 + 20 * 0.5 + 173 |
203 |
インスタンスが v8 を観察した後、part-44 を読み取ると、factory/predictions に対して次の出力が得られます。
{"assetId":"line-1","pieceId":"part-44","speed":10,"temperature":20,"modelVersion":8,"speedCoefficient":2,"temperatureCoefficient":0.5,"intercept":173,"kind":"prediction","predictedWeight":203}
状態検索キャッシュは書き込み成功後もv7を有効に保つことができます。 出力された modelVersion で、インスタンスが v8 を観察したタイミングを確認してください。 この例では、一致するモデルが存在することが前提となっています。モデル コンテキストがない場合や古い場合に備えて、拒否または復旧のパスを追加してください。
ルックアップは処理中に利用可能なモデルを使用します。 読み取りのタイムスタンプで選ばれたモデルには タイムスタンプマッチングを用いてください。
関連するコンテンツ