Giter Club home page Giter Club logo

datasketches-ruby's Introduction

DataSketches Ruby

DataSketches - sketch data structures - for Ruby

Build Status

Installation

Add this line to your application’s Gemfile:

gem "datasketches"

Sketch Families

Distinct counting

Most frequent

Quantiles and histograms

Sampling

CPC Sketch

Create a sketch

sketch = DataSketches::CpcSketch.new

Add data

sketch.update(1)
sketch.update(2.0)
sketch.update("three")

Estimate the count

sketch.estimate

Save a sketch

data = sketch.serialize

Load a sketch

sketch = DataSketches::CpcSketch.deserialize(data)

Get the union

u = DataSketches::CpcUnion.new(14)
u.update(sketch1)
u.update(sketch2)
u.result

HyperLogLog Sketch

Create a sketch

sketch = DataSketches::HllSketch.new(14)

Add data

sketch.update(1)
sketch.update(2.0)
sketch.update("three")

Estimate the count

sketch.estimate

Save a sketch

data = sketch.serialize_updatable
# or
data = sketch.serialize_compact

Load a sketch

sketch = DataSketches::HllSketch.deserialize(data)

Get the union

u = DataSketches::HllUnion.new(14)
u.update(sketch1)
u.update(sketch2)
u.result

Theta Sketch

Create a sketch

sketch = DataSketches::UpdateThetaSketch.new

Add data

sketch.update(1)
sketch.update(2.0)
sketch.update("three")

Estimate the count

sketch.estimate

Save a sketch

data = sketch.serialize

Load a sketch

sketch = DataSketches::UpdateThetaSketch.deserialize(data)

Get the union

u = DataSketches::ThetaUnion.new
u.update(sketch1)
u.update(sketch2)
u.result

Get the intersection

i = DataSketches::ThetaIntersection.new
i.update(sketch1)
i.update(sketch2)
i.result

Compute A not B

d = DataSketches::ThetaANotB.new
d.compute(a, b)

Frequent Item Sketch

Create a sketch

sketch = DataSketches::FrequentStringsSketch.new(64)

Add data

sketch.update("a")
sketch.update("b")
sketch.update("c")

Estimate the frequency of an item

sketch.estimate("a")

Save a sketch

data = sketch.serialize

Load a sketch

sketch = DataSketches::FrequentStringsSketch.deserialize(data)

KLL Sketch

Create a sketch

sketch = DataSketches::KllIntsSketch.new
# or
sketch = DataSketches::KllFloatsSketch.new

Add data

sketch.update(1)
sketch.update(2)
sketch.update(3)

Get quantiles

sketch.quantile(0.5)

Get the minimum and maximum values from the stream

sketch.min_value
sketch.max_value

Save a sketch

data = sketch.serialize

Load a sketch

sketch = DataSketches::KllIntsSketch.deserialize(data)

Merge sketches

sketch.merge(sketch2)

VarOpt Sketch

Create a sketch

sketch = DataSketches::VarOptSketch.new(14)

Add data

sketch.update(1)
sketch.update(2.0)
sketch.update("three")

Sample data

sketch.samples

Credits

This library is modeled after the DataSketches Python API.

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 --recursive https://github.com/ankane/datasketches-ruby.git
cd datasketches-ruby
bundle install
bundle exec rake compile
bundle exec rake test

datasketches-ruby's People

Contributors

ankane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

datasketches-ruby's Issues

core dump: std::bad_any_cast using DataSketches::KllIntsSketch

We're occasionally seeing this error, mostly in our CI test suite, but maybe production too:

terminate called after throwing an instance of 'std::bad_any_cast'
  what():  bad any_cast
Aborted (core dumped)

I don't have a good stack trace, but I believe the code that triggers this looks something like:

sketch = DataSketches::KllIntsSketch.new

subsketch = DataSketches::KllIntsSketch.new.tap do |s|
  s.update(45_000_000)
  s.update(60_000_000)
  s.update(60_000_000)
end

sketch.merge(subsketch)

sketch.quantile(0.95)

I haven't catalogued all the instances of this error, so it may or may not affect more than just this DataSketches::KllIntsSketch use-case.

Sorry I don't have much more detail, but I figured I'd report what I know so far.

Versions:

  • datasketches (0.4.0) (but experienced on older versions too)
  • rice (4.1.0)
  • ruby 3.2.2 in ruby:3.2.2-slim-bookworm Docker image on amd64

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.