class_docstr: LUNAR class for outlier detection. See https://www.aaai.org/AAAI22Papers/AAAI-51.GoodgeA.pdf for details.
  For an observation, its ordered list of distances to its k nearest neighbours is input to a neural network, 
  with one of the following outputs:
  
      1) SCORE_MODEL: network directly outputs the anomaly score.
      2) WEIGHT_MODEL: network outputs a set of weights for the k distances, the anomaly score is then the
          sum of weighted distances.
  
  See :cite:`goodge2022lunar` for details.
  
  Parameters
  ----------
  model_type: str in ['WEIGHT', 'SCORE'], optional (default = 'WEIGHT')
      Whether to use WEIGHT_MODEL or SCORE_MODEL for anomaly scoring.
  
  n_neighbors: int, optional (default = 5)
      Number of neighbors to use by default for k neighbors queries.
  
  negative_sampling: str in ['UNIFORM', 'SUBSPACE', MIXED'], optional (default = 'MIXED)
      Type of negative samples to use between:
  
      - 'UNIFORM': uniformly distributed samples
      - 'SUBSPACE': subspace perturbation (additive random noise in a subset of features)
      - 'MIXED': a combination of both types of samples
  
  val_size: float in [0,1], optional (default = 0.1)
      Proportion of samples to be used for model validation
  
  scaler: object in {StandardScaler(), MinMaxScaler(), optional (default = MinMaxScaler())
      Method of data normalization
  
  epsilon: float, optional (default = 0.1)
      Hyper-parameter for the generation of negative samples. 
      A smaller epsilon results in negative samples more similar to normal samples.
  
  proportion: float, optional (default = 1.0)
      Hyper-parameter for the proprotion of negative samples to use relative to the 
      number of normal training samples.
  
  n_epochs: int, optional (default = 200)
      Number of epochs to train neural network.
  
  lr: float, optional (default = 0.001)
      Learning rate.
  
  wd: float, optional (default = 0.1)
      Weight decay.
  
  verbose: int in {0,1}, optional (default = 0):
      To view or hide training progress
  
  Attributes
  ----------
class_docstr_tok: ["LUNAR","class","for","outlier","detection",".","See","https",":","\/\/www.aaai.org\/AAAI22Papers\/AAAI-51.GoodgeA.pdf","for","details",".","For","an","observation",",","its","ordered","list","of","distances","to","its","k","nearest","neighbours","is","input","to","a","neural","network",",","with","one","of","the","following","outputs",":","1",")","SCORE_MODEL",":","network","directly","outputs","the","anomaly","score",".","2",")","WEIGHT_MODEL",":","network","outputs","a","set","of","weights","for","the","k","distances",",","the","anomaly","score","is","then","the","sum","of","weighted","distances",".","See",":","cite",":","`","goodge2022lunar","`","for","details",".","Parameters","--","--","--","--","--","model_type",":","str","in","[","'WEIGHT","'",",","'SCORE","'","]",",","optional","(","default","=","'WEIGHT","'",")","Whether","to","use","WEIGHT_MODEL","or","SCORE_MODEL","for","anomaly","scoring",".","n_neighbors",":","int",",","optional","(","default","=","5",")","Number","of","neighbors","to","use","by","default","for","k","neighbors","queries",".","negative_sampling",":","str","in","[","'UNIFORM","'",",","'SUBSPACE","'",",","MIXED","'","]",",","optional","(","default","=","'MIXED",")","Type","of","negative","samples","to","use","between",":","-","'UNIFORM","'",":","uniformly","distributed","samples","-","'SUBSPACE","'",":","subspace","perturbation","(","additive","random","noise","in","a","subset","of","features",")","-","'MIXED","'",":","a","combination","of","both","types","of","samples","val_size",":","float","in","[","0,1","]",",","optional","(","default","=","0.1",")","Proportion","of","samples","to","be","used","for","model","validation","scaler",":","object","in","{","StandardScaler","(",")",",","MinMaxScaler","(",")",",","optional","(","default","=","MinMaxScaler","(",")",")","Method","of","data","normalization","epsilon",":","float",",","optional","(","default","=","0.1",")","Hyper-parameter","for","the","generation","of","negative","samples",".","A","smaller","epsilon","results","in","negative","samples","more","similar","to","normal","samples",".","proportion",":","float",",","optional","(","default","=","1.0",")","Hyper-parameter","for","the","proprotion","of","negative","samples","to","use","relative","to","the","number","of","normal","training","samples",".","n_epochs",":","int",",","optional","(","default","=","200",")","Number","of","epochs","to","train","neural","network",".","lr",":","float",",","optional","(","default","=","0.001",")","Learning","rate",".","wd",":","float",",","optional","(","default","=","0.1",")","Weight","decay",".","verbose",":","int","in","{","0,1","}",",","optional","(","default","=","0",")",":","To","view","or","hide","training","progress","Attributes","--","--","--","--","--"]
code: def __init__(
      self,
      model_type="WEIGHT",
      n_neighbours=5,
      negative_sampling="MIXED",
      val_size=0.1,
      scaler=MinMaxScaler(),
      epsilon=0.1,
      proportion=1.0,
      n_epochs=200,
      lr=0.001,
      wd=0.1,
      verbose=0,
      contamination=0.1,
  ):
      super(LUNAR, self).__init__(contamination=contamination)
  
      self.model_type = model_type
      self.n_neighbours = n_neighbours
      self.negative_sampling = negative_sampling
      self.epsilon = epsilon
      self.proportion = proportion
      self.n_epochs = n_epochs
      self.scaler = scaler
      self.lr = lr
      self.wd = wd
      self.val_size = val_size
      self.verbose = verbose
      self.device = torch.device(
          "cuda" if torch.cuda.is_available() else "cpu"
      )
  
      if model_type == "SCORE":
          self.network = SCORE_MODEL(n_neighbours).to(self.device)
      elif model_type == "WEIGHT":
          self.network = WEIGHT_MODEL(n_neighbours).to(self.device)
  
imports: from copy import deepcopy
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from sklearn.metrics import roc_auc_score
  from sklearn.model_selection import train_test_split
  from sklearn.neighbors import NearestNeighbors
  from sklearn.preprocessing import MinMaxScaler
  from sklearn.utils.validation import check_is_fitted
  from .base import BaseDetector
label_desc: Use image node_id 1 to create a new LUNAR object from inherited base classes: BaseDetector with example: obj = LUNAR(model_type, n_neighbours, negative_sampling, val_size, scaler, epsilon, proportion, n_epochs, lr, wd, verbose, contamination)