class_docstr: Trainer for a co-training model with agreement.
  
  Attributes:
    model_cls: An object whose type is a subclass of Model, representing the
      model for the sample classifier.
    model_agr: An object whose type is a subclass of Model, representing the
      model for the agreement model.
    max_num_iter_cotrain: An integer representing the maximum number of cotrain
      iterations to perform.
    min_num_iter_cls: An integer representing the minimum number of iterations
      to train the classification model for.
    max_num_iter_cls: An integer representing the maximum number of iterations
      to train the classification model for.
    num_iter_after_best_val_cls: An integer representing the number of extra
      iterations to perform after improving the validation accuracy of the
      classification model.
    min_num_iter_agr: An integer representing the minimum number of iterations
      to train the agreement model for.
    max_num_iter_agr: An integer representing the maximum number of iterations
      to train the agreement model.
    num_iter_after_best_val_agr: An integer representing the number of extra
      iterations to perform after improving the agreement validation accuracy.
    num_samples_to_label: Maximum number of samples to self-label after each
      cotrain iteration, provided that they have confidence higher than the
      min_confidence_new_label threshold.
    min_confidence_new_label: A float number between [0, 1] representing the
      minimum confidence the prediction for an unlabeled sample needs to have in
      order to allow it to be self-labeled. The confidence is the maximum
      probability the classification model assigns to any of the classes.
    keep_label_proportions: A boolean specifying whether to choose samples for
      self-labeling such that we maintain the original label proportions.
    num_warm_up_iter_agr: An integer representing the number of times we need to
      train the agreement model (i.e. number of cotrain iterations that train
      the agreement) before we start using it in the classification model's
      loss. While the agreement is not warmed up, the agreement model will
      always predict either disagreement, or agreement, by default, depending on
      the argument `agree_by_default`.
    optimizer: An optimizer.
    gradient_clip: A float number representing the maximum gradient norm allowed
      if we do gradient clipping. If None, no gradient clipping is performed.
    batch_size_agr: An integer representing the batch size of the agreement
      model.
    batch_size_cls: An integer representing the batch size of the classification
      model. This is used for the supervised component of the loss and for
      evaluation.
    learning_rate_cls: A float representing the learning rate used when training
      the classification model.
    learning_rate_agr: A float representing the learning rate used when training
      the agreement model.
    warm_start_cls: Boolean specifying if the classification model is trained
      from scratch in every cotrain itertion (if False), or if it continues from
      the parameter values in the previous cotrain iteration (if True).
    warm_start_agr: Boolean specifying if the agreement model is trained from
      scratch in every cotrain itertion (if False), or if it continues from the
      parameter values in the previous cotrain iteration (if True).
    enable_summaries: Boolean specifying whether to write TensorBoard summaries
      for the cotrain progress.
    enable_summaries_per_model: Boolean specifying whether to write TensorBoard
      summaries for the classification and agreement model progress.
    summary_dir: Directory path where to save the Tensorflow summaries.
    summary_step_cls: Integer representing the number of iterations after which
      to write TensorFlow summaries for the classification model.
    summary_step_agr: Integer representing the number of iterations after which
      to write TensorFlow summaries for the agreement model.
    logging_step_cls: Integer representing the number of iterations after which
      to log the loss and other training metrics for the classification model.
    logging_step_agr: Integer representing the number of iterations after which
      to log the loss and other training metrics for the agreement model.
    eval_step_cls: Integer representing the number of iterations after which to
      evaluate the classification model.
    eval_step_agr: Integer representing the number of iterations after which to
      evaluate the agreement model.
    checkpoints_step: Integer representing the number of iterations after which
      to save checkpoints.
    checkpoints_dir: Directory where to save checkpoints.
    data_dir: Directory where to write some files that contain self-labeled data
      backup.
    abs_loss_chg_tol: A float representing the absolute tolerance for checking
      if the training loss has converged. If the difference between the current
      loss and previous loss is less than `abs_loss_chg_tol`, we count this
      iteration towards convergence (see `loss_chg_iter_below_tol`).
    rel_loss_chg_tol: A float representing the relative tolerance for checking
      if the training loss has converged. If the ratio between the current loss
      and previous loss is less than `rel_loss_chg_tol`, we count this iteration
      towards convergence (see `loss_chg_iter_below_tol`).
    loss_chg_iter_below_tol: An integer representing the number of consecutive
      iterations that pass the convergence criteria before stopping training.
    use_perfect_agr: Boolean specifying whether to use a perfect agreement model
      that peeks at the correct test labels (for debugging only).
    use_perfect_cls: Boolean specifying whether to use a perfect classification
      model that peeks at the correct test labels (for debugging only).
    ratio_valid_agr: Ratio of the labeled sample pairs to use for validation
      whent training the agreement model.
    max_samples_valid_agr: Maximum number of sample pairs to use for validation
      whent training the agreement model.
    weight_decay_cls: Weight for the weight decay term in the classification
      model loss.
    weight_decay_schedule_cls: Schedule how to adjust the classification weight
      decay weight after every cotrain iteration.
    weight_decay_agr: Weight for the weight decay term in the agreement model
      loss.
    weight_decay_schedule_agr: Schedule how to adjust the agreement weight decay
      weight after every cotrain iteration.
    reg_weight_ll: A float representing the weight of the agreement loss term
      component of the classification model loss function, between
      labeled-labeled pairs of samples.
    reg_weight_lu: A float representing the weight of the agreement loss term
      component of the classification model loss function, between
      labeled-unlabeled pairs of samples.
    reg_weight_uu: A float representing the weight of the agreement loss term
      component of the classification model loss function, between
      unlabeled-unlabeled pairs of samples.
    num_pairs_reg: An integer representing the number of sample pairs of each
      type (LL, LU, UU) to include in each computation of the classification
      model loss.
    reg_weight_vat: A float representing the weight of the virtual adversarial
      training (VAT) regularization loss in the classification model loss
      function.
    use_ent_min: A boolean specifying whether to use entropy regularization with
      VAT.
    penalize_neg_agr: Whether to not only encourage agreement between samples
      that the agreement model believes should have the same label, but also
      penalize agreement when two samples agree when the agreement model
      predicts they should disagree.
    use_l2_cls: Whether to use L2 loss for classification, as opposed to the
      whichever loss is specified in the provided model_cls.
    first_iter_original: A boolean specifying whether the first cotrain
      iteration trains the original classification model (with no agreement
      term). We do this to evaluate how well a baseline model would do without
      the agreement. If true, there is no self-labeling after the first
      iteration, which trains original model. Self-labeling will be used only in
      the iterations that do include the agreement term.
    inductive: Boolean specifying whether this is an inductive or transductive
      setting. If inductive, then the validation and test labels are never seen
      when training the classification model. If transductive, the inputs of the
      test and validation samples are available at training time and can be used
      in the agreement loss term of the classification model as unsupervised
      regularization, and can also be labeled via self-labeling.
    seed: An integer representing the seed for the random number generator used
      when selecting batches of samples.
    eval_acc_pred_by_agr: Boolean specifying whether to evaluate the accuracy of
      a model that uses our trained agreement model to make predictions for the
      test samples, in a way similar to k-nearest neighbors, where the distance
      is given by the agreement model predictions.
    num_neighbors_pred_by_agr: An integer representing the number of neighbors
      to use when predicting by agreement. Note that this needs to be at least
      as much as the number of classes.
    load_from_checkpoint: A boolean specifying whethe the trained models are
      loaded from checkpoint, if one is available. If False, the models are
      always trained from scratch.
    use_graph: Boolean specifying whether to use to apply the agreement model on
      the graph edges, or otherwise use random pairs of samples.
    always_agree: Whether the agreement model should return 1.0 always (i.e. the
      samples always agree), to simulate the Neural Graph Machines model.
    add_negative_edges_agr:
docstr: Selects which samples to label next.
  
  Args:
    data: A CotrainData object.
    trainer_cls: A TrainerClassification object.
    session: A TensorFlow Session.
  
  Returns:
    selected_samples: numpy array containing the indices of the samples to be
      labeled.
    selected_labels: numpy array containing the indices of the labels to
      assign to each of the selected nodes.
docstr_tok: ["Selects","which","samples","to","label","next",".","Args",":","data",":","A","CotrainData","object",".","trainer_cls",":","A","TrainerClassification","object",".","session",":","A","TensorFlow","Session",".","Returns",":","selected_samples",":","numpy","array","containing","the","indices","of","the","samples","to","be","labeled",".","selected_labels",":","numpy","array","containing","the","indices","of","the","labels","to","assign","to","each","of","the","selected","nodes","."]
code: def _select_samples_to_label(self, data, trainer_cls, session):
      """Selects which samples to label next.
  
      Args:
        data: A CotrainData object.
        trainer_cls: A TrainerClassification object.
        session: A TensorFlow Session.
  
      Returns:
        selected_samples: numpy array containing the indices of the samples to be
          labeled.
        selected_labels: numpy array containing the indices of the labels to
          assign to each of the selected nodes.
      """
      # Select the candidate samples for self-labeling, and make predictions.
      # We remove the validation and test samples from the unlabeled data,
      # to avoid self-labeling them. We could potentially allow them to be
      # self-labeled, but once a node is self-labeled its label is fixed for
      # the remaining co-train iterations, so it would not take advantage
      # of the improved versions of the model.
      indices_unlabeled = data.get_indices_unlabeled()
      eval_ind = set(data.get_indices_val()) | set(
          data.get_indices_test()
      )
      indices_unlabeled = np.asarray(
          [ind for ind in indices_unlabeled if ind not in eval_ind]
      )
      predictions = trainer_cls.predict(
          session, indices_unlabeled, is_train=False
      )
  
      # Select most confident nodes. Compute confidence and most confident label,
      # which will be used as the new label.
      predicted_label = np.argmax(predictions, axis=-1)
      confidence = predictions[
          np.arange(predicted_label.shape[0]), predicted_label
      ]
      # Sort from most confident to least confident.
      indices_sorted = np.argsort(confidence)[::-1]
      indices_unlabeled = indices_unlabeled[indices_sorted]
      confidence = confidence[indices_sorted]
      predicted_label = predicted_label[indices_sorted]
  
      # Keep only samples that have at least min_confidence_new_label confidence.
      confident_indices = np.argwhere(
          confidence > self.min_confidence_new_label
      )[:, 0]
      if confident_indices.shape[0] == 0:
          logging.info(
              "No unlabeled nodes with confidence > %.2f. "
              "Skipping self-labeling...",
              self.min_confidence_new_label,
          )
          selected_samples = np.zeros((0,), dtype=np.int64)
          selected_labels = np.zeros((0,), dtype=np.int64)
          return selected_samples, selected_labels
  
      if data.keep_label_proportions:
          # Pick the top num_samples_to_label most confident nodes, while making
          # sure the ratio of the labels are kept.
          # First keep only nodes which achieve the min required confidence.
          num_confident = len(confident_indices)
          nodes_with_min_conf = indices_unlabeled[:num_confident]
          labels_with_min_conf = predicted_label[:num_confident]
          # Out of these, select the desired number of samples per class,
          # according to class proportions.
          selected_samples = []
          selected_labels = []
          for label, prop in data.label_prop.items():
              num_samples_to_select = int(
                  prop * self.num_samples_to_label
              )
              label_idxs = np.where(labels_with_min_conf == label)[0]
              if len(label_idxs) <= num_samples_to_select:
                  # Select all available samples labeled with this label.
                  selected_samples.append(
                      nodes_with_min_conf[label_idxs]
                  )
                  selected_labels.append(
                      labels_with_min_conf[label_idxs]
                  )
              elif num_samples_to_select > 0:
                  # Select the first ones, since they are sorted by confidence.
                  selected_samples.append(
                      nodes_with_min_conf[label_idxs][
                          :num_samples_to_select
                      ]
                  )
                  selected_labels.append(
                      labels_with_min_conf[label_idxs][
                          :num_samples_to_select
                      ]
                  )
          selected_samples = np.concatenate(selected_samples)
          selected_labels = np.concatenate(selected_labels)
      else:
          # Pick the top num_samples_to_label most confident nodes,
          # irrespective of their labels.
          idx = np.amax(confident_indices)
          max_idx = min(self.num_samples_to_label - 1, idx)
          selected_samples = indices_unlabeled[: max_idx + 1]
          selected_labels = predicted_label[: max_idx + 1]
  
      return selected_samples, selected_labels
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import logging
  import os
  from ..data.dataset import CotrainDataset
  from ..models.gcn import GCN
  import numpy
  import tensorflow
  from tqdm import tqdm
  from .trainer_agreement import TrainerAgreement
  from .trainer_agreement import TrainerAgreementAlwaysAgree
  from .trainer_agreement import TrainerPerfectAgreement
  from .trainer_base import Trainer
  from .trainer_classification import TrainerClassification
  from .trainer_classification import TrainerPerfectClassification
  from .trainer_classification_gcn import TrainerClassificationGCN
label_desc: Use image node_id 2 for calling the TrainerCotraining obj's underlying member method code with example usage: obj._select_samples_to_label(data, trainer_cls, session) and returns: selected_samples,  selected_labels, selected_samples,  selected_labels