<commit_before>"""
Filename: lae.py
Authors: <NAME>, <NAME>,

Computes a sequence of marginal densities for a continuous state space Markov
chain {X_t} where the transition probabilities can be represented as densities.
The estimate of the marginal density psi_t of X_t is

    (1/n) sum_{i=0}^n p(X_{t-1}^i, y)

This is a density in y.  

"""

import numpy as np

class LAE:
    """
    An instance is a representation of a look ahead estimator associated with
    a given stochastic kernel p and a vector of observations X.  For example,

        >>> psi = LAE(p, X)
        >>> y = np.linspace(0, 1, 100)
        >>> psi(y)  # Evaluate look ahead estimate at grid of points y
    """

    def __init__(self, p, X):
        """
        Parameters
        ==========
        p : function
            The stochastic kernel.  A function p(x, y) that is vectorized in
            both x and y

        X : array_like
            A vector containing observations
        """
        X = X.flatten()  # So we know what we're dealing with
        n = len(X)
        self.p, self.X = p, X.reshape((n, 1))


    def __call__(self, y):
        """
        Parameters
        ==========
        y : array_like
            A vector of points at which we wish to evaluate the look-ahead
            estimator

        Returns
        =======
        psi_vals : numpy.ndarray
            The values of the density estimate at the points in y

        """
        k = len(y)
        v = self.p(self.X, y.reshape((1, k)))
        psi_vals = np.mean(v, axis=0)    # Take mean along each row
        return psi_vals.flatten()

<commit_msg>cleaned up docstring of lae.py<commit_after>"""
Filename: lae.py
Authors: <NAME>, <NAME>,

Computes a sequence of marginal densities for a continuous state space Markov
chain X_t where the transition probabilities can be represented as densities.
The estimate of the marginal density of X_t is

.. math::
    (1/n) \sum_{i=0}^n p(X_{t-1}^i, y)

This is a density in y.  

"""

import numpy as np

class LAE:
    """
    An instance is a representation of a look ahead estimator associated with
    a given stochastic kernel p and a vector of observations X.  

    Example
    -------

    >>> psi = LAE(p, X)
    >>> y = np.linspace(0, 1, 100)
    >>> psi(y)  # Evaluate look ahead estimate at grid of points y

    """

    def __init__(self, p, X):
        """
        Parameters
        ----------
        p : function
            The stochastic kernel.  A function p(x, y) that is vectorized in
            both x and y
        X : array_like
            A vector containing observations

        """
        X = X.flatten()  # So we know what we're dealing with
        n = len(X)
        self.p, self.X = p, X.reshape((n, 1))


    def __call__(self, y):
        """
        A vectorized function that returns the value of the look ahead
        estimate at the values in the array y.

        Parameters
        ----------
        y : array_like
            A vector of points at which we wish to evaluate the look-ahead
            estimator

        Returns
        -------
        psi_vals : numpy.ndarray
            The values of the density estimate at the points in y

        """
        k = len(y)
        v = self.p(self.X, y.reshape((1, k)))
        psi_vals = np.mean(v, axis=0)    # Take mean along each row
        return psi_vals.flatten()


{'fraction_non_alphanumeric': 0.10363153232949512, 'fraction_numerical': 0.006495423678771774, 'mean_word_length': 1.8614864864864864, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7010503', 'n_tokens_mistral': 1040, 'n_tokens_neox': 981, 'n_words': 402}