(X, max_time_delay, max_dimension,
                                        stride=1, n_jobs=None, validate=True)
return time_delay, dimension
Compute the "optimal" parameters for a Takens (time-delay) embedding
    [1]_ of a univariate time series.

    First, an optimal time delay is found by minimising the time-delayed mutual
    information among values no greater than `max_time_delay`. Then, a
    heuristic based on an algorithm in [2]_ is used to select an embedding
    dimension which, when increased, does not reveal a large proportion of
    "false nearest neighbors".

    Parameters
    ----------
    X : ndarray of shape (n_samples,) or (n_samples, 1)
        Input data representing a single univariate time series.

    max_time_delay : int, required
        Maximum time delay between two consecutive values for constructing one
        embedded point.

    max_dimension : int, required
        Maximum embedding dimension that will be considered in the
        optimization.

    stride : int, optional, default: ``1``
        Stride duration between two consecutive embedded points. It defaults to
        1 as this is the usual value in the statement of Takens's embedding
        theorem.

    n_jobs : int or None, optional, default: ``None``
        The number of jobs to use for the computation. ``None`` means 1 unless
        in a :obj:`joblib.parallel_backend` context. ``-1`` means using all
        processors.

    validate : bool, optional, default: ``True``
        Whether the input and hyperparameters should be validated.

    Returns
    -------
    time_delay : int
        The "optimal" time delay less than or equal to `max_dimension`, as
        determined by minimizing the time-delayed mutual information.

    dimension : int
        The "optimal" embedding dimension less than or equal to
        `max_dimension`, as determined by a false nearest neighbors heuristic
        once `time_delay` is computed.

    See also
    --------
    SingleTakensEmbedding, TakensEmbedding, SlidingWindow

    References
    ----------
    .. [1] F. Takens, "Detecting strange attractors in turbulence". In: Rand
           D., Young LS. (eds) *Dynamical Systems and Turbulence, Warwick
           1980*. Lecture Notes in Mathematics, vol. 898. Springer, 1981;
           `DOI: 10.1007/BFb0091924 <https://doi.org/10.1007/BFb0091924>`_.

    .. [2] M. B. Kennel, R. Brown, and H. D. I. Abarbanel, "Determining
           embedding dimension for phase-space reconstruction using a
           geometrical construction"; *Phys. Rev. A* **45**, pp. 3403--3411,
           1992; `DOI: 10.1103/PhysRevA.45.3403
           <https://doi.org/10.1103/PhysRevA.45.3403>`_.
Compute the "optimal" parameters for a Takens (time-delay) embedding
    [1]_ of a univariate time series.
Compute the optimal parameters for a Takens ( time - delay ) embedding [ 1 ] _ of a univariate time series .
def takens_embedding_optimal_parameters(X, max_time_delay, max_dimension,
                                        stride=1, n_jobs=None, validate=True):
    """Compute the "optimal" parameters for a Takens (time-delay) embedding
    [1]_ of a univariate time series.

    First, an optimal time delay is found by minimising the time-delayed mutual
    information among values no greater than `max_time_delay`. Then, a
    heuristic based on an algorithm in [2]_ is used to select an embedding
    dimension which, when increased, does not reveal a large proportion of
    "false nearest neighbors".

    Parameters
    ----------
    X : ndarray of shape (n_samples,) or (n_samples, 1)
        Input data representing a single univariate time series.

    max_time_delay : int, required
        Maximum time delay between two consecutive values for constructing one
        embedded point.

    max_dimension : int, required
        Maximum embedding dimension that will be considered in the
        optimization.

    stride : int, optional, default: ``1``
        Stride duration between two consecutive embedded points. It defaults to
        1 as this is the usual value in the statement of Takens's embedding
        theorem.

    n_jobs : int or None, optional, default: ``None``
        The number of jobs to use for the computation. ``None`` means 1 unless
        in a :obj:`joblib.parallel_backend` context. ``-1`` means using all
        processors.

    validate : bool, optional, default: ``True``
        Whether the input and hyperparameters should be validated.

    Returns
    -------
    time_delay : int
        The "optimal" time delay less than or equal to `max_dimension`, as
        determined by minimizing the time-delayed mutual information.

    dimension : int
        The "optimal" embedding dimension less than or equal to
        `max_dimension`, as determined by a false nearest neighbors heuristic
        once `time_delay` is computed.

    See also
    --------
    SingleTakensEmbedding, TakensEmbedding, SlidingWindow

    References
    ----------
    .. [1] F. Takens, "Detecting strange attractors in turbulence". In: Rand
           D., Young LS. (eds) *Dynamical Systems and Turbulence, Warwick
           1980*. Lecture Notes in Mathematics, vol. 898. Springer, 1981;
           `DOI: 10.1007/BFb0091924 <https://doi.org/10.1007/BFb0091924>`_.

    .. [2] M. B. Kennel, R. Brown, and H. D. I. Abarbanel, "Determining
           embedding dimension for phase-space reconstruction using a
           geometrical construction"; *Phys. Rev. A* **45**, pp. 3403--3411,
           1992; `DOI: 10.1103/PhysRevA.45.3403
           <https://doi.org/10.1103/PhysRevA.45.3403>`_.

    """
    if validate:
        _hyperparameters = _TAKENS_EMBEDDING_HYPERPARAMETERS.copy()
        validate_params({'validate': validate}, {'validate': {'type': bool}})
        validate_params({'time_delay': max_time_delay,
                         'dimension': max_dimension, 'stride': stride},
                        _hyperparameters)
        X = column_or_1d(X)

    mutual_information_list = Parallel(n_jobs=n_jobs)(
        delayed(_mutual_information)(X, time_delay, n_bins=100)
        for time_delay in range(1, max_time_delay + 1))
    time_delay = \
        mutual_information_list.index(min(mutual_information_list)) + 1

    n_false_nbhrs_list = Parallel(n_jobs=n_jobs)(
        delayed(_false_nearest_neighbors)(X, time_delay, dim, stride=stride)
        for dim in range(1, max_dimension + 3))
    variation_list = [np.abs(n_false_nbhrs_list[dim - 1]
                             - 2 * n_false_nbhrs_list[dim] +
                             n_false_nbhrs_list[dim + 1])
                      / (n_false_nbhrs_list[dim] + 1) / dim
                      for dim in range(2, max_dimension + 1)]
    dimension = variation_list.index(min(variation_list)) + 2

    return time_delay, dimension
def takens_embedding_optimal_parameters ( X , max_time_delay , max_dimension , stride = 1 , n_jobs = None , validate = True ) : if validate : _hyperparameters = _TAKENS_EMBEDDING_HYPERPARAMETERS . copy ( ) validate_params ( { 'validate' : validate } , { 'validate' : { 'type' : bool } } ) validate_params ( { 'time_delay' : max_time_delay , 'dimension' : max_dimension , 'stride' : stride } , _hyperparameters ) X = column_or_1d ( X ) mutual_information_list = Parallel ( n_jobs = n_jobs ) ( delayed ( _mutual_information ) ( X , time_delay , n_bins = 100 ) for time_delay in range ( 1 , max_time_delay + 1 ) ) time_delay = mutual_information_list . index ( min ( mutual_information_list ) ) + 1 n_false_nbhrs_list = Parallel ( n_jobs = n_jobs ) ( delayed ( _false_nearest_neighbors ) ( X , time_delay , dim , stride = stride ) for dim in range ( 1 , max_dimension + 3 ) ) variation_list = [ np . abs ( n_false_nbhrs_list [ dim - 1 ] - 2 * n_false_nbhrs_list [ dim ] + n_false_nbhrs_list [ dim + 1 ] ) / ( n_false_nbhrs_list [ dim ] + 1 ) / dim for dim in range ( 2 , max_dimension + 1 ) ] dimension = variation_list . index ( min ( variation_list ) ) + 2 return time_delay , dimension