midas-edge 0.2.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,21 +17,19 @@
17
17
  #pragma once
18
18
 
19
19
  #include <cmath>
20
- #include <algorithm>
21
20
 
22
- #include "EdgeHash.hpp"
23
- #include "NodeHash.hpp"
21
+ #include "CountMinSketch.hpp"
24
22
 
25
23
  namespace MIDAS {
26
24
  struct RelationalCore {
27
- int timestampCurrent = 1;
25
+ int timestamp = 1;
28
26
  const float factor;
29
27
  int* const indexEdge; // Pre-compute the index to-be-modified, thanks to the same structure of CMSs
30
28
  int* const indexSource;
31
29
  int* const indexDestination;
32
- EdgeHash numCurrentEdge, numTotalEdge;
33
- NodeHash numCurrentSource, numTotalSource;
34
- NodeHash numCurrentDestination, numTotalDestination;
30
+ CountMinSketch numCurrentEdge, numTotalEdge;
31
+ CountMinSketch numCurrentSource, numTotalSource;
32
+ CountMinSketch numCurrentDestination, numTotalDestination;
35
33
 
36
34
  RelationalCore(int numRow, int numColumn, float factor = 0.5):
37
35
  factor(factor),
@@ -56,19 +54,19 @@ struct RelationalCore {
56
54
  }
57
55
 
58
56
  float operator()(int source, int destination, int timestamp) {
59
- if (timestamp > timestampCurrent) {
57
+ if (this->timestamp < timestamp) {
60
58
  numCurrentEdge.MultiplyAll(factor);
61
59
  numCurrentSource.MultiplyAll(factor);
62
60
  numCurrentDestination.MultiplyAll(factor);
63
- timestampCurrent = timestamp;
61
+ this->timestamp = timestamp;
64
62
  }
65
- numCurrentEdge.Hash(source, destination, indexEdge);
63
+ numCurrentEdge.Hash(indexEdge, source, destination);
66
64
  numCurrentEdge.Add(indexEdge);
67
65
  numTotalEdge.Add(indexEdge);
68
- numCurrentSource.Hash(source, indexSource);
66
+ numCurrentSource.Hash(indexSource, source);
69
67
  numCurrentSource.Add(indexSource);
70
68
  numTotalSource.Add(indexSource);
71
- numCurrentDestination.Hash(destination, indexDestination);
69
+ numCurrentDestination.Hash(indexDestination, destination);
72
70
  numCurrentDestination.Add(indexDestination);
73
71
  numTotalDestination.Add(indexDestination);
74
72
  return std::max({
@@ -78,4 +76,4 @@ struct RelationalCore {
78
76
  });
79
77
  }
80
78
  };
81
- }
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.2.1
4
+ version: 0.3.2
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: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2021-06-08 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: '2.2'
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: '2.2'
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
- - !ruby/object:Gem::Dependency
42
- name: bundler
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,21 +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
115
- - vendor/MIDAS/src/EdgeHash.hpp
60
+ - vendor/MIDAS/src/CountMinSketch.hpp
116
61
  - vendor/MIDAS/src/FilteringCore.hpp
117
- - vendor/MIDAS/src/NodeHash.hpp
118
62
  - vendor/MIDAS/src/NormalCore.hpp
119
63
  - vendor/MIDAS/src/RelationalCore.hpp
120
64
  homepage: https://github.com/ankane/midas
121
65
  licenses:
122
66
  - MIT
123
67
  metadata: {}
124
- post_install_message:
68
+ post_install_message:
125
69
  rdoc_options: []
126
70
  require_paths:
127
71
  - lib
@@ -129,15 +73,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
73
  requirements:
130
74
  - - ">="
131
75
  - !ruby/object:Gem::Version
132
- version: '2.4'
76
+ version: '2.6'
133
77
  required_rubygems_version: !ruby/object:Gem::Requirement
134
78
  requirements:
135
79
  - - ">="
136
80
  - !ruby/object:Gem::Version
137
81
  version: '0'
138
82
  requirements: []
139
- rubygems_version: 3.1.2
140
- signing_key:
83
+ rubygems_version: 3.2.3
84
+ signing_key:
141
85
  specification_version: 4
142
86
  summary: Edge stream anomaly detection for Ruby
143
87
  test_files: []
@@ -1,104 +0,0 @@
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 <algorithm>
20
-
21
- namespace MIDAS {
22
- struct NodeHash {
23
- // Fields
24
- // --------------------------------------------------------------------------------
25
-
26
- const int r, c;
27
- const int lenData;
28
- int* const param1;
29
- int* const param2;
30
- float* const data;
31
- constexpr static float infinity = std::numeric_limits<float>::infinity();
32
-
33
- // Methods
34
- // --------------------------------------------------------------------------------
35
-
36
- NodeHash() = delete;
37
- NodeHash& operator=(const NodeHash& b) = delete;
38
-
39
- NodeHash(int numRow, int numColumn):
40
- r(numRow),
41
- c(numColumn),
42
- lenData(r * c),
43
- param1(new int[r]),
44
- param2(new int[r]),
45
- data(new float[lenData]) {
46
- for (int i = 0; i < r; i++) {
47
- param1[i] = rand() + 1; // ×0 is not a good idea, see Hash()
48
- param2[i] = rand();
49
- }
50
- std::fill(data, data + lenData, 0);
51
- }
52
-
53
- NodeHash(const NodeHash& b):
54
- r(b.r),
55
- c(b.c),
56
- lenData(b.lenData),
57
- param1(new int[r]),
58
- param2(new int[r]),
59
- data(new float[lenData]) {
60
- std::copy(b.param1, b.param1 + r, param1);
61
- std::copy(b.param2, b.param2 + r, param2);
62
- std::copy(b.data, b.data + lenData, data);
63
- }
64
-
65
- ~NodeHash() {
66
- delete[] param1;
67
- delete[] param2;
68
- delete[] data;
69
- }
70
-
71
- void ClearAll(float with = 0) const {
72
- std::fill(data, data + lenData, with);
73
- }
74
-
75
- void MultiplyAll(float by) const {
76
- std::for_each(data, data + lenData, [&](float& a) { a *= by; }); // Magic of vectorization
77
- }
78
-
79
- void Hash(int a, int* indexOut) const {
80
- for (int i = 0; i < r; i++) {
81
- indexOut[i] = (a * param1[i] + param2[i]) % c;
82
- indexOut[i] += i * c + (indexOut[i] < 0 ? c : 0);
83
- }
84
- }
85
-
86
- float operator()(const int* index) const {
87
- float least = infinity;
88
- for (int i = 0; i < r; i++)
89
- least = std::min(least, data[index[i]]);
90
- return least;
91
- }
92
-
93
- float Assign(const int* index, float to) const {
94
- for (int i = 0; i < r; i++)
95
- data[index[i]] = to;
96
- return to;
97
- }
98
-
99
- void Add(const int* index, float by = 1) const {
100
- for (int i = 0; i < r; i++)
101
- data[index[i]] += by;
102
- }
103
- };
104
- }