midas-edge 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/NOTICE.txt +2 -1
- data/README.md +2 -3
- data/ext/midas/ext.cpp +49 -36
- data/ext/midas/extconf.rb +6 -2
- data/ext/midas/numo.hpp +867 -0
- data/lib/midas/detector.rb +1 -12
- data/lib/midas/version.rb +1 -1
- data/vendor/MIDAS/README.md +107 -32
- data/vendor/MIDAS/src/CountMinSketch.hpp +105 -0
- data/vendor/MIDAS/src/FilteringCore.hpp +98 -0
- data/vendor/MIDAS/src/NormalCore.hpp +53 -0
- data/vendor/MIDAS/src/RelationalCore.hpp +79 -0
- metadata +16 -67
@@ -0,0 +1,53 @@
|
|
1
|
+
// -----------------------------------------------------------------------------
|
2
|
+
// Copyright 2020 Rui Liu (liurui39660) and Siddharth Bhatia (bhatiasiddharth)
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
// -----------------------------------------------------------------------------
|
16
|
+
|
17
|
+
#pragma once
|
18
|
+
|
19
|
+
#include <cmath>
|
20
|
+
|
21
|
+
#include "CountMinSketch.hpp"
|
22
|
+
|
23
|
+
namespace MIDAS {
|
24
|
+
struct NormalCore {
|
25
|
+
int timestamp = 1;
|
26
|
+
int* const index; // Pre-compute the index to-be-modified, thanks to the same structure of CMSs
|
27
|
+
CountMinSketch numCurrent, numTotal;
|
28
|
+
|
29
|
+
NormalCore(int numRow, int numColumn):
|
30
|
+
index(new int[numRow]),
|
31
|
+
numCurrent(numRow, numColumn),
|
32
|
+
numTotal(numCurrent) { }
|
33
|
+
|
34
|
+
virtual ~NormalCore() {
|
35
|
+
delete[] index;
|
36
|
+
}
|
37
|
+
|
38
|
+
static float ComputeScore(float a, float s, float t) {
|
39
|
+
return s == 0 || t - 1 == 0 ? 0 : pow((a - s / t) * t, 2) / (s * (t - 1));
|
40
|
+
}
|
41
|
+
|
42
|
+
float operator()(int source, int destination, int timestamp) {
|
43
|
+
if (this->timestamp < timestamp) {
|
44
|
+
numCurrent.ClearAll();
|
45
|
+
this->timestamp = timestamp;
|
46
|
+
}
|
47
|
+
numCurrent.Hash(index, source, destination);
|
48
|
+
numCurrent.Add(index);
|
49
|
+
numTotal.Add(index);
|
50
|
+
return ComputeScore(numCurrent(index), numTotal(index), timestamp);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// -----------------------------------------------------------------------------
|
2
|
+
// Copyright 2020 Rui Liu (liurui39660) and Siddharth Bhatia (bhatiasiddharth)
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
// -----------------------------------------------------------------------------
|
16
|
+
|
17
|
+
#pragma once
|
18
|
+
|
19
|
+
#include <cmath>
|
20
|
+
|
21
|
+
#include "CountMinSketch.hpp"
|
22
|
+
|
23
|
+
namespace MIDAS {
|
24
|
+
struct RelationalCore {
|
25
|
+
int timestamp = 1;
|
26
|
+
const float factor;
|
27
|
+
int* const indexEdge; // Pre-compute the index to-be-modified, thanks to the same structure of CMSs
|
28
|
+
int* const indexSource;
|
29
|
+
int* const indexDestination;
|
30
|
+
CountMinSketch numCurrentEdge, numTotalEdge;
|
31
|
+
CountMinSketch numCurrentSource, numTotalSource;
|
32
|
+
CountMinSketch numCurrentDestination, numTotalDestination;
|
33
|
+
|
34
|
+
RelationalCore(int numRow, int numColumn, float factor = 0.5):
|
35
|
+
factor(factor),
|
36
|
+
indexEdge(new int[numRow]),
|
37
|
+
indexSource(new int[numRow]),
|
38
|
+
indexDestination(new int[numRow]),
|
39
|
+
numCurrentEdge(numRow, numColumn),
|
40
|
+
numTotalEdge(numCurrentEdge),
|
41
|
+
numCurrentSource(numRow, numColumn),
|
42
|
+
numTotalSource(numCurrentSource),
|
43
|
+
numCurrentDestination(numRow, numColumn),
|
44
|
+
numTotalDestination(numCurrentDestination) { }
|
45
|
+
|
46
|
+
virtual ~RelationalCore() {
|
47
|
+
delete[] indexEdge;
|
48
|
+
delete[] indexSource;
|
49
|
+
delete[] indexDestination;
|
50
|
+
}
|
51
|
+
|
52
|
+
static float ComputeScore(float a, float s, float t) {
|
53
|
+
return s == 0 || t - 1 == 0 ? 0 : pow((a - s / t) * t, 2) / (s * (t - 1));
|
54
|
+
}
|
55
|
+
|
56
|
+
float operator()(int source, int destination, int timestamp) {
|
57
|
+
if (this->timestamp < timestamp) {
|
58
|
+
numCurrentEdge.MultiplyAll(factor);
|
59
|
+
numCurrentSource.MultiplyAll(factor);
|
60
|
+
numCurrentDestination.MultiplyAll(factor);
|
61
|
+
this->timestamp = timestamp;
|
62
|
+
}
|
63
|
+
numCurrentEdge.Hash(indexEdge, source, destination);
|
64
|
+
numCurrentEdge.Add(indexEdge);
|
65
|
+
numTotalEdge.Add(indexEdge);
|
66
|
+
numCurrentSource.Hash(indexSource, source);
|
67
|
+
numCurrentSource.Add(indexSource);
|
68
|
+
numTotalSource.Add(indexSource);
|
69
|
+
numCurrentDestination.Hash(indexDestination, destination);
|
70
|
+
numCurrentDestination.Add(indexDestination);
|
71
|
+
numTotalDestination.Add(indexDestination);
|
72
|
+
return std::max({
|
73
|
+
ComputeScore(numCurrentEdge(indexEdge), numTotalEdge(indexEdge), timestamp),
|
74
|
+
ComputeScore(numCurrentSource(indexSource), numTotalSource(indexSource), timestamp),
|
75
|
+
ComputeScore(numCurrentDestination(indexDestination), numTotalDestination(indexDestination), timestamp),
|
76
|
+
});
|
77
|
+
}
|
78
|
+
};
|
79
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midas-edge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rice
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: numo-narray
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,64 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
42
|
-
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake-compiler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: minitest
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '5'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '5'
|
97
|
-
description:
|
98
|
-
email: andrew@chartkick.com
|
41
|
+
description:
|
42
|
+
email: andrew@ankane.org
|
99
43
|
executables: []
|
100
44
|
extensions:
|
101
45
|
- ext/midas/extconf.rb
|
@@ -107,16 +51,21 @@ files:
|
|
107
51
|
- README.md
|
108
52
|
- ext/midas/ext.cpp
|
109
53
|
- ext/midas/extconf.rb
|
54
|
+
- ext/midas/numo.hpp
|
110
55
|
- lib/midas-edge.rb
|
111
56
|
- lib/midas/detector.rb
|
112
57
|
- lib/midas/version.rb
|
113
58
|
- vendor/MIDAS/LICENSE
|
114
59
|
- vendor/MIDAS/README.md
|
60
|
+
- vendor/MIDAS/src/CountMinSketch.hpp
|
61
|
+
- vendor/MIDAS/src/FilteringCore.hpp
|
62
|
+
- vendor/MIDAS/src/NormalCore.hpp
|
63
|
+
- vendor/MIDAS/src/RelationalCore.hpp
|
115
64
|
homepage: https://github.com/ankane/midas
|
116
65
|
licenses:
|
117
66
|
- MIT
|
118
67
|
metadata: {}
|
119
|
-
post_install_message:
|
68
|
+
post_install_message:
|
120
69
|
rdoc_options: []
|
121
70
|
require_paths:
|
122
71
|
- lib
|
@@ -124,15 +73,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
73
|
requirements:
|
125
74
|
- - ">="
|
126
75
|
- !ruby/object:Gem::Version
|
127
|
-
version: '2.
|
76
|
+
version: '2.6'
|
128
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
78
|
requirements:
|
130
79
|
- - ">="
|
131
80
|
- !ruby/object:Gem::Version
|
132
81
|
version: '0'
|
133
82
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
135
|
-
signing_key:
|
83
|
+
rubygems_version: 3.2.3
|
84
|
+
signing_key:
|
136
85
|
specification_version: 4
|
137
86
|
summary: Edge stream anomaly detection for Ruby
|
138
87
|
test_files: []
|