1414from scipy .sparse import issparse
1515from distutils .version import LooseVersion
1616
17- from . import check_random_state
17+ from . import check_random_state , deprecated
1818from .fixes import qr_economic
1919from ._logistic_sigmoid import _log_logistic_sigmoid
2020from ..externals .six .moves import xrange
@@ -567,36 +567,38 @@ def svd_flip(u, v):
567567 return u , v
568568
569569
570+ @deprecated ('to be removed in 0.17; use scipy.special.expit or log_logistic' )
570571def logistic_sigmoid (X , log = False , out = None ):
571- """
572- Implements the logistic function, ``1 / (1 + e ** -x)`` and its log.
572+ """Logistic function, ``1 / (1 + e ** (-x))``, or its log."""
573+ from .fixes import expit
574+ fn = log_logistic if log else expit
575+ return fn (X , out )
576+
573577
574- This implementation is more stable by splitting on positive and negative
575- values and computing::
576578
577- 1 / (1 + exp(-x_i)) if x_i > 0
578- exp(x_i) / (1 + exp(x_i)) if x_i <= 0
579+ def log_logistic ( X , out = None ):
580+ """Compute the log of the logistic function, ``log(1 / (1 + e ** -x))``.
579581
580- The log is computed using::
582+ This implementation is numerically stable because it splits positive and
583+ negative values::
581584
582- -log(1 + exp(-x_i)) if x_i > 0
585+ -log(1 + exp(-x_i)) if x_i > 0
583586 x_i - log(1 + exp(x_i)) if x_i <= 0
584587
588+ For the ordinary logistic function, use ``sklearn.utils.fixes.expit``.
589+
585590 Parameters
586591 ----------
587592 X: array-like, shape (M, N)
588593 Argument to the logistic function
589594
590- log: boolean, default: False
591- Whether to compute the logarithm of the logistic function.
592-
593595 out: array-like, shape: (M, N), optional:
594596 Preallocated output array.
595597
596598 Returns
597599 -------
598600 out: array, shape (M, N)
599- Value of the logistic function evaluated at every point in x
601+ Log of the logistic function evaluated at every point in x
600602
601603 Notes
602604 -----
@@ -611,15 +613,7 @@ def logistic_sigmoid(X, log=False, out=None):
611613 if out is None :
612614 out = np .empty_like (X )
613615
614- if log :
615- _log_logistic_sigmoid (n_samples , n_features , X , out )
616- else :
617- # logistic(x) = (1 + tanh(x / 2)) / 2
618- out [:] = X
619- out *= .5
620- np .tanh (out , out )
621- out += 1
622- out *= .5
616+ _log_logistic_sigmoid (n_samples , n_features , X , out )
623617
624618 if is_1d :
625619 return np .squeeze (out )
0 commit comments