Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manu-bhadoria/statnr
A comprehensive statistical library for the Noir programming language.
https://github.com/manu-bhadoria/statnr
Last synced: 3 months ago
JSON representation
A comprehensive statistical library for the Noir programming language.
- Host: GitHub
- URL: https://github.com/manu-bhadoria/statnr
- Owner: manu-bhadoria
- License: apache-2.0
- Created: 2023-12-01T07:43:03.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2023-12-05T14:16:38.000Z (12 months ago)
- Last Synced: 2024-04-14T02:10:22.653Z (7 months ago)
- Language: Roff
- Size: 404 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-noir - Statistical Library - Noir Statistical Library is a comprehensive library for statistical computations in the Noir language (Get Coding / Libraries)
README
![Statnr Image](statnr.png)
# Noir Statistical Library (statnr)## Description
**Noir Statistical Library** is a comprehensive library for statistical computations in the Noir language. It includes functions for basic statistical measures such as mean, median, mode, and range, as well as advanced computations like linear regression, logistic regression, and interquartile range. The library supports operations on both integer (`u64`) and custom floating-point (`Float`) types.
## statnr's relevance in Zero-Knowledge Proofs (ZKP)
ZKP applications often require complex mathematical computations to ensure data privacy while proving the veracity of the information. Here, statnr's extensive suite of statistical functions will be helpful.## Features
- **Mean Calculation**: Compute the average of a fixed-size array of integers or custom floats.
- **Median Calculation**: Determine the middle value in a sorted array of integers or floats.
- **Mode Calculation**: Find the most frequent value in an array.
- **Range Calculation**: Compute the difference between the maximum and minimum values in an array.
- **Generate a range of integer or float numbers**: Generate a range of numbers using various parameters.
- **Standard Deviation and Variance**: Calculate the spread of a dataset.
- **Quartile Computations**: Determine Q1, Q2, and Q3 values for a dataset.
- **Linear Regression**: Perform simple linear regression analysis.
- **Logistic Regression**: Perform simple logistic regression analysis.
- **Utilities**: Functions for sorting data, finding minimum and maximum values, etc.### Examples
```noir
//Mean Calculation
let numbers: [u64; 5] = [1, 2, 3, 4, 5];
let average = mean(numbers);
assert(average == 3);//Median Calculation
let numbers: [Field; 5] = [1, 2, 3, 4, 5];
let median_value = median(numbers);
assert(median_value == 3);//Linear Regression
let data: [(u64, u64); 10] = [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10), (6, 12), (7, 14), (8, 16), (9, 18), (10, 20)];
let (slope, intercept) = linear_regression(data);
assert(slope == 2);
assert(intercept == 0);//Generate a range of float numbers
let start = Float { sign: 0, mantissa: 10000, exponent: 100 };
let end = Float { sign: 0, mantissa: 60000, exponent: 100 };
let step = Float { sign: 0, mantissa: 10000, exponent: 100 };let result = generate_range_floats(start, end, step);
let expected = [
Float { sign: 0, mantissa: 10000, exponent: 100 },
Float { sign: 0, mantissa: 20000, exponent: 100 },
Float { sign: 0, mantissa: 30000, exponent: 100 },
Float { sign: 0, mantissa: 40000, exponent: 100 },
Float { sign: 0, mantissa: 50000, exponent: 100 },
Float { sign: 0, mantissa: 0, exponent: 0 },
Float { sign: 0, mantissa: 0, exponent: 0 },
Float { sign: 0, mantissa: 0, exponent: 0 },
Float { sign: 0, mantissa: 0, exponent: 0 },
Float { sign: 0, mantissa: 0, exponent: 0 },
];for i in 0..10 {
assert(are_floats_equal(result[i], expected[i]));
}```
## TestingEach function is accompanied by a suite of tests to ensure correctness and robustness. Run the tests using Noir's built-in testing framework to validate functionality.
## Limitations
The current implementation of some functions is limited to fixed-size arrays. Adjustments are required to handle variable-sized arrays. Floating-point computations are approximations and might not be suitable for highly precise calculations.