docstr: Computes the MAP Query over the variables given the evidence. Returns the
  highest probable state in the joint distribution of `variables`.
  
  Parameters
  ----------
  variables: list
      list of variables over which we want to compute the max-marginal.
  
  evidence: dict
      a dict key, value pair as {var: state_of_var_observed}
      None if no evidence
  
  virtual_evidence: list (default:None)
      A list of pgmpy.factors.discrete.TabularCPD representing the virtual
      evidences.
  
  elimination_order: list
      order of variable eliminations (if nothing is provided) order is
      computed automatically
  
  show_progress: boolean
      If True, shows a progress bar.
  
  Examples
  --------
  >>> from pgmpy.inference import VariableElimination
  >>> from pgmpy.models import BayesianNetwork
  >>> import numpy as np
  >>> import pandas as pd
  >>> values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
  ...                       columns=['A', 'B', 'C', 'D', 'E'])
  >>> model = BayesianNetwork([('A', 'B'), ('C', 'B'), ('C', 'D'), ('B', 'E')])
  >>> model.fit(values)
  >>> inference = VariableElimination(model)
  >>> phi_query = inference.map_query(['A', 'B'])
docstr_tok: ["Computes","the","MAP","Query","over","the","variables","given","the","evidence",".","Returns","the","highest","probable","state","in","the","joint","distribution","of","`","variables","`",".","Parameters","--","--","--","--","--","variables",":","list","list","of","variables","over","which","we","want","to","compute","the","max-marginal",".","evidence",":","dict","a","dict","key",",","value","pair","as","{","var",":","state_of_var_observed","}","None","if","no","evidence","virtual_evidence",":","list","(","default",":","None",")","A","list","of","pgmpy.factors.discrete.TabularCPD","representing","the","virtual","evidences",".","elimination_order",":","list","order","of","variable","eliminations","(","if","nothing","is","provided",")","order","is","computed","automatically","show_progress",":","boolean","If","True",",","shows","a","progress","bar",".","Examples","--","--","--","--",">",">",">","from","pgmpy.inference","import","VariableElimination",">",">",">","from","pgmpy.models","import","BayesianNetwork",">",">",">","import","numpy","as","np",">",">",">","import","pandas","as","pd",">",">",">","values","=","pd.DataFrame","(","np.random.randint","(","low=0",",","high=2",",","size=","(","1000",",","5",")",")",",","...","columns=","[","'","A","'",",","'","B","'",",","'","C","'",",","'D","'",",","'","E","'","]",")",">",">",">","model","=","BayesianNetwork","(","[","(","'","A","'",",","'","B","'",")",",","(","'","C","'",",","'","B","'",")",",","(","'","C","'",",","'D","'",")",",","(","'","B","'",",","'","E","'",")","]",")",">",">",">","model.fit","(","values",")",">",">",">","inference","=","VariableElimination","(","model",")",">",">",">","phi_query","=","inference.map_query","(","[","'","A","'",",","'","B","'","]",")"]
code: def map_query(
      self,
      variables=None,
      evidence=None,
      virtual_evidence=None,
      elimination_order="MinFill",
      show_progress=True,
  ):
      """
      Computes the MAP Query over the variables given the evidence. Returns the
      highest probable state in the joint distribution of `variables`.
  
      Parameters
      ----------
      variables: list
          list of variables over which we want to compute the max-marginal.
  
      evidence: dict
          a dict key, value pair as {var: state_of_var_observed}
          None if no evidence
  
      virtual_evidence: list (default:None)
          A list of pgmpy.factors.discrete.TabularCPD representing the virtual
          evidences.
  
      elimination_order: list
          order of variable eliminations (if nothing is provided) order is
          computed automatically
  
      show_progress: boolean
          If True, shows a progress bar.
  
      Examples
      --------
      >>> from pgmpy.inference import VariableElimination
      >>> from pgmpy.models import BayesianNetwork
      >>> import numpy as np
      >>> import pandas as pd
      >>> values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
      ...                       columns=['A', 'B', 'C', 'D', 'E'])
      >>> model = BayesianNetwork([('A', 'B'), ('C', 'B'), ('C', 'D'), ('B', 'E')])
      >>> model.fit(values)
      >>> inference = VariableElimination(model)
      >>> phi_query = inference.map_query(['A', 'B'])
      """
      variables = [] if variables is None else variables
      evidence = evidence if evidence is not None else dict()
      common_vars = set(
          evidence if evidence is not None else []
      ).intersection(variables)
      if common_vars:
          raise ValueError(
              f"Can't have the same variables in both `variables` and `evidence`. Found in both: {common_vars}"
          )
  
      if isinstance(self.model, BayesianNetwork) and (
          virtual_evidence is not None
      ):
          self._virtual_evidence(virtual_evidence)
          virt_evidence = {
              "__" + cpd.variables[0]: 0 for cpd in virtual_evidence
          }
          return self.map_query(
              variables=variables,
              evidence={**evidence, **virt_evidence},
              virtual_evidence=None,
              elimination_order=elimination_order,
              show_progress=show_progress,
          )
  
      if isinstance(self.model, BayesianNetwork):
          model_reduced, evidence = self._prune_bayesian_model(
              variables, evidence
          )
      else:
          model_reduced = self.model
  
      reduced_ve = VariableElimination(model_reduced)
      reduced_ve._initialize_structures()
  
      final_distribution = reduced_ve._variable_elimination(
          variables=variables,
          operation="marginalize",
          evidence=evidence,
          elimination_order=elimination_order,
          joint=True,
          show_progress=show_progress,
      )
      argmax = compat_fns.argmax(final_distribution.values)
      assignment = final_distribution.assignment([argmax])[0]
  
      map_query_results = {}
      for var_assignment in assignment:
          var, value = var_assignment
          map_query_results[var] = value
  
      return map_query_results
  
imports: import copy
  import itertools
  import networkx
  import numpy
  from opt_einsum import contract
  from tqdm.auto import tqdm
  from pgmpy import config
  from pgmpy.factors import factor_product
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.inference import Inference
  from pgmpy.inference.EliminationOrder import MinFill, MinNeighbors, MinWeight, WeightedMinFill
  from pgmpy.models import BayesianNetwork, DynamicBayesianNetwork, JunctionTree, MarkovNetwork
  from pgmpy.utils import compat_fns
label_desc: Use image node_id 6 for calling the VariableElimination obj's underlying member method code with example usage: obj.map_query(variables, evidence, virtual_evidence, elimination_order, show_progress) and returns: map_query_results, self