so-python 0.3.0

High-performance statistical computing library written in Rust, exposed to Python via PyO3
Documentation
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
"""
StatOxide Python bindings - Type stubs for IDE support

This file provides type hints and autocompletion for the StatOxide library.
StatOxide is a statistical computing library implemented in Rust with Python bindings.
"""

from typing import Any, Dict, List, Optional, Tuple, Union, overload
import numpy as np

# ============================================================================
# Core Data Structures
# ============================================================================

class Series:
    """One-dimensional array-like object with statistical methods."""
    
    def __init__(self, name: str, data: List[float]) -> None:
        """Create a new Series.
        
        Args:
            name: Name of the series
            data: List of floating-point values
        """
        ...
    
    @property
    def name(self) -> str:
        """Get the name of the series."""
        ...
    
    @property
    def len(self) -> int:
        """Get the length of the series."""
        ...
    
    def is_empty(self) -> bool:
        """Check if the series is empty."""
        ...
    
    def mean(self) -> Optional[float]:
        """Compute the mean of the series."""
        ...
    
    def std(self, ddof: float = 1.0) -> Optional[float]:
        """Compute the standard deviation.
        
        Args:
            ddof: Delta degrees of freedom (default: 1.0 for sample std)
        """
        ...
    
    def var(self, ddof: float = 1.0) -> Optional[float]:
        """Compute the variance.
        
        Args:
            ddof: Delta degrees of freedom (default: 1.0 for sample var)
        """
        ...
    
    def min(self) -> Optional[float]:
        """Get the minimum value."""
        ...
    
    def max(self) -> Optional[float]:
        """Get the maximum value."""
        ...
    
    def quantile(self, q: float) -> Optional[float]:
        """Compute the q-th quantile (0 <= q <= 1)."""
        ...
    
    def to_list(self) -> List[float]:
        """Convert series to Python list."""
        ...
    
    def __repr__(self) -> str:
        ...


class DataFrame:
    """Two-dimensional tabular data structure."""
    
    def __init__(self, data: Dict[str, List[float]]) -> None:
        """Create a new DataFrame from a dictionary of columns.
        
        Args:
            data: Dictionary mapping column names to lists of values
        """
        ...
    
    @property
    def n_rows(self) -> int:
        """Get the number of rows."""
        ...
    
    @property
    def n_cols(self) -> int:
        """Get the number of columns."""
        ...
    
    def columns(self) -> List[str]:
        """Get the list of column names."""
        ...
    
    def get_column(self, name: str) -> Series:
        """Get a column as a Series.
        
        Args:
            name: Column name
            
        Raises:
            ValueError: If column not found
        """
        ...
    
    def with_column(self, series: Series) -> 'DataFrame':
        """Add or replace a column.
        
        Args:
            series: Series to add
            
        Returns:
            New DataFrame with the added column
        """
        ...
    
    def __repr__(self) -> str:
        ...


class Formula:
    """R-style formula for statistical models."""
    
    def __init__(self, formula: str) -> None:
        """Create a formula from a string.
        
        Args:
            formula: R-style formula like 'y ~ x1 + x2'
        """
        ...
    
    def variables(self) -> List[str]:
        """Get the variable names in the formula."""
        ...
    
    def __repr__(self) -> str:
        ...


# ============================================================================
# GLM (Generalized Linear Models)
# ============================================================================

class Family:
    """GLM family (distribution)."""
    
    def __init__(self) -> None:
        ...
    
    @staticmethod
    def gaussian() -> 'Family':
        """Gaussian (normal) distribution."""
        ...
    
    @staticmethod
    def binomial() -> 'Family':
        """Binomial distribution."""
        ...
    
    @staticmethod
    def poisson() -> 'Family':
        """Poisson distribution."""
        ...
    
    @staticmethod
    def gamma() -> 'Family':
        """Gamma distribution."""
        ...
    
    @staticmethod
    def inverse_gaussian() -> 'Family':
        """Inverse Gaussian distribution."""
        ...
    
    def name(self) -> str:
        """Get the family name."""
        ...


class Link:
    """GLM link function."""
    
    def __init__(self) -> None:
        ...
    
    @staticmethod
    def identity() -> 'Link':
        """Identity link: η = μ."""
        ...
    
    @staticmethod
    def log() -> 'Link':
        """Log link: η = log(μ)."""
        ...
    
    @staticmethod
    def logit() -> 'Link':
        """Logit link: η = log(μ/(1-μ))."""
        ...
    
    @staticmethod
    def probit() -> 'Link':
        """Probit link: η = Φ⁻¹(μ)."""
        ...
    
    @staticmethod
    def inverse() -> 'Link':
        """Inverse link: η = 1/μ."""
        ...


class GLMBuilder:
    """Builder for GLM configuration."""
    
    def __init__(self) -> None:
        ...
    
    def family(self, family: Family) -> 'GLMBuilder':
        """Set the family (distribution)."""
        ...
    
    def link(self, link: Link) -> 'GLMBuilder':
        """Set the link function."""
        ...
    
    def intercept(self, intercept: bool) -> 'GLMBuilder':
        """Include intercept term."""
        ...
    
    def max_iter(self, max_iter: int) -> 'GLMBuilder':
        """Set maximum IRLS iterations."""
        ...
    
    def scale(self, scale: float) -> 'GLMBuilder':
        """Set dispersion parameter."""
        ...
    
    def tol(self, tol: float) -> 'GLMBuilder':
        """Set convergence tolerance."""
        ...
    
    def build(self) -> 'GLM':
        """Build the GLM instance."""
        ...


class GLM:
    """Generalized Linear Model."""
    
    def __init__(self) -> None:
        ...
    
    @staticmethod
    def new() -> 'GLMBuilder':
        """Create a new GLM builder."""
        ...
    
    def fit(self, formula: str, data: DataFrame) -> 'GLMResults':
        """Fit model using formula and data."""
        ...
    
    def fit_matrix(self, x: List[List[float]], y: List[float]) -> 'GLMResults':
        """Fit model using design matrix and response vector."""
        ...


class GLMResults:
    """Results from GLM fitting."""
    
    @property
    def coefficients(self) -> List[float]:
        """Estimated coefficients."""
        ...
    
    @property
    def std_errors(self) -> List[float]:
        """Standard errors of coefficients."""
        ...
    
    @property
    def z_values(self) -> List[float]:
        """Z-values for coefficient tests."""
        ...
    
    @property
    def p_values(self) -> List[float]:
        """P-values for coefficient tests."""
        ...
    
    @property
    def fitted_values(self) -> List[float]:
        """Fitted values."""
        ...
    
    @property
    def pearson_residuals(self) -> List[float]:
        """Pearson residuals."""
        ...
    
    @property
    def residuals(self) -> List[float]:
        """Raw residuals (response scale)."""
        ...
    
    @property
    def hat_matrix_diag(self) -> List[float]:
        """Diagonal of hat matrix (leverage values)."""
        ...
    
    @property
    def deviance(self) -> float:
        """Model deviance."""
        ...
    
    @property
    def null_deviance(self) -> float:
        """Null deviance."""
        ...
    
    @property
    def df_residual(self) -> int:
        """Residual degrees of freedom."""
        ...
    
    @property
    def df_null(self) -> int:
        """Null degrees of freedom."""
        ...
    
    @property
    def aic(self) -> float:
        """Akaike Information Criterion."""
        ...
    
    @property
    def bic(self) -> float:
        """Bayesian Information Criterion."""
        ...
    
    @property
    def scale(self) -> float:
        """Dispersion parameter."""
        ...
    
    @property
    def iterations(self) -> int:
        """Number of IRLS iterations."""
        ...
    
    @property
    def converged(self) -> bool:
        """Whether IRLS converged."""
        ...
    
    def predict(self, x: List[List[float]]) -> List[float]:
        """Predict response for new data."""
        ...
    
    def summary(self) -> str:
        """Get summary statistics as string."""
        ...


# ============================================================================
# Time Series Analysis
# ============================================================================

class TimeSeries:
    """Time series data structure."""
    
    def __init__(self) -> None:
        ...
    
    @staticmethod
    def from_vectors(values: List[float], timestamps: List[str]) -> 'TimeSeries':
        """Create from value and timestamp vectors."""
        ...
    
    @staticmethod
    def from_dataframe(df: DataFrame, value_col: str, timestamp_col: str) -> 'TimeSeries':
        """Create from DataFrame columns."""
        ...
    
    @property
    def len(self) -> int:
        """Length of time series."""
        ...
    
    @property
    def values(self) -> List[float]:
        """Time series values."""
        ...
    
    def is_empty(self) -> bool:
        """Check if empty."""
        ...
    
    def mean(self) -> Optional[float]:
        """Mean of values."""
        ...
    
    def std(self, _ddof: float = 1.0) -> Optional[float]:
        """Standard deviation."""
        ...
    
    def var(self, _ddof: float = 1.0) -> Optional[float]:
        """Variance."""
        ...
    
    def __repr__(self) -> str:
        ...


class ARIMA:
    """ARIMA (AutoRegressive Integrated Moving Average) model."""
    
    def __init__(self, p: int, d: int, q: int) -> None:
        """Create ARIMA(p, d, q) model.
        
        Args:
            p: AR order
            d: Integration order  
            q: MA order
        """
        ...
    
    def with_constant(self, include: bool) -> 'ARIMA':
        """Include constant term."""
        ...
    
    def seasonal(self, _p: int, _d: int, _q: int, _s: int) -> 'ARIMA':
        """Set seasonal orders."""
        ...
    
    def method(self, method: str) -> 'ARIMA':
        """Set estimation method."""
        ...
    
    def max_iter(self, max_iter: int) -> 'ARIMA':
        """Set maximum iterations."""
        ...
    
    def tol(self, tol: float) -> 'ARIMA':
        """Set convergence tolerance."""
        ...
    
    def fit(self, data: Union['TimeSeries', List[float], Any]) -> 'ARIMAResults':
        """Fit model to time series data.
        
        Args:
            data: TimeSeries object, list of floats, or convertible object
        """
        ...


class ARIMAResults:
    """Results from ARIMA fitting."""
    
    @property
    def ar_coef(self) -> List[float]:
        """AR coefficients."""
        ...
    
    @property
    def ma_coef(self) -> List[float]:
        """MA coefficients."""
        ...
    
    @property
    def constant(self) -> Optional[float]:
        """Constant term."""
        ...
    
    @property
    def sigma2(self) -> float:
        """Innovation variance."""
        ...
    
    @property
    def log_likelihood(self) -> float:
        """Log-likelihood."""
        ...
    
    @property
    def aic(self) -> float:
        """Akaike Information Criterion."""
        ...
    
    @property
    def bic(self) -> float:
        """Bayesian Information Criterion."""
        ...
    
    @property
    def n_obs(self) -> int:
        """Number of observations."""
        ...
    
    @property
    def fitted(self) -> List[float]:
        """Fitted values."""
        ...
    
    @property
    def residuals(self) -> List[float]:
        """Residuals."""
        ...
    
    def forecast(self, steps: int) -> List[float]:
        """Forecast future values.
        
        Args:
            steps: Number of steps to forecast
        """
        ...
    
    def summary(self) -> str:
        """Get summary statistics."""
        ...


class GARCH:
    """GARCH (Generalized Autoregressive Conditional Heteroskedasticity) model."""
    
    def __init__(self, p: int, q: int) -> None:
        """Create GARCH(p, q) model.
        
        Args:
            p: GARCH order (autoregressive conditional heteroskedasticity)
            q: ARCH order (autoregressive conditional heteroskedasticity)
        """
        ...
    
    def arch(self, q: int) -> 'GARCH':
        """Set ARCH order (alias for constructor parameter)."""
        ...
    
    def distribution(self, distribution: str) -> 'GARCH':
        """Set error distribution."""
        ...
    
    def fit(self, data: Union['TimeSeries', List[float], Any]) -> 'GARCHResults':
        """Fit model to residuals or time series.
        
        Args:
            data: TimeSeries object, list of floats, or convertible object
        """
        ...


class GARCHResults:
    """Results from GARCH fitting."""
    
    @property
    def mu(self) -> float:
        """Mean parameter."""
        ...
    
    @property
    def omega(self) -> float:
        """Constant in conditional variance equation."""
        ...
    
    @property
    def arch_coef(self) -> List[float]:
        """ARCH coefficients."""
        ...
    
    @property
    def garch_coef(self) -> List[float]:
        """GARCH coefficients."""
        ...
    
    @property
    def df(self) -> Optional[float]:
        """Degrees of freedom for t-distribution."""
        ...
    
    @property
    def conditional_variances(self) -> List[float]:
        """Conditional variances."""
        ...
    
    @property
    def residuals(self) -> List[float]:
        """Raw residuals."""
        ...
    
    @property
    def standardized_residuals(self) -> List[float]:
        """Standardized residuals."""
        ...
    
    @property
    def log_likelihood(self) -> float:
        """Log-likelihood."""
        ...
    
    @property
    def aic(self) -> float:
        """Akaike Information Criterion."""
        ...
    
    @property
    def bic(self) -> float:
        """Bayesian Information Criterion."""
        ...
    
    @property
    def n_obs(self) -> int:
        """Number of observations."""
        ...
    
    def summary(self) -> str:
        """Get summary statistics."""
        ...


# ============================================================================
# Top-level Functions
# ============================================================================

def mean(data: List[float]) -> float:
    """Compute mean of a list of numbers."""
    ...


def std_dev(data: List[float]) -> float:
    """Compute standard deviation of a list of numbers."""
    ...


def correlation(x: List[float], y: List[float]) -> float:
    """Compute Pearson correlation between two lists.
    
    Args:
        x: First variable
        y: Second variable
        
    Returns:
        Correlation coefficient between -1 and 1
    """
    ...


def descriptive_summary(data: List[float]) -> Dict[str, float]:
    """Compute comprehensive descriptive statistics.
    
    Returns:
        Dictionary with keys: mean, std, min, q25, median, q75, max
    """
    ...


def train_test_split(data: List[float], test_size: float = 0.3) -> Tuple[List[float], List[float]]:
    """Split data into train and test sets.
    
    Args:
        data: List of values to split
        test_size: Proportion of data for test set (default: 0.3)
        
    Returns:
        Tuple of (train, test) lists
    """
    ...


def version() -> str:
    """Get library version."""
    ...


# ============================================================================
# Submodules
# ============================================================================

class _StatsModule:
    """Statistical functions submodule."""
    
    def mean(self, data: List[float]) -> float: ...
    def std_dev(self, data: List[float]) -> float: ...
    def correlation(self, x: List[float], y: List[float]) -> float: ...
    def descriptive_summary(self, data: List[float]) -> Dict[str, float]: ...
    # Statistical tests
    def t_test_one_sample(self, data: List[float], mu: float, alternative: str = "two-sided") -> Dict[str, Any]: ...
    def t_test_two_sample(self, x: List[float], y: List[float], alternative: str = "two-sided") -> Dict[str, Any]: ...
    def t_test_paired(self, x: List[float], y: List[float], alternative: str = "two-sided") -> Dict[str, Any]: ...
    def chi_square_test_independence(self, observed: List[List[float]]) -> Dict[str, Any]: ...
    def anova_one_way(self, groups: List[List[float]]) -> Dict[str, Any]: ...
    def shapiro_wilk_test(self, data: List[float]) -> Dict[str, Any]: ...


class _ModelsModule:
    """Statistical models submodule."""
    
    Family = Family
    Link = Link
    GLMBuilder = GLMBuilder
    GLM = GLM
    GLMResults = GLMResults


class _TSAModule:
    """Time series analysis submodule."""
    
    TimeSeries = TimeSeries
    ARIMA = ARIMA
    ARIMAResults = ARIMAResults
    GARCH = GARCH
    GARCHResults = GARCHResults


class _UtilsModule:
    """Utility functions submodule."""
    
    def train_test_split(self, data: List[float], test_size: float = 0.3) -> Tuple[List[float], List[float]]: ...


# Module exports
stats: _StatsModule
models: _ModelsModule
tsa: _TSAModule
utils: _UtilsModule

__all__: List[str]