MIDAS - edge stream anomaly detection - for Ruby
Add this line to your application’s Gemfile:
gem "midas-edge"Prep your data in the format [source, destination, time] (all integers) and sorted by time (ascending)
data = [
[2, 3, 1],
[3, 4, 2],
[5, 9, 2],
[2, 3, 3]
]Get anomaly scores
midas = Midas.new
scores = midas.fit_predict(data)Higher scores are more anomalous. There is not currently a defined threshold for anomalies.
Pass parameters - default values below
Midas.new(
rows: 2, # number of hash functions
buckets: 769, # number of buckets
alpha: 0.5, # temporal decay factor
threshold: nil, # todo
relations: true, # whether to use MIDAS-R or MIDAS
directed: true, # treat the graph as directed or undirected
seed: 0 # random seed
)Data can be an array of arrays
[[1, 2, 3], [4, 5, 6]]Or a Numo array
Numo::NArray.cast([[1, 2, 3], [4, 5, 6]])For large datasets, read data directly from files
midas.fit_predict("data.csv")View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone --recursive https://github.com/ankane/midas-ruby.git
cd midas-ruby
bundle install
bundle exec rake compile
bundle exec rake test