26 | {% trans %}Please activate JavaScript to enable the search 27 | functionality.{% endtrans %} 28 |
29 |31 | {% trans %}From here you can search these documents. Enter your search 32 | words into the box below and click "search". Note that the search 33 | function will automatically search for all of the words. Pages 34 | containing fewer words won't appear in the result list.{% endtrans %} 35 |
36 | 37 | {% if theme_bootstrap_version == "3" %} 38 | 45 | {% else %} 46 | 51 | {% endif %} 52 | 53 | {% if search_performed %} 54 |{{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}
57 | {% endif %} 58 | {% endif %} 59 |12 | From here you can search these documents. Enter your search 13 | words into the box below and click "search". 14 |
15 | 16 | 21 | 22 | {%- if search_performed %} 23 |Your search did not match any results.
26 | {%- endif %} 27 | {%- endif %} 28 |
").html($(this).html());
168 | });
169 | }});
170 |
171 | // Update sourcelink to remove outerdiv (fixes appearance in navbar).
172 | var $srcLink = $(".nav #sourcelink");
173 | $srcLink.parent().html($srcLink.html());
174 | });
175 | }(window.$jqTheme || window.jQuery));
176 |
--------------------------------------------------------------------------------
/doc/theme/static/js/jquery-fix.js:
--------------------------------------------------------------------------------
1 | // No Conflict in later (our) version of jQuery
2 | window.$jqTheme = jQuery.noConflict();
3 |
--------------------------------------------------------------------------------
/doc/theme/theme.conf:
--------------------------------------------------------------------------------
1 | # Bootstrap Theme
2 | [theme]
3 | inherit = basic
4 | stylesheet = bootstrap-sphinx.css
5 | pygments_style = tango
6 | # The sphinx bootstrap theme includes information typically presented in a
7 | # theme's sidebar in the navbar, so these are disabled by default.
8 | # Users can override this with `html_sidebars` in their conf.py.
9 | sidebars =
10 |
11 | # Configurable options.
12 | [options]
13 | # Navigation bar title. (Default: ``project`` value)
14 | navbar_title =
15 |
16 | # Tab name for entire site. (Default: "Site")
17 | navbar_site_name = Site
18 |
19 | # A list of tuples containting pages to link to. The value should be
20 | # in the form [(name, page), ..]
21 | navbar_links =
22 |
23 | # Render the next and previous page links in navbar. (Default: true)
24 | navbar_sidebarrel = true
25 |
26 | # Render the current pages TOC in the navbar. (Default: true)
27 | navbar_pagenav = true
28 |
29 | # Tab name for the current pages TOC. (Default: "Page")
30 | navbar_pagenav_name = Page
31 |
32 | # Global TOC depth for "site" navbar tab. (Default: 1)
33 | # Switching to -1 shows all levels.
34 | globaltoc_depth = 1
35 |
36 | # Include hidden TOCs in Site navbar?
37 | #
38 | # Note: If this is "false", you cannot have mixed ``:hidden:`` and
39 | # non-hidden ``toctree`` directives in the same page, or else the build
40 | # will break.
41 | #
42 | # Values: "true" (default) or "false"
43 | globaltoc_includehidden = true
44 |
45 | # HTML navbar class (Default: "navbar") to attach to (a|b|rc|alpha|beta){count})?" 34 | r"(-(?P\d+)-g(?P [a-z0-9]+))?" 35 | r"(?P -dirty)?" 36 | r"$" 37 | ) 38 | 39 | VERSION_LINE_PATTERN = re.compile( 40 | r'__version__ = "(?P .+?)"' 41 | ) 42 | 43 | NULL_VERSION = "0.0.0" 44 | 45 | 46 | def run(cmd: str | Sequence[str]) -> str: 47 | if isinstance(cmd, str) and os.name == "posix": 48 | cmd = shlex.split(cmd) 49 | with Popen( 50 | cmd, 51 | stdin=PIPE, 52 | stderr=PIPE, 53 | stdout=PIPE, 54 | text=True, 55 | encoding="utf-8" 56 | ) as p: 57 | stdout, _ = p.communicate() 58 | return stdout.strip() 59 | 60 | 61 | def is_git() -> bool: 62 | """ 63 | Return True if inside a git repo 64 | """ 65 | res = run("git rev-parse --is-inside-work-tree") 66 | return res == "return" 67 | 68 | 69 | def get_version_from_scm() -> str: 70 | """ 71 | Return a SemVer (& PEP440 compliant) from `git describe` output 72 | """ 73 | desc = run(DEFAULT_DESCRIBE) 74 | m = DESCRIBE_PATTERN.match(desc) 75 | 76 | if not m: 77 | return "" 78 | 79 | pre = m.group("pre") or "" 80 | version = m.group("version") 81 | commits = m.group("commits") 82 | 83 | if commits != "0": 84 | v = f"{version}.dev{commits}" 85 | else: 86 | v = f"{version}{pre}" 87 | 88 | return v 89 | 90 | 91 | def get_version_from_file() -> str: 92 | """ 93 | Read version from package/_version.py 94 | """ 95 | file = Path(__file__).parent.parent / "_version.py" 96 | 97 | if file.exists(): 98 | s = file.read_text() 99 | match = VERSION_LINE_PATTERN.search(s) 100 | if match: 101 | return match.group('version') 102 | return "" 103 | 104 | 105 | def get_version() -> str: 106 | """ 107 | Return a SemVer (& PEP440 compliant) from `git describe` output 108 | """ 109 | return get_version_from_scm() or get_version_from_file() or NULL_VERSION 110 | 111 | 112 | if __name__ == "__main__": 113 | print(get_version()) 114 | -------------------------------------------------------------------------------- /skmisc/_distributor_init.py: -------------------------------------------------------------------------------- 1 | """ Distributor init file 2 | 3 | Distributors: you can add custom code here to support particular distributions 4 | of scikit-misc. 5 | 6 | For example, this is a good place to put any checks for hardware requirements. 7 | 8 | The scikit-misc standard source distribution will not put code in this file, so 9 | you can safely replace this file with your own version. 10 | """ 11 | -------------------------------------------------------------------------------- /skmisc/_version.py.in: -------------------------------------------------------------------------------- 1 | # This file is dynamically generated by the build system to support 2 | # versioning with source control. Do not edit by hand 3 | 4 | __version__ = "@VERSION@" 5 | -------------------------------------------------------------------------------- /skmisc/loess/LICENSE.txt: -------------------------------------------------------------------------------- 1 | From the original C package: 2 | 3 | /* 4 | * The authors of this software are Cleveland, Grosse, and Shyu. 5 | * Copyright (c) 1989, 1992 by AT&T. 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose without fee is hereby granted, provided that this entire notice 8 | * is included in all copies of any software which is or includes a copy 9 | * or modification of this software and in all copies of the supporting 10 | * documentation for such software. 11 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 12 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY 13 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 14 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /skmisc/loess/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | ================================================= 3 | Locally-weighted regression (:mod:`skmisc.loess`) 4 | ================================================= 5 | 6 | Loess is a procedure for estimating a regression surface by a multivariate 7 | smoothing procedure. A linear or quadratic function of the independent 8 | variables is fit in a moving fashion that is analogous to how a moving 9 | average is computed for a time series. 10 | 11 | Compared to approaches that fit global parametric functions, loess 12 | substantially increases the domain of surfaces that can be estimated without 13 | distortion. However, analogues of the statistical procedures used 14 | in parametric function fitting -- for example, ANOVA and t intervals -- 15 | involve statistics whose distributions are well approximated by familiar 16 | distributions. 17 | 18 | .. autosummary:: 19 | :toctree: generated/ 20 | :template: cython_class.rst 21 | 22 | loess 23 | loess_inputs 24 | loess_model 25 | loess_control 26 | loess_outputs 27 | loess_prediction 28 | loess_confidence_intervals 29 | loess_anova 30 | 31 | Source 32 | ------ 33 | The original source code was written by William S. Cleveland, Eric Grosse 34 | and Ming-Jen Shyu. It is available at http://www.netlib.org/a/dloess. It 35 | was initially adapted to for use in Scipy by Pierre GF Gerard-Marchant. 36 | 37 | For more see references [1]_ [2]_ and [3]_. 38 | 39 | .. [1] W. S. Cleveland, E. Grosse, and M. J. Shyu. Local Regression Models. 40 | In J. M. Chambers and T. Hastie, editors, Statistical Models in S, 41 | pages 309--376. Chapman and Hall, New York, 1992. 42 | 43 | .. [2] W. S. Cleveland, S. J. Devlin, and E. Grosse. Regression by Local 44 | Fitting: Methods, Properties, and Computing. Journal of Econometrics, 37: 45 | pp. 87--114. 1988. 46 | 47 | .. [3] W. S. Cleveland. Robust Locally Weighted Regression and Smoothing 48 | Scatterplots. Journal of the American Statistical Association, 74: 49 | pp. 829--836. 1979. 50 | """ 51 | from ._loess import ( 52 | loess, 53 | loess_anova, 54 | loess_confidence_intervals, 55 | loess_control, 56 | loess_inputs, 57 | loess_model, 58 | loess_outputs, 59 | loess_prediction, 60 | ) 61 | 62 | __all__ = ['loess', 'loess_model', 'loess_control', 'loess_inputs', 63 | 'loess_model', 'loess_outputs', 'loess_prediction', 64 | 'loess_confidence_intervals', 'loess_anova'] 65 | -------------------------------------------------------------------------------- /skmisc/loess/meson.build: -------------------------------------------------------------------------------- 1 | fs = import('fs') 2 | 3 | __init__py = fs.copyfile('__init__.py') 4 | 5 | #### pyx -> c generator, depending on copied pxd files and init 6 | loess_cython_gen = generator( 7 | cython, 8 | arguments: cython_args, 9 | output: '_@BASENAME@.c', 10 | depends: [ 11 | __init__py, 12 | fs.copyfile('src/c_loess.pxd'), 13 | fs.copyfile('src/loess.h') 14 | ] 15 | ) 16 | ### 17 | 18 | #### Fortran Loess into a static library 19 | 20 | floess_lib = static_library( 21 | 'floess', 22 | sources: [ 23 | 'src/loessf.f', 24 | 'src/linpack_lite.f', 25 | 'src/blas_lite.f' 26 | ], 27 | fortran_args: [fortran_args, fortran_ignore_warnings], 28 | link_args: [fortran_link_args], 29 | ) 30 | ### 31 | 32 | #### Loess Extenstion Module 33 | py3.extension_module( 34 | '_loess', 35 | sources: [ 36 | 'src/loess.c', 37 | 'src/loessc.c', 38 | 'src/misc.c', 39 | 'src/predict.c', 40 | loess_cython_gen.process('src/_loess.pyx') 41 | ], 42 | c_args: [c_args, cython_c_args], 43 | dependencies: [py3_dep, npymath_lib, np_dep], 44 | link_with: [floess_lib], 45 | link_args: [cython_c_link_args], 46 | link_language: 'c', 47 | install: true, 48 | subdir: 'skmisc/loess' 49 | ) 50 | ### 51 | 52 | #### Include Python Sources in this Directory 53 | # Copy the subpackage __init__ to the build dir 54 | python_sources = [ 55 | '__init__.py' 56 | ] 57 | 58 | py3.install_sources( 59 | python_sources, 60 | subdir: 'skmisc/loess' 61 | ) 62 | ### 63 | 64 | #### Included sub-packages 65 | subdir('tests') 66 | ### 67 | -------------------------------------------------------------------------------- /skmisc/loess/src/S.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define Calloc(n,t) (t *)calloc((unsigned)(n),sizeof(t)) 5 | #define Free(p) free((char *)(p)) 6 | 7 | /* the mapping from f77 to C intermediate code -- may be machine dependent 8 | * the first definition satisfies lint's narrowminded preprocessing & should 9 | * stay the same for all implementations. The __STDC__ definition is for 10 | * ANSI standard conforming C compilers. The #else definition should 11 | * generate the version of the fortran subroutine & common block names x 12 | * handed to the local loader; e.g., "x_" in system V, Berkeley & 9th edition 13 | */ 14 | 15 | #ifdef _MSC_VER 16 | // Microsoft Visual C++ 17 | #define F77_SUB(x) x##_ 18 | #else 19 | // Other compilers 20 | #ifdef __STDC__ 21 | #define F77_SUB(x) x##_ 22 | #else 23 | #define F77_SUB(x) x/**/_ 24 | #endif 25 | #endif 26 | 27 | #define NULL_ENTRY ((int *)NULL) 28 | -------------------------------------------------------------------------------- /skmisc/loess/src/c_loess.pxd: -------------------------------------------------------------------------------- 1 | # -*- Mode: Python -*- 2 | 3 | cdef extern from "loess.h": 4 | ctypedef struct c_loess_errstatus "loess_errstatus": 5 | int err_status 6 | char *err_msg 7 | ctypedef struct c_loess_inputs "loess_inputs": 8 | long n 9 | long p 10 | double *y 11 | double *x 12 | double *weights 13 | ctypedef struct c_loess_model "loess_model": 14 | double span 15 | int degree 16 | int normalize 17 | int parametric[8] 18 | int drop_square[8] 19 | char *family 20 | ctypedef struct c_loess_control "loess_control": 21 | char *surface 22 | char *statistics 23 | double cell 24 | char *trace_hat 25 | int iterations 26 | ctypedef struct c_loess_kd_tree "loess_kd_tree": 27 | pass 28 | ctypedef struct c_loess_outputs "loess_outputs": 29 | double *fitted_values 30 | double *fitted_residuals 31 | double enp 32 | double residual_scale 33 | double one_delta 34 | double two_delta 35 | double *pseudovalues 36 | double trace_hat 37 | double *diagonal 38 | double *robust 39 | double *divisor 40 | ctypedef struct c_loess "loess": 41 | c_loess_inputs *inputs 42 | c_loess_model *model 43 | c_loess_control *control 44 | c_loess_kd_tree *kd_tree 45 | c_loess_outputs *outputs 46 | c_loess_errstatus status 47 | ctypedef struct c_prediction "prediction": 48 | double *fit 49 | double *se_fit 50 | int se 51 | int m 52 | double residual_scale 53 | double df 54 | # ctypedef struct c_anova "anova_struct": 55 | # double dfn 56 | # double dfd 57 | # double F_value 58 | # double Pr_F 59 | ctypedef struct c_confidence_intervals "confidence_intervals": 60 | double *fit 61 | double *upper 62 | double *lower 63 | 64 | void loess_setup(double *x, double *y, double *w, long n, long p, c_loess *lo) 65 | void loess_model_setup(c_loess_model *model) 66 | void loess_inputs_setup(double *x, double *y, double *w, long n, long p, c_loess_inputs *inputs) 67 | void loess_outputs_setup(long n, long p, c_loess_outputs *outputs) 68 | void loess_kd_tree_setup(long n, long p, c_loess_kd_tree *kd_tree) 69 | void loess_control_setup(c_loess_control *control) 70 | 71 | void loess_fit(c_loess *lo) 72 | 73 | void loess_inputs_free(c_loess_inputs *inputs) 74 | void loess_outputs_free(c_loess_outputs *outputs) 75 | void loess_kd_tree_free(c_loess_kd_tree *kd_tree) 76 | void loess_free_mem(c_loess *lo) 77 | 78 | void loess_summary(c_loess *lo) 79 | 80 | void predict_setup(c_prediction *pre, c_loess *lo, int se, int m); 81 | void c_predict "predict" (double *eval, c_loess *lo, c_prediction *pre) 82 | void predict_free(c_prediction *pre) 83 | 84 | void c_pointwise "pointwise" (c_prediction *pre, double coverage, c_confidence_intervals *ci) 85 | double pf (double q, double df1, double df2) 86 | double ibeta (double x, double a, double b) 87 | void pw_free_mem (c_confidence_intervals *ci) 88 | -------------------------------------------------------------------------------- /skmisc/loess/src/loess.c: -------------------------------------------------------------------------------- 1 | #include "S.h" 2 | #include "loess.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | static char *surf_stat; 9 | 10 | int error_status = 0; 11 | char *error_message = NULL; 12 | 13 | /* Declarations */ 14 | 15 | static void 16 | loess_(double *y, double *x_, int *size_info, double *weights, double *span, 17 | int *degree, int *parametric, int *drop_square, int *normalize, 18 | char **statistics, char **surface, double *cell, char **trace_hat_in, 19 | int *iterations, double *fitted_values, double *fitted_residuals, 20 | double *enp, double *residual_scale, double *one_delta, double *two_delta, 21 | double *pseudovalues, double *trace_hat_out, double *diagonal, 22 | double *robust, double *divisor, int *parameter, int *a, double *xi, 23 | double *vert, double *vval); 24 | 25 | void F77_SUB(lowesw)(double*, int*, double*, double*); 26 | void F77_SUB(lowesp)(int*, double*, double*, double*, 27 | double*, double*, double*); 28 | 29 | static void 30 | condition(char **surface, char *new_stat, char **trace_hat_in) 31 | { 32 | if(!strcmp(*surface, "interpolate")) { 33 | if(!strcmp(new_stat, "none")) 34 | surf_stat = "interpolate/none"; 35 | else if(!strcmp(new_stat, "exact")) 36 | surf_stat = "interpolate/exact"; 37 | else if(!strcmp(new_stat, "approximate")) 38 | { 39 | if(!strcmp(*trace_hat_in, "approximate")) 40 | surf_stat = "interpolate/2.approx"; 41 | else if(!strcmp(*trace_hat_in, "exact")) 42 | surf_stat = "interpolate/1.approx"; 43 | } 44 | } 45 | else if(!strcmp(*surface, "direct")) { 46 | if(!strcmp(new_stat, "none")) 47 | surf_stat = "direct/none"; 48 | else if(!strcmp(new_stat, "exact")) 49 | surf_stat = "direct/exact"; 50 | else if(!strcmp(new_stat, "approximate")) 51 | surf_stat = "direct/approximate"; 52 | } 53 | } 54 | 55 | int 56 | comp(const void *d1, const void *d2) 57 | { 58 | double *_d1 = (double *)d1; 59 | double *_d2 = (double *)d2; 60 | 61 | if(*_d1 < *_d2) 62 | return(-1); 63 | else if(*_d1 == *_d2) 64 | return(0); 65 | else 66 | return(1); 67 | } 68 | 69 | 70 | void 71 | loess_model_setup(loess_model *model) { 72 | int i; 73 | 74 | model->span = 0.75; 75 | model->degree = 2; 76 | model->normalize = TRUE; 77 | 78 | for(i = 0; i < 8; i++) { 79 | model->parametric[i] = FALSE; 80 | model->drop_square[i] = FALSE; 81 | } 82 | 83 | model->family = "gaussian"; 84 | } 85 | 86 | void 87 | loess_inputs_setup(double *x, double *y, double *w, long n, 88 | long p, loess_inputs *inputs) { 89 | int i; 90 | 91 | inputs->y = MALLOC(n * sizeof(double)); 92 | inputs->x = MALLOC(n * p * sizeof(double)); 93 | inputs->weights = MALLOC(n * sizeof(double)); 94 | 95 | for(i = 0; i < (n * p); i++) { 96 | inputs->x[i] = x[i]; 97 | } 98 | 99 | for(i = 0; i < n; i++) { 100 | inputs->y[i] = y[i]; 101 | inputs->weights[i] = w[i]; 102 | } 103 | 104 | inputs->n = n; 105 | inputs->p = p; 106 | } 107 | 108 | void loess_outputs_setup(long n, long p, loess_outputs *outputs) { 109 | outputs->fitted_values = MALLOC(n * sizeof(double)); 110 | outputs->fitted_residuals = MALLOC(n * sizeof(double)); 111 | outputs->diagonal = MALLOC(n * sizeof(double)); 112 | outputs->robust = MALLOC(n * sizeof(double)); 113 | outputs->divisor = MALLOC(p * sizeof(double)); 114 | outputs->pseudovalues = MALLOC(n * sizeof(double)); 115 | } 116 | 117 | void 118 | loess_kd_tree_setup(long n, long p, loess_kd_tree *kd_tree) { 119 | int max_kd; 120 | 121 | max_kd = n > 200 ? n : 200; 122 | 123 | kd_tree->parameter = MALLOC(7 * sizeof(int)); 124 | kd_tree->a = MALLOC(max_kd * sizeof(int)); 125 | kd_tree->xi = MALLOC(max_kd * sizeof(double)); 126 | kd_tree->vert = MALLOC(p * 2 * sizeof(double)); 127 | kd_tree->vval = MALLOC((p + 1) * max_kd * sizeof(double)); 128 | } 129 | 130 | void 131 | loess_control_setup(loess_control *control) { 132 | control->surface = "interpolate"; 133 | control->statistics = "approximate"; 134 | control->cell = 0.2; 135 | control->trace_hat = "wait.to.decide"; 136 | control->iterations = 4; 137 | } 138 | 139 | void 140 | loess_setup(double *x, double *y, double *w, long n, long p, loess *lo) 141 | { 142 | loess_inputs_setup(x, y, w, n, p, lo->inputs); 143 | loess_model_setup(lo->model); 144 | loess_control_setup(lo->control); 145 | loess_outputs_setup(n, p, lo->outputs); 146 | loess_kd_tree_setup(n, p, lo->kd_tree); 147 | } 148 | 149 | static void 150 | loess_(double *y, double *x_, int *size_info, double *weights, double *span, 151 | int *degree, int *parametric, int *drop_square, int *normalize, 152 | char **statistics, char **surface, double *cell, char **trace_hat_in, 153 | int *iterations, double *fitted_values, double *fitted_residuals, 154 | double *enp, double *residual_scale, double *one_delta, double *two_delta, 155 | double *pseudovalues, double *trace_hat_out, double *diagonal, 156 | double *robust, double *divisor, int *parameter, int *a, double *xi, 157 | double *vert, double *vval) 158 | { 159 | double *x, *x_tmp, new_cell, trL, delta1, delta2, sum_squares = 0, 160 | pseudo_resid, *temp, *xi_tmp, *vert_tmp, *vval_tmp, 161 | *diag_tmp, trL_tmp = 0, d1_tmp = 0, d2_tmp = 0, sum, mean; 162 | int i, j, k, p, N, D, sum_drop_sqr = 0, sum_parametric = 0, 163 | setLf, nonparametric = 0, *order_parametric, 164 | *order_drop_sqr, zero = 0, max_kd; 165 | int *param_tmp, *a_tmp; 166 | int cut; 167 | char *new_stat; 168 | 169 | D = size_info[0]; 170 | N = size_info[1]; 171 | max_kd = (N > 200 ? N : 200); 172 | *one_delta = *two_delta = *trace_hat_out = 0; 173 | 174 | x = MALLOC(D * N * sizeof(double)); 175 | x_tmp = MALLOC(D * N * sizeof(double)); 176 | temp = MALLOC(N * sizeof(double)); 177 | a_tmp = MALLOC(max_kd * sizeof(int)); 178 | xi_tmp = MALLOC(max_kd * sizeof(double)); 179 | vert_tmp = MALLOC(D * 2 * sizeof(double)); 180 | vval_tmp = MALLOC((D + 1) * max_kd * sizeof(double)); 181 | diag_tmp = MALLOC(N * sizeof(double)); 182 | param_tmp = MALLOC(N * sizeof(int)); 183 | order_parametric = MALLOC(D * sizeof(int)); 184 | order_drop_sqr = MALLOC(D * sizeof(int)); 185 | 186 | new_cell = (*span) * (*cell); 187 | for(i = 0; i < N; i++) 188 | robust[i] = 1; 189 | 190 | for(i = 0; i < (N * D); i++) 191 | x_tmp[i] = x_[i]; 192 | 193 | if((*normalize) && (D > 1)) { 194 | cut = ceil(0.100000000000000000001 * N); 195 | for(i = 0; i < D; i++) { 196 | k = i * N; 197 | for(j = 0; j < N; j++) 198 | temp[j] = x_[k + j]; 199 | qsort(temp, N, sizeof(double), comp); 200 | sum = 0; 201 | for(j = cut; j <= (N - cut - 1); j++) 202 | sum = sum + temp[j]; 203 | mean = sum / (N - 2 * cut); 204 | sum = 0; 205 | for(j = cut; j <= (N - cut - 1); j++) { 206 | temp[j] = temp[j] - mean; 207 | sum = sum + temp[j] * temp[j]; 208 | } 209 | divisor[i] = sqrt(sum / (N - 2 * cut - 1)); 210 | for(j = 0; j < N; j++) { 211 | p = k + j; 212 | x_tmp[p] = x_[p] / divisor[i]; 213 | } 214 | } 215 | } 216 | else 217 | for(i = 0; i < D; i++) divisor[i] = 1; 218 | 219 | j = D - 1; 220 | for(i = 0; i < D; i++) { 221 | sum_drop_sqr = sum_drop_sqr + drop_square[i]; 222 | sum_parametric = sum_parametric + parametric[i]; 223 | if(parametric[i]) 224 | order_parametric[j--] = i; 225 | else 226 | order_parametric[nonparametric++] = i; 227 | } 228 | //Reorder the predictors w/ the non-parametric first 229 | for(i = 0; i < D; i++) { 230 | order_drop_sqr[i] = 2 - drop_square[order_parametric[i]]; 231 | k = i * N; 232 | p = order_parametric[i] * N; 233 | for(j = 0; j < N; j++) 234 | x[k + j] = x_tmp[p + j]; 235 | } 236 | 237 | // Misc. checks ............................. 238 | if((*degree) == 1 && sum_drop_sqr) { 239 | error_status = 1; 240 | error_message = "Specified the square of a factor predictor to be "\ 241 | "dropped when degree = 1"; 242 | return; 243 | } 244 | 245 | if(D == 1 && sum_drop_sqr) { 246 | error_status = 1; 247 | error_message = "Specified the square of a predictor to be dropped "\ 248 | "with only one numeric predictor"; 249 | return; 250 | } 251 | 252 | if(sum_parametric == D) { 253 | error_status = 1; 254 | error_message = "Specified parametric for all predictors"; 255 | return; 256 | } 257 | 258 | // Start the iterations ..................... 259 | for(j = 0; j <= (*iterations); j++) { 260 | new_stat = j ? "none" : *statistics; 261 | for(i = 0; i < N; i++) 262 | robust[i] = weights[i] * robust[i]; 263 | condition(surface, new_stat, trace_hat_in); 264 | setLf = !strcmp(surf_stat, "interpolate/exact"); 265 | loess_raw(y, x, weights, robust, &D, &N, span, degree, 266 | &nonparametric, order_drop_sqr, &sum_drop_sqr, 267 | &new_cell, &surf_stat, fitted_values, parameter, a, 268 | xi, vert, vval, diagonal, &trL, &delta1, &delta2, 269 | &setLf); 270 | if(j == 0) { 271 | *trace_hat_out = trL; 272 | *one_delta = delta1; 273 | *two_delta = delta2; 274 | } 275 | for(i = 0; i < N; i++){ 276 | fitted_residuals[i] = y[i] - fitted_values[i]; 277 | }; 278 | if(j < (*iterations)) 279 | F77_SUB(lowesw)(fitted_residuals, &N, robust, temp); 280 | } 281 | 282 | if((*iterations) > 0) { 283 | F77_SUB(lowesp)(&N, y, fitted_values, weights, robust, temp, 284 | pseudovalues); 285 | loess_raw(pseudovalues, x, weights, weights, &D, &N, span, 286 | degree, &nonparametric, order_drop_sqr, &sum_drop_sqr, 287 | &new_cell, &surf_stat, temp, param_tmp, a_tmp, xi_tmp, 288 | vert_tmp, vval_tmp, diag_tmp, &trL_tmp, &d1_tmp, &d2_tmp, 289 | &zero); 290 | for(i = 0; i < N; i++) { 291 | pseudo_resid = pseudovalues[i] - temp[i]; 292 | sum_squares = sum_squares + weights[i] * pseudo_resid * pseudo_resid; 293 | } 294 | } else { 295 | for(i = 0; i < N; i++) 296 | sum_squares = sum_squares + weights[i] * 297 | fitted_residuals[i] * fitted_residuals[i]; 298 | } 299 | 300 | *enp = (*one_delta) + 2 * (*trace_hat_out) - N; 301 | *residual_scale = sqrt(sum_squares / (*one_delta)); 302 | 303 | //Clean the mess and leave .................. 304 | free(x); 305 | free(x_tmp); 306 | free(temp); 307 | free(xi_tmp); 308 | free(vert_tmp); 309 | free(vval_tmp); 310 | free(diag_tmp); 311 | free(a_tmp); 312 | free(param_tmp); 313 | free(order_parametric); 314 | free(order_drop_sqr); 315 | } 316 | 317 | void 318 | loess_fit(loess *lo) 319 | { 320 | int size_info[2], iterations; 321 | 322 | size_info[0] = lo->inputs->p; 323 | size_info[1] = lo->inputs->n; 324 | 325 | //Reset the default error status... 326 | error_status = 0; 327 | lo->status.err_status = 0; 328 | lo->status.err_msg = NULL; 329 | 330 | iterations = (!strcmp(lo->model->family, "gaussian")) ? 0 : 331 | lo->control->iterations; 332 | if(!strcmp(lo->control->trace_hat, "wait.to.decide")) { 333 | if(!strcmp(lo->control->surface, "interpolate")) 334 | lo->control->trace_hat = (lo->inputs->n < 500) ? "exact" : "approximate"; 335 | else 336 | lo->control->trace_hat = "exact"; 337 | } 338 | loess_(lo->inputs->y, lo->inputs->x, size_info, lo->inputs->weights, 339 | &lo->model->span, 340 | &lo->model->degree, 341 | lo->model->parametric, 342 | lo->model->drop_square, 343 | &lo->model->normalize, 344 | &lo->control->statistics, 345 | &lo->control->surface, 346 | &lo->control->cell, 347 | &lo->control->trace_hat, 348 | &iterations, 349 | lo->outputs->fitted_values, 350 | lo->outputs->fitted_residuals, 351 | &lo->outputs->enp, 352 | &lo->outputs->residual_scale, 353 | &lo->outputs->one_delta, 354 | &lo->outputs->two_delta, 355 | lo->outputs->pseudovalues, 356 | &lo->outputs->trace_hat, 357 | lo->outputs->diagonal, 358 | lo->outputs->robust, 359 | lo->outputs->divisor, 360 | lo->kd_tree->parameter, 361 | lo->kd_tree->a, 362 | lo->kd_tree->xi, 363 | lo->kd_tree->vert, 364 | lo->kd_tree->vval); 365 | 366 | if(error_status){ 367 | lo->status.err_status = error_status; 368 | lo->status.err_msg = error_message; 369 | } 370 | } 371 | 372 | 373 | void loess_inputs_free(loess_inputs *inputs) { 374 | free(inputs->x); 375 | free(inputs->y); 376 | free(inputs->weights); 377 | } 378 | 379 | void loess_outputs_free(loess_outputs *outputs) { 380 | free(outputs->fitted_values); 381 | free(outputs->fitted_residuals); 382 | free(outputs->diagonal); 383 | free(outputs->robust); 384 | free(outputs->divisor); 385 | free(outputs->pseudovalues); 386 | } 387 | 388 | void loess_kd_tree_free(loess_kd_tree *kd_tree) { 389 | free(kd_tree->parameter); 390 | free(kd_tree->a); 391 | free(kd_tree->xi); 392 | free(kd_tree->vert); 393 | free(kd_tree->vval); 394 | } 395 | 396 | void 397 | loess_free_mem(loess *lo) 398 | { 399 | loess_inputs_free(lo->inputs); 400 | loess_outputs_free(lo->outputs); 401 | loess_kd_tree_free(lo->kd_tree); 402 | } 403 | 404 | void 405 | loess_summary(loess *lo) 406 | { 407 | printf("Number of Observations : %ld\n", lo->inputs->n); 408 | printf("Equivalent Number of Parameters: %.1f\n", lo->outputs->enp); 409 | if(!strcmp(lo->model->family, "gaussian")) 410 | printf("Residual Standard Error : "); 411 | else 412 | printf("Residual Scale Estimate: "); 413 | printf("%.4f\n", lo->outputs->residual_scale); 414 | } 415 | 416 | -------------------------------------------------------------------------------- /skmisc/loess/src/loess.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define TRUE 1 5 | #define FALSE 0 6 | #define MALLOC(n) safe_malloc(n, __LINE__) 7 | 8 | /* Structures */ 9 | 10 | typedef struct { 11 | int err_status; 12 | char *err_msg; 13 | } loess_errstatus; 14 | 15 | typedef struct { 16 | long n; 17 | long p; 18 | double *y; 19 | double *x; 20 | double *weights; 21 | } loess_inputs; 22 | 23 | typedef struct { 24 | double span; 25 | int degree; 26 | int normalize; 27 | int parametric[8]; 28 | int drop_square[8]; 29 | char *family; 30 | } loess_model; 31 | 32 | typedef struct { 33 | char *surface; 34 | char *statistics; 35 | double cell; 36 | char *trace_hat; 37 | int iterations; 38 | } loess_control; 39 | 40 | typedef struct { 41 | int *parameter; 42 | int *a; 43 | double *xi; 44 | double *vert; 45 | double *vval; 46 | } loess_kd_tree; 47 | 48 | typedef struct { 49 | double *fitted_values; 50 | double *fitted_residuals; 51 | double enp; 52 | double residual_scale; 53 | double one_delta; 54 | double two_delta; 55 | double *pseudovalues; 56 | double trace_hat; 57 | double *diagonal; 58 | double *robust; 59 | double *divisor; 60 | } loess_outputs; 61 | 62 | typedef struct { 63 | loess_inputs *inputs; 64 | loess_model *model; 65 | loess_control *control; 66 | loess_kd_tree *kd_tree; 67 | loess_outputs *outputs; 68 | loess_errstatus status; 69 | } loess; 70 | 71 | typedef struct { 72 | double *fit; 73 | double *se_fit; 74 | int se; 75 | int m; 76 | double residual_scale; 77 | double df; 78 | } prediction; 79 | 80 | typedef struct { 81 | double dfn; 82 | double dfd; 83 | double F_value; 84 | double Pr_F; 85 | } anova_struct; 86 | 87 | typedef struct { 88 | double *fit; 89 | double *upper; 90 | double *lower; 91 | } confidence_intervals; 92 | 93 | // from loess.c 94 | void loess_model_setup(loess_model *model); 95 | void loess_inputs_setup(double *x, double *y, double *w, long n, long p, loess_inputs *inputs); 96 | void loess_outputs_setup(long n, long p, loess_outputs *outputs); 97 | void loess_control_setup(loess_control *control); 98 | void loess_kd_tree_setup(long n, long p, loess_kd_tree *kd_tree); 99 | void loess_setup(double *x, double *y, double *w, long n, long p, loess *lo); 100 | void loess_fit(loess *lo); 101 | void loess_inputs_free(loess_inputs *inputs); 102 | void loess_outputs_free(loess_outputs *outputs); 103 | void loess_kd_tree_free(loess_kd_tree *kd_tree); 104 | void loess_free_mem(loess *lo); 105 | void loess_summary(loess *lo); 106 | void loess_raw(double *y, double *x, double *weights, double *robust, int *d, 107 | int*n, double *span, int *degree, int *nonparametric, 108 | int *drop_square, int *sum_drop_sqr, double *cell, char **surf_stat, 109 | double *surface, int *parameter, int *a, double *xi, double *vert, 110 | double *vval, double *diagonal, double *trL, double *one_delta, 111 | double *two_delta, int *setLf); 112 | 113 | // from loessc.c 114 | void 115 | loess_ise(double *y, double *x, double *x_evaluate, double *weights, 116 | double *span, int *degree, int *nonparametric, int *drop_square, 117 | int *sum_drop_sqr, double *cell, int *d, int *n, int *m, 118 | double *fit, double *L); 119 | 120 | void 121 | loess_ifit(int *parameter, int *a, double *xi, double *vert, double *vval, 122 | int *m, double *x_evaluate, double *fit); 123 | 124 | void 125 | loess_dfitse(double *y, double *x, double *x_evaluate, double *weights, 126 | double *robust, int *family, double *span, int *degree, 127 | int *nonparametric, int *drop_square, int *sum_drop_sqr, 128 | int *d, int *n, int *m, double *fit, double *L); 129 | void 130 | loess_dfit(double *y, double *x, double *x_evaluate, double *weights, 131 | double *span, int *degree, int *nonparametric, 132 | int *drop_square, int *sum_drop_sqr, int *d, int *n, int *m, 133 | double *fit); 134 | 135 | // from misc.c 136 | void *safe_malloc(size_t n, unsigned long line); 137 | void pointwise(prediction *pre, double coverage, confidence_intervals *ci); 138 | void pw_free_mem(confidence_intervals *ci); 139 | double pf(double q, double df1, double df2); 140 | double ibeta(double x, double a, double b); 141 | 142 | // from predict.c 143 | void predict_setup(prediction *pre, loess *lo, int se, int m); 144 | void predict(double *eval, loess *lo, prediction *pre); 145 | void predict_free(prediction *pre); 146 | -------------------------------------------------------------------------------- /skmisc/loess/src/loessc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Cleveland, Grosse, and Shyu. 3 | * Copyright (c) 1989, 1992 by AT&T. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "S.h" 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | /* Declarations */ 21 | 22 | static void 23 | loess_workspace(int *d, int *n, double *span, int *degree, 24 | int *nonparametric, int *drop_square, 25 | int *sum_drop_sqr, int *setLf); 26 | 27 | static void 28 | loess_prune(int *parameter, int *a, double *xi, double *vert, 29 | double *vval); 30 | 31 | static void 32 | loess_grow(int *parameter, int *a, double *xi, double *vert, 33 | double *vval); 34 | 35 | static void 36 | loess_free(void); 37 | 38 | #define MIN(x,y) ((x) < (y) ? (x) : (y)) 39 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) 40 | #define GAUSSIAN 1 41 | #define SYMMETRIC 0 42 | 43 | static int *iv = NULL, liv, lv, tau; 44 | static double *v = NULL; 45 | 46 | extern char *error_message; 47 | extern int error_status; 48 | 49 | 50 | void F77_SUB(lowesa)(double*, int*, int*, int*, int*, double*, double*); 51 | void F77_SUB(lowesb)(double*, double*, double*, double*, int*, int*, double*); 52 | void F77_SUB(lowesc)(int*, double*, double*, double*, double*, double*); 53 | void F77_SUB(lowesd)(int*, int*, int*, double*, int*, int*, 54 | double*, int*, int*, int*, int*); 55 | void F77_SUB(lowese)(int*, double*, int*, double*, double*); 56 | void F77_SUB(lowesf)(double*, double*, double*, int*, double*, 57 | int*, double*, double*, int*, double*); 58 | void F77_SUB(lowesl)(int*, double*, int*, double*, double*); 59 | void F77_SUB(ehg169)(int*, int*, int*, int*, int*, int*, 60 | double*, int*, double*, int*, int*, int*); 61 | void F77_SUB(ehg196)(int*, int*, double*, double*); 62 | void F77_SUB(ehg182)(int *i); 63 | void F77_SUB(ehg183a)(char *s, int *nc,int *i,int *n,int *inc); 64 | void F77_SUB(ehg184a)(char *s, int *nc, double *x, int *n, int *inc); 65 | 66 | 67 | void 68 | loess_raw(double *y, double *x, double *weights, double *robust, int *d, 69 | int *n, double *span, int *degree, int *nonparametric, 70 | int *drop_square, int *sum_drop_sqr, double *cell, char **surf_stat, 71 | double *surface, int *parameter, int *a, double *xi, double *vert, 72 | double *vval, double *diagonal, double *trL, double *one_delta, 73 | double *two_delta, int *setLf) 74 | { 75 | int zero = 0, one = 1, two = 2, nsing, i, k; 76 | double *hat_matrix, *LL, dzero = 0; 77 | 78 | 79 | *trL = 0; 80 | loess_workspace(d, n, span, degree, nonparametric, drop_square, 81 | sum_drop_sqr, setLf); 82 | v[1] = *cell; 83 | if(!strcmp(*surf_stat, "interpolate/none")) { 84 | F77_SUB(lowesb)(x, y, robust, &dzero, &zero, iv, v); 85 | F77_SUB(lowese)(iv, v, n, x, surface); 86 | loess_prune(parameter, a, xi, vert, vval); 87 | } 88 | else if (!strcmp(*surf_stat, "direct/none")) { 89 | F77_SUB(lowesf)(x, y, robust, iv, v, n, x, &dzero, &zero, surface); 90 | } 91 | else if (!strcmp(*surf_stat, "interpolate/1.approx")) { 92 | F77_SUB(lowesb)(x, y, weights, diagonal, &one, iv, v); 93 | F77_SUB(lowese)(iv, v, n, x, surface); 94 | nsing = iv[29]; 95 | for(i = 0; i < (*n); i++) *trL = *trL + diagonal[i]; 96 | F77_SUB(lowesa)(trL, n, d, &tau, &nsing, one_delta, two_delta); 97 | loess_prune(parameter, a, xi, vert, vval); 98 | } 99 | else if (!strcmp(*surf_stat, "interpolate/2.approx")) { 100 | F77_SUB(lowesb)(x, y, weights, &dzero, &zero, iv, v); 101 | F77_SUB(lowese)(iv, v, n, x, surface); 102 | nsing = iv[29]; 103 | F77_SUB(ehg196)(&tau, d, span, trL); 104 | F77_SUB(lowesa)(trL, n, d, &tau, &nsing, one_delta, two_delta); 105 | loess_prune(parameter, a, xi, vert, vval); 106 | } 107 | else if (!strcmp(*surf_stat, "direct/approximate")) { 108 | F77_SUB(lowesf)(x, y, weights, iv, v, n, x, diagonal, &one, surface); 109 | nsing = iv[29]; 110 | for(i = 0; i < (*n); i++) *trL = *trL + diagonal[i]; 111 | F77_SUB(lowesa)(trL, n, d, &tau, &nsing, one_delta, two_delta); 112 | } 113 | else if (!strcmp(*surf_stat, "interpolate/exact")) { 114 | hat_matrix = Calloc((*n)*(*n), double); 115 | LL = Calloc((*n)*(*n), double); 116 | F77_SUB(lowesb)(x, y, weights, diagonal, &one, iv, v); 117 | F77_SUB(lowesl)(iv, v, n, x, hat_matrix); 118 | F77_SUB(lowesc)(n, hat_matrix, LL, trL, one_delta, two_delta); 119 | F77_SUB(lowese)(iv, v, n, x, surface); 120 | loess_prune(parameter, a, xi, vert, vval); 121 | Free(hat_matrix); 122 | Free(LL); 123 | 124 | } 125 | else if (!strcmp(*surf_stat, "direct/exact")) { 126 | hat_matrix = Calloc((*n)*(*n), double); 127 | LL = Calloc((*n)*(*n), double); 128 | F77_SUB(lowesf)(x, y, weights, iv, v, n, x, hat_matrix, &two, surface); 129 | F77_SUB(lowesc)(n, hat_matrix, LL, trL, one_delta, two_delta); 130 | k = (*n) + 1; 131 | for(i = 0; i < (*n); i++) 132 | diagonal[i] = hat_matrix[i * k]; 133 | Free(hat_matrix); 134 | Free(LL); 135 | } 136 | loess_free(); 137 | } 138 | 139 | void 140 | loess_dfit(double *y, double *x, double *x_evaluate, double *weights, 141 | double *span, int *degree, int *nonparametric, 142 | int *drop_square, int *sum_drop_sqr, int *d, int *n, int *m, 143 | double *fit) 144 | { 145 | int zero = 0; 146 | double dzero = 0.0; 147 | loess_workspace(d, n, span, degree, nonparametric, drop_square, 148 | sum_drop_sqr, &zero); 149 | F77_SUB(lowesf)(x, y, weights, iv, v, m, x_evaluate, &dzero, &zero, fit); 150 | loess_free(); 151 | } 152 | 153 | void 154 | loess_dfitse(double *y, double *x, double *x_evaluate, double *weights, 155 | double *robust, int *family, double *span, int *degree, 156 | int *nonparametric, int *drop_square, int *sum_drop_sqr, 157 | int *d, int *n, int *m, double *fit, double *L) 158 | { 159 | int zero = 0, two = 2; 160 | double dzero = 0.0; 161 | loess_workspace(d, n, span, degree, nonparametric, drop_square, 162 | sum_drop_sqr, &zero); 163 | if(*family == GAUSSIAN) 164 | F77_SUB(lowesf)(x, y, weights, iv, v, m, x_evaluate, L, &two, fit); 165 | else if(*family == SYMMETRIC) 166 | { 167 | F77_SUB(lowesf)(x, y, weights, iv, v, m, x_evaluate, L, &two, fit); 168 | F77_SUB(lowesf)(x, y, robust, iv, v, m, x_evaluate, &dzero, &zero, fit); 169 | } 170 | loess_free(); 171 | } 172 | 173 | void 174 | loess_ifit(int *parameter, int *a, double *xi, double *vert, double *vval, 175 | int *m, double *x_evaluate, double *fit) 176 | { 177 | loess_grow(parameter, a, xi, vert, vval); 178 | F77_SUB(lowese)(iv, v, m, x_evaluate, fit); 179 | loess_free(); 180 | } 181 | 182 | void 183 | loess_ise(double *y, double *x, double *x_evaluate, double *weights, 184 | double *span, int *degree, int *nonparametric, int *drop_square, 185 | int *sum_drop_sqr, double *cell, int *d, int *n, int *m, 186 | double *fit, double *L) 187 | { 188 | int zero = 0, one = 1; 189 | double dzero = 0.0; 190 | loess_workspace(d, n, span, degree, nonparametric, drop_square, 191 | sum_drop_sqr, &one); 192 | v[1] = *cell; 193 | F77_SUB(lowesb)(x, y, weights, &dzero, &zero, iv, v); 194 | F77_SUB(lowesl)(iv, v, m, x_evaluate, L); 195 | loess_free(); 196 | } 197 | 198 | // Set global variables tau, lv, liv , and allocate global arrays 199 | // v[1..lv], iv[1..liv] 200 | static void 201 | loess_workspace(int *d, int *n, double *span, int *degree, 202 | int *nonparametric, int *drop_square, int *sum_drop_sqr, 203 | int *setLf) 204 | { 205 | int D, N, tau0, nvmax, nf, i; 206 | double dlv, dliv; 207 | 208 | D = *d; 209 | N = *n; 210 | nvmax = MAX(200, N); 211 | nf = MIN(N, (int) floor(N * (*span) + 1e-5)); 212 | if (nf <= 0) { 213 | error_status = 1; 214 | error_message = "span is too small"; 215 | return; 216 | } 217 | tau0 = ((*degree) > 1) ? ((D + 2) * (D + 1) / 2) : (D + 1); 218 | tau = tau0 - (*sum_drop_sqr); 219 | dlv = 50 + (3 * D + 3) * nvmax + N + (tau0 + 2) * nf; 220 | dliv = 50 + (pow(2.0, (double) D) + 4.0) * nvmax + 2.0 * N; 221 | 222 | if (*setLf) { 223 | dlv = dlv + (D + 1.0) * nf * (double) nvmax; 224 | dliv = dliv + nf * (double) nvmax; 225 | } 226 | 227 | if (dlv < INT_MAX && dliv < INT_MAX) { 228 | lv = (int) dlv; 229 | liv = (int) dliv; 230 | } else { 231 | error_status = 1; 232 | error_message = "workspace required is too large"; 233 | return; 234 | } 235 | 236 | iv = Calloc(liv, int); 237 | v = Calloc(lv, double); 238 | 239 | F77_SUB(lowesd)(iv, &liv, &lv, v, d, n, span, degree, &nf, 240 | &nvmax, setLf); 241 | iv[32] = *nonparametric; 242 | for(i = 0; i < D; i++) 243 | iv[i + 40] = drop_square[i]; 244 | } 245 | 246 | static void 247 | loess_prune(int *parameter, int *a, double *xi, double *vert, double *vval) 248 | { 249 | int d, vc, a1, v1, xi1, vv1, nc, nv, nvmax, i, k; 250 | 251 | d = iv[1]; 252 | vc = iv[3] - 1; 253 | nc = iv[4]; 254 | nv = iv[5]; 255 | a1 = iv[6] - 1; 256 | v1 = iv[10] - 1; 257 | xi1 = iv[11] - 1; 258 | vv1 = iv[12] - 1; 259 | nvmax = iv[13]; 260 | 261 | for(i = 0; i < 5; i++) 262 | parameter[i] = iv[i + 1]; 263 | parameter[5] = iv[21] - 1; 264 | parameter[6] = iv[14] - 1; 265 | 266 | for(i = 0; i < d; i++) { 267 | k = nvmax * i; 268 | vert[i] = v[v1 + k]; 269 | vert[i + d] = v[v1 + vc + k]; 270 | } 271 | for(i = 0; i < nc; i++) { 272 | xi[i] = v[xi1 + i]; 273 | a[i] = iv[a1 + i]; 274 | } 275 | k = (d + 1) * nv; 276 | for(i = 0; i < k; i++) 277 | vval[i] = v[vv1 + i]; 278 | } 279 | 280 | static void 281 | loess_grow(int *parameter, int *a, double *xi, double *vert, double *vval) 282 | { 283 | int d, vc, nc, nv, a1, v1, xi1, vv1, i, k; 284 | 285 | d = parameter[0]; 286 | vc = parameter[2]; 287 | nc = parameter[3]; 288 | nv = parameter[4]; 289 | liv = parameter[5]; 290 | lv = parameter[6]; 291 | iv = Calloc(liv, int); 292 | v = Calloc(lv, double); 293 | 294 | iv[1] = d; 295 | iv[2] = parameter[1]; 296 | iv[3] = vc; 297 | iv[5] = iv[13] = nv; 298 | iv[4] = iv[16] = nc; 299 | iv[6] = 50; 300 | iv[7] = iv[6] + nc; 301 | iv[8] = iv[7] + vc * nc; 302 | iv[9] = iv[8] + nc; 303 | iv[10] = 50; 304 | iv[12] = iv[10] + nv * d; 305 | iv[11] = iv[12] + (d + 1) * nv; 306 | iv[27] = 173; 307 | 308 | v1 = iv[10] - 1; 309 | xi1 = iv[11] - 1; 310 | a1 = iv[6] - 1; 311 | vv1 = iv[12] - 1; 312 | 313 | for(i = 0; i < d; i++) { 314 | k = nv * i; 315 | v[v1 + k] = vert[i]; 316 | v[v1 + vc - 1 + k] = vert[i + d]; 317 | } 318 | for(i = 0; i < nc; i++) { 319 | v[xi1 + i] = xi[i]; 320 | iv[a1 + i] = a[i]; 321 | } 322 | k = (d + 1) * nv; 323 | for(i = 0; i < k; i++) 324 | v[vv1 + i] = vval[i]; 325 | 326 | F77_SUB(ehg169)(&d, &vc, &nc, &nc, &nv, &nv, v+v1, iv+a1, 327 | v+xi1, iv+iv[7]-1, iv+iv[8]-1, iv+iv[9]-1); 328 | } 329 | 330 | static void 331 | loess_free(void) 332 | { 333 | Free(v); 334 | Free(iv); 335 | } 336 | 337 | /* begin ehg's FORTRAN-callable C-codes */ 338 | 339 | void 340 | F77_SUB(ehg182)(int *i) 341 | { 342 | char *mess, mess2[50]; 343 | switch(*i){ 344 | case 100: 345 | mess="Wrong version number in lowesd. Probably typo in caller."; 346 | break; 347 | case 101: 348 | mess="d>dMAX in ehg131. Need to recompile with increased dimensions."; 349 | break; 350 | case 102: 351 | mess="liv too small. (Discovered by lowesd)"; 352 | break; 353 | case 103: 354 | mess="lv too small. (Discovered by lowesd)"; 355 | break; 356 | case 104: 357 | mess="Span too small. Fewer data values than degrees of freedom."; 358 | break; 359 | case 105: 360 | mess="k>d2MAX in ehg136. Need to recompile with increased dimensions."; 361 | break; 362 | case 106: 363 | mess="lwork too small"; 364 | break; 365 | case 107: 366 | mess="Invalid value for kernel"; 367 | break; 368 | case 108: 369 | mess="Invalid value for ideg"; 370 | break; 371 | case 109: 372 | mess="lowstt only applies when kernel=1."; 373 | break; 374 | case 110: 375 | mess="Not enough extra workspace for robustness calculation"; 376 | break; 377 | case 120: 378 | mess="Zero-width neighborhood. Make span bigger"; 379 | break; 380 | case 121: 381 | mess="All data on boundary of neighborhood. make span bigger"; 382 | break; 383 | case 122: 384 | mess="Extrapolation not allowed with blending"; 385 | break; 386 | case 123: 387 | mess="ihat=1 (diag L) in l2fit only makes sense if z=x (eval=data)."; 388 | break; 389 | case 171: 390 | mess="lowesd must be called first."; 391 | break; 392 | case 172: 393 | mess="lowesf must not come between lowesb and lowese, lowesr, or lowesl."; 394 | break; 395 | case 173: 396 | mess="lowesb must come before lowese, lowesr, or lowesl."; 397 | break; 398 | case 174: 399 | mess="lowesb need not be called twice."; 400 | break; 401 | case 175: 402 | mess="Need setLf=.true. for lowesl."; 403 | break; 404 | case 180: 405 | mess="nv>nvmax in cpvert."; 406 | break; 407 | case 181: 408 | mess="nt>20 in eval."; 409 | break; 410 | case 182: 411 | mess="svddc failed in l2fit."; 412 | break; 413 | case 183: 414 | mess="Did not find edge in vleaf."; 415 | break; 416 | case 184: 417 | mess="Zero-width cell found in vleaf."; 418 | break; 419 | case 185: 420 | mess="Trouble descending to leaf in vleaf."; 421 | break; 422 | case 186: 423 | mess="Insufficient workspace for lowesf."; 424 | break; 425 | case 187: 426 | mess="Insufficient stack space."; 427 | break; 428 | case 188: 429 | mess="lv too small for computing explicit L."; 430 | break; 431 | case 191: 432 | mess="Computed trace L was negative; something is wrong!"; 433 | break; 434 | case 192: 435 | mess="Computed delta was negative; something is wrong!"; 436 | break; 437 | case 193: 438 | mess="Workspace in loread appears to be corrupted."; 439 | break; 440 | case 194: 441 | mess="Trouble in l2fit/l2tr"; 442 | break; 443 | case 195: 444 | mess="Only constant, linear, or quadratic local models allowed"; 445 | break; 446 | case 196: 447 | mess="degree must be at least 1 for vertex influence matrix"; 448 | break; 449 | case 999: 450 | mess="not yet implemented"; 451 | break; 452 | default: 453 | sprintf(mess=mess2,"Assert failed; error code %d\n",*i); 454 | break; 455 | } 456 | error_status = 1; 457 | error_message = mess; 458 | } 459 | 460 | void F77_SUB(ehg183a)(char *s, int *nc, int *i, int *n,int *inc) 461 | { 462 | char mess[4000], num[20]; 463 | int j; 464 | strncpy(mess,s,*nc); 465 | mess[*nc] = '\0'; 466 | for (j=0; j<*n; j++) { 467 | snprintf(num, 20, " %d",i[j * *inc]); 468 | strcat(mess,num); 469 | } 470 | strcat(mess,"\n"); 471 | error_status = 1; 472 | error_message = mess; 473 | } 474 | 475 | void F77_SUB(ehg184a)(char *s, int *nc, double *x, int *n, int *inc) 476 | { 477 | char mess[4000], num[30]; 478 | int j; 479 | strncpy(mess,s,*nc); 480 | mess[*nc] = '\0'; 481 | for (j=0; j<*n; j++) { 482 | snprintf(num,30," %.5g",x[j * *inc]); 483 | strcat(mess,num); 484 | } 485 | strcat(mess,"\n"); 486 | error_status = 1; 487 | error_message = mess; 488 | } 489 | -------------------------------------------------------------------------------- /skmisc/loess/src/misc.c: -------------------------------------------------------------------------------- 1 | #include "S.h" 2 | #include "loess.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | void *safe_malloc(size_t n, unsigned long line) 9 | { 10 | void *p = malloc(n); 11 | 12 | if (!p) { 13 | fprintf(stderr, "[%s:%lu] Out of memory (%lu bytes)\n", 14 | __FILE__, line, (unsigned long)n); 15 | exit(EXIT_FAILURE); 16 | } 17 | 18 | return p; 19 | } 20 | 21 | 22 | /* static functions */ 23 | static double _fmin(double a, double b) 24 | { 25 | return(a < b ? a : b); 26 | } 27 | 28 | static double _fmax(double a, double b) 29 | { 30 | return(a > b ? a : b); 31 | } 32 | 33 | /* 34 | * Rational approximation to inverse Gaussian distribution. 35 | * Absolute error is bounded by 4.5e-4. 36 | * Reference: Abramowitz and Stegun, page 933. 37 | * Assumption: 0 < p < 1. 38 | */ 39 | static double num[] = { 40 | 2.515517, 41 | 0.802853, 42 | 0.010328 43 | }; 44 | 45 | static double den[] = { 46 | 1.000000, 47 | 1.432788, 48 | 0.189269, 49 | 0.001308 50 | }; 51 | 52 | double invigauss_quick(double p) 53 | { 54 | int lower; 55 | double t, n, d, q; 56 | 57 | if(p == 0.5) 58 | return(0); 59 | lower = p < 0.5; 60 | p = lower ? p : 1 - p; 61 | t = sqrt(-2 * log(p)); 62 | n = (num[2]*t + num[1])*t + num[0]; 63 | d = ((den[3]*t + den[2])*t + den[1])*t + den[0]; 64 | q = lower ? n/d - t : t - n/d; 65 | return(q); 66 | } 67 | 68 | /* 69 | * Quick approximation to inverse incomplete beta function, 70 | * by matching first two moments with the Gaussian distribution. 71 | * Assumption: 0 < p < 1, a,b > 0. 72 | */ 73 | 74 | static double invibeta_quick(double p, double a, double b) 75 | { 76 | double x, m, s; 77 | 78 | x = a + b; 79 | m = a / x; 80 | s = sqrt((a*b) / (x*x*(x+1))); 81 | return(_fmax(0.0, _fmin(1.0, invigauss_quick(p)*s + m))); 82 | } 83 | 84 | 85 | /* 86 | * Inverse incomplete beta function. 87 | * Assumption: 0 <= p <= 1, a,b > 0. 88 | */ 89 | static double invibeta(double p, double a, double b) 90 | { 91 | int i; 92 | double ql, qr, qm, qdiff; 93 | double pl, pr, pm, pdiff; 94 | 95 | /* MEANINGFUL(qm);*/ 96 | qm = 0; 97 | if(p == 0 || p == 1) 98 | return(p); 99 | 100 | /* initialize [ql,qr] containing the root */ 101 | ql = qr = invibeta_quick(p, a, b); 102 | pl = pr = ibeta(ql, a, b); 103 | if(pl == p) 104 | return(ql); 105 | if(pl < p) 106 | while(1) { 107 | qr += 0.05; 108 | if(qr >= 1) { 109 | pr = qr = 1; 110 | break; 111 | } 112 | pr = ibeta(qr, a, b); 113 | if(pr == p) 114 | return(pr); 115 | if(pr > p) 116 | break; 117 | } 118 | else 119 | while(1) { 120 | ql -= 0.05; 121 | if(ql <= 0) { 122 | pl = ql = 0; 123 | break; 124 | } 125 | pl = ibeta(ql, a, b); 126 | if(pl == p) 127 | return(pl); 128 | if(pl < p) 129 | break; 130 | } 131 | 132 | /* a few steps of bisection */ 133 | for(i = 0; i < 5; i++) { 134 | qm = (ql + qr) / 2; 135 | pm = ibeta(qm, a, b); 136 | qdiff = qr - ql; 137 | pdiff = pm - p; 138 | if(fabs(qdiff) < DBL_EPSILON*qm || fabs(pdiff) < DBL_EPSILON) 139 | return(qm); 140 | if(pdiff < 0) { 141 | ql = qm; 142 | pl = pm; 143 | } else { 144 | qr = qm; 145 | pr = pm; 146 | } 147 | } 148 | 149 | /* a few steps of secant */ 150 | for(i = 0; i < 40; i++) { 151 | qm = ql + (p-pl)*(qr-ql)/(pr-pl); 152 | pm = ibeta(qm, a, b); 153 | qdiff = qr - ql; 154 | pdiff = pm - p; 155 | if(fabs(qdiff) < 2*DBL_EPSILON*qm || fabs(pdiff) < 2*DBL_EPSILON) 156 | return(qm); 157 | if(pdiff < 0) { 158 | ql = qm; 159 | pl = pm; 160 | } else { 161 | qr = qm; 162 | pr = pm; 163 | } 164 | } 165 | 166 | /* no convergence */ 167 | return(qm); 168 | } 169 | 170 | 171 | static double qt(double p, double df) 172 | { 173 | double t; 174 | t = invibeta(fabs(2*p-1), 0.5, df/2); 175 | return((p>0.5?1:-1) * sqrt(t*df/(1-t))); 176 | } 177 | 178 | 179 | double pf(double q, double df1, double df2) 180 | { 181 | return(ibeta(q*df1/(df2+q*df1), df1/2, df2/2)); 182 | } 183 | 184 | /**********************************************************************/ 185 | /* 186 | * Incomplete beta function. 187 | * Reference: Abramowitz and Stegun, 26.5.8. 188 | * Assumptions: 0 <= x <= 1; a,b > 0. 189 | */ 190 | 191 | double ibeta(double x, double a, double b) 192 | { 193 | int flipped = 0, i, k, count; 194 | double I, temp, pn[6], ak, bk, next, prev, factor, val; 195 | 196 | if (x <= 0) 197 | return(0); 198 | if (x >= 1) 199 | return(1); 200 | 201 | /* use ibeta(x,a,b) = 1-ibeta(1-x,b,a) */ 202 | if ((a+b+1)*x > (a+1)) { 203 | flipped = 1; 204 | temp = a; 205 | a = b; 206 | b = temp; 207 | x = 1 - x; 208 | } 209 | 210 | pn[0] = 0.0; 211 | pn[2] = pn[3] = pn[1] = 1.0; 212 | count = 1; 213 | val = x/(1.0-x); 214 | bk = 1.0; 215 | next = 1.0; 216 | do { 217 | count++; 218 | k = count/2; 219 | prev = next; 220 | if (count%2 == 0) 221 | ak = -((a+k-1.0)*(b-k)*val)/((a+2.0*k-2.0)*(a+2.0*k-1.0)); 222 | else 223 | ak = ((a+b+k-1.0)*k*val)/((a+2.0*k)*(a+2.0*k-1.0)); 224 | pn[4] = bk*pn[2] + ak*pn[0]; 225 | pn[5] = bk*pn[3] + ak*pn[1]; 226 | next = pn[4] / pn[5]; 227 | for (i=0; i<=3; i++) 228 | pn[i] = pn[i+2]; 229 | if (fabs(pn[4]) >= DBL_MAX) 230 | for (i=0; i<=3; i++) 231 | pn[i] /= DBL_MAX; 232 | if (fabs(pn[4]) <= DBL_MIN) 233 | for (i=0; i<=3; i++) 234 | pn[i] /= DBL_MIN; 235 | } while (fabs(next-prev) > DBL_EPSILON*prev); 236 | factor = a*log(x) + (b-1)*log(1-x); 237 | factor -= lgamma(a+1) + lgamma(b) - lgamma(a+b); 238 | I = exp(factor) * next; 239 | return(flipped ? 1-I : I); 240 | } 241 | 242 | 243 | void anova(loess *one, loess *two, anova_struct *out) 244 | { 245 | double one_d1, one_d2, one_s, two_d1, two_d2, two_s, 246 | rssdiff, d1diff, tmp; 247 | int max_enp; 248 | 249 | one_d1 = one->outputs->one_delta; 250 | one_d2 = one->outputs->two_delta; 251 | one_s = one->outputs->residual_scale; 252 | two_d1 = two->outputs->one_delta; 253 | two_d2 = two->outputs->two_delta; 254 | two_s = two->outputs->residual_scale; 255 | 256 | rssdiff = fabs(one_s * one_s * one_d1 - two_s * two_s * two_d1); 257 | d1diff = fabs(one_d1 - two_d1); 258 | out->dfn = d1diff * d1diff / fabs(one_d2 - two_d2); 259 | max_enp = (one->outputs->enp > two->outputs->enp); 260 | tmp = max_enp ? one_d1 : two_d1; 261 | out->dfd = tmp * tmp / (max_enp ? one_d2 : two_d2); 262 | tmp = max_enp ? one_s : two_s; 263 | out->F_value = (rssdiff / d1diff) / (tmp * tmp); 264 | out->Pr_F = 1 - pf(out->F_value, out->dfn, out->dfd); 265 | } 266 | 267 | 268 | void pointwise(prediction *pre, double coverage, 269 | confidence_intervals *ci) 270 | { 271 | double t_dist, limit, fit; 272 | int i; 273 | 274 | ci->fit = MALLOC(pre->m * sizeof(double)); 275 | ci->upper = MALLOC(pre->m * sizeof(double)); 276 | ci->lower = MALLOC(pre->m * sizeof(double)); 277 | 278 | t_dist = qt(1 - (1 - coverage)/2, pre->df); 279 | for(i = 0; i < pre->m; i++) { 280 | limit = pre->se_fit[i] * t_dist; 281 | ci->fit[i] = fit = pre->fit[i]; 282 | ci->upper[i] = fit + limit; 283 | ci->lower[i] = fit - limit; 284 | } 285 | } 286 | 287 | 288 | void pw_free_mem(confidence_intervals *ci) 289 | { 290 | free(ci->fit); 291 | free(ci->upper); 292 | free(ci->lower); 293 | } 294 | 295 | 296 | 297 | typedef double doublereal; 298 | typedef int integer; 299 | 300 | void Recover(char *a, int *b) 301 | { 302 | printf("%s", a); 303 | exit(1); 304 | } 305 | 306 | /* d1mach may be replaced by Fortran code: 307 | mail netlib@netlib.bell-labs.com 308 | send d1mach from core. 309 | */ 310 | doublereal F77_SUB(d1mach)(integer *i) 311 | { 312 | switch(*i) { 313 | case 1: return DBL_MIN; 314 | case 2: return DBL_MAX; 315 | case 3: return DBL_EPSILON/FLT_RADIX; 316 | case 4: return DBL_EPSILON; 317 | case 5: return log10(FLT_RADIX); 318 | default: 319 | Recover("Invalid argument to d1mach()", 0L); 320 | return 0; 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /skmisc/loess/src/predict.c: -------------------------------------------------------------------------------- 1 | #include "S.h" 2 | #include "loess.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | extern char *error_message; 9 | extern int error_status; 10 | 11 | static void 12 | pred_(double *y, double *x_, double *new_x, int *size_info, double *residual_scale, 13 | double *weights, double *robust, double *span, int *degree, 14 | int *normalize, int *parametric, int *drop_square, char **surface, 15 | double *cell, char **family, int *parameter, int *a, double *xi, 16 | double *vert, double *vval, double *divisor, int *se, double *fit, 17 | double *se_fit) 18 | { 19 | double *x, *x_tmp, *x_evaluate, *L, new_cell, tmp, *fit_tmp, 20 | *temp; 21 | int N, D, M, sum_drop_sqr = 0, sum_parametric = 0, 22 | nonparametric = 0, *order_parametric, *order_drop_sqr; 23 | int i, j, k, p; 24 | int gaussian_family = !strcmp(*family, "gaussian"); 25 | int direct_surface = !strcmp(*surface, "direct"); 26 | 27 | D = size_info[0]; 28 | N = size_info[1]; 29 | M = size_info[2]; 30 | 31 | x = MALLOC(N * D * sizeof(double)); 32 | x_tmp = MALLOC(N * D * sizeof(double)); 33 | x_evaluate = MALLOC(M * D * sizeof(double)); 34 | L = MALLOC(N * M * sizeof(double)); 35 | order_parametric = MALLOC(D * sizeof(int)); 36 | order_drop_sqr = MALLOC(D * sizeof(int)); 37 | temp = MALLOC(N * D * sizeof(double)); 38 | 39 | for(i = 0; i < (N * D); i++) 40 | x_tmp[i] = x_[i]; 41 | for(i = 0; i < D; i++) { 42 | k = i * M; 43 | for(j = 0; j < M; j++) { 44 | p = k + j; 45 | new_x[p] = new_x[p] / divisor[i]; 46 | } 47 | } 48 | if(direct_surface || se) { 49 | for(i = 0; i < D; i++) { 50 | k = i * N; 51 | for(j = 0; j < N; j++) { 52 | p = k + j; 53 | x_tmp[p] = x_[p] / divisor[i]; 54 | } 55 | } 56 | } 57 | j = D - 1; 58 | for(i = 0; i < D; i++) { 59 | sum_drop_sqr = sum_drop_sqr + drop_square[i]; 60 | sum_parametric = sum_parametric + parametric[i]; 61 | if(parametric[i]) 62 | order_parametric[j--] = i; 63 | else 64 | order_parametric[nonparametric++] = i; 65 | } 66 | for(i = 0; i < D; i++) { 67 | order_drop_sqr[i] = 2 - drop_square[order_parametric[i]]; 68 | k = i * M; 69 | p = order_parametric[i] * M; 70 | for(j = 0; j < M; j++) 71 | x_evaluate[k + j] = new_x[p + j]; 72 | k = i * N; 73 | p = order_parametric[i] * N; 74 | for(j = 0; j < N; j++) 75 | x[k + j] = x_tmp[p + j]; 76 | } 77 | for(i = 0; i < N; i++) 78 | robust[i] = weights[i] * robust[i]; 79 | 80 | if(direct_surface) { 81 | if(*se) { 82 | loess_dfitse(y, x, x_evaluate, weights, robust, 83 | &gaussian_family, span, degree, 84 | &nonparametric, order_drop_sqr, &sum_drop_sqr, 85 | &D, &N, &M, fit, L); 86 | } 87 | else { 88 | loess_dfit(y, x, x_evaluate, robust, span, degree, 89 | &nonparametric, order_drop_sqr, &sum_drop_sqr, 90 | &D, &N, &M, fit); 91 | } 92 | } 93 | else { 94 | loess_ifit(parameter, a, xi, vert, vval, &M, x_evaluate, fit); 95 | if(*se) { 96 | new_cell = (*span) * (*cell); 97 | fit_tmp = MALLOC(M * sizeof(double)); 98 | loess_ise(y, x, x_evaluate, weights, span, degree, 99 | &nonparametric, order_drop_sqr, &sum_drop_sqr, 100 | &new_cell, &D, &N, &M, fit_tmp, L); 101 | free(fit_tmp); 102 | } 103 | } 104 | if(*se) { 105 | for(i = 0; i < N; i++) { 106 | k = i * M; 107 | for(j = 0; j < M; j++) { 108 | p = k + j; 109 | L[p] = L[p] / weights[i]; 110 | L[p] = L[p] * L[p]; 111 | } 112 | } 113 | for(i = 0; i < M; i++) { 114 | tmp = 0; 115 | for(j = 0; j < N; j++) 116 | tmp = tmp + L[i + j * M]; 117 | se_fit[i] = (*residual_scale) * sqrt(tmp); 118 | } 119 | } 120 | free(x); 121 | free(x_tmp); 122 | free(x_evaluate); 123 | free(L); 124 | free(order_parametric); 125 | free(order_drop_sqr); 126 | free(temp); 127 | } 128 | 129 | void 130 | predict_setup(prediction *pre, loess *lo, int se, int m) 131 | { 132 | pre->m = m; 133 | pre->se = se; 134 | pre->fit = MALLOC(m * sizeof(double)); 135 | if (se) { 136 | pre->se_fit = MALLOC(m * sizeof(double)); 137 | } 138 | 139 | pre->residual_scale = lo->outputs->residual_scale; 140 | pre->df = (lo->outputs->one_delta * lo->outputs->one_delta) / 141 | lo->outputs->two_delta; 142 | } 143 | 144 | void 145 | predict(double *eval, loess *lo, prediction *pre) 146 | { 147 | int size_info[3]; 148 | 149 | size_info[0] = lo->inputs->p; 150 | size_info[1] = lo->inputs->n; 151 | size_info[2] = pre->m; 152 | 153 | error_status = 0; 154 | lo->status.err_status = 0; 155 | lo->status.err_msg = NULL; 156 | 157 | pred_(lo->inputs->y, 158 | lo->inputs->x, eval, 159 | size_info, 160 | &lo->outputs->residual_scale, 161 | lo->inputs->weights, 162 | lo->outputs->robust, 163 | &lo->model->span, 164 | &lo->model->degree, 165 | &lo->model->normalize, 166 | lo->model->parametric, 167 | lo->model->drop_square, 168 | &lo->control->surface, 169 | &lo->control->cell, 170 | &lo->model->family, 171 | lo->kd_tree->parameter, 172 | lo->kd_tree->a, 173 | lo->kd_tree->xi, 174 | lo->kd_tree->vert, 175 | lo->kd_tree->vval, 176 | lo->outputs->divisor, 177 | &pre->se, 178 | pre->fit, 179 | pre->se_fit); 180 | 181 | if(error_status){ 182 | lo->status.err_status = error_status; 183 | lo->status.err_msg = error_message; 184 | } 185 | } 186 | 187 | 188 | void 189 | predict_free(prediction *pre) 190 | { 191 | free(pre->fit); 192 | if(pre->se) { 193 | free(pre->se_fit); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /skmisc/loess/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/has2k1/scikit-misc/e6a5577e51cade53814c076a90b7adfa80db5294/skmisc/loess/tests/__init__.py -------------------------------------------------------------------------------- /skmisc/loess/tests/co2_data: -------------------------------------------------------------------------------- 1 | 315.58 316.39 316.79 317.82 2 | 318.39 318.22 316.68 315.01 3 | 314.02 313.55 315.02 315.75 4 | 316.52 317.1 317.79 319.22 5 | 320.08 319.7 318.27 315.99 6 | 314.24 314.05 315.05 316.23 7 | 316.92 317.76 318.54 319.49 8 | 320.64 319.85 318.7 316.96 9 | 315.17 315.47 316.19 317.17 10 | 318.12 318.72 319.79 320.68 11 | 321.28 320.89 319.79 317.56 12 | 316.46 315.59 316.85 317.87 13 | 318.87 319.25 320.13 321.49 14 | 322.34 321.62 319.85 317.87 15 | 316.36 316.24 317.13 318.46 16 | 319.57 320.23 320.89 321.54 17 | 322.2 321.9 320.42 318.6 18 | 316.73 317.15 317.94 318.91 19 | 319.73 320.78 321.23 322.49 20 | 322.59 322.35 321.61 319.24 21 | 318.23 317.76 319.36 319.5 22 | 320.35 321.4 322.22 323.45 23 | 323.8 323.5 322.16 320.09 24 | 318.26 317.66 319.47 320.7 25 | 322.06 322.23 322.78 324.1 26 | 324.63 323.79 322.34 320.73 27 | 319 318.99 320.41 321.68 28 | 322.3 322.89 323.59 324.65 29 | 325.3 325.15 323.88 321.8 30 | 319.99 319.86 320.88 322.36 31 | 323.59 324.23 325.34 326.33 32 | 327.03 326.24 325.39 323.16 33 | 321.87 321.31 322.34 323.74 34 | 324.61 325.58 326.55 327.81 35 | 327.82 327.53 326.29 324.66 36 | 323.12 323.09 324.01 325.1 37 | 326.12 326.62 327.16 327.94 38 | 329.15 328.79 327.53 325.65 39 | 323.6 323.78 325.13 326.26 40 | 326.93 327.84 327.96 329.93 41 | 330.25 329.24 328.13 326.42 42 | 324.97 325.29 326.56 327.73 43 | 328.73 329.7 330.46 331.7 44 | 332.66 332.22 331.02 329.39 45 | 327.58 327.27 328.3 328.81 46 | 329.44 330.89 331.62 332.85 47 | 333.29 332.44 331.35 329.58 48 | 327.58 327.55 328.56 329.73 49 | 330.45 330.98 331.63 332.88 50 | 333.63 333.53 331.9 330.08 51 | 328.59 328.31 329.44 330.64 52 | 331.62 332.45 333.36 334.46 53 | 334.84 334.29 333.04 330.88 54 | 329.23 328.83 330.18 331.5 55 | 332.8 333.22 334.54 335.82 56 | 336.45 335.97 334.65 332.4 57 | 331.28 330.73 332.05 333.54 58 | 334.65 335.06 336.32 337.39 59 | 337.66 337.56 336.24 334.39 60 | 332.43 332.22 333.61 334.78 61 | 335.88 336.43 337.61 338.53 62 | 339.06 338.92 337.39 335.72 63 | 333.64 333.65 335.07 336.53 64 | 337.82 338.19 339.89 340.56 65 | 341.22 340.92 339.26 337.27 66 | 335.66 335.54 336.71 337.79 67 | 338.79 340.06 340.93 342.02 68 | 342.65 341.8 340.01 337.94 69 | 336.17 336.28 337.76 339.05 70 | 340.18 341.04 342.16 343.01 71 | 343.64 342.91 341.72 339.52 72 | 337.75 337.68 339.14 340.37 73 | 341.32 342.45 343.05 344.91 74 | 345.77 345.3 343.98 342.41 75 | 339.89 340.03 341.19 342.87 76 | 343.74 344.55 345.28 347 77 | 347.37 346.74 345.36 343.19 78 | 340.97 341.2 342.76 343.96 79 | 344.82 345.82 347.24 348.09 80 | 348.66 347.9 346.27 344.21 81 | 342.88 342.58 343.99 345.31 82 | 345.98 346.72 347.63 349.24 83 | 349.83 349.1 347.52 345.43 84 | 344.48 343.89 345.29 346.54 85 | 347.66 348.07 349.12 350.55 86 | 351.34 350.8 349.1 347.54 87 | 346.2 346.2 347.44 348.67 88 | -------------------------------------------------------------------------------- /skmisc/loess/tests/co2_results_real: -------------------------------------------------------------------------------- 1 | -0.1312545 0.5171010 1.081863 2.133283 2.733717 2.239956 0.9297554 -1.114420 -2.675813 -2.878533 -1.902167 -0.9602861 -0.1273115 0.5191532 1.098498 2.153796 2.741747 2.243891 0.9270887 -1.118383 -2.694288 -2.898298 -1.912531 -0.9604589 -0.1233273 0.5212451 1.115170 2.174344 2.749810 2.247854 0.9244474 -1.122326 -2.712748 -2.918053 -1.922890 -0.9606276 -0.1193415 0.5233380 1.131844 2.194892 2.757873 2.251818 0.9218062 -1.126269 -2.731208 -2.937807 -1.933248 -0.9607950 -0.1153538 0.5254319 1.148517 2.215437 2.765927 2.255767 0.9191428 -1.130242 -2.749705 -2.957601 -1.943650 -0.9610062 -0.1116722 0.5270622 1.165944 2.235751 2.775559 2.261016 0.9161811 -1.135213 -2.768593 -2.978176 -1.954524 -0.9614759 -0.1078705 0.5288079 1.183482 2.256165 2.785280 2.266341 0.9132813 -1.140137 -2.787447 -2.998728 -1.965384 -0.9619374 -0.1040655 0.5305554 1.201020 2.276579 2.795002 2.271666 0.9103814 -1.145061 -2.806301 -3.019279 -1.976244 -0.9624004 -0.1002634 0.5322961 1.218547 2.296975 2.804697 2.276956 0.9074391 -1.150033 -2.825208 -3.039885 -1.987159 -0.9629111 -9.6585110E-02 0.5345098 1.236650 2.317664 2.815235 2.282577 0.9041511 -1.156232 -2.844850 -3.061133 -1.998018 -0.9631324 -9.2793740E-02 0.5368271 1.254847 2.338434 2.825840 2.288252 0.9009027 -1.162404 -2.864474 -3.082371 -2.008873 -0.9633515 -8.9002162E-02 0.5391444 1.273044 2.359204 2.836445 2.293926 0.8976543 -1.168575 -2.884098 -3.103606 -2.019723 -0.9635568 -8.5187905E-02 0.5415012 1.291297 2.380054 2.847153 2.299733 0.8945679 -1.174553 -2.903498 -3.124593 -2.030300 -0.9634821 -8.3201811E-02 0.5438787 1.305556 2.400896 2.863496 2.306658 0.8878226 -1.185068 -2.920140 -3.144774 -2.038712 -0.9626333 -8.1342012E-02 0.5461245 1.319679 2.421609 2.879717 2.313476 0.8809856 -1.195659 -2.936841 -3.164999 -2.047152 -0.9618035 -7.9490878E-02 0.5483653 1.333800 2.442321 2.895938 2.320295 0.8741485 -1.206250 -2.953541 -3.185220 -2.055586 -0.9609529 -7.7605315E-02 0.5506690 1.348012 2.463167 2.912336 2.327341 0.8675922 -1.216508 -2.969857 -3.205015 -2.063553 -0.9596200 -7.7330299E-02 0.5503440 1.358636 2.482778 2.934216 2.336317 0.8568450 -1.230463 -2.981276 -3.223306 -2.070151 -0.9587819 -7.7154912E-02 0.5499091 1.369141 2.502276 2.955991 2.345202 0.8460240 -1.244474 -2.992736 -3.241627 -2.076766 -0.9579533 -7.6982312E-02 0.5494729 1.379645 2.521775 2.977765 2.354088 0.8352031 -1.258486 -3.004196 -3.259947 -2.083381 -0.9571256 -7.6811321E-02 0.5490321 1.390142 2.541260 2.999520 2.362947 0.8243483 -1.272537 -3.015701 -3.278312 -2.090042 -0.9563401 -7.6623864E-02 0.5482746 1.401835 2.560602 3.022145 2.372517 0.8129162 -1.287402 -3.027721 -3.297196 -2.096884 -0.9556683 -7.6317951E-02 0.5476279 1.413630 2.580036 3.044847 2.382150 0.8015336 -1.302230 -3.039716 -3.316063 -2.103717 -0.9549910 -7.6009966E-02 0.5469823 1.425426 2.599469 3.067550 2.391784 0.7901511 -1.317057 -3.051710 -3.334929 -2.110549 -0.9543115 -7.5698733E-02 0.5463407 1.437227 2.618907 3.090258 2.401424 0.7787760 -1.331874 -3.063692 -3.353776 -2.117358 -0.9536040 -7.6063856E-02 0.5461957 1.448669 2.638872 3.114306 2.410975 0.7667037 -1.348096 -3.076017 -3.372460 -2.123710 -0.9525445 -7.6393344E-02 0.5460796 1.460133 2.658854 3.138366 2.420532 0.7546321 -1.364318 -3.088346 -3.391149 -2.130067 -0.9514883 -7.6724812E-02 0.5459623 1.471596 2.678835 3.162424 2.430090 0.7425606 -1.380541 -3.100676 -3.409836 -2.136422 -0.9504288 -7.7051133E-02 0.5458546 1.483073 2.698837 3.186512 2.439687 0.7305394 -1.396702 -3.112931 -3.428438 -2.142681 -0.9492642 2 | 315.5519 315.6444 315.7370 315.8309 315.9249 316.0178 316.1107 316.2020 316.2933 316.3990 316.5046 316.6163 316.7279 316.8079 316.8878 316.9311 316.9743 317.0090 317.0437 317.0798 317.1160 317.1457 317.1753 317.2173 317.2592 317.3336 317.4079 317.5032 317.5985 317.6932 317.7880 317.8778 317.9677 318.0505 318.1334 318.2101 318.2868 318.3582 318.4297 318.4905 318.5515 318.6045 318.6576 318.7044 318.7512 318.7997 318.8482 318.8934 318.9387 318.9714 319.0042 319.0360 319.0678 319.1112 319.1547 319.2017 319.2487 319.2848 319.3208 319.3572 319.3935 319.4408 319.4881 319.5362 319.5844 319.6243 319.6643 319.7062 319.7481 319.8018 319.8554 319.9161 319.9768 320.0472 320.1175 320.1960 320.2744 320.3428 320.4112 320.4777 320.5442 320.6194 320.6946 320.7675 320.8404 320.8941 320.9478 321.0001 321.0525 321.1218 321.1912 321.2603 321.3293 321.3860 321.4426 321.4910 321.5395 321.5891 321.6387 321.6929 321.7472 321.8074 321.8677 321.9326 321.9974 322.0666 322.1357 322.2221 322.3085 322.3978 322.4871 322.5602 322.6334 322.7142 322.7951 322.9083 323.0215 323.1505 323.2796 323.4066 323.5336 323.6655 323.7974 323.9248 324.0522 324.1571 324.2621 324.3597 324.4574 324.5563 324.6551 324.7526 324.8501 324.9600 325.0699 325.1974 325.3250 325.4465 325.5681 325.6663 325.7645 325.8489 325.9333 326.0171 326.1010 326.1757 326.2505 326.3240 326.3975 326.4841 326.5707 326.6689 326.7671 326.8619 326.9567 327.0334 327.1101 327.1916 327.2731 327.3853 327.4976 327.6297 327.7618 327.9146 328.0674 328.2484 328.4293 328.6387 328.8480 329.0606 329.2731 329.4512 329.6294 329.7654 329.9015 329.9944 330.0872 330.1566 330.2260 330.2656 330.3052 330.3234 330.3416 330.3688 330.3960 330.4333 330.4705 330.4956 330.5207 330.5406 330.5605 330.5999 330.6394 330.6982 330.7570 330.8309 330.9047 330.9972 331.0897 331.2050 331.3204 331.4307 331.5411 331.6268 331.7126 331.7816 331.8506 331.9108 331.9710 332.0377 332.1044 332.1886 332.2728 332.3846 332.4964 332.6316 332.7668 332.9182 333.0696 333.2294 333.3892 333.5459 333.7026 333.8486 333.9946 334.1266 334.2587 334.3876 334.5166 334.6480 334.7794 334.9027 335.0260 335.1393 335.2527 335.3613 335.4700 335.5737 335.6774 335.7795 335.8816 335.9893 336.0971 336.2180 336.3389 336.4763 336.6138 336.7694 336.9250 337.0909 337.2568 337.4205 337.5841 337.7405 337.8969 338.0427 338.1884 338.3105 338.4326 338.5441 338.6555 338.7655 338.8755 338.9668 339.0580 339.1279 339.1978 339.2682 339.3386 339.4240 339.5094 339.5996 339.6898 339.7864 339.8830 339.9971 340.1111 340.2360 340.3608 340.4738 340.5868 340.6892 340.7917 340.9008 341.0099 341.1549 341.2999 341.4833 341.6667 341.8679 342.0690 342.2645 342.4600 342.6507 342.8414 343.0210 343.2006 343.3539 343.5072 343.6369 343.7666 343.8864 344.0062 344.1151 344.2241 344.3238 344.4236 344.5265 344.6294 344.7352 344.8410 344.9409 345.0409 345.1429 345.2449 345.3532 345.4615 345.5617 345.6619 345.7472 345.8325 345.9183 346.0041 346.1007 346.1973 346.2995 346.4017 346.5121 346.6226 346.7441 346.8656 346.9885 347.1115 347.2327 347.3539 347.4835 347.6131 347.7646 347.9162 348.1116 348.3071 348.4999 348.6928 348.8899 349.0870 349.2884 349.4897 349.7021 3 | 0.9473456 0.8820528 0.9981718 0.9523941 0.8169235 0.9968721 0.7275636 0.9908377 0.6374046 0.9900793 0.5952753 0.9727222 0.9657797 0.8412194 0.8863041 0.9650735 0.7412772 0.5911558 0.7918944 0.9976359 0.9126042 0.9287147 0.8981016 0.9992640 0.8516618 0.9641449 0.9999655 0.9084932 0.8229079 0.9775841 0.9999740 0.8893542 0.9814858 0.6921397 0.9997987 0.9893009 0.9868131 0.9194017 0.8840622 0.9997586 0.9944118 0.9979475 0.8869542 0.9995601 0.5853120 0.8529151 0.9910294 0.9921290 0.9993278 0.8233213 0.9964389 0.8739912 0.5036717 0.8577449 0.8799009 0.9003027 0.9457330 0.9885447 0.8570249 0.9877417 0.8345523 0.8603712 0.8764476 0.8674909 0.9248952 0.9995702 0.9426413 0.9972472 0.8482621 0.7178012 0.9944118 0.9972574 0.9405500 0.9139733 0.9851364 0.9969788 0.4954960 0.8312120 0.8113978 0.9723752 0.5457299 0.9453593 0.2643782 0.7797844 0.6239225 0.9947231 0.9904200 0.9260687 0.9922562 0.9681790 0.9866477 0.9993476 0.8408600 0.1812998 0.9994192 0.9156029 0.2818184 0.9746988 0.9856681 0.9676514 0.9889814 0.7985213 0.5947735 0.9931651 0.9261450 0.9992403 0.8309539 0.5941209 0.9845950 0.9931651 0.9551575 0.8795514 0.9389349 0.9398142 0.9144093 0.9944832 0.9138095 0.8916704 0.6464453 0.9860324 0.9495300 0.9990164 0.8044351 0.9871626 0.9498475 0.9004778 0.8719712 0.9955013 0.8243347 0.9442974 0.7816713 0.9952399 0.9405271 0.9865257 0.8954014 0.8391304 0.7213080 0.8975996 0.9288895 0.9381664 0.8617947 0.6964918 0.9709492 0.9894392 0.9655861 0.9818738 0.7010069 0.1039263 0.9831502 0.9979994 0.9821939 0.9348792 0.8464258 0.9887996 0.8859938 0.8913366 0.9858394 0.9611016 0.3264723 0.9174322 0.9840199 0.2168292 0.5075723 0.8040431 0.9408705 0.8893237 0.9207462 0.9894688 0.9976125 0.9792520 0.9570797 0.9320744 0.9494027 0.9463241 0.8543022 0.3240814 0.5827369 0.7932186 0.9575490 0.5153625 7.5613648E-02 0.9968399 0.9972875 0.9896256 0.9998081 0.7909694 0.9995499 0.8123233 0.9996711 0.9008568 0.9924324 0.9765879 0.9759859 0.8392387 0.5412561 0.6502172 0.9204307 0.8854656 0.9938530 0.9838016 0.8638172 0.9807110 0.9956102 0.9980421 0.9998107 0.9649314 0.9413726 0.9854034 0.9891018 0.9846898 0.9838746 0.9782504 0.9896938 0.7482746 0.8501588 0.9267029 0.9640011 0.8578818 0.9719143 0.9755108 0.9730045 0.9828760 0.9745318 0.8800598 0.8233213 0.9392827 0.9522703 0.9719781 0.8818638 0.9571581 0.9319032 0.9987569 0.7301404 0.9874538 0.9430911 0.8306218 0.9959595 0.9763831 0.9998436 0.9944333 0.9808433 0.9747442 0.9586537 0.8875102 0.8213251 0.9816285 0.9945189 0.9021925 0.8195850 0.9273343 0.9694217 0.9929974 0.7616304 0.9767481 0.3199174 0.9965921 0.9998900 0.8672252 0.9997818 0.9995781 0.9983168 0.9902315 0.9846542 0.8739912 0.9251511 0.6491545 0.7521552 0.9149528 0.8217025 0.9999934 0.7942597 0.6791515 0.5116771 0.9076493 0.9983443 0.9999844 0.9324158 0.8247468 0.6679452 0.9943252 0.9998839 0.9321719 0.9530309 0.9806179 0.8923972 0.9451830 0.9915662 0.9311679 0.8502639 0.9944261 0.5542958 0.9975463 0.8896603 0.8676236 0.7327968 0.1887221 0.8266525 0.9999914 0.8732761 0.9370639 0.9911562 0.9603313 0.9317075 0.8358660 0.9948754 0.9995601 0.9256614 0.9997001 0.3365756 0.9271325 0.9972321 0.9962590 0.9649491 0.9452492 0.4000554 0.9789069 0.9881831 0.9834098 0.9445416 0.8983963 0.9580159 0.9970051 0.9750311 0.9486145 0.9663744 0.9714338 0.8667263 0.9904200 0.9929007 0.9858394 0.9784330 0.8917311 0.5354862 0.9942672 0.9918803 0.9998053 0.9436064 0.8876644 0.8348811 0.8652251 0.9573147 0.9585381 0.7653055 0.9986812 0.8698055 0.7505626 0.9830258 0.9803512 4 | 2 5 | -0.1312545 0.5171010 1.081863 2.133283 2.733717 2.239956 0.9297554 -1.114420 -2.675813 -2.878533 -1.902167 -0.9602861 -0.1273115 0.5191532 1.098498 2.153796 2.741747 2.243891 0.9270887 -1.118383 -2.694288 -2.898298 -1.912531 -0.9604589 -0.1233273 0.5212451 1.115170 2.174344 2.749810 2.247854 0.9244474 -1.122326 -2.712748 -2.918053 -1.922890 -0.9606276 -0.1193415 0.5233380 1.131844 2.194892 2.757873 2.251818 0.9218062 -1.126269 -2.731208 -2.937807 -1.933248 -0.9607950 -0.1153538 0.5254319 1.148517 2.215437 2.765927 2.255767 0.9191428 -1.130242 -2.749705 -2.957601 -1.943650 -0.9610062 -0.1116722 0.5270622 1.165944 2.235751 2.775559 2.261016 0.9161811 -1.135213 -2.768593 -2.978176 -1.954524 -0.9614759 -0.1078705 0.5288079 1.183482 2.256165 2.785280 2.266341 0.9132813 -1.140137 -2.787447 -2.998728 -1.965384 -0.9619374 -0.1040655 0.5305554 1.201020 2.276579 2.795002 2.271666 0.9103814 -1.145061 -2.806301 -3.019279 -1.976244 -0.9624004 -0.1002634 0.5322961 1.218547 2.296975 2.804697 2.276956 0.9074391 -1.150033 -2.825208 -3.039885 -1.987159 -0.9629111 -9.6585110E-02 0.5345098 1.236650 2.317664 2.815235 2.282577 0.9041511 -1.156232 -2.844850 -3.061133 -1.998018 -0.9631324 -9.2793740E-02 0.5368271 1.254847 2.338434 2.825840 2.288252 0.9009027 -1.162404 -2.864474 -3.082371 -2.008873 -0.9633515 -8.9002162E-02 0.5391444 1.273044 2.359204 2.836445 2.293926 0.8976543 -1.168575 -2.884098 -3.103606 -2.019723 -0.9635568 -8.5187905E-02 0.5415012 1.291297 2.380054 2.847153 2.299733 0.8945679 -1.174553 -2.903498 -3.124593 -2.030300 -0.9634821 -8.3201811E-02 0.5438787 1.305556 2.400896 2.863496 2.306658 0.8878226 -1.185068 -2.920140 -3.144774 -2.038712 -0.9626333 -8.1342012E-02 0.5461245 1.319679 2.421609 2.879717 2.313476 0.8809856 -1.195659 -2.936841 -3.164999 -2.047152 -0.9618035 -7.9490878E-02 0.5483653 1.333800 2.442321 2.895938 2.320295 0.8741485 -1.206250 -2.953541 -3.185220 -2.055586 -0.9609529 -7.7605315E-02 0.5506690 1.348012 2.463167 2.912336 2.327341 0.8675922 -1.216508 -2.969857 -3.205015 -2.063553 -0.9596200 -7.7330299E-02 0.5503440 1.358636 2.482778 2.934216 2.336317 0.8568450 -1.230463 -2.981276 -3.223306 -2.070151 -0.9587819 -7.7154912E-02 0.5499091 1.369141 2.502276 2.955991 2.345202 0.8460240 -1.244474 -2.992736 -3.241627 -2.076766 -0.9579533 -7.6982312E-02 0.5494729 1.379645 2.521775 2.977765 2.354088 0.8352031 -1.258486 -3.004196 -3.259947 -2.083381 -0.9571256 -7.6811321E-02 0.5490321 1.390142 2.541260 2.999520 2.362947 0.8243483 -1.272537 -3.015701 -3.278312 -2.090042 -0.9563401 -7.6623864E-02 0.5482746 1.401835 2.560602 3.022145 2.372517 0.8129162 -1.287402 -3.027721 -3.297196 -2.096884 -0.9556683 -7.6317951E-02 0.5476279 1.413630 2.580036 3.044847 2.382150 0.8015336 -1.302230 -3.039716 -3.316063 -2.103717 -0.9549910 -7.6009966E-02 0.5469823 1.425426 2.599469 3.067550 2.391784 0.7901511 -1.317057 -3.051710 -3.334929 -2.110549 -0.9543115 -7.5698733E-02 0.5463407 1.437227 2.618907 3.090258 2.401424 0.7787760 -1.331874 -3.063692 -3.353776 -2.117358 -0.9536040 -7.6063856E-02 0.5461957 1.448669 2.638872 3.114306 2.410975 0.7667037 -1.348096 -3.076017 -3.372460 -2.123710 -0.9525445 -7.6393344E-02 0.5460796 1.460133 2.658854 3.138366 2.420532 0.7546321 -1.364318 -3.088346 -3.391149 -2.130067 -0.9514883 -7.6724812E-02 0.5459623 1.471596 2.678835 3.162424 2.430090 0.7425606 -1.380541 -3.100676 -3.409836 -2.136422 -0.9504288 -7.7051133E-02 0.5458546 1.483073 2.698837 3.186512 2.439687 0.7305394 -1.396702 -3.112931 -3.428438 -2.142681 -0.9492642 6 | 315.5519 315.6444 315.7370 315.8309 315.9249 316.0178 316.1107 316.2020 316.2933 316.3990 316.5046 316.6163 316.7279 316.8079 316.8878 316.9311 316.9743 317.0090 317.0437 317.0798 317.1160 317.1457 317.1753 317.2173 317.2592 317.3336 317.4079 317.5032 317.5985 317.6932 317.7880 317.8778 317.9677 318.0505 318.1334 318.2101 318.2868 318.3582 318.4297 318.4905 318.5515 318.6045 318.6576 318.7044 318.7512 318.7997 318.8482 318.8934 318.9387 318.9714 319.0042 319.0360 319.0678 319.1112 319.1547 319.2017 319.2487 319.2848 319.3208 319.3572 319.3935 319.4408 319.4881 319.5362 319.5844 319.6243 319.6643 319.7062 319.7481 319.8018 319.8554 319.9161 319.9768 320.0472 320.1175 320.1960 320.2744 320.3428 320.4112 320.4777 320.5442 320.6194 320.6946 320.7675 320.8404 320.8941 320.9478 321.0001 321.0525 321.1218 321.1912 321.2603 321.3293 321.3860 321.4426 321.4910 321.5395 321.5891 321.6387 321.6929 321.7472 321.8074 321.8677 321.9326 321.9974 322.0666 322.1357 322.2221 322.3085 322.3978 322.4871 322.5602 322.6334 322.7142 322.7951 322.9083 323.0215 323.1505 323.2796 323.4066 323.5336 323.6655 323.7974 323.9248 324.0522 324.1571 324.2621 324.3597 324.4574 324.5563 324.6551 324.7526 324.8501 324.9600 325.0699 325.1974 325.3250 325.4465 325.5681 325.6663 325.7645 325.8489 325.9333 326.0171 326.1010 326.1757 326.2505 326.3240 326.3975 326.4841 326.5707 326.6689 326.7671 326.8619 326.9567 327.0334 327.1101 327.1916 327.2731 327.3853 327.4976 327.6297 327.7618 327.9146 328.0674 328.2484 328.4293 328.6387 328.8480 329.0606 329.2731 329.4512 329.6294 329.7654 329.9015 329.9944 330.0872 330.1566 330.2260 330.2656 330.3052 330.3234 330.3416 330.3688 330.3960 330.4333 330.4705 330.4956 330.5207 330.5406 330.5605 330.5999 330.6394 330.6982 330.7570 330.8309 330.9047 330.9972 331.0897 331.2050 331.3204 331.4307 331.5411 331.6268 331.7126 331.7816 331.8506 331.9108 331.9710 332.0377 332.1044 332.1886 332.2728 332.3846 332.4964 332.6316 332.7668 332.9182 333.0696 333.2294 333.3892 333.5459 333.7026 333.8486 333.9946 334.1266 334.2587 334.3876 334.5166 334.6480 334.7794 334.9027 335.0260 335.1393 335.2527 335.3613 335.4700 335.5737 335.6774 335.7795 335.8816 335.9893 336.0971 336.2180 336.3389 336.4763 336.6138 336.7694 336.9250 337.0909 337.2568 337.4205 337.5841 337.7405 337.8969 338.0427 338.1884 338.3105 338.4326 338.5441 338.6555 338.7655 338.8755 338.9668 339.0580 339.1279 339.1978 339.2682 339.3386 339.4240 339.5094 339.5996 339.6898 339.7864 339.8830 339.9971 340.1111 340.2360 340.3608 340.4738 340.5868 340.6892 340.7917 340.9008 341.0099 341.1549 341.2999 341.4833 341.6667 341.8679 342.0690 342.2645 342.4600 342.6507 342.8414 343.0210 343.2006 343.3539 343.5072 343.6369 343.7666 343.8864 344.0062 344.1151 344.2241 344.3238 344.4236 344.5265 344.6294 344.7352 344.8410 344.9409 345.0409 345.1429 345.2449 345.3532 345.4615 345.5617 345.6619 345.7472 345.8325 345.9183 346.0041 346.1007 346.1973 346.2995 346.4017 346.5121 346.6226 346.7441 346.8656 346.9885 347.1115 347.2327 347.3539 347.4835 347.6131 347.7646 347.9162 348.1116 348.3071 348.4999 348.6928 348.8899 349.0870 349.2884 349.4897 349.7021 7 | 0.9473456 0.8820528 0.9981718 0.9523941 0.8169235 0.9968721 0.7275636 0.9908377 0.6374046 0.9900793 0.5952753 0.9727222 0.9657797 0.8412194 0.8863041 0.9650735 0.7412772 0.5911558 0.7918944 0.9976359 0.9126042 0.9287147 0.8981016 0.9992640 0.8516618 0.9641449 0.9999655 0.9084932 0.8229079 0.9775841 0.9999740 0.8893542 0.9814858 0.6921397 0.9997987 0.9893009 0.9868131 0.9194017 0.8840622 0.9997586 0.9944118 0.9979475 0.8869542 0.9995601 0.5853120 0.8529151 0.9910294 0.9921290 0.9993278 0.8233213 0.9964389 0.8739912 0.5036717 0.8577449 0.8799009 0.9003027 0.9457330 0.9885447 0.8570249 0.9877417 0.8345523 0.8603712 0.8764476 0.8674909 0.9248952 0.9995702 0.9426413 0.9972472 0.8482621 0.7178012 0.9944118 0.9972574 0.9405500 0.9139733 0.9851364 0.9969788 0.4954960 0.8312120 0.8113978 0.9723752 0.5457299 0.9453593 0.2643782 0.7797844 0.6239225 0.9947231 0.9904200 0.9260687 0.9922562 0.9681790 0.9866477 0.9993476 0.8408600 0.1812998 0.9994192 0.9156029 0.2818184 0.9746988 0.9856681 0.9676514 0.9889814 0.7985213 0.5947735 0.9931651 0.9261450 0.9992403 0.8309539 0.5941209 0.9845950 0.9931651 0.9551575 0.8795514 0.9389349 0.9398142 0.9144093 0.9944832 0.9138095 0.8916704 0.6464453 0.9860324 0.9495300 0.9990164 0.8044351 0.9871626 0.9498475 0.9004778 0.8719712 0.9955013 0.8243347 0.9442974 0.7816713 0.9952399 0.9405271 0.9865257 0.8954014 0.8391304 0.7213080 0.8975996 0.9288895 0.9381664 0.8617947 0.6964918 0.9709492 0.9894392 0.9655861 0.9818738 0.7010069 0.1039263 0.9831502 0.9979994 0.9821939 0.9348792 0.8464258 0.9887996 0.8859938 0.8913366 0.9858394 0.9611016 0.3264723 0.9174322 0.9840199 0.2168292 0.5075723 0.8040431 0.9408705 0.8893237 0.9207462 0.9894688 0.9976125 0.9792520 0.9570797 0.9320744 0.9494027 0.9463241 0.8543022 0.3240814 0.5827369 0.7932186 0.9575490 0.5153625 7.5613648E-02 0.9968399 0.9972875 0.9896256 0.9998081 0.7909694 0.9995499 0.8123233 0.9996711 0.9008568 0.9924324 0.9765879 0.9759859 0.8392387 0.5412561 0.6502172 0.9204307 0.8854656 0.9938530 0.9838016 0.8638172 0.9807110 0.9956102 0.9980421 0.9998107 0.9649314 0.9413726 0.9854034 0.9891018 0.9846898 0.9838746 0.9782504 0.9896938 0.7482746 0.8501588 0.9267029 0.9640011 0.8578818 0.9719143 0.9755108 0.9730045 0.9828760 0.9745318 0.8800598 0.8233213 0.9392827 0.9522703 0.9719781 0.8818638 0.9571581 0.9319032 0.9987569 0.7301404 0.9874538 0.9430911 0.8306218 0.9959595 0.9763831 0.9998436 0.9944333 0.9808433 0.9747442 0.9586537 0.8875102 0.8213251 0.9816285 0.9945189 0.9021925 0.8195850 0.9273343 0.9694217 0.9929974 0.7616304 0.9767481 0.3199174 0.9965921 0.9998900 0.8672252 0.9997818 0.9995781 0.9983168 0.9902315 0.9846542 0.8739912 0.9251511 0.6491545 0.7521552 0.9149528 0.8217025 0.9999934 0.7942597 0.6791515 0.5116771 0.9076493 0.9983443 0.9999844 0.9324158 0.8247468 0.6679452 0.9943252 0.9998839 0.9321719 0.9530309 0.9806179 0.8923972 0.9451830 0.9915662 0.9311679 0.8502639 0.9944261 0.5542958 0.9975463 0.8896603 0.8676236 0.7327968 0.1887221 0.8266525 0.9999914 0.8732761 0.9370639 0.9911562 0.9603313 0.9317075 0.8358660 0.9948754 0.9995601 0.9256614 0.9997001 0.3365756 0.9271325 0.9972321 0.9962590 0.9649491 0.9452492 0.4000554 0.9789069 0.9881831 0.9834098 0.9445416 0.8983963 0.9580159 0.9970051 0.9750311 0.9486145 0.9663744 0.9714338 0.8667263 0.9904200 0.9929007 0.9858394 0.9784330 0.8917311 0.5354862 0.9942672 0.9918803 0.9998053 0.9436064 0.8876644 0.8348811 0.8652251 0.9573147 0.9585381 0.7653055 0.9986812 0.8698055 0.7505626 0.9830258 0.9803512 8 | -------------------------------------------------------------------------------- /skmisc/loess/tests/gas_data: -------------------------------------------------------------------------------- 1 | E (observations) 2 | 0.831000 1.045000 1.021000 0.970000 0.825000 0.891000 0.710000 0.801000 1.074000 1.148000 1.000000 0.928000 0.767000 0.701000 0.807000 0.902000 0.997000 1.224000 1.089000 0.973000 0.980000 0.665000 NOx (response) 3 | 4.818000 2.849000 3.275000 4.691000 4.255000 5.064000 2.118000 4.602000 2.286000 0.970000 3.965000 5.344000 3.834000 1.990000 5.199000 5.283000 3.752000 0.537000 1.640000 5.055000 4.937000 1.561000 -------------------------------------------------------------------------------- /skmisc/loess/tests/gas_result: -------------------------------------------------------------------------------- 1 | loess(&gas): 2 | 4.883437 2.927639 3.572746 4.710510 4.815363 5.196193 2.512832 4.474939 2.149797 0.990044 4.089353 5.303627 3.864174 2.267121 4.575636 5.240293 4.154036 0.523682 1.853026 4.659184 4.521148 1.196414 3 | loess(&gas_null): 4 | 4.892690 3.362733 3.728575 4.489023 4.831715 5.177112 2.535887 4.530370 2.873000 1.453502 4.059136 5.052650 3.943568 2.265232 4.614320 5.163913 4.107184 -0.276342 2.604373 4.445040 4.351615 1.051719 5 | predict(gas_fit_E, m, &gas, &gas_pred, 0): 6 | 1.196414 5.068747 0.523682 7 | pointwise(&gas_pred, m, coverage, &gas_ci): 8 | 0.407208 1.196414 1.985621 3.249187 3.679498 4.109808 4.631187 5.055708 5.480229 4.704010 5.135260 5.566510 2.759703 3.143656 3.527609 0.683247 1.196932 1.710617 -0.424684 0.523682 1.472049 9 | anova(&gas_null, &gas, &gas_anova): 10 | 2.5531 15.663 10.1397 0.000860102 11 | -------------------------------------------------------------------------------- /skmisc/loess/tests/madeup_data: -------------------------------------------------------------------------------- 1 | one_two (observations) 2 | -0.957581 -2.809549 -0.696511 3.451000 0.509260 0.557854 0.052582 -2.050644 -1.115675 -1.183665 0.511959 0.334364 -2.057062 -0.121897 0.544238 0.600502 0.531074 0.495400 -1.608602 0.277371 0.290464 0.579894 -0.290441 1.306226 -0.482898 -0.716423 0.742413 -0.911613 1.279436 -0.189153 0.592293 0.952416 0.491436 -0.305681 -0.363871 -0.285424 -0.037209 -0.923529 1.138054 -1.331223 0.551234 -0.852726 1.196875 0.498782 0.320180 0.212447 1.009358 -0.900989 1.132164 0.018867 0.424170 -0.198621 0.955170 0.948321 0.473848 -0.699121 -0.612853 0.580431 1.277996 0.806797 -1.038559 1.008663 -0.578257 -0.323245 -0.756302 1.386352 0.722419 -1.216078 -0.498280 0.726247 -0.260119 -0.741135 -0.184111 0.307762 0.464568 -0.252531 -0.486504 0.426634 -1.303969 0.067149 1.771176 0.907249 0.432350 1.419897 -0.413389 2.442025 0.041138 0.509505 -0.282744 0.179882 -1.188083 0.982653 -1.042886 1.181365 -0.398340 -1.335565 -0.502790 0.484762 -0.806446 1.412077 -0.878874 -0.935197 -0.339255 0.164497 1.370018 -1.494684 1.380505 0.885084 0.835609 0.896235 -1.289541 0.233203 1.183198 -0.857934 -1.334234 -0.923351 0.769146 -0.377948 0.059114 -1.870615 -0.677868 0.038185 0.375301 0.964717 0.695051 -0.342140 -1.145463 -0.993246 -0.130573 1.213711 0.291241 1.106891 0.949571 0.463675 0.455723 0.398786 -0.015849 -1.397373 0.770062 0.083291 0.531798 0.049727 -0.734140 -0.963487 0.573561 -0.281942 -0.594503 0.770262 1.073983 -0.615706 -0.084794 -0.491630 -1.526969 -0.196881 0.165653 0.198357 0.974930 -0.954848 0.588474 -0.426883 0.177119 -0.916442 -1.885139 0.086894 0.456306 0.174285 -0.001308 -0.000585 0.284023 -0.365679 -0.548867 0.857848 0.699094 -0.140026 1.332454 1.601795 0.012415 0.243429 1.077369 1.859246 0.185910 0.033342 0.613008 1.068595 -0.683305 -0.128826 -1.655525 0.013086 0.062454 0.773042 0.127046 0.408652 1.195438 -0.185558 -1.299714 0.899675 -0.033648 -1.544602 0.655203 -0.713935 3 | response 4 | 14.453553 6.622825 13.671414 14.197518 12.860530 12.522856 14.214638 7.924264 12.506938 13.734205 14.710855 13.596223 5.890019 13.558654 14.043167 13.931391 13.218920 17.090560 15.199322 13.261667 15.760636 12.083855 14.344907 12.609494 11.932959 13.408674 13.700765 13.013366 15.794999 14.600198 16.275751 11.564349 14.809023 12.982361 15.003502 14.737337 15.747677 11.674508 14.047278 14.666917 13.806240 13.611149 13.347149 14.225152 14.718846 14.217216 14.418058 14.719634 12.799716 13.933038 15.264603 14.660387 9.738691 14.443424 14.417284 15.184538 13.344938 15.372943 13.811554 15.103777 15.383834 14.368612 12.525202 14.325033 15.259658 13.004547 14.515988 15.176982 14.924187 13.872430 15.395366 13.428076 15.203430 14.186631 13.305833 14.074624 14.103092 13.499669 11.584675 14.264891 14.885616 13.967297 16.604680 10.367606 14.743473 16.308827 14.108673 13.590988 14.674546 15.294047 14.686723 13.611422 11.970270 13.884157 15.071776 12.589816 13.818745 14.245317 14.406530 14.347941 -------------------------------------------------------------------------------- /skmisc/loess/tests/madeup_result: -------------------------------------------------------------------------------- 1 | loess(&madeup): 2 | 13.898675 5.225583 14.265096 14.237045 13.366442 13.157273 14.189032 7.971348 13.215581 12.835208 13.967757 14.457845 6.039091 14.722007 13.758002 14.654508 14.243303 14.733353 13.696778 12.510036 15.026972 14.346972 14.547927 11.702517 14.222303 14.288345 13.755227 13.742749 14.250887 14.188543 14.388616 12.552611 14.100045 14.552719 14.514971 14.556744 14.496872 12.868609 12.871890 14.427522 14.410413 14.598345 13.415146 14.731999 14.657565 14.778805 13.988940 13.723749 11.932352 14.908485 14.457978 14.616147 11.100703 14.254687 14.411890 14.519007 13.734456 14.634786 13.080897 14.415189 14.623631 13.340049 12.584224 14.510466 14.293842 13.954341 14.281046 14.643596 14.492646 14.497077 14.497688 13.732467 14.573564 14.548255 13.560984 13.917026 14.496924 14.452028 11.687567 13.865395 13.908958 14.184016 14.514209 10.835782 14.203921 15.273614 13.702645 14.383224 14.506619 14.707063 14.595778 13.877506 12.326903 14.236236 13.962165 12.281695 14.477443 13.192765 13.985441 13.206705 3 | loess(&madeup_new): 4 | 12.874079 10.889912 14.072472 14.688408 13.581655 13.741506 12.966195 11.778153 12.623840 12.391277 13.915575 14.549806 10.648311 13.714716 13.908051 14.338239 13.839956 14.661187 14.500423 12.892713 14.344422 14.557473 14.294094 14.258892 13.410545 14.058327 14.340850 12.675257 14.839750 12.706903 14.551439 14.002773 13.589104 14.094192 14.098484 14.246415 14.548803 11.925623 14.212327 14.501013 14.199258 14.517379 15.151176 14.202325 14.044125 14.549456 15.030205 12.957176 14.170346 14.166684 14.617600 14.160491 14.230993 14.821136 14.547624 14.489024 12.630700 14.292239 14.381246 14.834949 14.480650 14.747398 11.611371 14.519760 13.997474 14.591257 14.591759 14.478131 14.427821 14.785485 14.034793 12.821834 13.556879 14.606041 13.505266 12.561710 14.525273 14.555914 11.728344 13.296039 14.621341 14.570526 14.015254 14.451527 13.670446 15.113971 12.849321 14.570355 14.526773 13.616773 14.493652 14.496696 11.739043 14.886699 12.740301 12.265455 14.504240 13.584999 13.370259 15.378514 5 | loess(&madeup_new) (family = symmetric): 6 | 13.853372 13.076392 14.410502 14.317606 13.530344 13.909561 13.483542 13.661465 13.738437 13.662424 14.078653 14.471725 13.362504 14.161261 14.056621 14.370400 13.827138 14.543779 14.563051 13.263340 14.405462 14.511807 14.391442 13.655949 13.919863 14.406599 14.307597 13.717301 14.561751 13.479815 14.423533 13.588048 13.644027 14.268385 14.283955 14.361030 14.528760 13.151054 13.826620 14.570806 14.120641 14.538117 14.640103 14.309962 14.069715 14.527437 14.606612 13.824681 13.607361 14.370144 14.535820 14.399329 14.122194 14.580712 14.478250 14.541334 13.593458 14.346338 14.016117 14.580121 14.566098 14.522580 12.578184 14.528995 14.305679 14.422916 14.523434 14.533691 14.490958 14.574831 14.352653 13.714577 13.911857 14.540189 13.522831 13.495538 14.528432 14.462617 13.481391 13.705501 14.399779 14.509204 14.010568 13.623165 14.211318 14.586042 13.392231 14.520972 14.525897 13.822231 14.577431 14.267078 13.423198 14.589490 13.573646 13.655627 14.531561 13.811793 13.979165 14.705119 7 | loess(&madeup_new) (normalize = FALSE): 8 | 13.853372 13.076392 14.410502 14.317606 13.530344 13.909561 13.483542 13.661465 13.738437 13.662424 14.078653 14.471725 13.362504 14.161261 14.056621 14.370400 13.827138 14.543779 14.563051 13.263340 14.405462 14.511807 14.391442 13.655949 13.919863 14.406599 14.307597 13.717301 14.561751 13.479815 14.423533 13.588048 13.644027 14.268385 14.283955 14.361030 14.528760 13.151054 13.826620 14.570806 14.120641 14.538117 14.640103 14.309962 14.069715 14.527437 14.606612 13.824681 13.607361 14.370144 14.535820 14.399329 14.122194 14.580712 14.478250 14.541334 13.593458 14.346338 14.016117 14.580121 14.566098 14.522580 12.578184 14.528995 14.305679 14.422916 14.523434 14.533691 14.490958 14.574831 14.352653 13.714577 13.911857 14.540189 13.522831 13.495538 14.528432 14.462617 13.481391 13.705501 14.399779 14.509204 14.010568 13.623165 14.211318 14.586042 13.392231 14.520972 14.525897 13.822231 14.577431 14.267078 13.423198 14.589490 13.573646 13.655627 14.531561 13.811793 13.979165 14.705119 9 | predict(newdata1, m, &madeup, &madeup_pred, 0): 10 | 8.156780 14.493587 14.854142 11 | predict(newdata2, m, &madeup, &madeup_pred, 1): 12 | 14.491811 14.389726 13 | pointwise(&madeup_pred, m, coverage, &madeup_ci): 14 | 13.761833 14.491811 15.221789 13.656419 14.389726 15.123034 15 | anova(&madeup2, &madeup, &madeup_anova): 16 | 6.45034 81.2319 2.85933 0.0121449 17 | -------------------------------------------------------------------------------- /skmisc/loess/tests/meson.build: -------------------------------------------------------------------------------- 1 | #### Include Test Sources in this Directory 2 | # Copy the subpackage __init__ to the build dir 3 | python_sources = [ 4 | '__init__.py', 5 | 'co2_data', 6 | 'co2_results_double', 7 | 'co2_results_real', 8 | 'gas_data', 9 | 'gas_result', 10 | 'madeup_data', 11 | 'madeup_result', 12 | 'test_loess.py' 13 | ] 14 | 15 | py3.install_sources( 16 | python_sources, 17 | subdir: 'skmisc/loess/tests' 18 | ) 19 | -------------------------------------------------------------------------------- /skmisc/loess/tests/test_loess.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import tempfile 3 | from pathlib import Path 4 | 5 | import numpy as np 6 | import numpy.testing as npt 7 | import pytest 8 | 9 | from skmisc.loess import loess, loess_anova 10 | 11 | data_path = Path(__file__).parent 12 | 13 | 14 | def madeup_data(): 15 | dfile = data_path / 'madeup_data' 16 | rfile = data_path / 'madeup_result' 17 | 18 | with open(dfile, 'r') as f: 19 | f.readline() 20 | x = np.fromiter( 21 | (float(v) for v in f.readline().rstrip().split()), 22 | np.float64).reshape(-1, 2) 23 | f.readline() 24 | y = np.fromiter( 25 | (float(v) for v in f.readline().rstrip().split()), 26 | np.float64) 27 | 28 | results = [] 29 | with open(rfile, 'r') as f: 30 | for i in range(8): 31 | f.readline() 32 | z = np.fromiter( 33 | (float(v) for v in f.readline().rstrip().split()), 34 | np.float64) 35 | results.append(z) 36 | 37 | newdata1 = np.array([[-2.5, 0.], [2.5, 0.], [0., 0.]]) 38 | newdata2 = np.array([[-0.5, 0.5], [0., 0.]]) 39 | return (x, y, results, newdata1, newdata2) 40 | 41 | 42 | def gas_data(): 43 | NOx = np.array([4.818, 2.849, 3.275, 4.691, 4.255, 5.064, 2.118, 4.602, 44 | 2.286, 0.970, 3.965, 5.344, 3.834, 1.990, 5.199, 5.283, 45 | 3.752, 0.537, 1.640, 5.055, 4.937, 1.561]) 46 | E = np.array([0.831, 1.045, 1.021, 0.970, 0.825, 0.891, 0.71, 0.801, 47 | 1.074, 1.148, 1.000, 0.928, 0.767, 0.701, 0.807, 0.902, 48 | 0.997, 1.224, 1.089, 0.973, 0.980, 0.665]) 49 | gas_fit_E = np.array([0.665, 0.949, 1.224]) 50 | newdata = np.array([0.6650000, 0.7581667, 0.8513333, 0.9445000, 51 | 1.0376667, 1.1308333, 1.2240000]) 52 | alpha = 0.01 53 | 54 | rfile = data_path / 'gas_result' 55 | results = [] 56 | with open(rfile, 'r') as f: 57 | for i in range(8): 58 | f.readline() 59 | z = np.fromiter( 60 | (float(v) for v in f.readline().rstrip().split()), 61 | np.float64) 62 | results.append(z) 63 | return (E, NOx, gas_fit_E, newdata, alpha, results) 64 | 65 | 66 | class TestLoess2d(object): 67 | "Test class for lowess." 68 | d = madeup_data() 69 | 70 | def test_2dbasic(self): 71 | "2D standard" 72 | (x, y, results, _, _) = self.d 73 | madeup = loess(x, y) 74 | madeup.model.span = 0.5 75 | madeup.model.normalize = True 76 | madeup.fit() 77 | npt.assert_almost_equal(madeup.outputs.fitted_values, results[0], 5) 78 | npt.assert_almost_equal(madeup.outputs.enp, 14.9, 1) 79 | npt.assert_almost_equal(madeup.outputs.residual_scale, 0.9693, 4) 80 | 81 | def test_2d_modflags(self): 82 | "2D - modification of model flags" 83 | (x, y, results, _, _) = self.d 84 | madeup = loess(x, y) 85 | madeup.model.span = 0.8 86 | madeup.model.drop_square = [True, False] 87 | madeup.model.parametric = [True, False] 88 | npt.assert_equal(madeup.model.parametric[:2], [1, 0]) 89 | madeup.fit() 90 | npt.assert_almost_equal(madeup.outputs.fitted_values, results[1], 5) 91 | npt.assert_almost_equal(madeup.outputs.enp, 6.9, 1) 92 | npt.assert_almost_equal(madeup.outputs.residual_scale, 1.4804, 4) 93 | 94 | def test_2d_modfamily(self): 95 | "2D - family modification" 96 | (x, y, results, _, _) = self.d 97 | madeup = loess(x, y) 98 | madeup.model.span = 0.8 99 | madeup.model.drop_square = [True, False] 100 | madeup.model.parametric = [True, False] 101 | madeup.model.family = "symmetric" 102 | madeup.fit() 103 | npt.assert_almost_equal(madeup.outputs.fitted_values, results[2], 5) 104 | npt.assert_almost_equal(madeup.outputs.enp, 6.9, 1) 105 | npt.assert_almost_equal(madeup.outputs.residual_scale, 1.0868, 4) 106 | 107 | def test_2d_modnormalize(self): 108 | "2D - normalization modification" 109 | (x, y, results, _, _) = self.d 110 | madeup = loess(x, y) 111 | madeup.model.span = 0.8 112 | madeup.model.drop_square = [True, False] 113 | madeup.model.parametric = [True, False] 114 | madeup.model.family = "symmetric" 115 | madeup.model.normalize = False 116 | madeup.fit() 117 | npt.assert_almost_equal(madeup.outputs.fitted_values, results[3], 5) 118 | npt.assert_almost_equal(madeup.outputs.enp, 6.9, 1) 119 | npt.assert_almost_equal(madeup.outputs.residual_scale, 1.0868, 4) 120 | 121 | def test_2d_pred_nostderr(self): 122 | "2D prediction - no stderr" 123 | (x, y, results, newdata1, _) = self.d 124 | madeup = loess(x, y) 125 | madeup.model.span = 0.5 126 | madeup.model.normalize = True 127 | prediction = madeup.predict(newdata1, stderror=False) 128 | npt.assert_almost_equal(prediction.values, results[4], 5) 129 | # 130 | prediction = madeup.predict(newdata1, stderror=False) 131 | npt.assert_almost_equal(prediction.values, results[4], 5) 132 | 133 | def test_2d_pred_nodata(self): 134 | "2D prediction - nodata" 135 | (x, y, _, _, _) = self.d 136 | madeup = loess(x, y) 137 | try: 138 | madeup.predict(None) 139 | except ValueError: 140 | pass 141 | else: 142 | raise AssertionError("The test should have failed") 143 | 144 | def test_2d_pred_stderr(self): 145 | "2D prediction - w/ stderr" 146 | (x, y, results, _, newdata2) = self.d 147 | madeup = loess(x, y) 148 | madeup.model.span = 0.5 149 | madeup.model.normalize = True 150 | prediction = madeup.predict(newdata2, stderror=True) 151 | npt.assert_almost_equal(prediction.values, results[5], 5) 152 | npt.assert_almost_equal(prediction.stderr, [0.276746, 0.278009], 5) 153 | npt.assert_almost_equal(prediction.residual_scale, 0.969302, 6) 154 | npt.assert_almost_equal(prediction.df, 81.2319, 4) 155 | 156 | # Direct access 157 | prediction = madeup.predict(newdata2, stderror=True) 158 | npt.assert_almost_equal(prediction.values, results[5], 5) 159 | npt.assert_almost_equal(prediction.stderr, [0.276746, 0.278009], 5) 160 | npt.assert_almost_equal(prediction.residual_scale, 0.969302, 6) 161 | npt.assert_almost_equal(prediction.df, 81.2319, 4) 162 | 163 | def test_2d_pred_confinv(self): 164 | "2D prediction - confidence" 165 | (x, y, results, _, newdata2) = self.d 166 | madeup = loess(x, y) 167 | madeup.model.span = 0.5 168 | madeup.model.normalize = True 169 | prediction = madeup.predict(newdata2, stderror=True) 170 | ci = prediction.confidence(alpha=0.01) 171 | npt.assert_almost_equal(ci.lower, results[6][::3], 5) 172 | npt.assert_almost_equal(ci.fit, results[6][1::3], 5) 173 | npt.assert_almost_equal(ci.upper, results[6][2::3], 5) 174 | 175 | 176 | class TestLoessGas(object): 177 | "Test class for lowess." 178 | 179 | d = gas_data() 180 | 181 | def test_1dbasic(self): 182 | "Basic test 1d" 183 | (E, NOx, _, _, _, results) = self.d 184 | gas = loess(E, NOx) 185 | gas.model.span = 2./3. 186 | gas.fit() 187 | npt.assert_almost_equal(gas.outputs.fitted_values, results[0], 6) 188 | npt.assert_almost_equal(gas.outputs.enp, 5.5, 1) 189 | npt.assert_almost_equal(gas.outputs.residual_scale, 0.3404, 4) 190 | 191 | def test_1dbasic_alt(self): 192 | "Basic test 1d - part #2" 193 | (E, NOx, _, _, _, results) = self.d 194 | gas_null = loess(E, NOx) 195 | gas_null.model.span = 1.0 196 | gas_null.fit() 197 | npt.assert_almost_equal(gas_null.outputs.fitted_values, results[1], 6) 198 | npt.assert_almost_equal(gas_null.outputs.enp, 3.5, 1) 199 | npt.assert_almost_equal(gas_null.outputs.residual_scale, 0.5197, 4) 200 | 201 | def test_1dpredict(self): 202 | "Basic test 1d - prediction" 203 | (E, NOx, gas_fit_E, _, _, results) = self.d 204 | gas = loess(E, NOx, span=2./3.) 205 | gas.fit() 206 | predicted = gas.predict(gas_fit_E, stderror=False).values 207 | npt.assert_almost_equal(predicted, results[2], 6) 208 | 209 | def test_1dpredict_2(self): 210 | "Basic test 1d - new predictions" 211 | (E, NOx, _, newdata, _, results) = self.d 212 | # gas = loess(E, NOx, span=2./3.) 213 | gas = loess(E, NOx) 214 | gas.model.span = 2./3. 215 | prediction = gas.predict(newdata, stderror=True) 216 | ci = prediction.confidence(alpha=0.01) 217 | npt.assert_almost_equal(ci.lower, results[3][0::3], 6) 218 | npt.assert_almost_equal(ci.fit, results[3][1::3], 6) 219 | npt.assert_almost_equal(ci.upper, results[3][2::3], 6) 220 | 221 | def test_anova(self): 222 | "Tests anova" 223 | (E, NOx, _, _, _, results) = self.d 224 | gas = loess(E, NOx, span=2./3.) 225 | gas.fit() 226 | gas_null = loess(E, NOx, span=1.0) 227 | gas_null.fit() 228 | gas_anova = loess_anova(gas, gas_null) 229 | gas_anova_theo = results[4] 230 | npt.assert_almost_equal(gas_anova.dfn, gas_anova_theo[0], 5) 231 | npt.assert_almost_equal(gas_anova.dfd, gas_anova_theo[1], 5) 232 | npt.assert_almost_equal(gas_anova.F_value, gas_anova_theo[2], 5) 233 | npt.assert_almost_equal(gas_anova.Pr_F, gas_anova_theo[3], 5) 234 | 235 | def test_failures(self): 236 | "Tests failures" 237 | (E, NOx, gas_fit_E, _, _, _) = self.d 238 | gas = loess(E, NOx, span=2./3.) 239 | # This one should fail (all parametric) 240 | gas.model.parametric = True 241 | with pytest.raises(ValueError): 242 | gas.fit() 243 | 244 | # This one also (all drop_square) 245 | gas.model.drop_square = True 246 | with pytest.raises(ValueError): 247 | gas.fit() 248 | 249 | gas.model.degree = 1 250 | with pytest.raises(ValueError): 251 | gas.fit() 252 | 253 | # This one should not (revert to std) 254 | gas.model.parametric = False 255 | gas.model.drop_square = False 256 | gas.model.degree = 2 257 | gas.fit() 258 | 259 | # Now, for predict ................. 260 | prediction = gas.predict(gas_fit_E, stderror=False) 261 | # This one should fail (extrapolation & blending) 262 | with pytest.raises(ValueError): 263 | gas.predict(prediction.values, stderror=False) 264 | 265 | # But this one should not .......... 266 | gas.predict(gas_fit_E, stderror=False) 267 | 268 | def test_pickling(self): 269 | rs = np.random.RandomState(seed=123) 270 | n = 500 271 | np.arange(n) 272 | x = np.linspace(0, 500, n) 273 | y = rs.randint(1, 1000, n) 274 | lo = loess(y, x, span=0.3) 275 | lo.fit() 276 | 277 | # pickle lo, unpickle it as lo2 and compare 278 | # predictions from both 279 | with tempfile.TemporaryFile() as f: 280 | pickle.dump(lo, f) 281 | f.seek(0) 282 | lo2 = pickle.load(f) 283 | 284 | npt.assert_array_equal(lo.predict(x).values, lo2.predict(x).values) 285 | -------------------------------------------------------------------------------- /skmisc/meson.build: -------------------------------------------------------------------------------- 1 | # Ref: https://github.com/scipy/scipy/blob/main/scipy/meson.build 2 | # commit: 053a3e8 3 | # 4 | # NOTES: 5 | # - As scikit-misc does not use these librares/languages 6 | # - c++ 7 | # - f2py (https://numpy.org/doc/stable/f2py/), 8 | # - pythran 9 | # - pybind 10 | 11 | # Platform detection 12 | is_mingw = is_windows and cc.get_define('__MINGW32__') != '' 13 | if is_mingw and ff.get_id() != 'gcc' 14 | error('If you are using GCC on Windows, you must also use GFortran! Detected ' + ff.get_id()) 15 | endif 16 | 17 | c_args = [] 18 | cython_c_args = ['-DCYTHON_CCOMPLEX=0'] # see gh-18975 for why we need this 19 | cython_c_link_args = [] 20 | fortran_args = [] 21 | fortran_link_args = [] 22 | 23 | if is_mingw 24 | is_mingw_built_python = run_command( 25 | py3, ['-c', 'import sysconfig; print(sysconfig.get_platform())'], 26 | check: true).stdout().strip().startswith('mingw') 27 | if not is_mingw_built_python 28 | # For mingw-w64, link statically against the UCRT. 29 | gcc_link_args = ['-lucrt', '-static'] 30 | add_project_link_arguments(gcc_link_args, language: ['c', 'cpp']) 31 | # Force gcc to float64 long doubles for compatibility with MSVC 32 | # builds, for C only. 33 | add_project_arguments('-mlong-double-64', language: 'c') 34 | endif 35 | # Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118) 36 | add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp']) 37 | endif 38 | 39 | 40 | 41 | thread_dep = dependency('threads', required: false) 42 | 43 | # NumPy include directory - needed in all submodules 44 | # The chdir is needed because within numpy there's an `import signal` 45 | # statement, and we don't want that to pick up scipy's signal module rather 46 | # than the stdlib module. The try-except is needed because when things are 47 | # split across drives on Windows, there is no relative path and an exception 48 | # gets raised. There may be other such cases, so add a catch-all and switch to 49 | # an absolute path. Relative paths are needed when for example a virtualenv is 50 | # placed inside the source tree; Meson rejects absolute paths to places inside 51 | # the source tree. 52 | # For cross-compilation it is often not possible to run the Python interpreter 53 | # in order to retrieve numpy's include directory. It can be specified in the 54 | # cross file instead: 55 | # [properties] 56 | # numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include 57 | # 58 | # This uses the path as is, and avoids running the interpreter. 59 | incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given') 60 | if incdir_numpy == 'not-given' 61 | incdir_numpy = run_command(py3, 62 | [ 63 | '-c', 64 | '''import os 65 | os.chdir(os.path.join("..", "tools")) 66 | import numpy as np 67 | try: 68 | incdir = os.path.relpath(np.get_include()) 69 | except Exception: 70 | incdir = np.get_include() 71 | print(incdir) 72 | ''' 73 | ], 74 | check: true 75 | ).stdout().strip() 76 | 77 | # We do need an absolute path to feed to `cc.find_library` below 78 | _incdir_numpy_abs = run_command(py3, 79 | ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], 80 | check: true 81 | ).stdout().strip() 82 | else 83 | _incdir_numpy_abs = incdir_numpy 84 | endif 85 | inc_np = include_directories(incdir_numpy) 86 | # Don't use the deprecated NumPy C API. Define this to a fixed version instead of 87 | # NPY_API_VERSION in order not to break compilation for released SciPy versions 88 | # when NumPy introduces a new deprecation. 89 | numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'] 90 | np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_nodepr_api) 91 | 92 | # We do need an absolute path to feed to `cc.find_library` below 93 | _incdir_numpy_abs = run_command(py3, 94 | ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], 95 | check: true 96 | ).stdout().strip() 97 | 98 | npymath_path = _incdir_numpy_abs / '..' / 'lib' 99 | npymath_lib = cc.find_library('npymath', dirs: npymath_path) 100 | ### 101 | 102 | cython_args = ['-3', '--fast-fail', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] 103 | 104 | #### Check Supported Compiler Flags 105 | # Check if compiler flags are supported. This is necessary to ensure that SciPy 106 | # can be built with any supported compiler. We need so many warning flags 107 | # because we want to be able to build with `-Werror` in CI; that ensures that 108 | # for new code we add, there are no unexpected new issues introduced. 109 | # 110 | # Cleaning up code so we no longer need some of these warning flags is useful, 111 | # but not a priority. 112 | # 113 | # The standard convention used here is: 114 | # - for C, drop the leading dash and turn remaining dashes into underscores 115 | # - for C++, prepend `_cpp` and turn remaining dashes into underscores 116 | # - for Fortran, prepend `_fflags` and turn remaining dashes into underscores 117 | 118 | # C warning flags 119 | Wno_maybe_uninitialized = cc.get_supported_arguments('-Wno-maybe-uninitialized') 120 | Wno_discarded_qualifiers = cc.get_supported_arguments('-Wno-discarded-qualifiers') 121 | Wno_empty_body = cc.get_supported_arguments('-Wno-empty-body') 122 | Wno_implicit_function_declaration = cc.get_supported_arguments('-Wno-implicit-function-declaration') 123 | Wno_parentheses = cc.get_supported_arguments('-Wno-parentheses') 124 | Wno_switch = cc.get_supported_arguments('-Wno-switch') 125 | Wno_unused_label = cc.get_supported_arguments('-Wno-unused-label') 126 | Wno_unused_result = cc.get_supported_arguments('-Wno-unused-result') 127 | Wno_unused_variable = cc.get_supported_arguments('-Wno-unused-variable') 128 | 129 | # Fortran warning flags 130 | _fflag_Wno_argument_mismatch = ff.get_supported_arguments('-Wno-argument-mismatch') 131 | _fflag_Wno_conversion = ff.get_supported_arguments('-Wno-conversion') 132 | _fflag_Wno_intrinsic_shadow = ff.get_supported_arguments('-Wno-intrinsic-shadow') 133 | _fflag_Wno_maybe_uninitialized = ff.get_supported_arguments('-Wno-maybe-uninitialized') 134 | _fflag_Wno_surprising = ff.get_supported_arguments('-Wno-surprising') 135 | _fflag_Wno_uninitialized = ff.get_supported_arguments('-Wno-uninitialized') 136 | _fflag_Wno_unused_dummy_argument = ff.get_supported_arguments('-Wno-unused-dummy-argument') 137 | _fflag_Wno_unused_label = ff.get_supported_arguments('-Wno-unused-label') 138 | _fflag_Wno_unused_variable = ff.get_supported_arguments('-Wno-unused-variable') 139 | _fflag_Wno_tabs = ff.get_supported_arguments('-Wno-tabs') 140 | # The default list of warnings to ignore from Fortran code. There is a lot of 141 | # old, vendored code that is very bad and we want to compile it silently (at 142 | # least with GCC and Clang) 143 | fortran_ignore_warnings = ff.get_supported_arguments( 144 | _fflag_Wno_argument_mismatch, 145 | _fflag_Wno_conversion, 146 | _fflag_Wno_maybe_uninitialized, 147 | _fflag_Wno_unused_dummy_argument, 148 | _fflag_Wno_unused_label, 149 | _fflag_Wno_unused_variable, 150 | _fflag_Wno_tabs, 151 | ) 152 | 153 | # Deal with M_PI & friends; add `use_math_defines` to c_args or cpp_args 154 | # Cython doesn't always get this right itself (see, e.g., gh-16800), so 155 | # explicitly add the define as a compiler flag for Cython-generated code. 156 | use_math_defines = [] 157 | if is_windows 158 | use_math_defines += ['-D_USE_MATH_DEFINES'] 159 | # cgwin gfortran may insert symbol/function ___chkstk_ms to pad space around large 160 | # arrays allocated on the stack. But to the linker (msvsc) that symbol will be 161 | # undefined. These prevent gfortran from doing any stack checks and inserting that 162 | # symbols. An alternative would have been to add libgfortran as a link argument, 163 | # but what we tried failed. 164 | fortran_args += [ 165 | ff.get_supported_arguments('-fno-stack-check'), 166 | ff.get_supported_arguments('-fno-stack-protector'), 167 | ff.get_supported_arguments('-mno-stack-arg-probe'), 168 | ] 169 | elif is_macos 170 | Wlno_compact_unwind = cc.get_supported_link_arguments('-Wl,-no_compact_unwind') 171 | # TODO: This should not exist long term 172 | # Disable warning about undefined dynamic lookup of symbols. It is harmless. 173 | # https://github.com/python/cpython/issues/97524#issuecomment-1270616173 174 | Wlno_fixup_chains = cc.get_supported_link_arguments('-Wl,-no_fixup_chains') 175 | cython_c_link_args += [ 176 | Wlno_compact_unwind, 177 | Wlno_fixup_chains 178 | ] 179 | endif 180 | 181 | cython_c_args += [use_math_defines] 182 | ### 183 | 184 | #### Compilers 185 | compilers = { 186 | 'C': cc, 187 | 'CYTHON': meson.get_compiler('cython'), 188 | 'FORTRAN': meson.get_compiler('fortran') 189 | } 190 | 191 | machines = { 192 | 'HOST': host_machine, 193 | 'BUILD': build_machine, 194 | } 195 | 196 | 197 | #### Configuration Information 198 | conf_data = configuration_data() 199 | conf_data.set('VERSION', meson.project_version()) 200 | 201 | # Set compiler information 202 | foreach name, compiler : compilers 203 | conf_data.set(name + '_COMP', compiler.get_id()) 204 | conf_data.set(name + '_COMP_LINKER_ID', compiler.get_linker_id()) 205 | conf_data.set(name + '_COMP_VERSION', compiler.version()) 206 | conf_data.set(name + '_COMP_CMD_ARRAY', ', '.join(compiler.cmd_array())) 207 | conf_data.set(name + '_COMP_ARGS', ', '.join( 208 | get_option(name.to_lower() + '_args') 209 | ) 210 | ) 211 | conf_data.set(name + '_COMP_LINK_ARGS', ', '.join( 212 | get_option(name.to_lower() + '_link_args') 213 | ) 214 | ) 215 | endforeach 216 | 217 | # Machines CPU and system information 218 | foreach name, machine : machines 219 | conf_data.set(name + '_CPU', machine.cpu()) 220 | conf_data.set(name + '_CPU_FAMILY', machine.cpu_family()) 221 | conf_data.set(name + '_CPU_ENDIAN', machine.endian()) 222 | conf_data.set(name + '_CPU_SYSTEM', machine.system()) 223 | endforeach 224 | 225 | conf_data.set('CROSS_COMPILED', meson.is_cross_build()) 226 | 227 | # Python information 228 | conf_data.set('PYTHON_PATH', py3.full_path()) 229 | conf_data.set('PYTHON_VERSION', py3.language_version()) 230 | ### 231 | 232 | skmisc_dir = py3.get_install_dir() / 'skmisc' 233 | 234 | #### Include Python Sources in this Directory 235 | # Copy the main __init__ to the build dir 236 | python_sources = [ 237 | '__init__.py', 238 | '_distributor_init.py', 239 | ] 240 | 241 | py3.install_sources( 242 | python_sources, 243 | subdir: 'skmisc' 244 | ) 245 | 246 | #### Build __config__.py 247 | configure_file( 248 | input: '__config__.py.in', 249 | output: '__config__.py', 250 | configuration : conf_data, 251 | install_dir: skmisc_dir, 252 | ) 253 | ### 254 | 255 | #### Build _version.py 256 | configure_file( 257 | input: '_version.py.in', 258 | output: '_version.py', 259 | configuration: conf_data, 260 | install_dir: skmisc_dir, 261 | ) 262 | 263 | # Meson does not inculde any generated files in the source distribution 264 | # We want the generated _version.py so that a versioned build can be 265 | # created from the source dist. 266 | meson.add_dist_script('_build_utils/copy_version_to_dist.py') 267 | 268 | ### 269 | 270 | #### Included sub-packages 271 | subdir('loess') 272 | ### 273 | -------------------------------------------------------------------------------- /spin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Example stub for running `python -m spin` 4 | # 5 | # Copy this into your project root. 6 | 7 | import os 8 | import sys 9 | import runpy 10 | 11 | sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) 12 | try: 13 | runpy.run_module("spin", run_name="__main__") 14 | except ImportError: 15 | print("Cannot import spin; please install it using") 16 | print() 17 | print(" pip install spin") 18 | print() 19 | sys.exit(1) 20 | -------------------------------------------------------------------------------- /tools/build_theme.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # This script makes it easy to recompile install and tryout 4 | # a theme in case of any changes. It assumes the 5 | # sphinx-bootstrap-theme-customizer package is in the same directory 6 | # as the package, i.e one up the git toplevel. 7 | 8 | color5=$(tput setaf 5) 9 | reset=$(tput sgr0) # reset color codes 10 | 11 | toplevel=$(git rev-parse --show-toplevel) 12 | bootstrap=$(basename $(ls -d theme/static/bootstrap-*/)) 13 | 14 | # Compile theme 15 | cd $toplevel/../sphinx-bootstrap-theme-customizer/ 16 | ./build "$@" 17 | 18 | # Copy theme for sphinx to use 19 | rm -rf $toplevel/doc/theme 20 | cp -rf theme $toplevel/doc 21 | 22 | # Do a hotswap (it may be enough for us to see the results compared to 23 | # regenerating the html) 24 | 25 | cd $toplevel 26 | mkdir -p doc/_build/html/_static/$bootstrap/css 27 | cp $toplevel/doc/{theme/static,_build/html/_static}/$bootstrap/css/bootstrap.min.css 28 | 29 | echo "${color5}success${reset}" 30 | -------------------------------------------------------------------------------- /tools/deploy_documentation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Auto-deploy sphinx documentation with Github Actions 4 | # Credit: https://gist.github.com/domenic/ec8b0fc8ab45f39403dd 5 | set -o xtrace # Print command traces before executing command 6 | set -e # Exit with nonzero exit code if anything fails 7 | echo $BASH_VERSION # For debugging 8 | 9 | # Setup variables 10 | COMMIT_AUTHOR_NAME="Github Actions" 11 | COMMIT_AUTHOR_EMAIL="github-actions@github.com" 12 | release_re='[0-9]\+\.[0-9]\+\.[0-9]\+' 13 | pre_re='\(\(a\|b\|rc\|alpha\|beta\)[0-9]*\)\?' 14 | VERSION=$(echo $SOURCE_TAG | grep "^v${release_re}${pre_re}$") || VERSION="" 15 | RELEASE_VERSION=$(echo $SOURCE_TAG | grep "^v${release_re}$") || RELEASE_VERSION="" 16 | DEST_DIR="" 17 | NEW_RELEASE="No" 18 | 19 | # dev, latest, stable, v1.0.0 20 | if [[ "$SOURCE_BRANCH" == "main" ]]; then 21 | DEST_DIR="latest" 22 | elif [[ "$SOURCE_BRANCH" == "dev" ]]; then 23 | DEST_DIR="dev" 24 | elif [[ "${SOURCE_BRANCH:0:11}" == "refs/tags/v" ]]; then 25 | if [[ "$RELEASE_VERSION" ]]; then 26 | DEST_DIR="$RELEASE_VERSION" 27 | fi 28 | fi 29 | 30 | # A release (tag) without a corresponding directory entry means we 31 | # are seeing it for the first time. 32 | if [[ "$DEST_DIR" == "$RELEASE_VERSION" ]] && [[ ! -d "$DEST_DIR" ]]; then 33 | NEW_RELEASE="Yes" 34 | fi 35 | 36 | # Do not deploy if destination directory has been created at this point. 37 | # If the destination directory exists clear it out 38 | # Otherwise we create it 39 | if [[ -z "$DEST_DIR" ]]; then 40 | echo "Nothing to deploy."; exit 0 41 | elif [[ -d "$DEST_DIR" ]]; then 42 | rm -f "$DEST_DIR/*" 43 | else 44 | mkdir -p $DEST_DIR 45 | fi 46 | 47 | # Copy documentation 48 | touch .nojekyll 49 | cp -a "$HTML_DIR/." $DEST_DIR 50 | 51 | # A new release becomes the stable version 52 | # and also becomes the latest 53 | if [[ "$NEW_RELEASE" == "Yes" ]]; then 54 | rm stable 55 | 56 | ln -s "$DEST_DIR" stable 57 | 58 | rm -rf latest 59 | ln -sf $DEST_DIR latest 60 | 61 | # For debugging 62 | ls -la 63 | fi 64 | 65 | COMMIT_MSG="Documentation: ${DEST_DIR}" 66 | 67 | # Configure commit information 68 | git config user.name "$COMMIT_AUTHOR_NAME" 69 | git config user.email "$COMMIT_AUTHOR_EMAIL" 70 | 71 | # Commit the "changes", i.e. the new version. 72 | # The delta will show diffs between new and old versions. 73 | git add "$DEST_DIR" 74 | git add stable 75 | git add latest 76 | 77 | changes=$(git diff --cached --shortstat) 78 | if [[ -z "$changes" ]]; then 79 | echo "No changes to the output on this push; exiting." 80 | exit 0 81 | fi 82 | 83 | git commit -m "$COMMIT_MSG" 84 | git push 85 | -------------------------------------------------------------------------------- /tools/wheels/check_license.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | check_license.py [MODULE] 4 | 5 | Check the presence of a LICENSE.txt in the installed module directory, 6 | and that it appears to contain text prevalent for a scikit-misc binary 7 | distribution. 8 | 9 | """ 10 | import argparse 11 | import re 12 | import sys 13 | from pathlib import Path 14 | 15 | 16 | def check_text(text): 17 | ok = "Copyright (c)" in text and re.search( 18 | r"This binary distribution of \w+ also bundles the following software", 19 | text, 20 | re.IGNORECASE 21 | ) 22 | return ok 23 | 24 | 25 | def main(): 26 | p = argparse.ArgumentParser(usage=__doc__.rstrip()) 27 | p.add_argument("module", nargs="?", default="skmisc") 28 | args = p.parse_args() 29 | 30 | # Drop '' from sys.path 31 | sys.path.pop(0) 32 | 33 | # Find module path 34 | __import__(args.module) 35 | mod = sys.modules[args.module] 36 | 37 | # Check license text 38 | module_file = Path(mod.__file__) # type: ignore 39 | license_txt = module_file.parent / "LICENSE.txt" 40 | with open(license_txt, encoding="utf-8") as f: 41 | text = f.read() 42 | 43 | ok = check_text(text) 44 | if not ok: 45 | print( 46 | "ERROR: License text {} does not contain expected " 47 | "text fragments\n".format(license_txt) 48 | ) 49 | print(text) 50 | sys.exit(1) 51 | 52 | sys.exit(0) 53 | 54 | 55 | if __name__ == "__main__": 56 | main() 57 | -------------------------------------------------------------------------------- /tools/wheels/cibw_before_build.sh: -------------------------------------------------------------------------------- 1 | set -xe 2 | 3 | PROJECT_DIR="${1:-$PWD}" 4 | 5 | 6 | # remove any cruft from a previous run 7 | rm -rf build 8 | 9 | # Update license 10 | echo "" >> $PROJECT_DIR/LICENSE.txt 11 | echo "----" >> $PROJECT_DIR/LICENSE.txt 12 | echo "" >> $PROJECT_DIR/LICENSE.txt 13 | # cat $PROJECT_DIR/LICENSES_bundled.txt >> $PROJECT_DIR/LICENSE.txt 14 | if [[ $RUNNER_OS == "Linux" ]] ; then 15 | cat $PROJECT_DIR/tools/wheels/LICENSE_linux.txt >> $PROJECT_DIR/LICENSE.txt 16 | elif [[ $RUNNER_OS == "macOS" ]]; then 17 | cat $PROJECT_DIR/tools/wheels/LICENSE_osx.txt >> $PROJECT_DIR/LICENSE.txt 18 | elif [[ $RUNNER_OS == "Windows" ]]; then 19 | cat $PROJECT_DIR/tools/wheels/LICENSE_win32.txt >> $PROJECT_DIR/LICENSE.txt 20 | fi 21 | 22 | if [[ $RUNNER_OS == "Windows" ]]; then 23 | # delvewheel is the equivalent of delocate/auditwheel for windows. 24 | python -m pip install delvewheel wheel 25 | fi 26 | -------------------------------------------------------------------------------- /tools/wheels/cibw_test_command.sh: -------------------------------------------------------------------------------- 1 | set -xe 2 | 3 | if [[ $RUNNER_OS == "Windows" ]]; then 4 | # GH 20391 5 | PY_DIR=$(python -c "import sys; print(sys.prefix)") 6 | mkdir $PY_DIR/libs 7 | fi 8 | 9 | if [[ $RUNNER_OS == "macOS" && $RUNNER_ARCH == "X64" ]]; then 10 | # Not clear why this is needed but it seems on x86_64 this is not the default 11 | # and without it f2py tests fail 12 | export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib" 13 | # Needed so gfortran (not clang) can find system libraries like libm (-lm) 14 | # in f2py tests 15 | export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" 16 | fi 17 | 18 | python -c "import sys; import skmisc; sys.exit(skmisc.test())" 19 | -------------------------------------------------------------------------------- /tools/wheels/howto.txt: -------------------------------------------------------------------------------- 1 | 1. Use the latests tag version of scipy 2 | 3 | 2. Download 4 | - tools/wheels/LICENSE_linux.txt 5 | %s/scipy/scikit_misc/ 6 | - tools/wheels/LICENSE_osx.txt 7 | %s/scipy/scikit_misc/ 8 | - tools/wheels/LICENSE_win32.txt 9 | %s/scipy/scikit_misc/ 10 | - tools/wheels/check_license.py 11 | %s/scipy binary/scikit-misc binary/ 12 | %s/default="scipy"/default="skmisc"/ 13 | - tools/wheels/cibw_before_build_linux.sh 14 | - tools/wheels/cibw_before_build_macos.sh 15 | - tools/wheels/cibw_before_build_win.sh 16 | %s/make_init('scipy')/make_init('skmisc')/ 17 | - tools/wheels/cibw_test_command.sh 18 | %s/import scipy/import skmisc/ 19 | %s{scipy.test{skmisc.test{ 20 | - tools/wheels/gfortran_utils.sh 21 | - tools/wheels/repair_windows.sh 22 | %s/pushd scipy/pushd scikit_misc/ 23 | %s{find ./scipy*{find ./skmisc*{ 24 | - tools/wheels/test.f 25 | 26 | 3. Download 27 | - tools/openblas_support.py 28 | %s/via scipy/via scikit-misc/ 29 | %s/import scipy.linalg/import skmisc.loess/ 30 | %s/import scipy// 31 | %s/scipy.linalg.cython_blas.__file__/skmisc.loess._loess.__file__/ 32 | %s/OUT_SCIPY_DIR/OUT_SKMISC_DIR/ 33 | 34 | 4. Copy 35 | - pyproject.toml 36 | Copy [tool.cibuildwheel.*] sections 37 | 38 | 5. Update 39 | - .github/workflows/build-wheels.yml 40 | * Things to lookout for 41 | - rtools version. compare with scipy/.github/workflows/wheels.yml 42 | 43 | 6. Update 44 | - meson_options.txt 45 | - meson.build 46 | - skmisc/meson.build 47 | - skmisc/loess/meson.build 48 | -------------------------------------------------------------------------------- /tools/wheels/repair_windows.sh: -------------------------------------------------------------------------------- 1 | set -xe 2 | 3 | WHEEL="$1" 4 | DEST_DIR="$2" 5 | 6 | # create a temporary directory in the destination folder and unpack the wheel 7 | # into there 8 | 9 | pushd "$DEST_DIR" 10 | mkdir -p tmp 11 | pushd tmp 12 | wheel unpack "$WHEEL" 13 | pushd scikit_misc* 14 | 15 | # To avoid DLL hell, the file name of libopenblas that's being vendored with 16 | # the wheel has to be name-mangled. delvewheel is unable to name-mangle PYD 17 | # containing extra data at the end of the binary, which frequently occurs when 18 | # building with mingw. 19 | # We therefore find each PYD in the directory structure and strip them. 20 | 21 | for f in $(find ./skmisc* -name '*.pyd'); do strip $f; done 22 | 23 | 24 | # now repack the wheel and overwrite the original 25 | wheel pack . 26 | mv -fv ./*.whl "$WHEEL" 27 | 28 | cd "$DEST_DIR" 29 | rm -rf tmp 30 | 31 | delvewheel repair -w $DEST_DIR $WHEEL 32 | -------------------------------------------------------------------------------- /tools/wheels/test.f: -------------------------------------------------------------------------------- 1 | program first 2 | print *,'This is my first program' 3 | end program first 4 | --------------------------------------------------------------------------------