Giter Club home page Giter Club logo

librcf's Introduction

Random Cut Forest C/C++

Random Cut Forest (RCF) anomaly detection for C/C++

🌲 Also available for Ruby and PHP, and as a CLI

Build Status

Installation

Download the latest version:

You can also install it with Homebrew:

brew install ankane/brew/librcf

Getting Started

Include the header

#include "rcf.h"

Create a forest with 3 dimensions

rcf_forest *forest = rcf_create(3);

Set parameters

rcf_set_param(forest, "number_of_trees", "100");

Score a point

float point[] = {1.0, 2.0, 3.0};
double score = rcf_score(forest, point);

Update with a point

rcf_update(forest, point);

Free the forest

rcf_free(forest);

Example

#include <stdio.h>
#include <stdlib.h>

#include "rcf.h"

float randf() {
    return rand() / (float) RAND_MAX;
}

int main() {
    rcf_forest *forest = rcf_create(3);
    rcf_set_param(forest, "number_of_trees", "100");

    for (int i = 0; i < 200; i++) {
        float point[] = {randf(), randf(), randf()};

        // make the second to last point an anomaly
        if (i == 198) {
            point[1] = 2;
        }

        double score = rcf_score(forest, point);
        printf("point = %d, score = %f\n", i, score);
        rcf_update(forest, point);
    }

    rcf_free(forest);
    return 0;
}

Parameters

Name Description Default Value
shingle_size Shingle size to use 1
sample_size Points to keep in sample for each tree 256
number_of_trees Number of trees to use in the forest 100
random_seed Random seed to use 42
parallel Enable parallel execution false

Parameter values should always be passed as strings.

rcf_set_param(forest, "sample_size", "256");
rcf_set_param(forest, "parallel", "true");

rcf_set_param returns zero if successful and nonzero if the name or value is invalid or if it’s called after rcf_score or rcf_update.

References

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/librcf.git
cd librcf
cargo build
cargo test

To generate headers:

cbindgen > include/rcf.h

librcf's People

Contributors

ankane avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

some-forks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.