class_docstr: The evaluation interface for semi-supervised learning and transfer learning for 
  graph-level tasks with pretraining and finetuning datasets. You can refer to `the benchmark 
  code <https://github.com/divelab/DIG/tree/dig/benchmarks/sslgraph>`_ for examples of usage.
  
  Args:
      dataset (torch_geometric.data.Dataset): The graph dataset for finetuning and evaluation.
      dataset_pretrain (torch_geometric.data.Dataset): The graph dataset for pretraining.
      label_rate (float, optional): Ratio of labels to use in finetuning dataset.
          (default: :obj:`1`)
      epoch_select (string, optional): :obj:`"test_max"` or :obj:`"val_max"`.
          (default: :obj:`"test_max"`)
      n_folds (int, optional): Number of folds for evaluation. (default: :obj:`10`)
      device (int, or torch.device, optional): Device for computation. (default: :obj:`None`)
      **kwargs (optional): Training and evaluation configs in :meth:`setup_train_config`.
      
  Examples
  --------
  >>> dataset, pretrain_dataset = get_dataset("NCI1", "semisupervised")
  >>> evaluator = GraphSemisupervised(dataset, pretrain_dataset, device=0)
  >>> evaluator.evaluate(model, encoder) # semi-supervised learning
  
  >>> dataset = MoleculeNet("./transfer_data", "HIV")
  >>> pretrain_dataset = ZINC("./transfer_data")
  >>> evaluator = GraphSemisupervised(dataset, pretrain_dataset, device=0)
  >>> evaluator.evaluate(model, encoder) # transfer learning for molecule classification
  
  Note
  ----
  When using :obj:`torch_geometric.data.Dataset` without our provided :obj:`get_dataset`
  function, you may need to manually add self-loops before input to evaluator if some view 
  function requires them, such as diffusion.
class_docstr_tok: ["The","evaluation","interface","for","semi-supervised","learning","and","transfer","learning","for","graph-level","tasks","with","pretraining","and","finetuning","datasets",".","You","can","refer","to","`","the","benchmark","code","<","https",":","\/\/github.com\/divelab\/DIG\/tree\/dig\/benchmarks\/sslgraph",">","`","_","for","examples","of","usage",".","Args",":","dataset","(","torch_geometric.data.Dataset",")",":","The","graph","dataset","for","finetuning","and","evaluation",".","dataset_pretrain","(","torch_geometric.data.Dataset",")",":","The","graph","dataset","for","pretraining",".","label_rate","(","float",",","optional",")",":","Ratio","of","labels","to","use","in","finetuning","dataset",".","(","default",":",":","obj",":","`","1","`",")","epoch_select","(","string",",","optional",")",":",":","obj",":","`","``","test_max","''","`","or",":","obj",":","`","``","val_max","''","`",".","(","default",":",":","obj",":","`","``","test_max","''","`",")","n_folds","(","int",",","optional",")",":","Number","of","folds","for","evaluation",".","(","default",":",":","obj",":","`","10","`",")","device","(","int",",","or","torch.device",",","optional",")",":","Device","for","computation",".","(","default",":",":","obj",":","`","None","`",")","*","*","kwargs","(","optional",")",":","Training","and","evaluation","configs","in",":","meth",":","`","setup_train_config","`",".","Examples","--","--","--","--",">",">",">","dataset",",","pretrain_dataset","=","get_dataset","(","``","NCI1","''",",","``","semisupervised","''",")",">",">",">","evaluator","=","GraphSemisupervised","(","dataset",",","pretrain_dataset",",","device=0",")",">",">",">","evaluator.evaluate","(","model",",","encoder",")","#","semi-supervised","learning",">",">",">","dataset","=","MoleculeNet","(","``",".\/transfer_data","''",",","``","HIV","''",")",">",">",">","pretrain_dataset","=","ZINC","(","``",".\/transfer_data","''",")",">",">",">","evaluator","=","GraphSemisupervised","(","dataset",",","pretrain_dataset",",","device=0",")",">",">",">","evaluator.evaluate","(","model",",","encoder",")","#","transfer","learning","for","molecule","classification","Note","--","--","When","using",":","obj",":","`","torch_geometric.data.Dataset","`","without","our","provided",":","obj",":","`","get_dataset","`","function",",","you","may","need","to","manually","add","self-loops","before","input","to","evaluator","if","some","view","function","requires","them",",","such","as","diffusion","."]
docstr: Run evaluation with given learning model and encoder(s).
  
  Args:
      learning_model: An object of a contrastive model (sslgraph.method.Contrastive)
          or a predictive model.
      encoder (torch.nn.Module, or list): Trainable pytorch model or list of models.
      pred_head (torch.nn.Module, optional): Prediction head. If None, will use linear 
          projection. (default: :obj:`None`)
  
  :rtype: (float, float)
code: def evaluate(
      self, learning_model, encoder, pred_head=None, fold_seed=12345
  ):
      r"""Run evaluation with given learning model and encoder(s).
  
      Args:
          learning_model: An object of a contrastive model (sslgraph.method.Contrastive)
              or a predictive model.
          encoder (torch.nn.Module, or list): Trainable pytorch model or list of models.
          pred_head (torch.nn.Module, optional): Prediction head. If None, will use linear
              projection. (default: :obj:`None`)
  
      :rtype: (float, float)
      """
      pretrain_loader = DataLoader(
          self.dataset_pretrain, self.batch_size, shuffle=True
      )
      p_optimizer = self.get_optim(self.p_optim)(
          encoder.parameters(),
          lr=self.p_lr,
          weight_decay=self.p_weight_decay,
      )
      if self.p_epoch > 0:
          encoder = next(
              learning_model.train(
                  encoder, pretrain_loader, p_optimizer, self.p_epoch
              )
          )
      model = PredictionModel(
          encoder, pred_head, learning_model.z_dim, self.out_dim
      ).to(self.device)
  
      test_scores = []
      val_losses = []
      val = not (
          self.epoch_select == "test_max"
          or self.epoch_select == "test_min"
      )
  
      for fold, train_loader, test_loader, val_loader in k_fold(
          self.n_folds,
          self.dataset,
          self.batch_size,
          self.label_rate,
          val,
          fold_seed,
      ):
          fold_model = copy.deepcopy(model)
          f_optimizer = self.get_optim(self.f_optim)(
              fold_model.parameters(),
              lr=self.f_lr,
              weight_decay=self.f_weight_decay,
          )
          with trange(self.f_epoch) as t:
              for epoch in t:
                  t.set_description("Fold %d, finetuning" % (fold + 1))
                  self.finetune(fold_model, f_optimizer, train_loader)
                  val_loss = self.eval_loss(fold_model, val_loader)
                  test_score = self.eval_metric(fold_model, test_loader)
                  val_losses.append(val_loss)
                  test_scores.append(test_score)
  
                  t.set_postfix(
                      val_loss="{:.4f}".format(val_loss),
                      acc="{:.4f}".format(test_score),
                  )
  
      val_losses, test_scores = torch.tensor(val_losses), torch.tensor(
          test_scores
      )
      val_losses = val_losses.view(self.n_folds, self.f_epoch)
      test_scores = test_scores.view(self.n_folds, self.f_epoch)
  
      if self.epoch_select == "test_max":
          _, selection = test_scores.mean(dim=0).max(dim=0)
          selection = selection.repeat(self.n_folds)
      elif self.epoch_select == "test_min":
          _, selection = test_scores.mean(dim=0).min(dim=0)
          selection = selection.repeat(self.n_folds)
      else:
          _, selection = val_losses.min(dim=1)
  
      test_scores = test_scores[
          torch.arange(self.n_folds, dtype=torch.long), selection
      ]
      test_acc_mean = test_scores.mean().item()
      test_acc_std = test_scores.std().item()
  
      return test_acc_mean, test_acc_std
  
imports: import copy
  import torch
  import numpy
  import torch.nn
  from tqdm import trange
  from sklearn.model_selection import StratifiedKFold
  from torch_geometric.loader import DataLoader
  from sklearn.svm import SVC
  from sklearn import preprocessing
  from sklearn.metrics import accuracy_score
  from sklearn.model_selection import GridSearchCV
label_desc: Use image node_id 3 for calling the GraphSemisupervised obj's underlying member method code with example usage: obj.evaluate(learning_model, encoder, pred_head, fold_seed) and returns: test_acc_mean,  test_acc_std