class_docstr: Class for Bayesian structure scoring for BayesianNetworks with
  Dirichlet priors.  The BDs score is the result of setting all Dirichlet
  hyperparameters/pseudo_counts to
  `equivalent_sample_size/modified_variable_cardinality` where for the
  modified_variable_cardinality only the number of parent configurations
  where there were observed variable counts are considered.  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`.)
  
  equivalent_sample_size: int (default: 10)
      The equivalent/imaginary sample size (of uniform pseudo samples) for the dirichlet
      hyperparameters.
      The score is sensitive to this value, runs with different values might be useful.
  
  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] Scutari, Marco. An Empirical-Bayes Score for Discrete Bayesian Networks.
  Journal of Machine Learning Research, 2016, pp. 438–48
class_docstr_tok: ["Class","for","Bayesian","structure","scoring","for","BayesianNetworks","with","Dirichlet","priors",".","The","BDs","score","is","the","result","of","setting","all","Dirichlet","hyperparameters\/pseudo_counts","to","`","equivalent_sample_size\/modified_variable_cardinality","`","where","for","the","modified_variable_cardinality","only","the","number","of","parent","configurations","where","there","were","observed","variable","counts","are","considered",".","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","`",".",")","equivalent_sample_size",":","int","(","default",":","10",")","The","equivalent\/imaginary","sample","size","(","of","uniform","pseudo","samples",")","for","the","dirichlet","hyperparameters",".","The","score","is","sensitive","to","this","value",",","runs","with","different","values","might","be","useful",".","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","]","Scutari",",","Marco",".","An","Empirical-Bayes","Score","for","Discrete","Bayesian","Networks",".","Journal","of","Machine","Learning","Research",",","2016",",","pp",".","438\u201348"]
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)
      num_parents_states = np.prod(
          [len(self.state_names[var]) for var in parents]
      )
  
      counts = np.asarray(state_counts)
      # counts size is different because reindex=False is dropping columns.
      counts_size = num_parents_states * len(self.state_names[variable])
      log_gamma_counts = np.zeros_like(counts, dtype=float)
      alpha = self.equivalent_sample_size / state_counts.shape[1]
      beta = self.equivalent_sample_size / counts_size
      # Compute log(gamma(counts + beta))
      gammaln(counts + beta, out=log_gamma_counts)
  
      # Compute the log-gamma conditional sample size
      log_gamma_conds = np.sum(counts, axis=0, dtype=float)
      gammaln(log_gamma_conds + alpha, out=log_gamma_conds)
  
      # Adjustment because of missing 0 columns when using reindex=False for computing state_counts to save memory.
      gamma_counts_adj = (
          (num_parents_states - counts.shape[1])
          * len(self.state_names[variable])
          * gammaln(beta)
      )
      gamma_conds_adj = (
          num_parents_states - counts.shape[1]
      ) * gammaln(alpha)
  
      score = (
          (np.sum(log_gamma_counts) + gamma_counts_adj)
          - (np.sum(log_gamma_conds) + gamma_conds_adj)
          + state_counts.shape[1] * lgamma(alpha)
          - counts_size * lgamma(beta)
      )
      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 4 for calling the BDsScore obj's underlying member method code with example usage: obj.local_score(variable, parents) and returns: score