Implementations
Python
Install from PyPI:
pip install pragmastat==8.0.0
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/py
Pragmastat on PyPI: https://pypi.org/project/pragmastat/
Demo:
from pragmastat import (
Rng,
center,
spread,
rel_spread,
shift,
ratio,
avg_spread,
disparity,
center_bounds,
shift_bounds,
ratio_bounds,
)
from pragmastat.distributions import Additive, Exp, Multiplic, Power, Uniform
def main():
# --- Randomization ---
rng = Rng("demo-uniform")
print(rng.uniform()) # 0.2640554428629759
print(rng.uniform()) # 0.9348534835582796
rng = Rng("demo-sample")
print(rng.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3)) # [3, 8, 9]
rng = Rng("demo-shuffle")
print(rng.shuffle([1, 2, 3, 4, 5])) # [4, 2, 3, 5, 1]
rng = Rng("demo-resample")
print(rng.resample([1, 2, 3, 4, 5], 7)) # [5, 1, 1, 3, 3, 4, 5]
# --- Distribution Sampling ---
rng = Rng("demo-dist-uniform")
dist = Uniform(0, 10)
print(dist.sample(rng)) # 6.54043657816832
rng = Rng("demo-dist-additive")
dist = Additive(0, 1)
print(dist.sample(rng)) # 0.17410448679568188
rng = Rng("demo-dist-exp")
dist = Exp(1)
print(dist.sample(rng)) # 0.6589065267276553
rng = Rng("demo-dist-power")
dist = Power(1, 2)
print(dist.sample(rng)) # 1.023677535537084
rng = Rng("demo-dist-multiplic")
dist = Multiplic(0, 1)
print(dist.sample(rng)) # 1.1273244602673853
# --- Single-Sample Statistics ---
x = [1, 3, 5, 7, 9]
print(center(x)) # 5
print(spread(x)) # 4
print(spread([v + 10 for v in x])) # 4
print(spread([v * 2 for v in x])) # 8
print(rel_spread(x)) # 0.8
# --- Two-Sample Comparison ---
x = [0, 3, 6, 9, 12]
y = [0, 2, 4, 6, 8]
print(shift(x, y)) # 2
print(shift(y, x)) # -2
print(avg_spread(x, y)) # 5
print(disparity(x, y)) # 0.4
print(disparity(y, x)) # -0.4
x = [1, 2, 4, 8, 16]
y = [2, 4, 8, 16, 32]
print(ratio(x, y)) # 0.5
print(ratio(y, x)) # 2
# --- One-Sample Bounds ---
x = list(range(1, 11))
print(center(x)) # 5.5
bounds = center_bounds(x, 0.05) # Bounds(lower=3.5, upper=7.5)
print(f"Bounds(lower={bounds.lower}, upper={bounds.upper})")
# --- Two-Sample Bounds ---
x = list(range(1, 31))
y = list(range(21, 51))
print(shift(x, y)) # -20
bounds = shift_bounds(x, y, 1e-4) # Bounds(lower=-30, upper=-10)
print(f"Bounds(lower={bounds.lower}, upper={bounds.upper})")
x = [1, 2, 3, 4, 5]
y = [2, 3, 4, 5, 6]
bounds = ratio_bounds(x, y, 0.05) # Bounds(lower=0.333..., upper=1.5)
print(f"Bounds(lower={bounds.lower}, upper={bounds.upper})")
if __name__ == "__main__":
main()
TypeScript
Install from npm:
npm i pragmastat@8.0.0
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/ts
Pragmastat on npm: https://www.npmjs.com/package/pragmastat
Demo:
import {
center, spread, relSpread, shift, ratio, avgSpread, disparity,
centerBounds, shiftBounds, ratioBounds,
Rng, Uniform, Additive, Exp, Power, Multiplic
} from '../src';
function main() {
// --- Randomization ---
let rng = new Rng("demo-uniform");
console.log(rng.uniform()); // 0.2640554428629759
console.log(rng.uniform()); // 0.9348534835582796
rng = new Rng("demo-sample");
console.log(rng.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3)); // [3, 8, 9]
rng = new Rng("demo-shuffle");
console.log(rng.shuffle([1, 2, 3, 4, 5])); // [4, 2, 3, 5, 1]
rng = new Rng("demo-resample");
console.log(rng.resample([1, 2, 3, 4, 5], 7)); // [5, 1, 1, 3, 3, 4, 5]
// --- Distribution Sampling ---
rng = new Rng("demo-dist-uniform");
let dist = new Uniform(0, 10);
console.log(dist.sample(rng)); // 6.54043657816832
rng = new Rng("demo-dist-additive");
let addDist = new Additive(0, 1);
console.log(addDist.sample(rng)); // 0.17410448679568188
rng = new Rng("demo-dist-exp");
let expDist = new Exp(1);
console.log(expDist.sample(rng)); // 0.6589065267276553
rng = new Rng("demo-dist-power");
let powDist = new Power(1, 2);
console.log(powDist.sample(rng)); // 1.023677535537084
rng = new Rng("demo-dist-multiplic");
let mulDist = new Multiplic(0, 1);
console.log(mulDist.sample(rng)); // 1.1273244602673853
// --- Single-Sample Statistics ---
let x = [1, 3, 5, 7, 9];
console.log(center(x)); // 5
console.log(spread(x)); // 4
console.log(spread(x.map(v => v + 10))); // 4
console.log(spread(x.map(v => v * 2))); // 8
console.log(relSpread(x)); // 0.8
// --- Two-Sample Comparison ---
x = [0, 3, 6, 9, 12];
let y = [0, 2, 4, 6, 8];
console.log(shift(x, y)); // 2
console.log(shift(y, x)); // -2
console.log(avgSpread(x, y)); // 5
console.log(disparity(x, y)); // 0.4
console.log(disparity(y, x)); // -0.4
x = [1, 2, 4, 8, 16];
y = [2, 4, 8, 16, 32];
console.log(ratio(x, y)); // 0.5
console.log(ratio(y, x)); // 2
// --- One-Sample Bounds ---
x = Array.from({ length: 10 }, (_, i) => i + 1);
console.log(center(x)); // 5.5
console.log(centerBounds(x, 0.05)); // { lower: 3.5, upper: 7.5 }
// --- Two-Sample Bounds ---
x = Array.from({ length: 30 }, (_, i) => i + 1);
y = Array.from({ length: 30 }, (_, i) => i + 21);
console.log(shift(x, y)); // -20
console.log(shiftBounds(x, y, 1e-4)); // { lower: -30, upper: -10 }
x = [1, 2, 3, 4, 5];
y = [2, 3, 4, 5, 6];
console.log(ratioBounds(x, y, 0.05)); // { lower: 0.333..., upper: 1.5 }
}
main();
R
Install from GitHub:
install.packages("remotes") # If 'remotes' is not installed
remotes::install_github("AndreyAkinshin/pragmastat",
subdir = "r/pragmastat", ref = "v8.0.0")
library(pragmastat)
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/r
Demo:
library(pragmastat)
# --- Randomization ---
r <- rng("demo-uniform")
print(r$uniform()) # 0.2640554428629759
print(r$uniform()) # 0.9348534835582796
r <- rng("demo-sample")
print(r$sample(0:9, 3)) # [3, 8, 9]
r <- rng("demo-shuffle")
print(r$shuffle(c(1, 2, 3, 4, 5))) # [4, 2, 3, 5, 1]
r <- rng("demo-resample")
print(r$resample(c(1, 2, 3, 4, 5), 7)) # [5, 1, 1, 3, 3, 4, 5]
# --- Distribution Sampling ---
r <- rng("demo-dist-uniform")
dist <- dist_uniform(0, 10)
print(dist$sample(r)) # 6.54043657816832
r <- rng("demo-dist-additive")
dist <- dist_additive(0, 1)
print(dist$sample(r)) # 0.17410448679568188
r <- rng("demo-dist-exp")
dist <- dist_exp(1)
print(dist$sample(r)) # 0.6589065267276553
r <- rng("demo-dist-power")
dist <- dist_power(1, 2)
print(dist$sample(r)) # 1.023677535537084
r <- rng("demo-dist-multiplic")
dist <- dist_multiplic(0, 1)
print(dist$sample(r)) # 1.1273244602673853
# --- Single-Sample Statistics ---
x <- c(1, 3, 5, 7, 9)
print(median(x)) # 5
print(center(x)) # 5
print(spread(x)) # 4
print(spread(x + 10)) # 4
print(spread(x * 2)) # 8
print(rel_spread(x)) # 0.8
# --- Two-Sample Comparison ---
x <- c(0, 3, 6, 9, 12)
y <- c(0, 2, 4, 6, 8)
print(shift(x, y)) # 2
print(shift(y, x)) # -2
print(avg_spread(x, y)) # 5
print(disparity(x, y)) # 0.4
print(disparity(y, x)) # -0.4
x <- c(1, 2, 4, 8, 16)
y <- c(2, 4, 8, 16, 32)
print(ratio(x, y)) # 0.5
print(ratio(y, x)) # 2
# --- One-Sample Bounds ---
x <- 1:10
print(center(x)) # 5.5
bounds <- center_bounds(x, 0.05) # [lower=3.5, upper=7.5]
print(paste("[", bounds$lower, ", ", bounds$upper, "]", sep=""))
# --- Two-Sample Bounds ---
x <- 1:30
y <- 21:50
print(shift(x, y)) # -20
bounds <- shift_bounds(x, y, 1e-4) # [lower=-30, upper=-10]
print(paste("[", bounds$lower, ", ", bounds$upper, "]", sep=""))
x <- c(1, 2, 3, 4, 5)
y <- c(2, 3, 4, 5, 6)
bounds <- ratio_bounds(x, y, 0.05) # [lower=0.333..., upper=1.5]
print(paste("[", bounds$lower, ", ", bounds$upper, "]", sep=""))
C#
Install from NuGet via .NET CLI:
dotnet add package Pragmastat --version 8.0.0
Install from NuGet via Package Manager Console:
NuGet\Install-Package Pragmastat -Version 8.0.0
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/cs
Pragmastat on NuGet: https://www.nuget.org/packages/Pragmastat/
Demo:
using static System.Console;
using Pragmastat.Distributions;
using Pragmastat.Randomization;
namespace Pragmastat.Demo;
class Program
{
static void Main()
{
// --- Randomization ---
var rng = new Rng("demo-uniform");
WriteLine(rng.Uniform()); // 0.2640554428629759
WriteLine(rng.Uniform()); // 0.9348534835582796
rng = new Rng("demo-sample");
WriteLine(string.Join(", ", rng.Sample([0.0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3))); // 3, 8, 9
rng = new Rng("demo-shuffle");
WriteLine(string.Join(", ", rng.Shuffle([1.0, 2, 3, 4, 5]))); // 4, 2, 3, 5, 1
rng = new Rng("demo-resample");
WriteLine(string.Join(", ", rng.Resample([1.0, 2, 3, 4, 5], 7))); // 5, 1, 1, 3, 3, 4, 5
// --- Distribution Sampling ---
rng = new Rng("demo-dist-uniform");
IDistribution dist = new Uniform(0, 10);
WriteLine(dist.Sample(rng)); // 6.54043657816832
rng = new Rng("demo-dist-additive");
dist = new Additive(0, 1);
WriteLine(dist.Sample(rng)); // 0.17410448679568188
rng = new Rng("demo-dist-exp");
dist = new Exp(1);
WriteLine(dist.Sample(rng)); // 0.6589065267276553
rng = new Rng("demo-dist-power");
dist = new Power(1, 2);
WriteLine(dist.Sample(rng)); // 1.023677535537084
rng = new Rng("demo-dist-multiplic");
dist = new Multiplic(0, 1);
WriteLine(dist.Sample(rng)); // 1.1273244602673853
// --- Single-Sample Statistics ---
var x = new Sample(1, 3, 5, 7, 9);
WriteLine(x.Center()); // 5
WriteLine(x.Spread()); // 4
WriteLine((x + 10).Spread()); // 4
WriteLine((x * 2).Spread()); // 8
WriteLine(x.RelSpread()); // 0.8
// --- Two-Sample Comparison ---
x = new Sample(0, 3, 6, 9, 12);
var y = new Sample(0, 2, 4, 6, 8);
WriteLine(Toolkit.Shift(x, y)); // 2
WriteLine(Toolkit.Shift(y, x)); // -2
WriteLine(Toolkit.AvgSpread(x, y)); // 5
WriteLine(Toolkit.Disparity(x, y)); // 0.4
WriteLine(Toolkit.Disparity(y, x)); // -0.4
x = new Sample(1, 2, 4, 8, 16);
y = new Sample(2, 4, 8, 16, 32);
WriteLine(Toolkit.Ratio(x, y)); // 0.5
WriteLine(Toolkit.Ratio(y, x)); // 2
// --- One-Sample Bounds ---
x = new Sample(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
WriteLine(Toolkit.Center(x)); // 5.5
WriteLine(Toolkit.CenterBounds(x, 0.05)); // [3.5, 7.5]
// --- Two-Sample Bounds ---
x = new Sample(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30);
y = new Sample(
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50);
WriteLine(Toolkit.Shift(x, y)); // -20
WriteLine(Toolkit.ShiftBounds(x, y, 1e-4)); // [-30, -10]
x = new Sample(1, 2, 3, 4, 5);
y = new Sample(2, 3, 4, 5, 6);
WriteLine(Toolkit.RatioBounds(x, y, 0.05)); // [0.333..., 1.5]
}
}
Kotlin
Install from Maven Central Repository via Apache Maven:
<dependency>
<groupId>dev.pragmastat</groupId>
<artifactId>pragmastat</artifactId>
<version>8.0.0</version>
</dependency>
Install from Maven Central Repository via Gradle:
implementation 'dev.pragmastat:pragmastat:8.0.0'
Install from Maven Central Repository via Gradle (Kotlin):
implementation("dev.pragmastat:pragmastat:8.0.0")
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/kt
Pragmastat on Maven Central Repository: https://central.sonatype.com/artifact/dev.pragmastat/pragmastat/overview
Demo:
package dev.pragmastat.demo
import dev.pragmastat.*
import dev.pragmastat.distributions.*
fun main() {
// --- Randomization ---
var rng = Rng("demo-uniform")
println(rng.uniform()) // 0.2640554428629759
println(rng.uniform()) // 0.9348534835582796
rng = Rng("demo-sample")
println(rng.sample(listOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), 3)) // [3, 8, 9]
rng = Rng("demo-shuffle")
println(rng.shuffle(listOf(1.0, 2.0, 3.0, 4.0, 5.0))) // [4, 2, 3, 5, 1]
rng = Rng("demo-resample")
println(rng.resample(listOf(1.0, 2.0, 3.0, 4.0, 5.0), 7)) // [5, 1, 1, 3, 3, 4, 5]
// --- Distribution Sampling ---
rng = Rng("demo-dist-uniform")
var dist: Distribution = Uniform(0.0, 10.0)
println(dist.sample(rng)) // 6.54043657816832
rng = Rng("demo-dist-additive")
dist = Additive(0.0, 1.0)
println(dist.sample(rng)) // 0.17410448679568188
rng = Rng("demo-dist-exp")
dist = Exp(1.0)
println(dist.sample(rng)) // 0.6589065267276553
rng = Rng("demo-dist-power")
dist = Power(1.0, 2.0)
println(dist.sample(rng)) // 1.023677535537084
rng = Rng("demo-dist-multiplic")
dist = Multiplic(0.0, 1.0)
println(dist.sample(rng)) // 1.1273244602673853
// --- Single-Sample Statistics ---
var x = listOf(1.0, 3.0, 5.0, 7.0, 9.0)
println(center(x)) // 5
println(spread(x)) // 4
println(spread(x.map { it + 10 })) // 4
println(spread(x.map { it * 2 })) // 8
println(relSpread(x)) // 0.8
// --- Two-Sample Comparison ---
x = listOf(0.0, 3.0, 6.0, 9.0, 12.0)
var y = listOf(0.0, 2.0, 4.0, 6.0, 8.0)
println(shift(x, y)) // 2
println(shift(y, x)) // -2
println(avgSpread(x, y)) // 5
println(disparity(x, y)) // 0.4
println(disparity(y, x)) // -0.4
x = listOf(1.0, 2.0, 4.0, 8.0, 16.0)
y = listOf(2.0, 4.0, 8.0, 16.0, 32.0)
println(ratio(x, y)) // 0.5
println(ratio(y, x)) // 2
// --- One-Sample Bounds ---
x = (1..10).map { it.toDouble() }
println(center(x)) // 5.5
println(centerBounds(x, 0.05)) // Bounds(lower=3.5, upper=7.5)
// --- Two-Sample Bounds ---
x = (1..30).map { it.toDouble() }
y = (21..50).map { it.toDouble() }
println(shift(x, y)) // -20
println(shiftBounds(x, y, 1e-4)) // Bounds(lower=-30.0, upper=-10.0)
x = listOf(1.0, 2.0, 3.0, 4.0, 5.0)
y = listOf(2.0, 3.0, 4.0, 5.0, 6.0)
println(ratioBounds(x, y, 0.05)) // Bounds(lower=0.333..., upper=1.5)
}
Rust
Install from crates.io via cargo:
cargo add pragmastat@8.0.0
Install from crates.io via Cargo.toml:
[dependencies]
pragmastat = "8.0.0"
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/rs
Pragmastat on crates.io: https://crates.io/crates/pragmastat
Demo:
use pragmastat::distributions::{Additive, Distribution, Exp, Multiplic, Power, Uniform};
use pragmastat::*;
fn print<E: std::fmt::Debug>(result: Result<f64, E>) {
println!("{}", result.unwrap());
}
fn add(x: &[f64], val: f64) -> Vec<f64> {
x.iter().map(|v| v + val).collect()
}
fn multiply(x: &[f64], val: f64) -> Vec<f64> {
x.iter().map(|v| v * val).collect()
}
fn main() {
// --- Randomization ---
let mut rng = Rng::from_string("demo-uniform");
println!("{}", rng.uniform()); // 0.2640554428629759
println!("{}", rng.uniform()); // 0.9348534835582796
let mut rng = Rng::from_string("demo-sample");
println!(
"{:?}",
rng.sample(&[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], 3)
); // [3, 8, 9]
let mut rng = Rng::from_string("demo-shuffle");
println!("{:?}", rng.shuffle(&[1.0, 2.0, 3.0, 4.0, 5.0])); // [4, 2, 3, 5, 1]
let mut rng = Rng::from_string("demo-resample");
println!("{:?}", rng.resample(&[1.0, 2.0, 3.0, 4.0, 5.0], 7)); // [5, 1, 1, 3, 3, 4, 5]
// --- Distribution Sampling ---
let mut rng = Rng::from_string("demo-dist-uniform");
let dist = Uniform::new(0.0, 10.0);
println!("{}", dist.sample(&mut rng)); // 6.54043657816832
let mut rng = Rng::from_string("demo-dist-additive");
let dist = Additive::new(0.0, 1.0);
println!("{}", dist.sample(&mut rng)); // 0.17410448679568188
let mut rng = Rng::from_string("demo-dist-exp");
let dist = Exp::new(1.0);
println!("{}", dist.sample(&mut rng)); // 0.6589065267276553
let mut rng = Rng::from_string("demo-dist-power");
let dist = Power::new(1.0, 2.0);
println!("{}", dist.sample(&mut rng)); // 1.023677535537084
let mut rng = Rng::from_string("demo-dist-multiplic");
let dist = Multiplic::new(0.0, 1.0);
println!("{}", dist.sample(&mut rng)); // 1.1273244602673853
// --- Single-Sample Statistics ---
let x = vec![1.0, 3.0, 5.0, 7.0, 9.0];
print(center(&x)); // 5
print(spread(&x)); // 4
print(spread(&add(&x, 10.0))); // 4
print(spread(&multiply(&x, 2.0))); // 8
print(rel_spread(&x)); // 0.8
// --- Two-Sample Comparison ---
let x = vec![0.0, 3.0, 6.0, 9.0, 12.0];
let y = vec![0.0, 2.0, 4.0, 6.0, 8.0];
print(shift(&x, &y)); // 2
print(shift(&y, &x)); // -2
print(avg_spread(&x, &y)); // 5
print(disparity(&x, &y)); // 0.4
print(disparity(&y, &x)); // -0.4
let x = vec![1.0, 2.0, 4.0, 8.0, 16.0];
let y = vec![2.0, 4.0, 8.0, 16.0, 32.0];
print(ratio(&x, &y)); // 0.5
print(ratio(&y, &x)); // 2
// --- One-Sample Bounds ---
let x: Vec<f64> = (1..=10).map(|i| i as f64).collect();
print(center(&x)); // 5.5
let bounds = center_bounds(&x, 0.05).unwrap(); // {lower: 3.5, upper: 7.5}
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper);
// --- Two-Sample Bounds ---
let x: Vec<f64> = (1..=30).map(|i| i as f64).collect();
let y: Vec<f64> = (21..=50).map(|i| i as f64).collect();
print(shift(&x, &y)); // -20
let bounds = shift_bounds(&x, &y, 1e-4).unwrap(); // {lower: -30, upper: -10}
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper);
let x = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let y = vec![2.0, 3.0, 4.0, 5.0, 6.0];
let bounds = ratio_bounds(&x, &y, 0.05).unwrap(); // {lower: 0.333..., upper: 1.5}
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper);
}
Go
Install from GitHub:
go get github.com/AndreyAkinshin/pragmastat/go/v4@v8.0.0
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v8.0.0/go
Demo:
package main
import (
"fmt"
"log"
pragmastat "github.com/AndreyAkinshin/pragmastat/go/v4"
)
func must[T any](val T, err error) T {
if err != nil {
log.Fatal(err)
}
return val
}
func print(val float64, err error) {
fmt.Println(must(val, err))
}
func add(x []float64, val float64) []float64 {
result := make([]float64, len(x))
for i, v := range x {
result[i] = v + val
}
return result
}
func multiply(x []float64, val float64) []float64 {
result := make([]float64, len(x))
for i, v := range x {
result[i] = v * val
}
return result
}
func main() {
// --- Randomization ---
rng := pragmastat.NewRngFromString("demo-uniform")
fmt.Println(rng.Uniform()) // 0.2640554428629759
fmt.Println(rng.Uniform()) // 0.9348534835582796
rng = pragmastat.NewRngFromString("demo-sample")
fmt.Println(pragmastat.Sample(rng, []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 3)) // [3 8 9]
rng = pragmastat.NewRngFromString("demo-shuffle")
fmt.Println(pragmastat.Shuffle(rng, []float64{1, 2, 3, 4, 5})) // [4 2 3 5 1]
rng = pragmastat.NewRngFromString("demo-resample")
fmt.Println(pragmastat.Resample(rng, []float64{1, 2, 3, 4, 5}, 7)) // [5 1 1 3 3 4 5]
// --- Distribution Sampling ---
rng = pragmastat.NewRngFromString("demo-dist-uniform")
dist := pragmastat.NewUniform(0, 10)
fmt.Println(dist.Sample(rng)) // 6.54043657816832
rng = pragmastat.NewRngFromString("demo-dist-additive")
addDist := pragmastat.NewAdditive(0, 1)
fmt.Println(addDist.Sample(rng)) // 0.17410448679568188
rng = pragmastat.NewRngFromString("demo-dist-exp")
expDist := pragmastat.NewExp(1)
fmt.Println(expDist.Sample(rng)) // 0.6589065267276553
rng = pragmastat.NewRngFromString("demo-dist-power")
powDist := pragmastat.NewPower(1, 2)
fmt.Println(powDist.Sample(rng)) // 1.023677535537084
rng = pragmastat.NewRngFromString("demo-dist-multiplic")
mulDist := pragmastat.NewMultiplic(0, 1)
fmt.Println(mulDist.Sample(rng)) // 1.1273244602673853
// --- Single-Sample Statistics ---
x := []float64{1, 3, 5, 7, 9}
print(pragmastat.Center(x)) // 5
print(pragmastat.Spread(x)) // 4
print(pragmastat.Spread(add(x, 10))) // 4
print(pragmastat.Spread(multiply(x, 2))) // 8
print(pragmastat.RelSpread(x)) // 0.8
// --- Two-Sample Comparison ---
x = []float64{0, 3, 6, 9, 12}
y := []float64{0, 2, 4, 6, 8}
print(pragmastat.Shift(x, y)) // 2
print(pragmastat.Shift(y, x)) // -2
print(pragmastat.AvgSpread(x, y)) // 5
print(pragmastat.Disparity(x, y)) // 0.4
print(pragmastat.Disparity(y, x)) // -0.4
x = []float64{1, 2, 4, 8, 16}
y = []float64{2, 4, 8, 16, 32}
print(pragmastat.Ratio(x, y)) // 0.5
print(pragmastat.Ratio(y, x)) // 2
// --- One-Sample Bounds ---
x = []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
print(pragmastat.Center(x)) // 5.5
fmt.Println(must(pragmastat.CenterBounds(x, 0.05))) // {Lower: 3.5, Upper: 7.5}
// --- Two-Sample Bounds ---
x = []float64{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}
y = []float64{
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}
print(pragmastat.Shift(x, y)) // -20
fmt.Println(must(pragmastat.ShiftBounds(x, y, 1e-4))) // {Lower: -30, Upper: -10}
x = []float64{1, 2, 3, 4, 5}
y = []float64{2, 3, 4, 5, 6}
fmt.Println(must(pragmastat.RatioBounds(x, y, 0.05))) // {Lower: 0.333..., Upper: 1.5}
}