GithubHelp home page GithubHelp logo

kaspi314 / stathelpers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robtillaart/stathelpers

0.0 0.0 0.0 16 KB

Arduino library with a number of statistic helper functions.

License: MIT License

C++ 100.00%

stathelpers's Introduction

Arduino CI License: MIT GitHub release

statHelpers

Arduino library with a number of statistic helper functions.

Description

This library contains functions that have the goal to help with some basic statistical calculations.

Functions

Permutation

returns how many different ways one can choose a set of k elements from a set of n. The order does matter. The limits mentioned is the n for which all k still work.

  • uint32_t permutations(n, k) exact up to 12
  • uint64_t permutations64(n, k) exact up to 20
  • double dpermutations(n, k) not exact up to 34 (4 byte) or 170 (8 byte)

If you need a larger n but k is near 0 the functions will still work, but to which k differs per value for n. (no formula found, and an overflow detection takes overhead).

Factorial

  • uint32_t factorial(n) exact up to 12!
  • uint64_t factorial64(n) exact up to 20! (Print 64 bit ints with my printHelpers)
  • double dfactorial(n) not exact up to 34! (4 byte) or 170! (8 byte)
  • double stirling(n) approximation function for factorial (right magnitude)

dfactorial() is quite accurate over the whole range. stirling() is up to 3x faster for large n (> 100), but accuracy is less than the dfactorial(), see example.

Combination

returns how many different ways one can choose a set of k elements from a set of n. The order does not matter. The number of combinations grows fast so n is limited per function. The limits mentioned is the n for which all k still work.

  • uint32_t combinations(n, k) n = 0 .. 30 (iterative version)
  • uint64_t combinations64(n, k) n = 0 .. 61 (iterative version)
  • uint32_t rcombinations(n, k) n = 0 .. 30 (recursive version, slightly slower)
  • uint64_t rcombinations64(n, k) n = 0 .. 61 (recursive version, slightly slower)
  • double dcombinations(n, k) n = 0 .. 125 (4bit) n = 0 .. 1020 (8 bit)

If you need a larger n but k is near 0 or near n the functions will still work, but for which k differs per value for n. (no formula found, and an overflow detection takes overhead).

  • combPascal(n, k) n = 0 .. 30 but due to double recursion per iteration it takes time and a lot of it for larger values. Added for recreational purposes, limited tested.

Notes

  • perm1 is a sketch in the examples that shows a recursive permutation algorithm. It generates all permutations of a given char string. It allows you to process every instance. It is added to this library as it fits in the context.

Future

  • code & example for get Nth Permutation
  • investigate valid range detection for a given (n, k) for combinations and permutations.

Operation

See examples

stathelpers's People

Contributors

robtillaart avatar

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.