riantr/moonbit_dowhy/utils does not have a README file

    GlmFamily

    pub enum GlmFamily {
    Gaussian
    Binomial
    Poisson
    }

    The response distribution of a generalised linear model.

    GlmFamily::binomial

    fn GlmFamily::binomial() -> GlmFamily

    The binomial family, with the logit link.

    GlmFamily::gaussian

    fn GlmFamily::gaussian() -> GlmFamily

    The normal family, with the identity link.

    GlmFamily::name

    fn GlmFamily::name(self : GlmFamily) -> String

    The name of a generalised linear model family.

    GlmFamily::poisson

    fn GlmFamily::poisson() -> GlmFamily

    The poisson family, with the log link.

    GlmFit

    pub struct GlmFit {
    beta : Array[Double]
    mu : Array[Double]
    eta : Array[Double]
    cov : Matrix
    se : Array[Double]
    iterations : Int
    converged : Bool
    family : GlmFamily
    }

    The result of a generalised linear model fit.

    GlmFit::empty

    fn GlmFit::empty() -> GlmFit

    A generalised linear model without any data.

    LogisticFit

    pub struct LogisticFit {
    beta : Array[Double]
    iterations : Int
    converged : Bool
    }

    Result of a logistic regression fit.

    Matrix

    pub struct Matrix {
    rows : Int
    cols : Int
    data : Array[Double]
    }

    Dense row-major matrix used by the estimation routines.

    This mirrors the small subset of numpy that the DoWhy estimators rely on: a design matrix is built from a data frame, a model is fitted against a response vector and the fitted coefficients / standard errors are read back.

    Matrix::col

    fn Matrix::col(self : Matrix, j : Int) -> Array[Double]

    Column j as an array.

    Matrix::copy

    fn Matrix::copy(self : Matrix) -> Matrix

    A copy of the matrix.

    Matrix::from_columns

    fn Matrix::from_columns(columns : Array[Array[Double]]) -> Matrix

    Build a matrix whose rows are the given vectors.

    Matrix::from_flat

    fn Matrix::from_flat(rows : Int, cols : Int, data : Array[Double]) -> Matrix

    Build a matrix from a flat array in row-major order.

    Matrix::from_rows

    fn Matrix::from_rows(rows : Array[Array[Double]]) -> Matrix

    Build a matrix from a list of rows.

    Matrix::get

    fn Matrix::get(self : Matrix, i : Int, j : Int) -> Double

    Element access.

    Matrix::identity

    fn Matrix::identity(n : Int) -> Matrix

    Build the identity matrix of size n.

    Matrix::matvec

    fn Matrix::matvec(self : Matrix, v : Array[Double]) -> Array[Double]

    Matrix-vector product self * v.

    Matrix::matvec_t

    fn Matrix::matvec_t(self : Matrix, v : Array[Double]) -> Array[Double]

    Transpose-vector product self^T * v.

    Matrix::mul

    fn Matrix::mul(self : Matrix, other : Matrix) -> Matrix

    Matrix product self * other.

    Matrix::mul_t

    fn Matrix::mul_t(self : Matrix, other : Matrix) -> Matrix

    self^T * other.

    Matrix::ncols

    fn Matrix::ncols(self : Matrix) -> Int

    Number of columns.

    Matrix::nrows

    fn Matrix::nrows(self : Matrix) -> Int

    Number of rows.

    Matrix::row

    fn Matrix::row(self : Matrix, i : Int) -> Array[Double]

    Row i as an array.

    Matrix::set

    fn Matrix::set(self : Matrix, i : Int, j : Int, v : Double) -> Unit

    Element assignment.

    Matrix::transpose

    fn Matrix::transpose(self : Matrix) -> Matrix

    Transpose of the matrix.

    Matrix::zeros

    fn Matrix::zeros(rows : Int, cols : Int) -> Matrix

    Build a zero filled matrix of the given shape.

    OlsFit

    pub struct OlsFit {
    beta : Array[Double]
    fitted : Array[Double]
    residuals : Array[Double]
    rss : Double
    n : Int
    rank : Int
    df_resid : Int
    sigma2 : Double
    cov : Matrix
    se : Array[Double]
    tstat : Array[Double]
    }

    Result of an ordinary least squares fit.

    OlsFit::empty

    fn OlsFit::empty() -> OlsFit

    An ordinary least squares fit without any data.

    Random

    pub struct Random {
    state : UInt64
    }

    A small deterministic pseudo random generator.

    The refuters need reproducible randomness, so the port carries its own generator instead of relying on the platform entropy of the toolchain. It is a 64 bit xorshift, which is enough for the resampling and the noise the refuters add.

    Random::new

    fn Random::new(seed : UInt64) -> Random

    A generator with the given seed.

    Random::next_double

    fn Random::next_double(self : Random) -> Double

    The next value in [0, 1).

    Random::next_int

    fn Random::next_int(self : Random, bound : Int) -> Int

    The next value in [0, bound).

    Random::next_normal

    fn Random::next_normal(self : Random) -> Double

    The next value from the standard normal distribution.

    Box-Muller transform; the second variate is discarded.

    Random::next_u64

    fn Random::next_u64(self : Random) -> UInt64

    The next raw 64 bit value.

    Random::sample_with_replacement

    fn Random::sample_with_replacement(self : Random, values : Array[Double], size : Int) -> Array[Double]

    A sample of size values drawn with replacement.

    Random::shuffle

    fn Random::shuffle(self : Random, values : Array[Double]) -> Array[Double]

    A random permutation of the given values.

    average_rank

    fn average_rank(values : Array[Double]) -> Array[Double]

    Average ranks of the values, matching pandas.Series.rank(ascending=True).

    Tied values receive the mean of the ranks they span.

    betainc

    fn betainc(a : Double, b : Double, x : Double) -> Double

    Regularised incomplete beta function I_x(a, b).

    chi2_cdf

    fn chi2_cdf(x : Double, df : Double) -> Double

    The cumulative distribution function of the chi-square distribution.

    chi2_ppf

    fn chi2_ppf(p : Double, df : Double) -> Double

    The quantile function of the chi-square distribution.

    The quantile p is the x for which the distribution function is p.

    chi2_sf

    fn chi2_sf(x : Double, df : Double) -> Double

    The survival function of the chi-square distribution.

    compare_double

    fn compare_double(a : Double, b : Double) -> Int

    Compare two doubles, returning a negative / zero / positive integer.

    cov

    fn cov(x : Array[Double], y : Array[Double]) -> Double

    Sample covariance (ddof=1, matching numpy.cov).

    erf

    fn erf(x : Double) -> Double

    Error function.

    erfc

    fn erfc(x : Double) -> Double

    Complementary error function.

    It is 1 - erf(x), the probability that a normal distributed variable with the mean zero and the variance one half is above x.

    The port computes it from the regularised upper incomplete gamma function with the shape one half, because erfc(x) = Q(1/2, x^2). The series and the continued fraction of that function are the ones of the gamma distribution, so the whole range of the arguments is covered with the precision of SciPy.

    exp

    fn exp(x : Double) -> Double

    The exponential of a number.

    f_cdf

    fn f_cdf(f : Double, df1 : Double, df2 : Double) -> Double

    The cumulative distribution function of the F distribution.

    f_ppf

    fn f_ppf(p : Double, df1 : Double, df2 : Double) -> Double

    The quantile function of the F distribution.

    f_sf

    fn f_sf(f : Double, df1 : Double, df2 : Double) -> Double

    The survival function of the F distribution.

    gammainc

    fn gammainc(a : Double, x : Double) -> Double

    The regularised lower incomplete gamma function.

    It is P(a, x), the probability that a gamma distributed variable with the shape a and the scale 1 is at most x.

    gammaincc

    fn gammaincc(a : Double, x : Double) -> Double

    The regularised upper incomplete gamma function.

    It is Q(a, x), the probability that a gamma distributed variable with the shape a and the scale 1 is more than x. It is the complement of gammainc, and it is computed without the subtraction of the two, so it keeps its precision where the complement of gammainc would lose it.

    glm_fit

    fn glm_fit(x : Matrix, y : Array[Double], family : GlmFamily, max_iter : Int, tol : Double) -> GlmFit

    Fit a generalised linear model.

    x is the design matrix, the intercept column included when one is wanted, and y the response vector.
    fn glm_link_derivative(family : GlmFamily, mu : Array[Double]) -> Array[Double]

    The derivative of the inverse link of a family, evaluated at the means of the response.

    The derivative is what the delta method needs to turn the covariance of the coefficients into the variance of an estimate that is a function of them.

    glm_predict

    fn glm_predict(fit : GlmFit, x : Matrix) -> Array[Double]

    The predicted means of a generalised linear model.

    is_nan

    fn is_nan(x : Double) -> Bool

    Whether the value is "not a number".

    jacobi_eigen

    fn jacobi_eigen(a : Matrix) -> (Array[Double], Matrix)

    Symmetric eigen decomposition by the cyclic Jacobi method.

    Returns the eigenvalues together with the eigenvectors stored as columns.

    kendall_tau

    fn kendall_tau(x : Array[Double], y : Array[Double]) -> Double

    The Kendall rank correlation of two samples.

    It is the tau-b variant, the one scipy.stats.kendalltau computes by default.
    fn ln(x : Double) -> Double

    The natural logarithm of a positive number.

    ln_gamma

    fn ln_gamma(x : Double) -> Double

    Natural logarithm of the gamma function (Lanczos approximation).

    logistic_fit

    fn logistic_fit(x : Matrix, y : Array[Double], c : Double, max_iter : Int, tol : Double) -> LogisticFit

    Fit a logistic regression with an L2 penalty.

    The objective minimised is sum_i log_loss(y_i, p_i) + 1/(2C) * ||w||², which is the convention used by sklearn.linear_model.LogisticRegression with the default penalty="l2" and C=1.0.

    logistic_predict

    fn logistic_predict(beta : Array[Double], x : Matrix) -> Array[Double]

    Predicted probabilities of a logistic model.

    lstsq

    fn lstsq(a : Matrix, b : Array[Double]) -> Array[Double]

    Least squares solution of A x ≈ b (minimum norm when rank deficient).

    mat_inverse

    fn mat_inverse(m : Matrix) -> Matrix?

    Invert a square matrix with Gauss-Jordan elimination and partial pivoting.

    Returns None when the matrix is singular.

    mat_pinv

    fn mat_pinv(a : Matrix) -> Matrix

    Moore-Penrose pseudo inverse of a matrix.

    The pseudo inverse is obtained from the eigen decomposition of AᵀA, so rank deficient designs give the minimum norm least squares solution, the same convention statsmodels uses for OLS.

    mean

    fn mean(values : Array[Double]) -> Double

    Arithmetic mean of an array.

    median

    fn median(values : Array[Double]) -> Double

    Median of an array.

    nan

    fn nan() -> Double

    The "not a number" value, like numpy.nan.

    The p-value merging of the gcm package drops the values that are not a number, so the value has to be reachable from there.

    normal_cdf

    fn normal_cdf(z : Double) -> Double

    Cumulative distribution function of the standard normal distribution.

    normal_ppf

    fn normal_ppf(p : Double) -> Double

    Inverse of the standard normal cumulative distribution function.

    ols_fit

    fn ols_fit(x : Matrix, y : Array[Double]) -> OlsFit

    Fit an ordinary least squares model.

    x is the design matrix (already including the intercept column when one is wanted) and y the response vector.

    pearson_corr

    fn pearson_corr(x : Array[Double], y : Array[Double]) -> Double

    The Pearson correlation of two samples.

    percentile

    fn percentile(values : Array[Double], q : Double) -> Double

    Linear-interpolation percentile of an array, matching numpy.percentile.

    q is expressed in the 0..100 range.

    round_half_even

    fn round_half_even(x : Double) -> Double

    Round half to even, matching numpy.round / pandas.Series.round(0).

    sigmoid

    fn sigmoid(x : Double) -> Double

    Logistic function.

    spearman_corr

    fn spearman_corr(x : Array[Double], y : Array[Double]) -> Double

    The Spearman rank correlation of two samples.

    It is the Pearson correlation of the ranks, and the ranks of a tie get the mean rank, exactly like pandas.Series.rank.

    std

    fn std(values : Array[Double]) -> Double

    Population standard deviation (ddof=0).

    std_sample

    fn std_sample(values : Array[Double]) -> Double

    Sample standard deviation (ddof=1).

    t_cdf

    fn t_cdf(t : Double, df : Double) -> Double

    Cumulative distribution function of Student's t distribution.

    t_ppf

    fn t_ppf(p : Double, df : Double) -> Double

    Quantile of the Student's t distribution.

    t_pvalue

    fn t_pvalue(t : Double, df : Double) -> Double

    Two sided p-value of a t statistic.

    var_pop

    fn var_pop(values : Array[Double]) -> Double

    Population variance (ddof=0).

    var_sample

    fn var_sample(values : Array[Double]) -> Double

    Sample variance (ddof=1).

    variance

    fn variance(values : Array[Double], ddof : Int) -> Double

    Sample variance with the given delta degrees of freedom.

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io