hea 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hea-0.2.0 → hea-0.2.1}/PKG-INFO +1 -1
- {hea-0.2.0 → hea-0.2.1}/hea/R/_linpack.py +145 -17
- {hea-0.2.0 → hea-0.2.1}/hea/R/formula_helpers.py +18 -21
- hea-0.2.1/hea/R/glm_fit.py +224 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/lbfgsb.py +16 -12
- {hea-0.2.0 → hea-0.2.1}/hea/R/linalg.py +111 -32
- {hea-0.2.0 → hea-0.2.1}/hea/R/matrix.py +14 -20
- {hea-0.2.0 → hea-0.2.1}/hea/R/nmath.py +11 -9
- {hea-0.2.0 → hea-0.2.1}/hea/R/stats_summary.py +19 -5
- {hea-0.2.0 → hea-0.2.1}/hea/R/uncmin.py +2 -1
- hea-0.2.1/hea/_bandchol.py +73 -0
- hea-0.2.1/hea/_crspl.py +150 -0
- hea-0.2.1/hea/_dispatch.py +71 -0
- hea-0.2.1/hea/_libm.py +23 -0
- hea-0.2.1/hea/_rfma.py +71 -0
- hea-0.2.1/hea/_rformat.py +142 -0
- hea-0.2.1/hea/_rlinalg.py +803 -0
- hea-0.2.1/hea/_rpow.py +160 -0
- hea-0.2.1/hea/_rquantile.py +31 -0
- hea-0.2.1/hea/_rsplines.py +201 -0
- hea-0.2.1/hea/_rsum.py +205 -0
- {hea-0.2.0 → hea-0.2.1}/hea/family.py +947 -1247
- {hea-0.2.0 → hea-0.2.1}/hea/formula.py +1465 -928
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/label_format.py +6 -1
- hea-0.2.1/hea/models/_fit3.py +1110 -0
- hea-0.2.1/hea/models/_fit4.py +601 -0
- hea-0.2.1/hea/models/_gdi.py +1508 -0
- hea-0.2.1/hea/models/_magic.py +645 -0
- hea-0.2.1/hea/models/_mgcv_c.py +503 -0
- hea-0.2.1/hea/models/_xwxd.py +957 -0
- {hea-0.2.0 → hea-0.2.1}/hea/models/bam.py +2659 -1397
- {hea-0.2.0 → hea-0.2.1}/hea/models/gam.py +2372 -1352
- {hea-0.2.0 → hea-0.2.1}/hea/models/glm.py +131 -268
- {hea-0.2.0 → hea-0.2.1}/hea/models/gmm.py +48 -21
- {hea-0.2.0 → hea-0.2.1}/hea/models/lm.py +2 -4
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/series.py +7 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/inline.py +9 -2
- {hea-0.2.0 → hea-0.2.1}/hea/translate/py_to_r.py +12 -1
- {hea-0.2.0 → hea-0.2.1}/hea/translate/r_to_py.py +29 -4
- {hea-0.2.0 → hea-0.2.1}/pyproject.toml +1 -1
- {hea-0.2.0 → hea-0.2.1}/rust/src/discrete.rs +3 -4
- hea-0.2.1/rust/src/family/tweedie.rs +526 -0
- hea-0.2.1/rust/src/gdi.rs +3499 -0
- hea-0.2.1/rust/src/lapack/auxiliary.rs +568 -0
- hea-0.2.1/rust/src/lapack/bdsqr.rs +980 -0
- hea-0.2.1/rust/src/lapack/blas.rs +474 -0
- hea-0.2.1/rust/src/lapack/chol.rs +547 -0
- hea-0.2.1/rust/src/lapack/gesdd.rs +3160 -0
- hea-0.2.1/rust/src/lapack/larrv.rs +1609 -0
- hea-0.2.1/rust/src/lapack/lasd.rs +1810 -0
- hea-0.2.1/rust/src/lapack/lasq.rs +1249 -0
- hea-0.2.1/rust/src/lapack/lu.rs +302 -0
- hea-0.2.1/rust/src/lapack/mm_table.rs +132 -0
- hea-0.2.1/rust/src/lapack/mod.rs +108 -0
- hea-0.2.1/rust/src/lapack/ormtr.rs +444 -0
- hea-0.2.1/rust/src/lapack/qr.rs +466 -0
- hea-0.2.1/rust/src/lapack/stedc.rs +1783 -0
- hea-0.2.1/rust/src/lapack/stemr.rs +1234 -0
- hea-0.2.1/rust/src/lapack/steqr.rs +669 -0
- hea-0.2.1/rust/src/lapack/syevr.rs +179 -0
- hea-0.2.1/rust/src/lapack/sytrd.rs +374 -0
- hea-0.2.1/rust/src/lapack_py.rs +598 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/lib.rs +21 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/linalg/qr.rs +101 -50
- hea-0.2.1/rust/src/magic.rs +1049 -0
- hea-0.2.1/rust/src/mgcv_c.rs +576 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/mod.rs +3 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/util.rs +61 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/optimize/lbfgsb.rs +47 -24
- {hea-0.2.0 → hea-0.2.1}/rust/src/optimize/linpack.rs +12 -72
- hea-0.2.1/rust/src/ralign.rs +72 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/blas.rs +107 -0
- hea-0.2.1/rust/src/tprs.rs +627 -0
- hea-0.2.1/rust/src/xwxd.rs +1449 -0
- hea-0.2.0/hea/_dispatch.py +0 -52
- hea-0.2.0/hea/_rfma.py +0 -42
- hea-0.2.0/rust/src/family/tweedie.rs +0 -471
- hea-0.2.0/rust/src/tprs.rs +0 -171
- {hea-0.2.0 → hea-0.2.1}/LICENSE +0 -0
- {hea-0.2.0 → hea-0.2.1}/README.md +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/_fexact.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/_shared.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/clustering.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/coerce.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/diagnostics.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/distance.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/distributions.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/emmeans.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/factor.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/functional.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/htest.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/lm_aov_extras.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/math.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/model_generics.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/model_selection.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/optimize.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/plotmath.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/predicates.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/rng.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/shape.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/tables.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/R/vector.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/_polars_compat.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/_rs.pyi +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/dtypes.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/_block.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/_measure.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/_util.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/aes.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/annotate.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/build.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/coords/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/coords/cartesian.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/coords/coord.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/coords/flip.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/coords/polar.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/coords/trans.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/core.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/expansion.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/facets/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/facets/facet.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/facets/grid.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/facets/null.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/facets/wrap.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/bar.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/bin2d.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/blank.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/boxplot.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/contour.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/density.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/density_ridges.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/dotplot.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/errorbar.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/geom.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/histogram.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/path.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/point.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/polygon.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/rect.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/refline.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/ribbon.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/segment.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/smooth.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/text.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/geoms/violin.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/guides.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/labels.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/layer.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/patchwork.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/dodge.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/identity.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/jitter.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/nudge.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/position.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/positions/stack.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/render.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/_breaks.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/_palettes.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/color_continuous.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/continuous.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/discrete.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/list.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/non_color.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/ordinal.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/percent.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/scale.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/temporal.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/scales/transformed.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/bin.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/bin2d.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/boxplot.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/count.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/density.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/density_ridges.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/ecdf.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/function.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/identity.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/qq.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/smooth.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/stat.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/sum.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/summary.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/unique.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/stats/ydensity.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/ggplot/theme.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/io.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/models/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/_util.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/annotate.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/barplot.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/boxplot.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/curve.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/density.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/diagnostic.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/dispatch.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/formula_eval.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/helpers.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/hist.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/par.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/scatter.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/plot/stubs.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/session_info.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/sparse/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/sparse/lsq.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/sparse/pattern.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/_shared.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/basics.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/binning.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/dataframe.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/dates.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/factors.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/groupby.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/joins.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/strings.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/summary.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/tidy/window.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/_datasets.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/_py_capture.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/gaps.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/nse.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/r_ast.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/r_lexer.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/r_parser.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/registry/__init__.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/registry/functions.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/registry/ggplot.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/registry/verbs.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/translate/runner.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/hea/utils.py +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/Cargo.lock +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/Cargo.toml +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/build.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/rebuild.sh +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/cluster/cutree.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/cluster/dist.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/cluster/hclust.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/cluster/kmeans.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/cluster/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/family/cox.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/family/gamlss.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/family/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/fexact.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/linalg/chol.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/linalg/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/linalg/pls.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/linalg/reml.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/loess.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/bd0_scale.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/coeffs.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/consts.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/contin.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/discrete.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/exp.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/gamma.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/hyper.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/lgamma.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/loader.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/noncentral.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/norm.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/psigamma.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/qbeta.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/tf.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/toms708.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/nmath/tukey.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/optimize/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/optimize/uncmin.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/par.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/rng/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/rng/mt.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/aat.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/amd.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/dense.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/balance.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/bucketsort.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/coarsen.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/compress.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/ctrl.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/fm.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/gklib.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/graph.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/initpart.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/mcutil.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/mmd.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/ometis.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/pqueue.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/refine.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/rng.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/separator.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/sfm.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/srefine.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/tests.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis/wspace.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/metis_order.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/mod.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/numeric.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/pattern.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/py.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/solve.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/spinv.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/super_numeric.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/super_solve.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/super_symbolic.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/symbolic.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/testcorpus.rs +0 -0
- {hea-0.2.0 → hea-0.2.1}/rust/src/sparse/ws.rs +0 -0
{hea-0.2.0 → hea-0.2.1}/PKG-INFO
RENAMED
|
@@ -17,21 +17,17 @@ darwin/arm64 — where it was probed empirically via ``ctypes`` against
|
|
|
17
17
|
|
|
18
18
|
* ``_ddot`` — Accelerate is plain sequential accumulation for n ≤ 3 and
|
|
19
19
|
the pair tree ``(s0+s2) + (s1+s3)`` at n = 4 (verified bit-exact over
|
|
20
|
-
adversarial mixed-magnitude probes, alignment-independent).
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
length-5..7 dots inside ``dtrsl`` on the ``2·col`` system and drifts
|
|
32
|
-
~1 ulp per such call. On reference-BLAS platforms (Linux CI) the
|
|
33
|
-
sequential order is exact at every length, so no such boundary
|
|
34
|
-
exists there.
|
|
20
|
+
adversarial mixed-magnitude probes, alignment-independent). From five
|
|
21
|
+
terms on its kernel rounds by its own reduction and by where its second
|
|
22
|
+
operand starts, so where the BLAS is Accelerate
|
|
23
|
+
(``hea._dispatch.ACCELERATE``) the call goes to Accelerate's ``ddot_``
|
|
24
|
+
itself when both operands are contiguous, as the columns of R's
|
|
25
|
+
column-major arrays are; a strided operand keeps the sequential loop,
|
|
26
|
+
as the extension's ``incx != 1`` path does. The callers lay their
|
|
27
|
+
arrays out as R does (column-major, the L-BFGS-B workspace in one block
|
|
28
|
+
carved at ``setulb``'s offsets) so that each operand starts where R's
|
|
29
|
+
does. On reference-BLAS platforms (Linux CI) the sequential order is
|
|
30
|
+
exact at every length.
|
|
35
31
|
* ``_daxpy`` — Accelerate fuses ``y + a*x`` per element (probed: fma
|
|
36
32
|
matches, plain does not); mirrored via ``_rfma`` (fused on arm64,
|
|
37
33
|
plain on x86-64, matching R-as-built per arch).
|
|
@@ -56,25 +52,67 @@ dimension submatrix calls).
|
|
|
56
52
|
|
|
57
53
|
from __future__ import annotations
|
|
58
54
|
|
|
55
|
+
import ctypes
|
|
59
56
|
import math
|
|
60
57
|
import platform
|
|
61
58
|
import sys
|
|
62
59
|
|
|
60
|
+
import numpy as np
|
|
61
|
+
|
|
62
|
+
from .._dispatch import ACCELERATE
|
|
63
63
|
from ._shared import _rfma
|
|
64
64
|
|
|
65
65
|
_ACCEL_PAIR4 = sys.platform == "darwin" and platform.machine() == "arm64"
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
def _accelerate_ddot():
|
|
69
|
+
"""Accelerate's Fortran ``ddot_``, the routine R's ``ddot`` reaches on
|
|
70
|
+
darwin, when the extension's BLAS is Accelerate; ``None`` otherwise."""
|
|
71
|
+
if not ACCELERATE:
|
|
72
|
+
return None
|
|
73
|
+
lib = ctypes.CDLL("/System/Library/Frameworks/Accelerate.framework/Accelerate")
|
|
74
|
+
fn = lib.ddot_
|
|
75
|
+
fn.restype = ctypes.c_double
|
|
76
|
+
pi = ctypes.POINTER(ctypes.c_int)
|
|
77
|
+
fn.argtypes = [pi, ctypes.c_void_p, pi, ctypes.c_void_p, pi]
|
|
78
|
+
return fn
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
_ACCEL_DDOT = _accelerate_ddot()
|
|
82
|
+
|
|
83
|
+
|
|
68
84
|
def _ddot(n, dx, dy, ox=0, oy=0):
|
|
69
85
|
"""R-linked ``ddot`` over ``n`` entries of ``dx[ox:]``/``dy[oy:]``:
|
|
70
|
-
sequential
|
|
71
|
-
|
|
86
|
+
sequential, except Accelerate's pair tree at n = 4 on darwin/arm64 and,
|
|
87
|
+
where the BLAS is Accelerate, Accelerate's own call from five contiguous
|
|
88
|
+
terms on (see module docstring)."""
|
|
72
89
|
if n == 4 and _ACCEL_PAIR4:
|
|
73
90
|
s0 = float(dx[ox]) * float(dy[oy])
|
|
74
91
|
s1 = float(dx[ox + 1]) * float(dy[oy + 1])
|
|
75
92
|
s2 = float(dx[ox + 2]) * float(dy[oy + 2])
|
|
76
93
|
s3 = float(dx[ox + 3]) * float(dy[oy + 3])
|
|
77
94
|
return (s0 + s2) + (s1 + s3)
|
|
95
|
+
if n >= 5 and _ACCEL_DDOT is not None:
|
|
96
|
+
x = dx[ox : ox + n]
|
|
97
|
+
y = dy[oy : oy + n]
|
|
98
|
+
if (
|
|
99
|
+
isinstance(x, np.ndarray)
|
|
100
|
+
and isinstance(y, np.ndarray)
|
|
101
|
+
and x.dtype == np.float64
|
|
102
|
+
and y.dtype == np.float64
|
|
103
|
+
and x.strides == (8,)
|
|
104
|
+
and y.strides == (8,)
|
|
105
|
+
):
|
|
106
|
+
nn, one = ctypes.c_int(n), ctypes.c_int(1)
|
|
107
|
+
return float(
|
|
108
|
+
_ACCEL_DDOT(
|
|
109
|
+
ctypes.byref(nn),
|
|
110
|
+
x.ctypes.data,
|
|
111
|
+
ctypes.byref(one),
|
|
112
|
+
y.ctypes.data,
|
|
113
|
+
ctypes.byref(one),
|
|
114
|
+
)
|
|
115
|
+
)
|
|
78
116
|
dtemp = 0.0
|
|
79
117
|
for i in range(n):
|
|
80
118
|
dtemp += float(dx[ox + i]) * float(dy[oy + i])
|
|
@@ -173,3 +211,93 @@ def _dpofa(a, n):
|
|
|
173
211
|
return j
|
|
174
212
|
a[j - 1, j - 1] = math.sqrt(s)
|
|
175
213
|
return 0
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _dasum(n, dx, ox=0):
|
|
217
|
+
"""``dasum``: the sum of ``|dx[ox:ox+n]|`` accumulated left to right,
|
|
218
|
+
which is the reference BLAS order (its unrolled loop adds in sequence).
|
|
219
|
+
Accelerate's reduction order for this kernel has not been probed, so on
|
|
220
|
+
darwin/arm64 the result can differ from R's in the last bit."""
|
|
221
|
+
s = 0.0
|
|
222
|
+
for i in range(n):
|
|
223
|
+
s += abs(float(dx[ox + i]))
|
|
224
|
+
return s
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _dtrco(t, n, job):
|
|
228
|
+
"""LINPACK ``dtrco`` (src/appl/dtrco.f): an estimate of the reciprocal
|
|
229
|
+
1-norm condition number of the triangular ``t`` (``job = 0`` lower,
|
|
230
|
+
otherwise upper), returned as ``rcond``. It solves ``t'y = e`` with the
|
|
231
|
+
signs of ``e`` chosen for local growth, then ``t z = y``, rescaling to
|
|
232
|
+
avoid overflow, and reports ``‖z‖₁ / (‖t‖₁ ‖y‖₁)``. The products folded
|
|
233
|
+
into a sum are fused through ``_rfma``, as gfortran contracts them."""
|
|
234
|
+
lower = job == 0
|
|
235
|
+
tnorm = 0.0
|
|
236
|
+
for j in range(1, n + 1):
|
|
237
|
+
ln = n + 1 - j if lower else j
|
|
238
|
+
i1 = j if lower else 1
|
|
239
|
+
tnorm = max(tnorm, _dasum(ln, t[:, j - 1], ox=i1 - 1))
|
|
240
|
+
|
|
241
|
+
# solve trans(t)*y = e
|
|
242
|
+
ek = 1.0
|
|
243
|
+
z = [0.0] * n
|
|
244
|
+
for kk in range(1, n + 1):
|
|
245
|
+
k = n + 1 - kk if lower else kk
|
|
246
|
+
km = k - 1
|
|
247
|
+
tkk = float(t[km, km])
|
|
248
|
+
if z[km] != 0.0:
|
|
249
|
+
ek = math.copysign(ek, -z[km])
|
|
250
|
+
if abs(ek - z[km]) > abs(tkk):
|
|
251
|
+
s = abs(tkk) / abs(ek - z[km])
|
|
252
|
+
_dscal(n, s, z)
|
|
253
|
+
ek = s * ek
|
|
254
|
+
wk = ek - z[km]
|
|
255
|
+
wkm = -ek - z[km]
|
|
256
|
+
s = abs(wk)
|
|
257
|
+
sm = abs(wkm)
|
|
258
|
+
if tkk != 0.0:
|
|
259
|
+
wk = wk / tkk
|
|
260
|
+
wkm = wkm / tkk
|
|
261
|
+
else:
|
|
262
|
+
wk = 1.0
|
|
263
|
+
wkm = 1.0
|
|
264
|
+
if kk != n:
|
|
265
|
+
j1 = 1 if lower else k + 1
|
|
266
|
+
j2 = k - 1 if lower else n
|
|
267
|
+
for j in range(j1, j2 + 1):
|
|
268
|
+
tkj = float(t[km, j - 1])
|
|
269
|
+
sm = sm + abs(_rfma(wkm, tkj, z[j - 1]))
|
|
270
|
+
z[j - 1] = _rfma(wk, tkj, z[j - 1])
|
|
271
|
+
s = s + abs(z[j - 1])
|
|
272
|
+
if s < sm:
|
|
273
|
+
w = wkm - wk
|
|
274
|
+
wk = wkm
|
|
275
|
+
for j in range(j1, j2 + 1):
|
|
276
|
+
z[j - 1] = _rfma(w, float(t[km, j - 1]), z[j - 1])
|
|
277
|
+
z[km] = wk
|
|
278
|
+
s = 1.0 / _dasum(n, z)
|
|
279
|
+
_dscal(n, s, z)
|
|
280
|
+
|
|
281
|
+
ynorm = 1.0
|
|
282
|
+
# solve t*z = y
|
|
283
|
+
for kk in range(1, n + 1):
|
|
284
|
+
k = kk if lower else n + 1 - kk
|
|
285
|
+
km = k - 1
|
|
286
|
+
tkk = float(t[km, km])
|
|
287
|
+
if abs(z[km]) > abs(tkk):
|
|
288
|
+
s = abs(tkk) / abs(z[km])
|
|
289
|
+
_dscal(n, s, z)
|
|
290
|
+
ynorm = s * ynorm
|
|
291
|
+
if tkk != 0.0:
|
|
292
|
+
z[km] = z[km] / tkk
|
|
293
|
+
if tkk == 0.0:
|
|
294
|
+
z[km] = 1.0
|
|
295
|
+
i1 = k + 1 if lower else 1
|
|
296
|
+
if kk < n:
|
|
297
|
+
w = -z[km]
|
|
298
|
+
_daxpy(n - kk, w, t[:, km], z, ox=i1 - 1, oy=i1 - 1)
|
|
299
|
+
s = 1.0 / _dasum(n, z)
|
|
300
|
+
_dscal(n, s, z)
|
|
301
|
+
ynorm = s * ynorm
|
|
302
|
+
|
|
303
|
+
return ynorm / tnorm if tnorm != 0.0 else 0.0
|
|
@@ -36,6 +36,8 @@ from dataclasses import dataclass
|
|
|
36
36
|
import numpy as np
|
|
37
37
|
import polars as pl
|
|
38
38
|
|
|
39
|
+
from .._rpow import _rpow
|
|
40
|
+
from .._rsum import r_colsums, r_mean
|
|
39
41
|
from ..formula import (
|
|
40
42
|
BinOp,
|
|
41
43
|
Call,
|
|
@@ -51,7 +53,7 @@ from ..formula import (
|
|
|
51
53
|
expand,
|
|
52
54
|
parse,
|
|
53
55
|
)
|
|
54
|
-
from .linalg import dqrdc2, dqrsl
|
|
56
|
+
from .linalg import dqrdc2, dqrsl, r_vector_like
|
|
55
57
|
|
|
56
58
|
__all__ = [
|
|
57
59
|
"DF2formula",
|
|
@@ -496,12 +498,8 @@ class Poly(np.ndarray):
|
|
|
496
498
|
|
|
497
499
|
|
|
498
500
|
def _r_mean(x: np.ndarray) -> float:
|
|
499
|
-
"""R's ``mean.default``
|
|
500
|
-
|
|
501
|
-
n = xl.size
|
|
502
|
-
tmp = xl.sum() / n
|
|
503
|
-
tmp = tmp + (xl - tmp).sum() / n
|
|
504
|
-
return float(tmp)
|
|
501
|
+
"""R's ``mean.default`` on a double vector (``real_mean``)."""
|
|
502
|
+
return r_mean(x)
|
|
505
503
|
|
|
506
504
|
|
|
507
505
|
def _poly_fit(x: np.ndarray, degree: int):
|
|
@@ -519,24 +517,23 @@ def _poly_fit(x: np.ndarray, degree: int):
|
|
|
519
517
|
xc = x - xbar
|
|
520
518
|
n = x.size
|
|
521
519
|
p = degree + 1
|
|
522
|
-
X = np.column_stack(
|
|
520
|
+
X = np.column_stack(
|
|
521
|
+
[_rpow(xc, float(d)) for d in range(p)]
|
|
522
|
+
) # outer(x, 0:degree, `^`)
|
|
523
523
|
qr, qraux, _jpvt, rank = dqrdc2(X, 1e-7)
|
|
524
524
|
if rank < degree:
|
|
525
525
|
raise ValueError("'degree' must be less than number of unique points")
|
|
526
|
-
|
|
527
|
-
|
|
526
|
+
# qr.qy(QR, z), z <- QR$qr*(row==col): dqrqy applies dqrsl to each column
|
|
527
|
+
# of its own copy of z, so every column lies where R's n x p copy has it
|
|
528
|
+
Z = r_vector_like((n, p))
|
|
529
|
+
for j in range(p):
|
|
528
530
|
col = np.zeros(n)
|
|
529
531
|
col[j] = qr[j, j]
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
(xc.astype(np.longdouble)[:, None] * Zl**2).sum(axis=0) / norm2
|
|
536
|
-
+ np.longdouble(xbar),
|
|
537
|
-
dtype=float,
|
|
538
|
-
)[:degree]
|
|
539
|
-
norm2 = np.concatenate([[1.0], np.asarray(norm2, dtype=float)])
|
|
532
|
+
dqrsl(qr, n, rank, qraux, col, 10000, qy=Z[:, j])
|
|
533
|
+
Z2 = Z * Z
|
|
534
|
+
norm2 = r_colsums(Z2) # colSums(Z^2)
|
|
535
|
+
alpha = (r_colsums(xc[:, None] * Z2) / norm2 + xbar)[:degree]
|
|
536
|
+
norm2 = np.concatenate([[1.0], norm2])
|
|
540
537
|
Zn = Z / np.sqrt(norm2[1:])
|
|
541
538
|
return Zn[:, 1:], alpha, norm2
|
|
542
539
|
|
|
@@ -588,7 +585,7 @@ def poly(x, *args, degree=1, coefs=None, raw=False, simple=False):
|
|
|
588
585
|
raise ValueError("'degree' must be at least 1")
|
|
589
586
|
x = x.astype(float)
|
|
590
587
|
if raw:
|
|
591
|
-
Z = np.column_stack([x
|
|
588
|
+
Z = np.column_stack([_rpow(x, float(d)) for d in range(1, degree + 1)])
|
|
592
589
|
names = [str(d) for d in range(1, degree + 1)]
|
|
593
590
|
if simple:
|
|
594
591
|
return Z
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""R's ``glm.fit`` (stats glm.R): iteratively reweighted least squares, each
|
|
2
|
+
step a LINPACK least squares fit (``Cdqrls``) of the working response on
|
|
3
|
+
the weighted model matrix."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import warnings
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
from .._rlinalg import r_matprod
|
|
12
|
+
from .._rsum import r_sum
|
|
13
|
+
from .linalg import Cdqrls
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def glm_fit(
|
|
17
|
+
x: np.ndarray,
|
|
18
|
+
y: np.ndarray,
|
|
19
|
+
*,
|
|
20
|
+
family,
|
|
21
|
+
weights: np.ndarray | None = None,
|
|
22
|
+
offset: np.ndarray | None = None,
|
|
23
|
+
start: np.ndarray | None = None,
|
|
24
|
+
etastart: np.ndarray | None = None,
|
|
25
|
+
mustart: np.ndarray | None = None,
|
|
26
|
+
epsilon: float = 1e-8,
|
|
27
|
+
maxit: int = 25,
|
|
28
|
+
intercept: bool = True,
|
|
29
|
+
binom_n: np.ndarray | None = None,
|
|
30
|
+
) -> dict:
|
|
31
|
+
"""``glm.fit(x, y, weights, start, etastart, mustart, offset, family,
|
|
32
|
+
control = glm.control(epsilon, maxit), intercept)`` for a model matrix
|
|
33
|
+
with at least one column. The starting linear predictor is
|
|
34
|
+
``etastart``, else ``offset + x %*% start`` (``start`` also being the
|
|
35
|
+
first step's fallback), else the link of ``mustart``, else of the
|
|
36
|
+
family's ``initialize``; then
|
|
37
|
+
IRLS steps until ``|dev - devold| / (0.1 + |dev|) < epsilon``, halving a
|
|
38
|
+
step towards the previous coefficients while the deviance is not finite
|
|
39
|
+
or the linear predictor or means are invalid. ``binom_n`` is binomial's
|
|
40
|
+
trials vector (R's ``n`` from ``initialize`` for a two-column
|
|
41
|
+
response), which its ``initialize`` and ``aic`` take.
|
|
42
|
+
|
|
43
|
+
Returns R's list: ``coefficients`` (NA for the aliased ones),
|
|
44
|
+
``residuals`` (working), ``fitted``, ``effects``, ``R``, ``rank``, ``qr``
|
|
45
|
+
(``Cdqrls``'s ``qr``, ``rank``, ``qraux``, ``pivot``, ``tol``),
|
|
46
|
+
``linear_predictors``, ``deviance``, ``aic``, ``null_deviance``,
|
|
47
|
+
``iter``, ``weights`` (working), ``prior_weights``, ``df_residual``,
|
|
48
|
+
``df_null``, ``converged`` and ``boundary``, with R's warnings."""
|
|
49
|
+
x = np.asarray(x, dtype=float)
|
|
50
|
+
y = np.asarray(y, dtype=float)
|
|
51
|
+
nobs = y.size
|
|
52
|
+
nvars = x.shape[1]
|
|
53
|
+
weights = np.ones(nobs) if weights is None else np.asarray(weights, dtype=float)
|
|
54
|
+
offset = np.zeros(nobs) if offset is None else np.asarray(offset, dtype=float)
|
|
55
|
+
link = family.link
|
|
56
|
+
init_kw = {} if binom_n is None else {"n": binom_n}
|
|
57
|
+
mu_init = family.initialize(y, weights, **init_kw)
|
|
58
|
+
if mustart is not None:
|
|
59
|
+
mu_init = np.asarray(mustart, dtype=float)
|
|
60
|
+
coefold = None
|
|
61
|
+
if etastart is not None:
|
|
62
|
+
eta = np.asarray(etastart, dtype=float)
|
|
63
|
+
elif start is not None:
|
|
64
|
+
start = np.asarray(start, dtype=float)
|
|
65
|
+
if start.size != nvars:
|
|
66
|
+
raise ValueError(
|
|
67
|
+
f"length of 'start' should equal {nvars} and correspond to "
|
|
68
|
+
"initial coefs"
|
|
69
|
+
)
|
|
70
|
+
coefold = start
|
|
71
|
+
xs = (
|
|
72
|
+
x[:, 0] * start[0]
|
|
73
|
+
if nvars == 1
|
|
74
|
+
else r_matprod(x, start.reshape(-1, 1))[:, 0]
|
|
75
|
+
)
|
|
76
|
+
eta = offset + xs
|
|
77
|
+
else:
|
|
78
|
+
eta = link.link(mu_init)
|
|
79
|
+
mu = link.linkinv(eta)
|
|
80
|
+
if not (family.validmu(mu) and link.valideta(eta)):
|
|
81
|
+
raise ValueError("cannot find valid starting values: please specify some")
|
|
82
|
+
devold = r_sum(family.dev_resids(y, mu, weights))
|
|
83
|
+
boundary = conv = False
|
|
84
|
+
start = np.zeros(nvars)
|
|
85
|
+
coef = None
|
|
86
|
+
fit = None
|
|
87
|
+
good = weights > 0
|
|
88
|
+
w = np.zeros(0)
|
|
89
|
+
dev = devold
|
|
90
|
+
it = 0
|
|
91
|
+
for it in range(1, maxit + 1):
|
|
92
|
+
good = weights > 0
|
|
93
|
+
varmu = family.variance(mu)[good]
|
|
94
|
+
if np.any(np.isnan(varmu)):
|
|
95
|
+
raise ValueError("NAs in V(mu)")
|
|
96
|
+
if np.any(varmu == 0):
|
|
97
|
+
raise ValueError("0s in V(mu)")
|
|
98
|
+
mu_eta_val = link.mu_eta(eta)
|
|
99
|
+
if np.any(np.isnan(mu_eta_val[good])):
|
|
100
|
+
raise ValueError("NAs in d(mu)/d(eta)")
|
|
101
|
+
good = (weights > 0) & (mu_eta_val != 0)
|
|
102
|
+
if not np.any(good):
|
|
103
|
+
conv = False
|
|
104
|
+
warnings.warn(
|
|
105
|
+
f"no observations informative at iteration {it}", stacklevel=2
|
|
106
|
+
)
|
|
107
|
+
break
|
|
108
|
+
z = (eta - offset)[good] + (y - mu)[good] / mu_eta_val[good]
|
|
109
|
+
w = np.sqrt((weights[good] * mu_eta_val[good] ** 2) / family.variance(mu)[good])
|
|
110
|
+
fit = Cdqrls(x[good] * w[:, None], z * w, min(1e-7, epsilon / 1000))
|
|
111
|
+
if not np.all(np.isfinite(fit["coefficients"])):
|
|
112
|
+
conv = False
|
|
113
|
+
warnings.warn(f"non-finite coefficients at iteration {it}", stacklevel=2)
|
|
114
|
+
break
|
|
115
|
+
if nobs < fit["rank"]:
|
|
116
|
+
raise ValueError(
|
|
117
|
+
f"X matrix has rank {fit['rank']}, but only {nobs} observations"
|
|
118
|
+
)
|
|
119
|
+
start = start.copy()
|
|
120
|
+
start[np.asarray(fit["pivot"]) - 1] = fit["coefficients"]
|
|
121
|
+
eta = r_matprod(x, start.reshape(-1, 1))[:, 0] + offset
|
|
122
|
+
mu = link.linkinv(eta)
|
|
123
|
+
dev = r_sum(family.dev_resids(y, mu, weights))
|
|
124
|
+
boundary = False
|
|
125
|
+
if not np.isfinite(dev):
|
|
126
|
+
if coefold is None:
|
|
127
|
+
raise ValueError(
|
|
128
|
+
"no valid set of coefficients has been found: please supply "
|
|
129
|
+
"starting values"
|
|
130
|
+
)
|
|
131
|
+
warnings.warn("step size truncated due to divergence", stacklevel=2)
|
|
132
|
+
ii = 1
|
|
133
|
+
while not np.isfinite(dev):
|
|
134
|
+
if ii > maxit:
|
|
135
|
+
raise ValueError("inner loop 1; cannot correct step size")
|
|
136
|
+
ii += 1
|
|
137
|
+
start = (start + coefold) / 2
|
|
138
|
+
eta = r_matprod(x, start.reshape(-1, 1))[:, 0] + offset
|
|
139
|
+
mu = link.linkinv(eta)
|
|
140
|
+
dev = r_sum(family.dev_resids(y, mu, weights))
|
|
141
|
+
boundary = True
|
|
142
|
+
if not (link.valideta(eta) and family.validmu(mu)):
|
|
143
|
+
if coefold is None:
|
|
144
|
+
raise ValueError(
|
|
145
|
+
"no valid set of coefficients has been found: please supply "
|
|
146
|
+
"starting values"
|
|
147
|
+
)
|
|
148
|
+
warnings.warn("step size truncated: out of bounds", stacklevel=2)
|
|
149
|
+
ii = 1
|
|
150
|
+
while not (link.valideta(eta) and family.validmu(mu)):
|
|
151
|
+
if ii > maxit:
|
|
152
|
+
raise ValueError("inner loop 2; cannot correct step size")
|
|
153
|
+
ii += 1
|
|
154
|
+
start = (start + coefold) / 2
|
|
155
|
+
eta = r_matprod(x, start.reshape(-1, 1))[:, 0] + offset
|
|
156
|
+
mu = link.linkinv(eta)
|
|
157
|
+
boundary = True
|
|
158
|
+
dev = r_sum(family.dev_resids(y, mu, weights))
|
|
159
|
+
if abs(dev - devold) / (0.1 + abs(dev)) < epsilon:
|
|
160
|
+
conv = True
|
|
161
|
+
coef = start
|
|
162
|
+
break
|
|
163
|
+
devold = dev
|
|
164
|
+
coef = coefold = start
|
|
165
|
+
if not conv:
|
|
166
|
+
warnings.warn("glm.fit: algorithm did not converge", stacklevel=2)
|
|
167
|
+
if boundary:
|
|
168
|
+
warnings.warn("glm.fit: algorithm stopped at boundary value", stacklevel=2)
|
|
169
|
+
eps = 10 * float(np.finfo(float).eps)
|
|
170
|
+
if family.name == "binomial" and (np.any(mu > 1 - eps) or np.any(mu < eps)):
|
|
171
|
+
warnings.warn(
|
|
172
|
+
"glm.fit: fitted probabilities numerically 0 or 1 occurred", stacklevel=2
|
|
173
|
+
)
|
|
174
|
+
if family.name == "poisson" and np.any(mu < eps):
|
|
175
|
+
warnings.warn("glm.fit: fitted rates numerically 0 occurred", stacklevel=2)
|
|
176
|
+
if fit is None:
|
|
177
|
+
raise ValueError("glm.fit: no informative observations")
|
|
178
|
+
rank = int(fit["rank"])
|
|
179
|
+
pivot = np.asarray(fit["pivot"], dtype=np.int64)
|
|
180
|
+
coef = np.array(coef, dtype=float)
|
|
181
|
+
if rank < nvars:
|
|
182
|
+
coef[pivot[rank:] - 1] = np.nan
|
|
183
|
+
residuals = (y - mu) / link.mu_eta(eta)
|
|
184
|
+
qr = np.asarray(fit["qr"], dtype=float)
|
|
185
|
+
nr = min(int(np.sum(good)), nvars)
|
|
186
|
+
if nr < nvars:
|
|
187
|
+
Rmat = np.eye(nvars)
|
|
188
|
+
Rmat[:nr, :nvars] = qr[:nr, :nvars]
|
|
189
|
+
else:
|
|
190
|
+
Rmat = qr[:nvars, :nvars].copy()
|
|
191
|
+
Rmat = np.triu(Rmat)
|
|
192
|
+
wt = np.zeros(nobs)
|
|
193
|
+
wt[good] = w**2
|
|
194
|
+
wtdmu = r_sum(weights * y) / r_sum(weights) if intercept else link.linkinv(offset)
|
|
195
|
+
nulldev = r_sum(family.dev_resids(y, np.broadcast_to(wtdmu, y.shape), weights))
|
|
196
|
+
n_ok = nobs - int(np.sum(weights == 0))
|
|
197
|
+
aic_n = nobs if binom_n is None else binom_n
|
|
198
|
+
aic_model = family.aic(y, mu, dev, weights, aic_n) + 2 * rank
|
|
199
|
+
return {
|
|
200
|
+
"coefficients": coef,
|
|
201
|
+
"residuals": residuals,
|
|
202
|
+
"fitted": mu,
|
|
203
|
+
"effects": np.asarray(fit["effects"], dtype=float),
|
|
204
|
+
"R": Rmat,
|
|
205
|
+
"rank": rank,
|
|
206
|
+
"qr": {
|
|
207
|
+
"qr": qr,
|
|
208
|
+
"rank": rank,
|
|
209
|
+
"qraux": np.asarray(fit["qraux"], dtype=float),
|
|
210
|
+
"pivot": pivot,
|
|
211
|
+
"tol": min(1e-7, epsilon / 1000),
|
|
212
|
+
},
|
|
213
|
+
"linear_predictors": eta,
|
|
214
|
+
"deviance": float(dev),
|
|
215
|
+
"aic": float(aic_model),
|
|
216
|
+
"null_deviance": float(nulldev),
|
|
217
|
+
"iter": it,
|
|
218
|
+
"weights": wt,
|
|
219
|
+
"prior_weights": weights,
|
|
220
|
+
"df_residual": n_ok - rank,
|
|
221
|
+
"df_null": n_ok - int(intercept),
|
|
222
|
+
"converged": conv,
|
|
223
|
+
"boundary": boundary,
|
|
224
|
+
}
|
|
@@ -1522,18 +1522,22 @@ def setulb(n, m, x, lo, u, nbd, f, g, factr, pgtol, task, iprint, state):
|
|
|
1522
1522
|
returns ``(f, task)``."""
|
|
1523
1523
|
if task.startswith("START"):
|
|
1524
1524
|
state.clear()
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1525
|
+
# R's lbfgsb() hands setulb one S_alloc block, which starts on a
|
|
1526
|
+
# 16-byte boundary, and setulb carves the parts out of it at lws = 1,
|
|
1527
|
+
# lwy = lws + m n, ... (lbfgsb.c:335-346), each column-major;
|
|
1528
|
+
# Accelerate's ddot rounds by where its second operand starts
|
|
1529
|
+
parts = (
|
|
1530
|
+
("ws", (n, m)), ("wy", (n, m)), ("sy", (m, m)), ("ss", (m, m)),
|
|
1531
|
+
("wt", (m, m)), ("wn", (2 * m, 2 * m)), ("snd", (2 * m, 2 * m)),
|
|
1532
|
+
("z", (n,)), ("r", (n,)), ("d", (n,)), ("t", (n,)), ("wa", (8 * m,)),
|
|
1533
|
+
) # fmt: skip
|
|
1534
|
+
total = sum(math.prod(shape) for _, shape in parts)
|
|
1535
|
+
raw = np.zeros(total + 2)
|
|
1536
|
+
at = (16 - raw.ctypes.data % 16) % 16 // 8
|
|
1537
|
+
for name, shape in parts:
|
|
1538
|
+
size = math.prod(shape)
|
|
1539
|
+
state[name] = raw[at : at + size].reshape(shape, order="F")
|
|
1540
|
+
at += size
|
|
1537
1541
|
state["indx"] = np.zeros(n, dtype=np.int64)
|
|
1538
1542
|
state["iwhere"] = np.zeros(n, dtype=np.int64)
|
|
1539
1543
|
state["indx2"] = np.zeros(n, dtype=np.int64)
|