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","--","--","--","--","--"]
docstr: Predict raw anomaly score of X using the fitted detector.
  For consistency, outliers are assigned with larger anomaly scores.
  Parameters
  ----------
  X : numpy array of shape (n_samples, n_features)
      The training input samples.
  Returns
  -------
  anomaly_scores : numpy array of shape (n_samples,)
      The anomaly score of the input samples.
docstr_tok: ["Predict","raw","anomaly","score","of","X","using","the","fitted","detector",".","For","consistency",",","outliers","are","assigned","with","larger","anomaly","scores",".","Parameters","--","--","--","--","--","X",":","numpy","array","of","shape","(","n_samples",",","n_features",")","The","training","input","samples",".","Returns","--","--","--","-","anomaly_scores",":","numpy","array","of","shape","(","n_samples",",",")","The","anomaly","score","of","the","input","samples","."]
code: def decision_function(self, X):
      """Predict raw anomaly score of X using the fitted detector.
      For consistency, outliers are assigned with larger anomaly scores.
      Parameters
      ----------
      X : numpy array of shape (n_samples, n_features)
          The training input samples.
      Returns
      -------
      anomaly_scores : numpy array of shape (n_samples,)
          The anomaly score of the input samples.
      """
  
      check_is_fitted(self, ["decision_scores_"])
      # X = check_array(X)
      X = X.astype("float32")
  
      # scale data
      if self.scaler == None:
          pass
      else:
          X = self.scaler.transform(X)
  
      # nearest neighbour search
      dist, _ = self.neigh.kneighbors(X, self.n_neighbours)
      dist = torch.tensor(dist, dtype=torch.float32).to(self.device)
      # forward pass
      with torch.no_grad():
          self.network.eval()
          anomaly_scores = self.network(dist)
  
      scores = anomaly_scores.cpu().detach().numpy().ravel()
  
      return scores
  
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 3 for calling the LUNAR obj's underlying member method code with example usage: obj.decision_function(X) and returns: scores