<commit_before>"""
Probabilistic factor analysis to perform dimensionality reduction on mouse images.
With the probabilistic approach, we can handle missing data in the images.
Technically this holds for missing at random data, but we can try it
out on images where we treat cable pixels as missing, even though they
won't be random. This should give us a model-based way to fill in pixels,
and hopefully a more robust way to estimate principle components for modeling.
"""
import abc
import numpy as np

from pybasicbayes.abstractions import Model, \
    ModelGibbsSampling, ModelMeanField, ModelMeanFieldSVI, ModelEM
from pybasicbayes.util.stats import sample_gaussian
from pybasicbayes.util.general import objarray

from pybasicbayes.distributions import DiagonalRegression

from pybasicbayes.util.profiling import line_profiled
PROFILING = True

class FactorAnalysisStates(object):
    """
    Wrapper for the latent states of a factor analysis model
    """
    def __init__(self, model, data, mask=None, **kwargs):
        self.model = model
        self.X = data
        self.mask = mask
        if mask is None:
            mask = np.ones_like(data, dtype=bool)
        assert data.shape == mask.shape and mask.dtype == bool
        assert self.X.shape[1] == self.D_obs

        # Initialize latent states<commit_msg>fixing mask bug in factor_analysis<commit_after>"""
Probabilistic factor analysis to perform dimensionality reduction on mouse images.
With the probabilistic approach, we can handle missing data in the images.
Technically this holds for missing at random data, but we can try it
out on images where we treat cable pixels as missing, even though they
won't be random. This should give us a model-based way to fill in pixels,
and hopefully a more robust way to estimate principle components for modeling.
"""
import abc
import numpy as np

from pybasicbayes.abstractions import Model, \
    ModelGibbsSampling, ModelMeanField, ModelMeanFieldSVI, ModelEM
from pybasicbayes.util.stats import sample_gaussian
from pybasicbayes.util.general import objarray

from pybasicbayes.distributions import DiagonalRegression

from pybasicbayes.util.profiling import line_profiled
PROFILING = True

class FactorAnalysisStates(object):
    """
    Wrapper for the latent states of a factor analysis model
    """
    def __init__(self, model, data, mask=None, **kwargs):
        self.model = model
        self.X = data
        if mask is None:
            mask = np.ones_like(data, dtype=bool)
        self.mask = mask
        assert data.shape == mask.shape and mask.dtype == bool
        assert self.X.shape[1] == self.D_obs

        # Initialize latent states
{'fraction_non_alphanumeric': 0.05990265818045676, 'fraction_numerical': 0.0007487832272557095, 'mean_word_length': 3.7460035523978688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2218567', 'n_tokens_mistral': 736, 'n_tokens_neox': 701, 'n_words': 303}