class_docstr: The evaluation interface for unsupervised graph representation learning evaluated with 
  linear classification. 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 classification dataset.
      classifier (string, optional): Linear classifier for evaluation, :obj:`"SVC"` or 
          :obj:`"LogReg"`. (default: :obj:`"SVC"`)
      log_interval (int, optional): Perform evaluation per k epochs. (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
  --------
  >>> encoder = Encoder(...)
  >>> model = Contrastive(...)
  >>> evaluator = GraphUnsupervised(dataset, log_interval=10, device=0, p_lr = 0.001)
  >>> evaluator.evaluate(model, encoder)
class_docstr_tok: ["The","evaluation","interface","for","unsupervised","graph","representation","learning","evaluated","with","linear","classification",".","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","classification","dataset",".","classifier","(","string",",","optional",")",":","Linear","classifier","for","evaluation",",",":","obj",":","`","``","SVC","''","`","or",":","obj",":","`","``","LogReg","''","`",".","(","default",":",":","obj",":","`","``","SVC","''","`",")","log_interval","(","int",",","optional",")",":","Perform","evaluation","per","k","epochs",".","(","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","--","--","--","--",">",">",">","encoder","=","Encoder","(","...",")",">",">",">","model","=","Contrastive","(","...",")",">",">",">","evaluator","=","GraphUnsupervised","(","dataset",",","log_interval=10",",","device=0",",","p_lr","=","0.001",")",">",">",">","evaluator.evaluate","(","model",",","encoder",")"]
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): Trainable pytorch model or list of models.
      fold_seed (int, optional): Seed for fold split. (default: :obj:`None`)
  
  :rtype: (float, float)
code: def evaluate(self, learning_model, encoder, fold_seed=None):
      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): Trainable pytorch model or list of models.
          fold_seed (int, optional): Seed for fold split. (default: :obj:`None`)
  
      :rtype: (float, float)
      """
  
      pretrain_loader = DataLoader(
          self.dataset, self.batch_size, shuffle=True
      )
      if isinstance(encoder, list):
          params = [{"params": enc.parameters()} for enc in encoder]
      else:
          params = encoder.parameters()
  
      p_optimizer = self.get_optim(self.p_optim)(
          params, lr=self.p_lr, weight_decay=self.p_weight_decay
      )
  
      test_scores_m, test_scores_sd = [], []
      for i, enc in enumerate(
          learning_model.train(
              encoder, pretrain_loader, p_optimizer, self.p_epoch, True
          )
      ):
          if (i + 1) % self.log_interval == 0:
              test_scores = []
              loader = DataLoader(
                  self.dataset, self.batch_size, shuffle=False
              )
              embed, lbls = self.get_embed(enc.to(self.device), loader)
              lbs = np.array(
                  preprocessing.LabelEncoder().fit_transform(lbls)
              )
  
              kf = StratifiedKFold(
                  n_splits=self.n_folds,
                  shuffle=True,
                  random_state=fold_seed,
              )
              for fold, (train_index, test_index) in enumerate(
                  kf.split(embed, lbls)
              ):
                  test_score = self.get_clf()(
                      embed[train_index],
                      lbls[train_index],
                      embed[test_index],
                      lbls[test_index],
                  )
                  test_scores.append(test_score)
  
              kfold_scores = torch.tensor(test_scores)
              test_score_mean = kfold_scores.mean().item()
              test_score_std = kfold_scores.std().item()
              test_scores_m.append(test_score_mean)
              test_scores_sd.append(test_score_std)
  
      idx = np.argmax(test_scores_m)
      acc = test_scores_m[idx]
      sd = test_scores_sd[idx]
      print(
          "Best epoch %d: acc %.4f +/-(%.4f)"
          % ((idx + 1) * self.log_interval, acc, sd)
      )
      return acc, sd
  
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 GraphUnsupervised obj's underlying member method code with example usage: obj.evaluate(learning_model, encoder, fold_seed) and returns: acc,  sd