メインコンテンツ

TCN 異常検出器の学習とテスト

ファイル sineWaveAnomalyData.mat を読み込みます。このファイルには、3 チャネルの合成正弦波信号が 2 セット含まれています。

sineWaveNormal には、10 個の安定した周波数と振幅の正弦波が含まれています。各信号に小振幅の影響のような一連の劣化があります。信号ごとに長さと初期位相が異なります。

load sineWaveAnomalyData.mat sineWaveNormal sineWaveAbnormal
s1 = 3;

入力信号のプロット

最初の 3 つの正常な信号をプロットします。各信号に 3 つの入力チャネルがあります。

tiledlayout("vertical")
ax = zeros(s1,1);
for kj = 1:s1
    ax(kj) = nexttile;
    plot(sineWaveNormal{kj})
    title("Normal Signal Channels")
end

Figure contains 3 axes objects. Axes object 1 with title Normal Signal Channels contains 3 objects of type line. Axes object 2 with title Normal Signal Channels contains 3 objects of type line. Axes object 3 with title Normal Signal Channels contains 3 objects of type line.

sineWaveAbnormal には、すべて同じ長さの 3 つの信号が含まれています。このセットの各信号には 1 つ以上の異常があります。

  • 1 つ目の信号には、すべてのチャネルに一定の時間にわたって続く周波数の急激な変化があります。

  • 2 つ目の信号には、チャネルの 1 つに一定期間の振幅の変化があります。

  • 3 つ目の信号には、すべてのチャネルにランダムな時点で発生するスパイクがあります。

異常がある 3 つの信号をプロットします。

tiledlayout("vertical")
ax = zeros(s1,1);
for kj = 1:s1
    ax(kj) = nexttile;
    plot(sineWaveAbnormal{kj})
    title("Anomalous Signal")
end

Figure contains 3 axes objects. Axes object 1 with title Anomalous Signal contains 3 objects of type line. Axes object 2 with title Anomalous Signal contains 3 objects of type line. Axes object 3 with title Anomalous Signal contains 3 objects of type line.

検出器の作成

tcnAD 関数を使用して、既定のオプションで tcnDetector オブジェクトを作成します。

detector_tcn = tcnAD(3)
detector_tcn = 
  TcnDetector with properties:

               FilterSize: 7
       DropoutProbability: 0.2500
    DetectionWindowLength: 10
          DetectionStride: 10
               NumFilters: 32
                IsTrained: 0
              NumChannels: 3
                   Layers: [23×1 nnet.cnn.layer.Layer]
                    Dlnet: [1×1 dlnetwork]
                Threshold: []
          ThresholdMethod: 'kSigma'
       ThresholdParameter: 3
        ThresholdFunction: []
            Normalization: 'zscore'

検出器の学習

trainingOptions オプション セットをカスタマイズして detector_tcn に学習させる準備を行います。ソルバーを "adam" に、学習エポック数の制限を 100 に設定します。

trainopts = trainingOptions("adam",MaxEpochs=100);

通常状態のデータと trainopts を使用して detector_tcn に学習させます。

detector_tcn = train(detector_tcn,sineWaveNormal,trainingOpts=trainopts);
    Iteration    Epoch    TimeElapsed    LearnRate    TrainingLoss
    _________    _____    ___________    _________    ____________
            1        1       00:00:00        0.001          1.6331
           50       50       00:00:03        0.001         0.13097
          100      100       00:00:06        0.001        0.085445
Training stopped: Max epochs completed
Computing threshold...
Threshold computation completed.

train によって計算されて detector_tcn 内に保存されたしきい値を確認します。この計算値は、学習に使用されたデータのサブセットなどのランダム因子の影響を受け、学習セッションやマシンの違いによって多少変わることがあります。

thresh = detector_tcn.Threshold
thresh = single

3.2729

通常状態のデータについての異常スコアのヒストグラムをプロットします。各スコアが単一の検出ウィンドウで計算されます。しきい値は垂直な線としてプロットされ、スコアの範囲を常に完全に示すとは限りません。

plotHistogram(detector_tcn,sineWaveNormal)

Figure contains an axes object. The axes object with title Window Anomaly Score Distribution, xlabel Anomaly Score, ylabel Probability (Histogram) contains 2 objects of type histogram, constantline. This object represents Data.

検出器を使用した異常の識別

detect 関数を使用して、異常状態のデータの異常スコアを判定します。

results = detect(detector_tcn, sineWaveAbnormal)
results=3×1 cell array
    {130×3 table}
    {130×3 table}
    {130×3 table}

results は、チャネルごとに 1 つずつ、3 つの table を含む cell 配列です。cell の各 table に 3 つの変数 WindowLabelWindowAnomalyScoreWindowStartIndices が含まれています。table 変数の名前を確認します。

varnames = results{1}.Properties.VariableNames
varnames = 1×3 cell
    {'WindowLabels'}    {'WindowAnomalyScores'}    {'WindowStartIndices'}

結果のプロット

通常状態のデータ、異常状態のデータ、およびしきい値を示すヒストグラムを 1 つのプロットにプロットします。

plotHistogram(detector_tcn,sineWaveNormal,sineWaveAbnormal)

Figure contains an axes object. The axes object with title Window Anomaly Score Distribution, xlabel Anomaly Score, ylabel Probability (Histogram) contains 3 objects of type histogram, constantline. These objects represent Data 1, Data 2.

ヒストグラムでは、通常状態のデータと異常状態のデータに異なる色が使用されます。

3 つ目の異常な信号セットについて、検出された異常をプロットします。

plot(detector_tcn,sineWaveAbnormal{3})

Figure contains 3 axes objects. Axes object 1 with ylabel Channel 1 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 2 with ylabel Channel 2 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 3 with xlabel Samples, ylabel Channel 3 contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent Raw Signal, Anomalies.

Figure contains an axes object. The axes object with title Anomaly Score, xlabel Window Index, ylabel Score contains 2 objects of type stem, constantline.

上のプロットには、赤のオーバーレイで異常の発生箇所が示されています。下のプロットは、信号セット 3 の通常状態と異常スコアの切り分けにしきい値がどの程度効果的であるかを示しています。

参考

| | | | | | | | |

トピック