docs: def to_factor_graph(self):
          """
          Converts the markov model into factor graph.
  
          A factor graph contains two types of nodes. One type corresponds to
          random variables whereas the second type corresponds to factors over
          these variables. The graph only contains edges between variables and
          factor nodes. Each factor node is associated with one factor whose
          scope is the set of variables that are its neighbors.
  
          Examples
          --------
          >>> from pgmpy.models import MarkovModel
          >>> from pgmpy.factors.discrete import DiscreteFactor
          >>> student = MarkovModel([('Alice', 'Bob'), ('Bob', 'Charles')])
          >>> factor1 = DiscreteFactor(['Alice', 'Bob'], [3, 2], np.random.rand(6))
          >>> factor2 = DiscreteFactor(['Bob', 'Charles'], [2, 2], np.random.rand(4))
          >>> student.add_factors(factor1, factor2)
          >>> factor_graph = student.to_factor_graph()
          """
          from pgmpy.models import FactorGraph
          factor_graph = FactorGraph()
  
          if not self.factors:
              raise ValueError('Factors not associated with the random variables.')
  
          factor_graph.add_nodes_from(self.nodes())
          for factor in self.factors:
              scope = factor.scope()
              factor_node = 'phi_' + '_'.join(scope)
              factor_graph.add_edges_from(itertools.product(scope, [factor_node]))
              factor_graph.add_factors(factor)
  
          return factor_graph