Giter VIP home page Giter VIP logo

random-sampling-with-a-reservoir's Introduction

Random-Sampling-With-A-Reservoir

Code for random sampling without replacement with a reservoir. It randomly choose a sample of k items from a file containing n items. Typically n is large enough that it doesn't fit into the main memory. This algorithm is also suitable for streaming data

Getting Started

The python and java code are independent from each other and any of them can be used separately. The java code uses a randomized queue

Prerequisites

For the python code: python 3.4 or grater

For the java code: java 8 or grater and the library algs4.jar

Installing

Python code:

Ready to work using your favorite IDE. If you are in the folder containing the code, you can run it using:

python reservoirSampling.py k file_name

where k is the size of the sample and file_name is the file where you can extract the sample. You must put your file inside the directory called TestData. If no arguments are provided, default arguments takes place (k = 50 file_name = Moby-Dick.txt). You can also hardcode your file name in the code. To avoid incompatibilities between OS the pathlib was used to set the path to the files.

Java code:

You can build the project using your favorite IDE. You must add the algs4.jar library to your classpath.

To run the code you must provide the size of the sample and the file names as arguments.

License

Licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • This short project was inspire from the Princeton course Algorithms I

random-sampling-with-a-reservoir's People

Contributors

edxz7 avatar

Forkers

rainmanwang

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.