コード例 #1
0
ファイル: polymer.py プロジェクト: agreen991/refl1d
def _getmax(t, seen_t={}):
    try:
        return seen_t[t]
    except KeyError:
        from numpy.core import getlimits
        fmax = getlimits.finfo(t).max
        seen_t[t]=fmax
        return fmax
コード例 #2
0
ファイル: polymer.py プロジェクト: usnistgov/refl1d
def _getmax(t, seen_t={}):
    try:
        return seen_t[t]
    except KeyError:
        from numpy.core import getlimits
        fmax = getlimits.finfo(t).max
        seen_t[t] = fmax
        return fmax
コード例 #3
0
def real_if_close(a, tol=100):
    """
    If input is complex with all imaginary parts close to zero, return
    real parts.

    "Close to zero" is defined as `tol` * (machine epsilon of the type for
    `a`).

    Parameters
    ----------
    a : array_like
        Input array.
    tol : float
        Tolerance in machine epsilons for the complex part of the elements
        in the array.

    Returns
    -------
    out : ndarray
        If `a` is real, the type of `a` is used for the output.  If `a`
        has complex elements, the returned type is float.

    See Also
    --------
    real, imag, angle

    Notes
    -----
    Machine epsilon varies from machine to machine and between data types
    but Python floats on most platforms have a machine epsilon equal to
    2.2204460492503131e-16.  You can use 'np.finfo(float).eps' to print
    out the machine epsilon for floats.

    Examples
    --------
    >>> np.finfo(float).eps
    2.2204460492503131e-16 # may vary

    >>> np.real_if_close([2.1 + 4e-14j, 5.2 + 3e-15j], tol=1000)
    array([2.1, 5.2])
    >>> np.real_if_close([2.1 + 4e-13j, 5.2 + 3e-15j], tol=1000)
    array([2.1+4.e-13j, 5.2 + 3e-15j])

    """
    a = asanyarray(a)
    if not issubclass(a.dtype.type, _nx.complexfloating):
        return a
    if tol > 1:
        from numpy.core import getlimits

        f = getlimits.finfo(a.dtype.type)
        tol = f.eps * tol
    if _nx.all(_nx.absolute(a.imag) < tol):
        a = a.real
    return a
    def transform(self, X):
        result = X

        for column in X.columns:
            datatype = result.loc[:, column].dtype.type
            limits = getlimits.finfo(datatype)

            result.loc[:, column].replace(np.inf, limits.max, inplace=True)
            result.loc[:, column].replace(-np.inf, limits.min, inplace=True)

        return result
コード例 #5
0
ファイル: type_check.py プロジェクト: vkarthi46/numpy
def real_if_close(a, tol=100):
    """
    If complex input returns a real array if complex parts are close to zero.

    "Close to zero" is defined as `tol` * (machine epsilon of the type for
    `a`).

    Parameters
    ----------
    a : array_like
        Input array.
    tol : float
        Tolerance in machine epsilons for the complex part of the elements
        in the array.

    Returns
    -------
    out : ndarray
        If `a` is real, the type of `a` is used for the output.  If `a`
        has complex elements, the returned type is float.

    See Also
    --------
    real, imag, angle

    Notes
    -----
    Machine epsilon varies from machine to machine and between data types
    but Python floats on most platforms have a machine epsilon equal to
    2.2204460492503131e-16.  You can use 'np.finfo(np.float).eps' to print
    out the machine epsilon for floats.

    Examples
    --------
    >>> np.finfo(np.float).eps
    2.2204460492503131e-16

    >>> np.real_if_close([2.1 + 4e-14j], tol=1000)
    array([ 2.1])
    >>> np.real_if_close([2.1 + 4e-13j], tol=1000)
    array([ 2.1 +4.00000000e-13j])

    """
    a = asanyarray(a)
    if not issubclass(a.dtype.type, _nx.complexfloating):
        return a
    if tol > 1:
        from numpy.core import getlimits

        f = getlimits.finfo(a.dtype.type)
        tol = f.eps * tol
    if _nx.allclose(a.imag, 0, atol=tol):
        a = a.real
    return a
コード例 #6
0
def _getmaxmin(t):
    from numpy.core import getlimits
    f = getlimits.finfo(t)
    return f.max, f.min
コード例 #7
0
ファイル: type_check.py プロジェクト: Horta/numpy
def _getmaxmin(t):
    from numpy.core import getlimits
    f = getlimits.finfo(t)
    return f.max, f.min
コード例 #8
0
ファイル: util.py プロジェクト: xpw0222/uchicago-pyanno
import numpy as np
from numpy import log
from numpy.core import getlimits
from scipy.special import gammaln
import time

import logging
logger = logging.getLogger(__name__)

#: In annotations arrays, this is the value used to indicate missing values
MISSING_VALUE = -1

#: Smallest possible floating point number, somtimes used instead of -np.inf
#: to make numberical calculation return a meaningful value
SMALLEST_FLOAT = getlimits.finfo(np.float).min


class PyannoValueError(ValueError):
    """ValueError subclass raised by pyAnno functions and methods.
    """
    pass


def random_categorical(distr, nsamples):
    """Return an array of samples from a categorical distribution.

    Arguments
    ---------
    distr : ndarray
        distr[i] is the probability of item i
コード例 #9
0
ファイル: lsmethod.py プロジェクト: rava-dosa/pylsm
epsilon     = config.getfloat('LSM', 'epsilon')
lambda1     = config.getfloat('LSM', 'lambda1')
lambda2     = config.getfloat('LSM', 'lambda2')
upsilon     = config.getfloat('LSM', 'upsilon')
mu          = config.getfloat('LSM', 'mu')
eta         = config.getfloat('LSM', 'eta')

delta_t     = config.getfloat('LSM', 'delta_t')
t_0         = config.getfloat('LSM', 't_0')
t_f         = config.getfloat('LSM', 't_f')

R_min       = config.getfloat('LSM', 'R_min')
R_max       = config.getfloat('LSM', 'R_max')

eps = finfo(float).eps

if use_pythode:
    from pythode.ivp import ConstantIVPSolver, IVPSolverModule, return_rejected
    import pythode.ivp.parameters as para
    from pythode.ivp.schemes import feuler
    from pythode.lib import deep_copy_update, parametrizable
    TOLERANCE = delta_t #1e-2
#############

logging.basicConfig(filename='lsmethod.log')

log = logging.getLogger("lsmethod")
log.setLevel(logging.DEBUG)

#############