class_docstr: Train PyTorch or TensorFlow predictors while mitigating unfairness .
  
  This model implements the supervised learning method proposed in
  "Mitigating Unwanted Biases with Adversarial Learning". :footcite:`zhang2018mitigating`
  This algorithm takes as input two neural network
  models, a predictor model and an adversarial model, defined either as a
  `PyTorch module
  <https://pytorch.org/docs/stable/generated/torch.nn.Module.html>`_ or
  `TensorFlow2 model
  <https://www.tensorflow.org/api_docs/python/tf/keras/Model>`_. You train this
  predictor using an API that is similar to estimators in `sklearn`.
  
  The predictor model takes the features :code:`X` as input and seeks
  to predict :code:`y`.
  For real-valued predictions of :code:`y`, regression takes place.
  For binary classification, the predictor model should return a single
  real-valued score, which is transformed into a probability of the
  positive class via the logistic function (aka sigmoid), similarly to
  logistic regression. For multi-class classification, the predictor
  model should return a vector of real-valued scores, which are
  transformed into class probabilities via the softmax function,
  similarly to multinomial logistic regression. The training loss is
  the negative log likelihood (aka log loss, logistic loss,
  cross-entropy loss). For regression, the squared error is taken, as
  it is proven to be equivalent to a scaled cross-entropy loss (under
  certain distribution assumptions).
  
  The adversarial model for demographic parity takes scores
  produced by the predictor model as input, and seeks to predict
  :code:`sensitive_features`. Depending on the type of the provided
  sensitive features, the model should produce a scalar
  or vector output. Three types of sensitive features are supported:
  (1) a single binary feature; (2) a single discrete feature; (3) one or
  multiple real-valued features. For a single binary sensitive feature
  and a single discrete feature, the network outputs are transformed
  by the logistic function and the softmax function, respectively, and
  the loss is the negative log likelihood. For one or multiple
  real-valued features, the network output is left as is, and the
  loss is a square loss.
  
  The adversarial model for equalized odds additionaly takes
  :code:`y` as input. For multi-class classification, :code:`y` is
  transformed using one-hot encoding.
  
  Parameters
  ----------
  backend : str, BackendEngine, default = 'auto'
      The backend to use. Must be one of :code:`'torch'`, :code:`'tensorflow'`,
      or :code:`'auto'` which indicates PyTorch, TensorFlow, or to
      automatically infer
      the backend from the :code:`predictor_model`.
      You can also pass in a BackendEngine class.
  
  predictor_model : list, torch.nn.Module, tensorflow.keras.Model
      The predictor model to train.
      Instead of a neural network model, it is possible to pass a list
      :math:`[k_1, k_2, \dots]`, where each :math:`k_i` either indicates
      the number of nodes (if :math:`k_i` is an integer) or
      an activation function (if :math:`k_i` is a string) or
      a layer or activation function instance directly (if :math:`k_i` is
      a callable). The default parameter is :code:`[]`, which indicates
      a neural network without any hidden layers.
      However, the number of nodes in the input
      and output layer are automatically inferred from data, and the final
      activation function (such as softmax for categorical
      predictors) are inferred from data.
      If :code:`backend` is specified, you cannot pass a model
      that uses a different backend.
  
  adversary_model : list, torch.nn.Module, tensorflow.keras.Model
      The adversary model to train. Defined similarly as :code:`predictor_model`.
      Must be the same type as the
      :code:`predictor_model`.
  
  predictor_optimizer : str, torch.optim, tensorflow.keras.optimizers, callable, default = 'Adam'
      The optimizer class to use. If a string is passed instead, this must be
      either 'SGD' or 'Adam'. A corresponding SGD or Adam optimizer is
      initialized with the given predictor model and learning rate.
      If an instance of a subclass of torch.optim.Optimizer
      or tensorflow.keras.optimizers.Optimizer is passed, this
      is used directly. If a callable :code:`fn` is passed, we call this
      callable and pass our model, and set the result of this call
      as the optimizer, so: :code:`predictor_optimizer=fn(predictor_model)`.
  
  adversary_optimizer : str, torch.optim, tensorflow.keras.optimizers, callable, default = 'Adam'
      The optimizer class to use. Defined similarly as
      :code:`predictor_optimizer`.
  
  constraints : str, default = 'demographic_parity'
      The fairness constraint. Must be either 'demographic_parity'
      or 'equalized_odds'.
  
  y_transform : str, sklearn.base.TransformerMixin, default = "auto"
      The preprocessor to use on the predictions :code:`y`.
      Either a keyword such as :code:`"auto"` or :code:`"one_hot_encoder",
      None, or a preprocessor. None indicates to pass-through data directly
      without preprocessing.
      The given transformer *must* map data
      to a 2d ndarray containing only floats.
  
  sf_transform : str, sklearn.base.TransformerMixin, default = "auto"
      The preprocessor to use on the :code:`sensitive_features`.
      Either a keyword such as :code:`"auto"` or :code:`"one_hot_encoder",
      None, or a preprocessor. None indicates to pass-through data directly
      without preprocessing.
      The given transformer *must* map data
      to a 2d ndarray containing only floats.
  
  learning_rate : float, default = 0.001
      A small number greater than zero to set as a learning rate.
  
  alpha : float, default = 1.0
      A small number :math:`\alpha` as specified in the paper. It
      is the factor that balances the training towards predicting :code:`y`
      (choose :math:`\alpha` closer to zero) or enforcing fairness constraint
      (choose larger :math:`\alpha`).
  
  epochs : int, default = 1
      Number of epochs to train for.
  
  batch_size : int, default = 32
      Batch size. For no batching, set this to -1.
  
  shuffle : bool, default = False
      When true, shuffle the data before every epoch (including the first).
  
  progress_updates : number, optional, default = None
      If a number :math:`t` is provided, we print an update
      about the training loop after processing a batch and :math:`t` seconds
      have passed since the previous update.
  
  skip_validation : bool, default = False
      Skip the validation of the data. Useful because validate_input is
      a costly operation, and we may instead pass all data to validate_input
      at an earlier stage. Note that not only checking :code:`X`
      is skipped, but also no tranform is applied to :code:`y` and
      :code:`sensitive_features`.
  
  callbacks : callable
      Callback function, called after every batch. For instance useable when
      wanting to validate. A list of callback functions can also be provided.
      Each callback function is passed two arguments :code:`self` (the
      estimator instance) and :code:`step` (the completed iteration), and
      may return a Boolean value. If the returned value is `True`, the
      optimization algorithm terminates. This can be used to implement
      *early stopping*.
  
  cuda : str, default = None
      A string to indicate which device to use when training. For instance,
      set :code:`cuda='cuda:0'` to train on the first GPU. Only for PyTorch
      backend.
  
  warm_start : bool, default = False
      Normally, when set to False, a call to :code:`fit()` triggers reinitialization,
      which discards the models and intializes them again. Setting to
      True triggers reuse of these models. Note: if pre-initialized models
      are passed, the models (and their parameters) are never discarded.
  
  random_state : int, RandomState, default = None
      Controls the randomized aspects of this algorithm, such as shuffling.
      Useful to get reproducible output across multiple function calls.
  
  References
  ----------
  .. footbibliography::
class_docstr_tok: ["Train","PyTorch","or","TensorFlow","predictors","while","mitigating","unfairness",".","This","model","implements","the","supervised","learning","method","proposed","in","''","Mitigating","Unwanted","Biases","with","Adversarial","Learning","''",".",":","footcite",":","`","zhang2018mitigating","`","This","algorithm","takes","as","input","two","neural","network","models",",","a","predictor","model","and","an","adversarial","model",",","defined","either","as","a","`","PyTorch","module","<","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.Module.html",">","`","_","or","`","TensorFlow2","model","<","https",":","\/\/www.tensorflow.org\/api_docs\/python\/tf\/keras\/Model",">","`","_",".","You","train","this","predictor","using","an","API","that","is","similar","to","estimators","in","`","sklearn","`",".","The","predictor","model","takes","the","features",":","code",":","`","X","`","as","input","and","seeks","to","predict",":","code",":","`","y","`",".","For","real-valued","predictions","of",":","code",":","`","y","`",",","regression","takes","place",".","For","binary","classification",",","the","predictor","model","should","return","a","single","real-valued","score",",","which","is","transformed","into","a","probability","of","the","positive","class","via","the","logistic","function","(","aka","sigmoid",")",",","similarly","to","logistic","regression",".","For","multi-class","classification",",","the","predictor","model","should","return","a","vector","of","real-valued","scores",",","which","are","transformed","into","class","probabilities","via","the","softmax","function",",","similarly","to","multinomial","logistic","regression",".","The","training","loss","is","the","negative","log","likelihood","(","aka","log","loss",",","logistic","loss",",","cross-entropy","loss",")",".","For","regression",",","the","squared","error","is","taken",",","as","it","is","proven","to","be","equivalent","to","a","scaled","cross-entropy","loss","(","under","certain","distribution","assumptions",")",".","The","adversarial","model","for","demographic","parity","takes","scores","produced","by","the","predictor","model","as","input",",","and","seeks","to","predict",":","code",":","`","sensitive_features","`",".","Depending","on","the","type","of","the","provided","sensitive","features",",","the","model","should","produce","a","scalar","or","vector","output",".","Three","types","of","sensitive","features","are","supported",":","(","1",")","a","single","binary","feature",";","(","2",")","a","single","discrete","feature",";","(","3",")","one","or","multiple","real-valued","features",".","For","a","single","binary","sensitive","feature","and","a","single","discrete","feature",",","the","network","outputs","are","transformed","by","the","logistic","function","and","the","softmax","function",",","respectively",",","and","the","loss","is","the","negative","log","likelihood",".","For","one","or","multiple","real-valued","features",",","the","network","output","is","left","as","is",",","and","the","loss","is","a","square","loss",".","The","adversarial","model","for","equalized","odds","additionaly","takes",":","code",":","`","y","`","as","input",".","For","multi-class","classification",",",":","code",":","`","y","`","is","transformed","using","one-hot","encoding",".","Parameters","--","--","--","--","--","backend",":","str",",","BackendEngine",",","default","=","'auto'","The","backend","to","use",".","Must","be","one","of",":","code",":","`","'torch","'","`",",",":","code",":","`","'tensorflow","'","`",",","or",":","code",":","`","'auto","'","`","which","indicates","PyTorch",",","TensorFlow",",","or","to","automatically","infer","the","backend","from","the",":","code",":","`","predictor_model","`",".","You","can","also","pass","in","a","BackendEngine","class",".","predictor_model",":","list",",","torch.nn.Module",",","tensorflow.keras.Model","The","predictor","model","to","train",".","Instead","of","a","neural","network","model",",","it","is","possible","to","pass","a","list",":","math",":","`","[","k_1",",","k_2",",","\\dots","]","`",",","where","each",":","math",":","`","k_i","`","either","indicates","the","number","of","nodes","(","if",":","math",":","`","k_i","`","is","an","integer",")","or","an","activation","function","(","if",":","math",":","`","k_i","`","is","a","string",")","or","a","layer","or","activation","function","instance","directly","(","if",":","math",":","`","k_i","`","is","a","callable",")",".","The","default","parameter","is",":","code",":","`","[","]","`",",","which","indicates","a","neural","network","without","any","hidden","layers",".","However",",","the","number","of","nodes","in","the","input","and","output","layer","are","automatically","inferred","from","data",",","and","the","final","activation","function","(","such","as","softmax","for","categorical","predictors",")","are","inferred","from","data",".","If",":","code",":","`","backend","`","is","specified",",","you","can","not","pass","a","model","that","uses","a","different","backend",".","adversary_model",":","list",",","torch.nn.Module",",","tensorflow.keras.Model","The","adversary","model","to","train",".","Defined","similarly","as",":","code",":","`","predictor_model","`",".","Must","be","the","same","type","as","the",":","code",":","`","predictor_model","`",".","predictor_optimizer",":","str",",","torch.optim",",","tensorflow.keras.optimizers",",","callable",",","default","=","'Adam'","The","optimizer","class","to","use",".","If","a","string","is","passed","instead",",","this","must","be","either","'SGD","'","or","'Adam","'",".","A","corresponding","SGD","or","Adam","optimizer","is","initialized","with","the","given","predictor","model","and","learning","rate",".","If","an","instance","of","a","subclass","of","torch.optim.Optimizer","or","tensorflow.keras.optimizers.Optimizer","is","passed",",","this","is","used","directly",".","If","a","callable",":","code",":","`","fn","`","is","passed",",","we","call","this","callable","and","pass","our","model",",","and","set","the","result","of","this","call","as","the","optimizer",",","so",":",":","code",":","`","predictor_optimizer=fn","(","predictor_model",")","`",".","adversary_optimizer",":","str",",","torch.optim",",","tensorflow.keras.optimizers",",","callable",",","default","=","'Adam'","The","optimizer","class","to","use",".","Defined","similarly","as",":","code",":","`","predictor_optimizer","`",".","constraints",":","str",",","default","=","'demographic_parity'","The","fairness","constraint",".","Must","be","either","'demographic_parity'","or","'equalized_odds","'",".","y_transform",":","str",",","sklearn.base.TransformerMixin",",","default","=","``","auto","''","The","preprocessor","to","use","on","the","predictions",":","code",":","`","y","`",".","Either","a","keyword","such","as",":","code",":","`","``","auto","''","`","or",":","code",":","`","``","one_hot_encoder","''",",","None",",","or","a","preprocessor",".","None","indicates","to","pass-through","data","directly","without","preprocessing",".","The","given","transformer","*","must","*","map","data","to","a","2d","ndarray","containing","only","floats",".","sf_transform",":","str",",","sklearn.base.TransformerMixin",",","default","=","``","auto","''","The","preprocessor","to","use","on","the",":","code",":","`","sensitive_features","`",".","Either","a","keyword","such","as",":","code",":","`","``","auto","''","`","or",":","code",":","`","``","one_hot_encoder","''",",","None",",","or","a","preprocessor",".","None","indicates","to","pass-through","data","directly","without","preprocessing",".","The","given","transformer","*","must","*","map","data","to","a","2d","ndarray","containing","only","floats",".","learning_rate",":","float",",","default","=","0.001","A","small","number","greater","than","zero","to","set","as","a","learning","rate",".","alpha",":","float",",","default","=","1.0","A","small","number",":","math",":","`","\\alpha","`","as","specified","in","the","paper",".","It","is","the","factor","that","balances","the","training","towards","predicting",":","code",":","`","y","`","(","choose",":","math",":","`","\\alpha","`","closer","to","zero",")","or","enforcing","fairness","constraint","(","choose","larger",":","math",":","`","\\alpha","`",")",".","epochs",":","int",",","default","=","1","Number","of","epochs","to","train","for",".","batch_size",":","int",",","default","=","32","Batch","size",".","For","no","batching",",","set","this","to","-1.","shuffle",":","bool",",","default","=","False","When","true",",","shuffle","the","data","before","every","epoch","(","including","the","first",")",".","progress_updates",":","number",",","optional",",","default","=","None","If","a","number",":","math",":","`","t","`","is","provided",",","we","print","an","update","about","the","training","loop","after","processing","a","batch","and",":","math",":","`","t","`","seconds","have","passed","since","the","previous","update",".","skip_validation",":","bool",",","default","=","False","Skip","the","validation","of","the","data",".","Useful","because","validate_input","is","a","costly","operation",",","and","we","may","instead","pass","all","data","to","validate_input","at","an","earlier","stage",".","Note","that","not","only","checking",":","code",":","`","X","`","is","skipped",",","but","also","no","tranform","is","applied","to",":","code",":","`","y","`","and",":","code",":","`","sensitive_features","`",".","callbacks",":","callable","Callback","function",",","called","after","every","batch",".","For","instance","useable","when","wanting","to","validate",".","A","list","of","callback","functions","can","also","be","provided",".","Each","callback","function","is","passed","two","arguments",":","code",":","`","self","`","(","the","estimator","instance",")","and",":","code",":","`","step","`","(","the","completed","iteration",")",",","and","may","return","a","Boolean","value",".","If","the","returned","value","is","`","True","`",",","the","optimization","algorithm","terminates",".","This","can","be","used","to","implement","*","early","stopping","*",".","cuda",":","str",",","default","=","None","A","string","to","indicate","which","device","to","use","when","training",".","For","instance",",","set",":","code",":","`","cuda='cuda:0","'","`","to","train","on","the","first","GPU",".","Only","for","PyTorch","backend",".","warm_start",":","bool",",","default","=","False","Normally",",","when","set","to","False",",","a","call","to",":","code",":","`","fit","(",")","`","triggers","reinitialization",",","which","discards","the","models","and","intializes","them","again",".","Setting","to","True","triggers","reuse","of","these","models",".","Note",":","if","pre-initialized","models","are","passed",",","the","models","(","and","their","parameters",")","are","never","discarded",".","random_state",":","int",",","RandomState",",","default","=","None","Controls","the","randomized","aspects","of","this","algorithm",",","such","as","shuffling",".","Useful","to","get","reproducible","output","across","multiple","function","calls",".","References","--","--","--","--","--","..","footbibliography",":",":"]
docstr: Perform one epoch on given samples and update model.
  
  Parameters
  ----------
  X : numpy.ndarray
      Two-dimensional numpy array containing training data
  
  y : array
      Array-like containing training targets
  
  sensitive_features : array
      Array-like containing the sensitive feature of the
      training data.
docstr_tok: ["Perform","one","epoch","on","given","samples","and","update","model",".","Parameters","--","--","--","--","--","X",":","numpy.ndarray","Two-dimensional","numpy","array","containing","training","data","y",":","array","Array-like","containing","training","targets","sensitive_features",":","array","Array-like","containing","the","sensitive","feature","of","the","training","data","."]
code: def partial_fit(self, X, y, *, sensitive_features=None):
      """
      Perform one epoch on given samples and update model.
  
      Parameters
      ----------
      X : numpy.ndarray
          Two-dimensional numpy array containing training data
  
      y : array
          Array-like containing training targets
  
      sensitive_features : array
          Array-like containing the sensitive feature of the
          training data.
      """
      X, Y, A = self._validate_input(
          X, y, sensitive_features, reinitialize=False
      )
      self.backendEngine_.train_step(X, Y, A)
  
      return self
  
imports: from math import ceil
  from time import time
  from sklearn.utils import check_scalar
  from ._constants import _IMPORT_ERROR_MESSAGE, _KWARG_ERROR_MESSAGE, _PREDICTION_FUNCTION_AMBIGUOUS, _PROGRESS_UPDATE, _CALLBACK_RETURNS_ERROR
  from ._backend_engine import BackendEngine
  from ._pytorch_engine import PytorchEngine
  from ._tensorflow_engine import TensorflowEngine
  from ._preprocessor import FloatTransformer, _get_type
  from sklearn.base import ClassifierMixin, RegressorMixin, BaseEstimator, TransformerMixin
  from sklearn.utils.validation import check_is_fitted, check_random_state, check_array
  from sklearn.exceptions import NotFittedError
  from numpy import zeros, argmax, arange
  import logging
label_desc: Use image node_id 4 for calling the _AdversarialFairness obj's underlying member method code with example usage: obj.partial_fit(X, y) and returns: self