Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Fix SR anomaly score calculation at beginning#5502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2058a36cf294085eaa0a055bcfe7a9dfaecd8a0d9b411fdea79a87ce0f516fcc8abadf17303e0fc780bcFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -309,6 +309,15 @@ public void Process() | ||
| _previousBatch = _previousBatch.GetRange(_batch.Count, _bLen); | ||
| _previousBatch.AddRange(_batch); | ||
| _modeler.Train(_previousBatch.ToArray(), ref _results); | ||
| // move the values to front | ||
| for (int i = 0; i < _batch.Count; ++i) | ||
| { | ||
| for (int j = 0; j < _outputLength; ++j) | ||
| { | ||
| _results[i][j] = _results[_bLen + i][j]; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| @@ -334,7 +343,7 @@ public ValueGetter<VBuffer<double>> CreateGetter(DataViewRowCursor input, string | ||
| double src = default; | ||
| srcGetter(ref src); | ||
| var result = VBufferEditor.Create(ref dst, _outputLength); | ||
| _results[input.Position % _batchSize + _bLen].CopyTo(result.Values); | ||
| _results[input.Position % _batchSize].CopyTo(result.Values); | ||
| dst = result.Commit(); | ||
| }; | ||
| return getter; | ||
| @@ -351,6 +360,15 @@ internal sealed class SrCnnEntireModeler | ||
| private static readonly double _deanomalyThreshold = 0.35; | ||
| private static readonly double _boundSensitivity = 93.0; | ||
| private static readonly double _unitForZero = 0.3; | ||
| private static readonly double _minimumScore = 0.0; | ||
| private static readonly double _maximumScore = 1.0; | ||
| // If the score window is smaller than this value, the anomaly score is tend to be small. | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still a bit confused at Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not the same as batchSize, it is the In reply to: 527820502 [](ancestors = 527820502) | ||
| // Proof: For each point, the SR anomaly score is calculated as (w is average window size): | ||
| // (mag - avg_mag) / avg_mag | ||
| // = max (w * mag_{a} - sum_{i=0 to w-1} mag_{a - i}) / sum_{i=0 to w-1} mag_{a - i} | ||
| // = max ((w - 1) * mag_{a} + C) / (mag_{a} + C) | ||
| // <= w - 1 | ||
| private static readonly int _minimumScoreWindowSize = (int)(_maximumScore * 10) + 1; | ||
| // pseudo-code to generate the factors. | ||
| // factors = [] | ||
| @@ -577,15 +595,20 @@ private void SpectralResidual(double[] values, double[][] results, double thresh | ||
| { | ||
| _ifftMagList[i] = Math.Sqrt(_ifftRe[i] * _ifftRe[i] + _ifftIm[i] * _ifftIm[i]); | ||
| } | ||
| AverageFilter(_ifftMagList, Math.Min(_ifftMagList.Length, _judgementWindowSize)); | ||
| for (int i = 0; i <= Math.Min(length, _minimumScoreWindowSize); ++i) | ||
| { | ||
| _cumSumList[i] = _cumSumList[Math.Min(length, _minimumScoreWindowSize) - 1]; | ||
| } | ||
| // Step 7: Calculate raw score and set result | ||
| for (int i = 0; i < results.GetLength(0); ++i) | ||
| { | ||
| var score = CalculateScore(_ifftMagList[i], _cumSumList[i]); | ||
| score /= 10.0f; | ||
| score = Math.Min(score, 1); | ||
| score = Math.Max(score, 0); | ||
| score = Math.Min(score, _maximumScore); | ||
| score = Math.Max(score, _minimumScore); | ||
| var detres = score > threshold ? 1 : 0; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| Value | ||
| 181.944 | ||
| 37.176 | ||
| 57.14 | ||
| 67.128 | ||
| 72.12 | ||
| 77.112 | ||
| 82.104 | ||
| 83.1 | ||
| 87.09 | ||
| 92.088 | ||
| 92.01 | ||
| 97.08 | ||
| 102.072 | ||
| 107.05 | ||
| 107.06 | ||
| 117.048 | ||
| 122.04 | ||
| 132.024 | ||
| 147 | ||
| 151.82 | ||
| 151.992 | ||
| 151.72 | ||
| 151.94 | ||
| 156.969 | ||
| 156.984 | ||
| 156.92 | ||
| 161.976 | ||
| 161.94 | ||
| 161.97 | ||
| 166.968 | ||
| 176.952 | ||
| 181.94 | ||
| 186.936 | ||
| 201.91 | ||
| 201.912 | ||
| 201.9 | ||
| 206.904 | ||
| 216.88 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only for the first batch right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code snippet is for another bug, which is the result not aligned for the last batch. It is not related with the reported case.
In reply to: 527820005 [](ancestors = 527820005)