def sample_from_prior(self):
        """ Sample elements of the stochastic transition matrix from the prior
        distribution, based on gradable adjectives. """

        # simple_path_dict caches the results of the graph traversal that finds
        # simple paths between pairs of nodes, so that it doesn't have to be
        # executed for every sampled transition matrix.

        node_pairs = list(permutations(self.nodes(), 2))
        simple_path_dict = {
            node_pair: [
                list(pairwise(path))
                for path in nx.all_simple_paths(self, *node_pair)
            ]
            for node_pair in node_pairs
        }

        self.transition_matrix_collection = []

        elements = self.get_latent_state_components()

        for i in range(self.res):
            A = pd.DataFrame(
                np.identity(2 * len(self)), index=elements, columns=elements
            )

            for node in self.nodes:
                A[f"∂({node})/∂t"][node] = self.Δt

            for node_pair in node_pairs:
                A[f"∂({node_pair[0]})/∂t"][node_pair[1]] = sum(
                    np.prod(
                        [
                            self.edges[edge[0], edge[1]]["βs"][i]
                            for edge in simple_path_edge_list
                        ]
                    )
                    * self.Δt
                    for simple_path_edge_list in simple_path_dict[node_pair]
                )
            self.transition_matrix_collection.append(A)
def sample_from_prior ( self ) : node_pairs = list ( permutations ( self . nodes ( ) , 2 ) ) simple_path_dict = { node_pair : [ list ( pairwise ( path ) ) for path in nx . all_simple_paths ( self , * node_pair ) ] for node_pair in node_pairs } self . transition_matrix_collection = [ ] elements = self . get_latent_state_components ( ) for i in range ( self . res ) : A = pd . DataFrame ( np . identity ( 2 * len ( self ) ) , index = elements , columns = elements ) for node in self . nodes : A [ f"∂({node})/∂t" ] [ node ] = self . Δt for node_pair in node_pairs : A [ f"∂({node_pair[0]})/∂t" ] [ node_pair [ 1 ] ] = sum ( np . prod ( [ self . edges [ edge [ 0 ] , edge [ 1 ] ] [ "βs" ] [ i ] for edge in simple_path_edge_list ] ) * self . Δt for simple_path_edge_list in simple_path_dict [ node_pair ] ) self . transition_matrix_collection . append ( A )
Sample elements of the stochastic transition matrix from the prior
        distribution, based on gradable adjectives.