repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
scipy | scipy-main/scipy/stats/tests/test_contingency.py | import numpy as np
from numpy.testing import (assert_equal, assert_array_equal,
assert_array_almost_equal, assert_approx_equal,
assert_allclose)
import pytest
from pytest import raises as assert_raises
from scipy.special import xlogy
from scipy.stats.contingency imp... | 7,706 | 30.847107 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_continuous_basic.py | import sys
import numpy as np
import numpy.testing as npt
import pytest
from pytest import raises as assert_raises
from scipy.integrate import IntegrationWarning
import itertools
from scipy import stats
from .common_tests import (check_normalization, check_moment,
check_mean_expect,
... | 41,529 | 40.200397 | 112 | py |
scipy | scipy-main/scipy/stats/tests/test_variation.py | import numpy as np
from numpy.testing import assert_equal, assert_allclose
import pytest
from scipy.stats import variation
class TestVariation:
"""
Test class for scipy.stats.variation
"""
def test_ddof(self):
x = np.arange(9.0)
assert_allclose(variation(x, ddof=1), np.sqrt(60/8)/4)
... | 6,245 | 38.283019 | 79 | py |
scipy | scipy-main/scipy/stats/tests/common_tests.py | import pickle
import numpy as np
import numpy.testing as npt
from numpy.testing import assert_allclose, assert_equal
from pytest import raises as assert_raises
import numpy.ma.testutils as ma_npt
from scipy._lib._util import getfullargspec_no_self as _getfullargspec
from scipy import stats
def check_named_results(... | 12,269 | 34.057143 | 83 | py |
scipy | scipy-main/scipy/stats/tests/test_entropy.py | import numpy as np
from numpy.testing import assert_equal, assert_allclose
# avoid new uses of the following; prefer assert/np.testing.assert_allclose
from numpy.testing import (assert_, assert_almost_equal,
assert_array_almost_equal)
import pytest
from pytest import raises as assert_raises
... | 11,277 | 38.296167 | 78 | py |
scipy | scipy-main/scipy/stats/tests/test_discrete_basic.py | import numpy.testing as npt
from numpy.testing import assert_allclose
import numpy as np
import pytest
from scipy import stats
from .common_tests import (check_normalization, check_moment,
check_mean_expect,
check_var_expect, check_skew_expect,
... | 19,847 | 35.552486 | 80 | py |
scipy | scipy-main/scipy/stats/tests/test_kdeoth.py | from scipy import stats, linalg, integrate
import numpy as np
from numpy.testing import (assert_almost_equal, assert_, assert_equal,
assert_array_almost_equal,
assert_array_almost_equal_nulp, assert_allclose)
import pytest
from pytest import raises as assert_raises
... | 20,382 | 32.579901 | 89 | py |
scipy | scipy-main/scipy/stats/tests/test_resampling.py | import numpy as np
import pytest
from scipy.stats import bootstrap, monte_carlo_test, permutation_test
from numpy.testing import assert_allclose, assert_equal, suppress_warnings
from scipy import stats
from scipy import special
from .. import _resampling as _resampling
from scipy._lib._util import rng_integers
from sci... | 70,711 | 39.944991 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_distributions.py | """
Test functions for stats module
"""
import warnings
import re
import sys
import pickle
from pathlib import Path
import os
import json
import platform
from numpy.testing import (assert_equal, assert_array_equal,
assert_almost_equal, assert_array_almost_equal,
as... | 374,190 | 38.626284 | 87 | py |
scipy | scipy-main/scipy/stats/tests/test_multicomp.py | import copy
import numpy as np
import pytest
from numpy.testing import assert_allclose
from scipy import stats
from scipy.stats._multicomp import _pvalue_dunnett, DunnettResult
class TestDunnett:
# For the following tests, p-values were computed using Matlab, e.g.
# sample = [18. 15. 18. 16. 17. 15... | 17,826 | 43.017284 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_multivariate.py | """
Test functions for multivariate normal distributions.
"""
import pickle
from numpy.testing import (assert_allclose, assert_almost_equal,
assert_array_almost_equal, assert_equal,
assert_array_less, assert_)
import pytest
from pytest import raises as assert_rais... | 146,088 | 38.494188 | 97 | py |
scipy | scipy-main/scipy/stats/tests/test_hypotests.py | from itertools import product
import numpy as np
import random
import functools
import pytest
from numpy.testing import (assert_, assert_equal, assert_allclose,
assert_almost_equal) # avoid new uses
from pytest import raises as assert_raises
import scipy.stats as stats
from scipy.stats imp... | 78,912 | 41.494884 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_qmc.py | import os
from collections import Counter
from itertools import combinations, product
import pytest
import numpy as np
from numpy.testing import assert_allclose, assert_equal, assert_array_equal
from scipy.spatial import distance
from scipy.stats import shapiro
from scipy.stats._sobol import _test_find_index
from sci... | 52,217 | 37.452135 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_censored_data.py | # Tests for the CensoredData class.
import pytest
import numpy as np
from numpy.testing import assert_equal, assert_array_equal
from scipy.stats import CensoredData
class TestCensoredData:
def test_basic(self):
uncensored = [1]
left = [0]
right = [2, 5]
interval = [[2, 3]]
... | 6,935 | 44.333333 | 78 | py |
scipy | scipy-main/scipy/stats/tests/test_discrete_distns.py | import pytest
import itertools
from scipy.stats import (betabinom, hypergeom, nhypergeom, bernoulli,
boltzmann, skellam, zipf, zipfian, binom, nbinom,
nchypergeom_fisher, nchypergeom_wallenius, randint)
import numpy as np
from numpy.testing import (
assert_almost_... | 20,463 | 34.466205 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_mstats_extras.py | import numpy as np
import numpy.ma as ma
import scipy.stats.mstats as ms
from numpy.testing import (assert_equal, assert_almost_equal, assert_,
assert_allclose)
def test_compare_medians_ms():
x = np.arange(7)
y = x + 10
assert_almost_equal(ms.compare_medians_ms(x, y), 0)
y... | 7,297 | 41.184971 | 82 | py |
scipy | scipy-main/scipy/stats/tests/test_boost_ufuncs.py | import pytest
import numpy as np
from numpy.testing import assert_allclose
from scipy.stats import _boost
type_char_to_type_tol = {'f': (np.float32, 32*np.finfo(np.float32).eps),
'd': (np.float64, 32*np.finfo(np.float64).eps)}
# Each item in this list is
# (func, args, expected_value)
# A... | 1,824 | 37.020833 | 79 | py |
scipy | scipy-main/scipy/stats/tests/__init__.py | 0 | 0 | 0 | py | |
scipy | scipy-main/scipy/stats/tests/test_sensitivity_analysis.py | from typing import Tuple
import numpy as np
from numpy.testing import assert_allclose, assert_array_less
import pytest
from scipy import stats
from scipy.stats import sobol_indices
from scipy.stats._resampling import BootstrapResult
from scipy.stats._sensitivity_analysis import (
BootstrapSobolResult, f_ishigami,... | 10,160 | 32.534653 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_fit.py | import os
import numpy as np
import numpy.testing as npt
from numpy.testing import assert_allclose, assert_equal
import pytest
from scipy import stats
from scipy.optimize import differential_evolution
from .test_continuous_basic import distcont
from scipy.stats._distn_infrastructure import FitError
from scipy.stats._d... | 43,633 | 42.941591 | 99 | py |
scipy | scipy-main/scipy/stats/tests/test_rank.py | import numpy as np
from numpy.testing import assert_equal, assert_array_equal
from scipy.stats import rankdata, tiecorrect
import pytest
class TestTieCorrect:
def test_empty(self):
"""An empty array requires no correction, should return 1.0."""
ranks = np.array([], dtype=np.float64)
c = ... | 11,321 | 33.623853 | 77 | py |
scipy | scipy-main/scipy/stats/tests/test_stats.py | """ Test functions for stats module
WRITTEN BY LOUIS LUANGKESORN <lluang@yahoo.com> FOR THE STATS MODULE
BASED ON WILKINSON'S STATISTICS QUIZ
https://www.stanford.edu/~clint/bench/wilk.txt
Additional tests by a host of SciPy developers.
"""
import os
import re
import warnings
from collections import n... | 347,719 | 40.56844 | 124 | py |
scipy | scipy-main/scipy/stats/tests/test_mstats_basic.py | """
Tests for the stats.mstats module (support for masked arrays)
"""
import warnings
import platform
import numpy as np
from numpy import nan
import numpy.ma as ma
from numpy.ma import masked, nomask
import scipy.stats.mstats as mstats
from scipy import stats
from .common_tests import check_named_results
import pyte... | 85,050 | 41.042017 | 108 | py |
scipy | scipy-main/scipy/stats/tests/test_crosstab.py | import pytest
import numpy as np
from numpy.testing import assert_array_equal, assert_equal
from scipy.stats.contingency import crosstab
@pytest.mark.parametrize('sparse', [False, True])
def test_crosstab_basic(sparse):
a = [0, 0, 9, 9, 0, 0, 9]
b = [2, 1, 3, 1, 2, 3, 3]
expected_avals = [0, 9]
expect... | 3,882 | 32.474138 | 73 | py |
scipy | scipy-main/scipy/stats/tests/test_generation/reference_distributions.py | import numpy as np
import mpmath
from mpmath import mp
class ReferenceDistribution:
"""Minimalist distribution infrastructure for generating reference data.
The purpose is to generate reference values for unit tests of SciPy
distribution accuracy and robustness.
Handles array input with standard bro... | 15,416 | 34.770302 | 83 | py |
scipy | scipy-main/scipy/stats/tests/test_generation/studentized_range_mpmath_ref.py | # To run this script, run
# `python studentized_range_mpmath_ref.py`
# in the "scipy/stats/tests/" directory
# This script generates a JSON file "./data/studentized_range_mpmath_ref.json"
# that is used to compare the accuracy of `studentized_range` functions against
# precise (20 DOP) results generated using `mpmath`... | 7,631 | 29.166008 | 79 | py |
scipy | scipy-main/scipy/stats/tests/test_generation/reference_distribution_infrastructure_tests.py | # Note: this file is to be run locally, not on CI. It is only for tests of the
# reference distribution *infrastructure*; unit tests of SciPy distributions
# do not go here.
import numpy as np
import pytest
from scipy import stats
from numpy.testing import assert_allclose
import scipy.stats.tests.test_generation.refe... | 3,041 | 32.428571 | 78 | py |
scipy | scipy-main/scipy/stats/tests/data/fisher_exact_results_from_r.py | # DO NOT EDIT THIS FILE!
# This file was generated by the R script
# generate_fisher_exact_results_from_r.R
# The script was run with R version 3.6.2 (2019-12-12) at 2020-11-09 06:16:09
from collections import namedtuple
import numpy as np
Inf = np.inf
Parameters = namedtuple('Parameters',
... | 27,349 | 43.983553 | 77 | py |
scipy | scipy-main/scipy/stats/tests/data/_mvt.py | # flake8: noqa
import math
import numpy as np
from scipy import special
from scipy.stats._qmc import primes_from_2_to
def _primes(n):
# Defined to facilitate comparison between translation and source
# In Matlab, primes(10.5) -> first four primes, primes(11.5) -> first five
return primes_from_2_to(math.ce... | 6,920 | 39.00578 | 101 | py |
scipy | scipy-main/scipy/stats/_unuran/setup.py | import os
def unuran_pre_build_hook(build_clib, build_info):
from scipy._build_utils.compiler_helper import (get_c_std_flag,
try_compile, has_flag)
c = build_clib.compiler
c_flag = get_c_std_flag(c)
if c_flag is not None:
if "extra_compiler_a... | 4,856 | 33.204225 | 74 | py |
scipy | scipy-main/scipy/stats/_unuran/__init__.py | 0 | 0 | 0 | py | |
scipy | scipy-main/scipy/stats/_rcont/setup.py | from os.path import join
import numpy as np
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('_rcont', parent_package, top_path)
config.add_extension(
'rcont',
sources=['rcont.c', '_rcont.c', 'logfactorial.c']... | 730 | 27.115385 | 62 | py |
scipy | scipy-main/scipy/stats/_rcont/__init__.py | #
from .rcont import rvs_rcont1, rvs_rcont2
__all__ = ["rvs_rcont1", "rvs_rcont2"]
| 84 | 16 | 41 | py |
scipy | scipy-main/scipy/fft/_realtransforms.py | from ._basic import _dispatch
from scipy._lib.uarray import Dispatchable
import numpy as np
__all__ = ['dct', 'idct', 'dst', 'idst', 'dctn', 'idctn', 'dstn', 'idstn']
@_dispatch
def dctn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False,
workers=None, *, orthogonalize=None):
"""
Return mult... | 25,282 | 35.430836 | 88 | py |
scipy | scipy-main/scipy/fft/setup.py | def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('fft', parent_package, top_path)
config.add_subpackage('_pocketfft')
config.add_data_dir('tests')
return config
if __name__ == '__main__':
from numpy.distutils.core i... | 381 | 30.833333 | 59 | py |
scipy | scipy-main/scipy/fft/_basic.py | from scipy._lib.uarray import generate_multimethod, Dispatchable
import numpy as np
def _x_replacer(args, kwargs, dispatchables):
"""
uarray argument replacer to replace the transform input array (``x``)
"""
if len(args) > 0:
return (dispatchables[0],) + args[1:], kwargs
kw = kwargs.copy()... | 62,991 | 37.645399 | 90 | py |
scipy | scipy-main/scipy/fft/_helper.py | from functools import update_wrapper, lru_cache
from ._pocketfft import helper as _helper
def next_fast_len(target, real=False):
"""Find the next fast size of input data to ``fft``, for zero-padding, etc.
SciPy's FFT algorithms gain their speed by a recursive divide and conquer
strategy. This relies on ... | 3,435 | 32.686275 | 80 | py |
scipy | scipy-main/scipy/fft/_fftlog.py | '''Fast Hankel transforms using the FFTLog algorithm.
The implementation closely follows the Fortran code of Hamilton (2000).
added: 14/11/2020 Nicolas Tessore <n.tessore@ucl.ac.uk>
'''
import numpy as np
from warnings import warn
from ._basic import rfft, irfft
from ..special import loggamma, poch
__all__ = [
... | 11,879 | 29.383632 | 79 | py |
scipy | scipy-main/scipy/fft/_fftlog_multimethods.py | '''Multimethods for fast Hankel transforms.
'''
import numpy as np
from ._basic import _dispatch
from ._fftlog import fht as _fht
from ._fftlog import ifht as _ifht
from scipy._lib.uarray import Dispatchable
__all__ = ['fht', 'ifht']
@_dispatch
def fht(a, dln, mu, offset=0.0, bias=0.0):
"""fht multimethod."""... | 575 | 18.2 | 43 | py |
scipy | scipy-main/scipy/fft/__init__.py | """
==============================================
Discrete Fourier transforms (:mod:`scipy.fft`)
==============================================
.. currentmodule:: scipy.fft
Fast Fourier Transforms (FFTs)
==============================
.. autosummary::
:toctree: generated/
fft - Fast (discrete) Fourier Transf... | 3,567 | 30.298246 | 78 | py |
scipy | scipy-main/scipy/fft/_debug_backends.py | import numpy as np
class NumPyBackend:
"""Backend that uses numpy.fft"""
__ua_domain__ = "numpy.scipy.fft"
@staticmethod
def __ua_function__(method, args, kwargs):
kwargs.pop("overwrite_x", None)
fn = getattr(np.fft, method.__name__, None)
return (NotImplemented if fn is None
... | 598 | 25.043478 | 64 | py |
scipy | scipy-main/scipy/fft/_backend.py | import scipy._lib.uarray as ua
from . import _fftlog
from . import _pocketfft
class _ScipyBackend:
"""The default backend for fft calculations
Notes
-----
We use the domain ``numpy.scipy`` rather than ``scipy`` because ``uarray``
treats the domain as a hierarchy. This means the user can install a... | 6,388 | 32.276042 | 104 | py |
scipy | scipy-main/scipy/fft/_pocketfft/setup.py | def pre_build_hook(build_ext, ext):
from scipy._build_utils.compiler_helper import (
set_cxx_flags_hook, try_add_flag, try_compile, has_flag)
cc = build_ext._cxx_compiler
args = ext.extra_compile_args
set_cxx_flags_hook(build_ext, ext)
if cc.compiler_type == 'msvc':
args.append('/E... | 1,819 | 36.142857 | 80 | py |
scipy | scipy-main/scipy/fft/_pocketfft/helper.py | from numbers import Number
import operator
import os
import threading
import contextlib
import numpy as np
# good_size is exposed (and used) from this import
from .pypocketfft import good_size # noqa: F401
_config = threading.local()
_cpu_count = os.cpu_count()
def _iterable_of_int(x, name=None):
"""Convert ``... | 5,721 | 25.368664 | 79 | py |
scipy | scipy-main/scipy/fft/_pocketfft/realtransforms.py | import numpy as np
from . import pypocketfft as pfft
from .helper import (_asfarray, _init_nd_shape_and_axes, _datacopied,
_fix_shape, _fix_shape_1d, _normalization, _workers)
import functools
def _r2r(forward, transform, x, type=2, n=None, axis=-1, norm=None,
overwrite_x=False, workers=... | 3,378 | 29.441441 | 75 | py |
scipy | scipy-main/scipy/fft/_pocketfft/__init__.py | """ FFT backend using pypocketfft """
from .basic import *
from .realtransforms import *
from .helper import *
from scipy._lib._testutils import PytestTester
test = PytestTester(__name__)
del PytestTester
| 207 | 19.8 | 46 | py |
scipy | scipy-main/scipy/fft/_pocketfft/basic.py | """
Discrete Fourier Transforms - basic.py
"""
import numpy as np
import functools
from . import pypocketfft as pfft
from .helper import (_asfarray, _init_nd_shape_and_axes, _datacopied,
_fix_shape, _fix_shape_1d, _normalization,
_workers)
def c2c(forward, x, n=None, axis=-1, ... | 9,841 | 32.026846 | 79 | py |
scipy | scipy-main/scipy/fft/_pocketfft/tests/test_real_transforms.py | from os.path import join, dirname
from typing import Callable, Dict, Tuple, Union, Type
import numpy as np
from numpy.testing import (
assert_array_almost_equal, assert_equal, assert_allclose)
import pytest
from pytest import raises as assert_raises
from scipy.fft._pocketfft.realtransforms import (
dct, idct,... | 16,438 | 32.277328 | 83 | py |
scipy | scipy-main/scipy/fft/_pocketfft/tests/test_basic.py | # Created by Pearu Peterson, September 2002
from numpy.testing import (assert_, assert_equal, assert_array_almost_equal,
assert_array_almost_equal_nulp, assert_array_less,
assert_allclose)
import pytest
from pytest import raises as assert_raises
from scipy.fft._poc... | 35,617 | 34.022616 | 80 | py |
scipy | scipy-main/scipy/fft/_pocketfft/tests/__init__.py | 0 | 0 | 0 | py | |
scipy | scipy-main/scipy/fft/tests/test_numpy.py | import queue
import threading
import multiprocessing
import numpy as np
import pytest
from numpy.random import random
from numpy.testing import (
assert_array_almost_equal, assert_array_equal, assert_allclose
)
from pytest import raises as assert_raises
import scipy.fft as fft
def fft1(x):
L = len(... | 14,432 | 38.542466 | 81 | py |
scipy | scipy-main/scipy/fft/tests/test_real_transforms.py | import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
import pytest
from scipy.fft import dct, idct, dctn, idctn, dst, idst, dstn, idstn
import scipy.fft as fft
from scipy import fftpack
import math
SQRT_2 = math.sqrt(2)
# scipy.fft wraps the fftpack versions but with normalized inverse tr... | 7,637 | 34.361111 | 78 | py |
scipy | scipy-main/scipy/fft/tests/test_fftlog.py | import warnings
import numpy as np
from numpy.testing import assert_allclose
import pytest
from scipy.fft._fftlog import fht, ifht, fhtoffset
from scipy.special import poch
def test_fht_agrees_with_fftlog():
# check that fht numerically agrees with the output from Fortran FFTLog,
# the results were generated... | 5,819 | 34.925926 | 76 | py |
scipy | scipy-main/scipy/fft/tests/mock_backend.py | import numpy as np
class _MockFunction:
def __init__(self, return_value = None):
self.number_calls = 0
self.return_value = return_value
self.last_args = ([], {})
def __call__(self, *args, **kwargs):
self.number_calls += 1
self.last_args = (args, kwargs)
return s... | 1,769 | 28.5 | 49 | py |
scipy | scipy-main/scipy/fft/tests/test_backend.py | from functools import partial
import numpy as np
import scipy.fft
from scipy.fft import _fftlog, _pocketfft, set_backend
from scipy.fft.tests import mock_backend
from numpy.testing import assert_allclose, assert_equal
import pytest
fnames = ('fft', 'fft2', 'fftn',
'ifft', 'ifft2', 'ifftn',
'rfft'... | 4,256 | 42 | 79 | py |
scipy | scipy-main/scipy/fft/tests/test_helper.py | from scipy.fft._helper import next_fast_len, _init_nd_shape_and_axes
from numpy.testing import assert_equal, assert_array_equal
from pytest import raises as assert_raises
import pytest
import numpy as np
import sys
_5_smooth_numbers = [
2, 3, 4, 5, 6, 8, 9, 10,
2 * 3 * 5,
2**3 * 3**5,
2**3 * 3**3 * 5**... | 9,795 | 31.54485 | 80 | py |
scipy | scipy-main/scipy/fft/tests/__init__.py | 0 | 0 | 0 | py | |
scipy | scipy-main/scipy/fft/tests/test_multithreading.py | from scipy import fft
import numpy as np
import pytest
from numpy.testing import assert_allclose
import multiprocessing
import os
@pytest.fixture(scope='module')
def x():
return np.random.randn(512, 128) # Must be large enough to qualify for mt
@pytest.mark.parametrize("func", [
fft.fft, fft.ifft, fft.fft2... | 2,132 | 24.392857 | 78 | py |
scipy | scipy-main/scipy/fft/tests/test_fft_function.py | import numpy as np
import subprocess
import sys
TEST_BODY = r"""
import pytest
import numpy as np
from numpy.testing import assert_allclose
import scipy
import sys
import pytest
np.random.seed(1234)
x = np.random.randn(10) + 1j * np.random.randn(10)
X = np.fft.fft(x)
# Callable before scipy.fft is imported
with pytes... | 1,048 | 22.840909 | 72 | py |
scipy | scipy-main/doc/source/scipyoptdoc.py | """
===========
scipyoptdoc
===========
Proper docstrings for scipy.optimize.minimize et al.
Usage::
.. scipy-optimize:function:: scipy.optimize.minimize
:impl: scipy.optimize._optimize._minimize_nelder_mead
:method: Nelder-Mead
Produces output similar to autodoc, except
- The docstring is obtain... | 5,487 | 33.515723 | 104 | py |
scipy | scipy-main/doc/source/conf.py | import math
import os
from os.path import relpath, dirname
import re
import sys
import warnings
from datetime import date
from docutils import nodes
from docutils.parsers.rst import Directive
import matplotlib
import matplotlib.pyplot as plt
from numpydoc.docscrape_sphinx import SphinxDocString
from sphinx.util import... | 16,583 | 31.839604 | 87 | py |
scipy | scipy-main/doc/source/doi_role.py | # -*- coding: utf-8 -*-
"""
doilinks
~~~~~~~~
Extension to add links to DOIs. With this extension you can use e.g.
:doi:`10.1016/S0022-2836(05)80360-2` in your documents. This will
create a link to a DOI resolver
(``https://doi.org/10.1016/S0022-2836(05)80360-2``).
The link caption will be t... | 1,785 | 32.698113 | 77 | py |
scipy | scipy-main/doc/source/tutorial/examples/newton_krylov_preconditioning.py | import numpy as np
from scipy.optimize import root
from scipy.sparse import spdiags, kron
from scipy.sparse.linalg import spilu, LinearOperator
from numpy import cosh, zeros_like, mgrid, zeros, eye
# parameters
nx, ny = 75, 75
hx, hy = 1./(nx-1), 1./(ny-1)
P_left, P_right = 0, 0
P_top, P_bottom = 1, 0
def get_precon... | 2,492 | 25.242105 | 70 | py |
scipy | scipy-main/doc/source/tutorial/examples/optimize_global_1.py | import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize
def eggholder(x):
return (-(x[1] + 47) * np.sin(np.sqrt(abs(x[0]/2 + (x[1] + 47))))
-x[0] * np.sin(np.sqrt(abs(x[0] - (x[1] + 47)))))
bounds = [(-512, 512), (-512, 512)]
x = np.arange(-512, 513)
y = np.arange(-512, 513)
... | 1,623 | 30.230769 | 75 | py |
scipy | scipy-main/doc/source/tutorial/examples/normdiscr_plot2.py | import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
npoints = 20 # number of integer support points of the distribution minus 1
npointsh = npoints // 2
npointsf = float(npoints)
nbound = 4 # bounds for the truncated normal
normbound = (1 + 1/npointsf) * nbound # actual bounds of truncated nor... | 1,631 | 33 | 81 | py |
scipy | scipy-main/doc/source/tutorial/examples/plot_boundary_modes.py | import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
img = np.array([-2, -1, 0, 1, 2], float)
x = np.linspace(-2, 6, num=1000)
modes = ['constant', 'grid-constant', 'nearest', 'reflect', 'mirror', 'wrap',
'grid-wrap']
fig, axes = plt.subplots(len(modes), 3, figsize=(11, 8), sharex=Tr... | 1,744 | 31.314815 | 77 | py |
scipy | scipy-main/doc/source/tutorial/examples/normdiscr_plot1.py | import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
npoints = 20 # number of integer support points of the distribution minus 1
npointsh = npoints // 2
npointsf = float(npoints)
nbound = 4 # bounds for the truncated normal
normbound = (1 + 1/npointsf) * nbound # actual bounds of truncated nor... | 1,536 | 33.931818 | 79 | py |
scipy | scipy-main/doc/source/tutorial/examples/gaussian_filter_plot1.py | import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage import gaussian_filter
grids = 2
boxs = 5
voxelarray = np.zeros((boxs * grids, boxs * grids, boxs * grids))
i = 1
for xi in range(0, 2):
for yi in range(0, 2):
for zi in range(0, 2):
voxelarray[
xi * boxs: x... | 1,256 | 25.744681 | 76 | py |
scipy | scipy-main/doc/source/tutorial/examples/morphology_binary_dilation_erosion.py | import matplotlib.pyplot as plt
import numpy as np
import scipy.ndimage
# code for ball taken from
# https://github.com/scikit-image/scikit-image/blob/main/skimage/morphology/footprints.py#L225-L252
# and therefore same as `from skimage.morphology import ball`
def ball(radius, dtype=np.uint8):
n = 2 * radius + 1... | 1,332 | 28.622222 | 99 | py |
scipy | scipy-main/doc/source/tutorial/examples/optimize_global_2.py | import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def eggholder(x):
return (-(x[1] + 47) * np.sin(np.sqrt(abs(x[0]/2 + (x[1] + 47))))
-x[0] * np.sin(np.sqrt(abs(x[0] - (x[1] + 47)))))
bounds = [(-512, 512), (-512, 512)]
x = np.arange(-512, 513)
y = np.arange... | 657 | 24.307692 | 70 | py |
scipy | scipy-main/doc/source/tutorial/examples/plot_interp_grid.py | import math
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker
orders = [2, 3]
fig, axes = plt.subplots(1, len(orders), figsize=(11, 5))
n_cells = 7 # grid will be size (n_cells, n_cells)
# desired interpolation coordinate (xi, yi)
xi, yi = 3.3, 3.7
def get_start(cc, order):
if ... | 1,993 | 30.15625 | 70 | py |
scipy | scipy-main/doc/source/tutorial/examples/ndimage/3D_binary_structure.py | import matplotlib.pyplot as plt
import scipy.ndimage
def plot_voxels(varray, ax, title):
ax.view_init(20, 200)
ax.voxels(varray, edgecolor="k")
ax.set_title(title, fontsize=30)
fig = plt.figure(figsize=(16, 9))
for i in [1, 2, 3]:
ax = fig.add_subplot(1, 3, i, projection="3d")
arrray = scipy.nd... | 454 | 21.75 | 64 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/kde_plot4.py | from functools import partial
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
def my_kde_bandwidth(obj, fac=1./5):
"""We use Scott's Rule, multiplied by a constant factor."""
return np.power(obj.n, -1./(obj.d+4)) * fac
loc1, scale1, size1 = (-2, 1, 175)
loc2, scale2, size2 = (2, ... | 1,457 | 31.4 | 78 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/hinv_plot.py | import numpy as np
from scipy.stats.sampling import NumericalInverseHermite
from scipy.stats import norm
from scipy.special import ndtr
import matplotlib.pyplot as plt
class StandardNormal:
def pdf(self, x):
return 1/np.sqrt(2*np.pi) * np.exp(-x**2 / 2)
def cdf(self, x):
return ndtr(x)
dist... | 752 | 24.965517 | 72 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_conv_mc.py | """Integration convergence.
The function is a synthetic example specifically designed
to verify the correctness of the implementation [1]_.
References
----------
.. [1] Art B. Owen. On dropping the first Sobol' point. arXiv 2008.08051,
2020.
"""
from collections import namedtuple
import numpy as np
import matpl... | 1,704 | 22.040541 | 73 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_mc.py | """Multiple MC to show how it can be bad."""
from scipy.stats import qmc
from scipy.stats._qmc import check_random_state
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng()
n_sample = 256
dim = 2
sample = {}
# MC
sample['MC 1'] = rng.random((n_sample, dim))
sample["MC 2"] = rng.random... | 606 | 18.580645 | 58 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/kde_plot3.py | import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
rng = np.random.default_rng()
x1 = rng.normal(size=200) # random data, normal distribution
xs = np.linspace(x1.min()-1, x1.max()+1, 200)
kde1 = stats.gaussian_kde(x1)
kde2 = stats.gaussian_kde(x1, bw_method='silverman')
fig = plt.figure(fig... | 1,249 | 28.761905 | 78 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_conv_mc_sobol.py | """Integration convergence comparison: MC vs Sobol'.
The function is a synthetic example specifically designed
to verify the correctness of the implementation [2]_.
References
----------
.. [1] I. M. Sobol. The distribution of points in a cube and the accurate
evaluation of integrals. Zh. Vychisl. Mat. i Mat. Phy... | 2,387 | 24.956522 | 73 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_mc_qmc.py | """MC vs QMC in terms of space filling."""
from scipy.stats import qmc
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng()
n_sample = 256
dim = 2
sample = {}
# MC
sample['MC'] = rng.random((n_sample, dim))
# Sobol'
engine = qmc.Sobol(d=dim, seed=rng)
sample["Sobol'"] = engine.random(... | 673 | 18.823529 | 74 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/mgc_plot3.py | import numpy as np
import matplotlib.pyplot as plt
def mgc_plot(x, y, sim_name):
"""Plot sim and MGC-plot"""
# simulation
plt.figure(figsize=(8, 8))
ax = plt.gca()
ax.set_title(sim_name + " Simulation", fontsize=20)
ax.scatter(x, y)
ax.set_xlabel('X', fontsize=15)
ax.set_ylabel('Y', fo... | 648 | 23.037037 | 58 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_discrepancy.py | """Calculate the discrepancy of 2 designs and compare them."""
import numpy as np
from scipy.stats import qmc
import matplotlib.pyplot as plt
space_1 = np.array([[1, 3], [2, 6], [3, 2], [4, 5], [5, 1], [6, 4]])
space_2 = np.array([[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 6]])
l_bounds = [0.5, 0.5]
u_bounds = [6.5... | 847 | 28.241379 | 74 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/kde_plot5.py | import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
def measure(n):
"""Measurement model, return two coupled measurements."""
m1 = np.random.normal(size=n)
m2 = np.random.normal(scale=0.5, size=n)
return m1+m2, m1-m2
m1, m2 = measure(2000)
xmin = m1.min()
xmax = m1.max()
ymin ... | 814 | 22.285714 | 61 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/mgc_plot2.py | import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import multiscale_graphcorr
def mgc_plot(x, y, mgc_dict):
"""Plot sim and MGC-plot"""
plt.figure(figsize=(8, 8))
ax = plt.gca()
# local correlation map
mgc_map = mgc_dict["mgc_map"]
# draw heatmap
ax.set_title("Local Cor... | 1,282 | 25.183673 | 61 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/kde_plot2.py | import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
x1 = np.array([-7, -5, 1, 4, 5], dtype=float)
x_eval = np.linspace(-10, 10, num=200)
kde1 = stats.gaussian_kde(x1)
kde2 = stats.gaussian_kde(x1, bw_method='silverman')
def my_kde_bandwidth(obj, fac=1./5):
"""We use Scott's Rule, multiplied... | 630 | 26.434783 | 63 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/mgc_plot1.py | import numpy as np
import matplotlib.pyplot as plt
def mgc_plot(x, y, sim_name):
"""Plot sim and MGC-plot"""
# simulation
plt.figure(figsize=(8, 8))
ax = plt.gca()
ax.set_title(sim_name + " Simulation", fontsize=20)
ax.scatter(x, y)
ax.set_xlabel('X', fontsize=15)
ax.set_ylabel('Y', fo... | 577 | 21.230769 | 55 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_sobol_halton.py | """Sobol' and Halton sequences."""
from scipy.stats import qmc
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng()
n_sample = 256
dim = 2
sample = {}
# Sobol'
engine = qmc.Sobol(d=dim, seed=rng)
sample["Sobol'"] = engine.random(n_sample)
# Halton
engine = qmc.Halton(d=dim, seed=rng)
... | 706 | 19.2 | 74 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/mgc_plot4.py | import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import multiscale_graphcorr
def mgc_plot(x, y, mgc_dict):
"""Plot sim and MGC-plot"""
plt.figure(figsize=(8, 8))
ax = plt.gca()
# local correlation map
mgc_map = mgc_dict["mgc_map"]
# draw heatmap
ax.set_title("Local Cor... | 1,352 | 26.612245 | 61 | py |
scipy | scipy-main/doc/source/tutorial/stats/plots/qmc_plot_curse.py | """Visualize the curse-of-dimensionality.
It presents a saturated design in 1, 2 and 3 dimensions for a
given discretization.
"""
import matplotlib.pyplot as plt
import numpy as np
disc = 10
x = np.linspace(0, 1, disc)
y = np.linspace(0, 1, disc)
z = np.linspace(0, 1, disc)
xx, yy, zz = np.meshgrid(x, y, z)
fig = ... | 770 | 19.289474 | 61 | py |
PTMCMCSampler | PTMCMCSampler-master/setup.py | from setuptools import setup
setup(
name="ptmcmcsampler",
author="Justin A. Ellis",
author_email="justin.ellis18@gmail.com",
packages=["PTMCMCSampler"],
package_dir={"PTMCMCSampler": "PTMCMCSampler"},
url="https://github.com/jellis18/PTMCMCSampler",
license="MIT",
zip_safe=False,
de... | 1,284 | 37.939394 | 101 | py |
PTMCMCSampler | PTMCMCSampler-master/examples/simple.py | #!/usr/bin/env python
# coding: utf-8
from pathlib import Path
import numpy as np
from PTMCMCSampler import PTMCMCSampler
# ## Define the likelihood and posterior
#
# Functions must read in parameter vector and output log-likelihood or log-prior.
# Usually easiest to use a class if you need to store some other dat... | 2,794 | 21.723577 | 99 | py |
PTMCMCSampler | PTMCMCSampler-master/tests/test_simple.py | """
Integration tests to make sure the sampler at least runs. Better than nothing...
"""
import shutil
from unittest import TestCase
import numpy as np
from mpi4py import MPI
from PTMCMCSampler import PTMCMCSampler
from PTMCMCSampler import nompi4py as MPIDUMMY
class GaussianLikelihood(object):
def __init__(sel... | 2,808 | 25.5 | 107 | py |
PTMCMCSampler | PTMCMCSampler-master/tests/test_nuts.py | import shutil
from unittest import TestCase
import numpy as np
import scipy.linalg as sl
import scipy.optimize as so
from mpi4py import MPI
from PTMCMCSampler import PTMCMCSampler
from PTMCMCSampler import nompi4py as MPIDUMMY
class GaussianLikelihood(object):
def __init__(self, ndim=2, pmin=-10, pmax=10):
... | 6,886 | 29.339207 | 115 | py |
PTMCMCSampler | PTMCMCSampler-master/docs/conf.py | # -*- coding: utf-8 -*-
#
# PTMCMCSampler documentation build configuration file, created by
# sphinx-quickstart on Sat Mar 28 20:40:33 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.... | 10,464 | 30.521084 | 95 | py |
PTMCMCSampler | PTMCMCSampler-master/PTMCMCSampler/nutsjump.py | """
Implementation of the No-U-Turn-Sampler. Code follows algorithm 6 from the NUTS
paper (Hoffman & Gelman, 2011)
reference: arXiv:1111.4246
"The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte
Carlo", Matthew D. Hoffman & Andrew Gelman
Rutger van Haasteren
"""
import os
import sys
import ... | 30,428 | 35.181926 | 119 | py |
PTMCMCSampler | PTMCMCSampler-master/PTMCMCSampler/PTMCMCSampler.py | import os
import sys
import time
import numpy as np
from .nutsjump import HMCJump, MALAJump, NUTSJump
try:
from mpi4py import MPI
except ImportError:
print("Optional mpi4py package is not installed. MPI support is not available.")
from . import nompi4py as MPI
try:
import acor
except ImportError:
... | 34,034 | 32.075802 | 118 | py |
PTMCMCSampler | PTMCMCSampler-master/PTMCMCSampler/nompi4py.py | # Dummy class for packages that have no MPI
class MPIDummy(object):
def __init__(self):
pass
def Get_rank(self):
return 0
def Get_size(self):
return 1
def barrier(self):
pass
def send(self, lnlike0, dest=1, tag=55):
pass
def recv(self, source=1, tag=5... | 702 | 17.5 | 44 | py |
PTMCMCSampler | PTMCMCSampler-master/PTMCMCSampler/__init__.py | from PTMCMCSampler import PTMCMCSampler # noqa: F401
from .version import version
__version__ = version
| 107 | 17 | 53 | py |
MENET | MENET-master/light/inference.py | # -*- coding: utf-8 -*-
# @File : derain_wgan_tf/inference.py
# @Info : @ TSMC-SIGGRAPH, 2019/5/30
# @Desc :
# -.-.. - ... -- -.-. .-.. .- -... .---. -.-- ..- .-.. --- -. --. ..-. .- -.
import os
from datetime import datetime
import cv2
import numpy as np
import tensorflow as tf
from configuration impo... | 2,443 | 37.793651 | 119 | py |
MENET | MENET-master/light/build_h5_dataset.py | # -*- coding: utf-8 -*-
# @File : derain_gradnorm_tf/build_h5_dataset.py
# @Info : @ TSMC-SIGGRAPH, 2019/5/29
# @Desc :
# -.-.. - ... -- -.-. .-.. .- -... .---. -.-- ..- .-.. --- -. --. ..-. .- -.
import os
from random import shuffle
import h5py
import numpy as np
from PIL import Image
from configura... | 4,172 | 42.926316 | 127 | py |
MENET | MENET-master/light/validation.py | # -*- coding: utf-8 -*-
# @File : derain_wgan_tf/validation.py
# @Info : @ TSMC-SIGGRAPH, 2019/5/30
# @Desc :
# -.-.. - ... -- -.-. .-.. .- -... .---. -.-- ..- .-.. --- -. --. ..-. .- -.
import os
import platform
from datetime import datetime
from time import time
import numpy as np
import tensorflow ... | 2,654 | 31.777778 | 114 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.