<commit_before># Author: <NAME> <<EMAIL>>
# Contributors: <NAME>
# Copyright (c) 2017, Stanford University and the Authors
# All rights reserved.

from __future__ import print_function, division, absolute_import

import copy
import numpy as np
from msmbuilder.msm import MarkovStateModel
import functools
import multiprocessing
import os


class BACE(MarkovStateModel):
    """Bayesian Agglomerative Clustering Engine (BACE) for coarse-graining (lumping)
    microstates into macrostates.

    Parameters
    ----------
    n_macrostates : int or None
        The desired number of macrostates in the lumped model. If None,
        only the linkages are calcluated (see ``use_scipy``)
    filter : float (default=1.1)
        Prune states with Bayes factors less than this number. Default is
        approximation log(3), so states with less than a 3:1 ratio are pruned.
        NOTE : MSMs not built directly from pairwise RMSD, we recommend
        setting this parameter to zero.
    save_all_maps : boolean (default=True)
        Creates a dicitonary where the keys are the number of macrostates
        and the values are the mapping for that macrostate. Since BACE
        uses agglomerative clustering, the mapping for every number of
        macrostates higher than the one chosen is automatically computed,
        and setting this to True saves them all.
    n_proc : int (default=1)
        Number of processors to use
    kwargs : optional
        Additional keyword arguments to be passed to MarkovStateModel.  See
        msmbuilder.msm.MarkovStateModel for possible options.

    Attributes
    ----------
    microstate_mapping_ : np.array, [number of microstates]
    map_dict : dictionary, [n_macrostates : microstate_mapping_]

    Notes
    -----
    BACE was implemented with as much fidelity to the MSMBuilder 2 version
    as possible. BACE was implemented before sliding windows were used;
    therefore, if a sliding window was used to build the MSM, then the
    counts matrix is multiplied by the lag time before proceeding. This 
    is because the prior probability for each transition is hard-coded
    to be 1 over the number of microstates. In order to produce identical
    results to the MSMB2 version, states with Bayes factors less than 1.1
    are merged with the kinetically closest state before clustering begins.
    When coarse-graining MSMs not built from RMSD-based clustering, however,
    we recommend setting filter=0.

    The MSMB2 version of BACE included an option for sparse matrices, which
    we have removed in this implementation. However, the reciprocal of the
    distance matrix is still taken during the calculation, which was 
    needed for the sparse formulation. For this reason, there might be
    some precision issues when compared to coding BACE separatey.

    BACE is a subclass of MarkovStateModel.  However, the MSM properties
    and attributes on BACE refer to the MICROSTATE properties--e.g.
    mvca.transmat_ is the microstate transition matrix.  To get the
    macrostate transition matrix, you must fit a new MarkovStateModel
    object on the output (assignments) of BACE().
    BACE will scale poorly with the number of microstates. Consider
    use_scipy=False and n_landmarks < number of microstates.
    """

    def __init__(self, n_macrostates, filter=1.1, save_all_maps=True,
                 n_proc=1, chunk_size=100, **kwargs):
        self.n_macrostates = n_macrostates
        self.filter = filter
        self.save_all_maps = save_all_maps
        self.n_proc = n_proc
        self.chunk_size = chunk_size

        if self.save_all_maps:
            self.map_dict = {}

        super(BACE, self).__init__(**kwargs)
<commit_msg>added bace citation to docs<commit_after># Author: <NAME> <<EMAIL>>
# Contributors: <NAME>
# Copyright (c) 2017, Stanford University and the Authors
# All rights reserved.

from __future__ import print_function, division, absolute_import

import copy
import numpy as np
from msmbuilder.msm import MarkovStateModel
import functools
import multiprocessing
import os


class BACE(MarkovStateModel):
    """Bayesian Agglomerative Clustering Engine (BACE) for coarse-graining (lumping)
    microstates into macrostates.

    Parameters
    ----------
    n_macrostates : int or None
        The desired number of macrostates in the lumped model. If None,
        only the linkages are calcluated (see ``use_scipy``)
    filter : float (default=1.1)
        Prune states with Bayes factors less than this number. Default is
        approximation log(3), so states with less than a 3:1 ratio are pruned.
        NOTE : MSMs not built directly from pairwise RMSD, we recommend
        setting this parameter to zero.
    save_all_maps : boolean (default=True)
        Creates a dicitonary where the keys are the number of macrostates
        and the values are the mapping for that macrostate. Since BACE
        uses agglomerative clustering, the mapping for every number of
        macrostates higher than the one chosen is automatically computed,
        and setting this to True saves them all.
    n_proc : int (default=1)
        Number of processors to use
    kwargs : optional
        Additional keyword arguments to be passed to MarkovStateModel.  See
        msmbuilder.msm.MarkovStateModel for possible options.

    Attributes
    ----------
    microstate_mapping_ : np.array, [number of microstates]
    map_dict : dictionary, [n_macrostates : microstate_mapping_]

    Notes
    -----
    BACE was implemented with as much fidelity to the MSMBuilder 2 version
    as possible. BACE was implemented before sliding windows were used;
    therefore, if a sliding window was used to build the MSM, then the
    counts matrix is multiplied by the lag time before proceeding. This 
    is because the prior probability for each transition is hard-coded
    to be 1 over the number of microstates. In order to produce identical
    results to the MSMB2 version, states with Bayes factors less than 1.1
    are merged with the kinetically closest state before clustering begins.
    When coarse-graining MSMs not built from RMSD-based clustering, however,
    we recommend setting filter=0.

    The MSMB2 version of BACE included an option for sparse matrices, which
    we have removed in this implementation. However, the reciprocal of the
    distance matrix is still taken during the calculation, which was 
    needed for the sparse formulation. For this reason, there might be
    some precision issues when compared to coding BACE separatey.

    Please see <NAME>. Phys. 137 134111 (2012).

    BACE is a subclass of MarkovStateModel.  However, the MSM properties
    and attributes on BACE refer to the MICROSTATE properties--e.g.
    mvca.transmat_ is the microstate transition matrix.  To get the
    macrostate transition matrix, you must fit a new MarkovStateModel
    object on the output (assignments) of BACE().
    BACE will scale poorly with the number of microstates. Consider
    use_scipy=False and n_landmarks < number of microstates.
    """

    def __init__(self, n_macrostates, filter=1.1, save_all_maps=True,
                 n_proc=1, chunk_size=100, **kwargs):
        self.n_macrostates = n_macrostates
        self.filter = filter
        self.save_all_maps = save_all_maps
        self.n_proc = n_proc
        self.chunk_size = chunk_size

        if self.save_all_maps:
            self.map_dict = {}

        super(BACE, self).__init__(**kwargs)

{'fraction_non_alphanumeric': 0.05294039205227364, 'fraction_numerical': 0.007867715695426056, 'mean_word_length': 3.0894220283533262, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, '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': '2070316', 'n_tokens_mistral': 2057, 'n_tokens_neox': 1944, 'n_words': 893}