class_docstr: Bayesian probit regression with a Gaussian prior.
  
  ```none
  # The `+ 1` is for the bias term.
  for i in range(num_features + 1):
    weights[i] ~ Normal(loc=0, scale=1)
  
  for j in range(num_datapoints):
    label[j] ~ Bernoulli(probit=concat([features[j], [1]) @ weights)
  ```
class_docstr_tok: ["Bayesian","probit","regression","with","a","Gaussian","prior",".","``","`","none","#","The","`","+","1","`","is","for","the","bias","term",".","for","i","in","range","(","num_features","+","1",")",":","weights","[","i","]","~","Normal","(","loc=0",",","scale=1",")","for","j","in","range","(","num_datapoints",")",":","label","[","j","]","~","Bernoulli","(","probit=concat","(","[","features","[","j","]",",","[","1","]",")","@","weights",")","``","`"]
docstr: Construct the probit regression model.
  
  Args:
    train_features: Floating-point `Tensor` with shape `[num_train_points,
      num_features]`. Training features.
    train_labels: Integer `Tensor` with shape `[num_train_points]`. Training
      labels.
    test_features: Floating-point `Tensor` with shape `[num_test_points,
      num_features]`. Testing features. Can be `None`, in which case
      test-related sample transformations are not computed.
    test_labels: Integer `Tensor` with shape `[num_test_points]`. Testing
      labels. Can be `None`, in which case test-related sample transformations
      are not computed.
    name: Python `str` name prefixed to Ops created by this class.
    pretty_name: A Python `str`. The pretty name of this model.
  
  Raises:
    ValueError: If `test_features` and `test_labels` are either not both
      `None` or not both specified.
docstr_tok: ["Construct","the","probit","regression","model",".","Args",":","train_features",":","Floating-point","`","Tensor","`","with","shape","`","[","num_train_points",",","num_features","]","`",".","Training","features",".","train_labels",":","Integer","`","Tensor","`","with","shape","`","[","num_train_points","]","`",".","Training","labels",".","test_features",":","Floating-point","`","Tensor","`","with","shape","`","[","num_test_points",",","num_features","]","`",".","Testing","features",".","Can","be","`","None","`",",","in","which","case","test-related","sample","transformations","are","not","computed",".","test_labels",":","Integer","`","Tensor","`","with","shape","`","[","num_test_points","]","`",".","Testing","labels",".","Can","be","`","None","`",",","in","which","case","test-related","sample","transformations","are","not","computed",".","name",":","Python","`","str","`","name","prefixed","to","Ops","created","by","this","class",".","pretty_name",":","A","Python","`","str","`",".","The","pretty","name","of","this","model",".","Raises",":","ValueError",":","If","`","test_features","`","and","`","test_labels","`","are","either","not","both","`","None","`","or","not","both","specified","."]
code: def __init__(
      self,
      train_features,
      train_labels,
      test_features=None,
      test_labels=None,
      name="probit_regression",
      pretty_name="Probit Regression",
  ):
      """Construct the probit regression model.
  
      Args:
        train_features: Floating-point `Tensor` with shape `[num_train_points,
          num_features]`. Training features.
        train_labels: Integer `Tensor` with shape `[num_train_points]`. Training
          labels.
        test_features: Floating-point `Tensor` with shape `[num_test_points,
          num_features]`. Testing features. Can be `None`, in which case
          test-related sample transformations are not computed.
        test_labels: Integer `Tensor` with shape `[num_test_points]`. Testing
          labels. Can be `None`, in which case test-related sample transformations
          are not computed.
        name: Python `str` name prefixed to Ops created by this class.
        pretty_name: A Python `str`. The pretty name of this model.
  
      Raises:
        ValueError: If `test_features` and `test_labels` are either not both
          `None` or not both specified.
      """
      with tf.name_scope(name):
          num_features = int(train_features.shape[1] + 1)
          self._prior_dist = tfd.Sample(
              tfd.Normal(0.0, 1.0), num_features
          )
  
          def log_likelihood_fn(
              weights, features, labels, reduce_sum=True
          ):
              """The log_likelihood function."""
              features = tf.convert_to_tensor(features, tf.float32)
              features = _add_bias(features)
              labels = tf.convert_to_tensor(labels)
  
              probits = tf.einsum("nd,...d->...n", features, weights)
              log_likelihood = tfd.ProbitBernoulli(
                  probits=probits
              ).log_prob(labels)
              if reduce_sum:
                  return tf.reduce_sum(log_likelihood, [-1])
              else:
                  return log_likelihood
  
          self._train_log_likelihood_fn = functools.partial(
              log_likelihood_fn,
              features=train_features,
              labels=train_labels,
          )
  
          sample_transformations = {
              "identity": model.Model.SampleTransformation(
                  fn=lambda params: params,
                  pretty_name="Identity",
              )
          }
          if (test_features is not None) != (test_labels is not None):
              raise ValueError(
                  "`test_features` and `test_labels` must either both "
                  "be `None` or both specified. Got: test_features={}, "
                  "test_labels={}".format(test_features, test_labels)
              )
  
          if test_features is not None and test_labels is not None:
              test_log_likelihood_fn = functools.partial(
                  log_likelihood_fn,
                  features=test_features,
                  labels=test_labels,
              )
  
              sample_transformations[
                  "test_nll"
              ] = model.Model.SampleTransformation(
                  fn=test_log_likelihood_fn,
                  pretty_name="Test NLL",
              )
              sample_transformations[
                  "per_example_test_nll"
              ] = model.Model.SampleTransformation(
                  fn=functools.partial(
                      test_log_likelihood_fn, reduce_sum=False
                  ),
                  pretty_name="Per-example Test NLL",
              )
  
      super(ProbitRegression, self).__init__(
          default_event_space_bijector=tfb.Identity(),
          event_shape=self._prior_dist.event_shape,
          dtype=self._prior_dist.dtype,
          name=name,
          pretty_name=pretty_name,
          sample_transformations=sample_transformations,
      )
  
file_path: probability/spinoffs/inference_gym/inference_gym/targets/probit_regression.py
imports: import functools
  import tensorflow.compat.v2
  import tensorflow_probability
  from tensorflow_probability.python.internal import prefer_static
  from inference_gym.internal import data
  from inference_gym.targets import bayesian_model
  from inference_gym.targets import model
  from inference_gym.targets.ground_truth import german_credit_numeric_probit_regression
label_desc: Use image node_id 1 to create a new ProbitRegression object from inherited base classes: bayesian_model with example: obj = ProbitRegression(train_features, train_labels, test_features, test_labels, name, pretty_name)