class_docstr: Class for Bayesian structure scoring for BayesianNetworks with
  Dirichlet priors.  The BIC/MDL score ("Bayesian Information Criterion",
  also "Minimal Descriptive Length") is a log-likelihood score with an
  additional penalty for network complexity, to avoid overfitting.  The
  `score`-method measures how well a model is able to describe the given
  data set.
  
  Parameters
  ----------
  data: pandas DataFrame object
      dataframe object where each column represents one variable.
      (If some values in the data are missing the data cells should be set to `numpy.NaN`.
      Note that pandas converts each column containing `numpy.NaN`s to dtype `float`.)
  
  state_names: dict (optional)
      A dict indicating, for each variable, the discrete set of states (or values)
      that the variable can take. If unspecified, the observed values in the data set
      are taken to be the only possible states.
  
  References
  ---------
  [1] Koller & Friedman, Probabilistic Graphical Models - Principles and Techniques, 2009
  Section 18.3.4-18.3.6 (esp. page 802)
  [2] AM Carvalho, Scoring functions for learning Bayesian networks,
  http://www.lx.it.pt/~asmc/pub/talks/09-TA/ta_pres.pdf
class_docstr_tok: ["Class","for","Bayesian","structure","scoring","for","BayesianNetworks","with","Dirichlet","priors",".","The","BIC\/MDL","score","(","``","Bayesian","Information","Criterion","''",",","also","``","Minimal","Descriptive","Length","''",")","is","a","log-likelihood","score","with","an","additional","penalty","for","network","complexity",",","to","avoid","overfitting",".","The","`","score","`","-method","measures","how","well","a","model","is","able","to","describe","the","given","data","set",".","Parameters","--","--","--","--","--","data",":","pandas","DataFrame","object","dataframe","object","where","each","column","represents","one","variable",".","(","If","some","values","in","the","data","are","missing","the","data","cells","should","be","set","to","`","numpy.NaN","`",".","Note","that","pandas","converts","each","column","containing","`","numpy.NaN","`","s","to","dtype","`","float","`",".",")","state_names",":","dict","(","optional",")","A","dict","indicating",",","for","each","variable",",","the","discrete","set","of","states","(","or","values",")","that","the","variable","can","take",".","If","unspecified",",","the","observed","values","in","the","data","set","are","taken","to","be","the","only","possible","states",".","References","--","--","--","--","-","[","1","]","Koller","&","Friedman",",","Probabilistic","Graphical","Models","-","Principles","and","Techniques",",","2009","Section","18.3.4-18.3.6","(","esp",".","page","802",")","[","2","]","AM","Carvalho",",","Scoring","functions","for","learning","Bayesian","networks",",","http",":","\/\/www.lx.it.pt\/~asmc\/pub\/talks\/09-TA\/ta_pres.pdf"]
docstr: Computes a score that measures how much a         given variable is "influenced" by a given list of potential parents.
docstr_tok: ["Computes","a","score","that","measures","how","much","a","given","variable","is","``","influenced","''","by","a","given","list","of","potential","parents","."]
code: def local_score(self, variable, parents):
      'Computes a score that measures how much a \
          given variable is "influenced" by a given list of potential parents.'
  
      var_states = self.state_names[variable]
      var_cardinality = len(var_states)
      parents = list(parents)
      state_counts = self.state_counts(variable, parents, reindex=False)
      sample_size = len(self.data)
      num_parents_states = np.prod(
          [len(self.state_names[var]) for var in parents]
      )
  
      counts = np.asarray(state_counts)
      log_likelihoods = np.zeros_like(counts, dtype=float)
  
      # Compute the log-counts
      np.log(counts, out=log_likelihoods, where=counts > 0)
  
      # Compute the log-conditional sample size
      log_conditionals = np.sum(counts, axis=0, dtype=float)
      np.log(
          log_conditionals,
          out=log_conditionals,
          where=log_conditionals > 0,
      )
  
      # Compute the log-likelihoods
      log_likelihoods -= log_conditionals
      log_likelihoods *= counts
  
      score = np.sum(log_likelihoods)
      score -= (
          0.5
          * log(sample_size)
          * num_parents_states
          * (var_cardinality - 1)
      )
  
      return score
  
imports: from math import lgamma, log
  import numpy
  from scipy.special import gammaln
  from pgmpy.estimators import BaseEstimator
label_desc: Use image node_id 2 for calling the BicScore obj's underlying member method code with example usage: obj.local_score(variable, parents) and returns: score