text: import warnings
  import pickle
  import matplotlib.pyplot as plt
  import matplotlib
  import numpy as np
  import sys
  import os
  import math
  import bisect
  import tensorflow as tf
  import warnings
  
  sys.path.insert(0, '../../..')
  
  from cde.density_estimator import GPDExtremeValueMixtureDensityNetwork,NoNaNGPDExtremeValueMixtureDensityNetwork, NewGPDExtremeValueMixtureDensityNetwork
  from cde.density_estimator import MixtureDensityNetwork
  from cde.density_estimator import ExtremeValueMixtureDensityNetwork
  
  from cde.data_collector import MatlabDataset, MatlabDatasetH5, get_most_common_unique_states
  from cde.density_estimator import plot_conditional_hist, measure_percentile, measure_percentile_allsame, measure_tail, measure_tail_allsame, init_tail_index_hill, estimate_tail_index_hill
  from cde.evaluation.empirical_eval import evaluate_models_singlestate, empirical_measurer, evaluate_model_allstates, evaluate_models_allstates_plot, obtain_exp_value, evaluate_models_allstates_agg, evaluate_models_save_plots
  
  
  """ Load or Create Project """
  # this project uses the train dataset with arrival rate 0.95, and service rate 1
  
  # name
  PROJECT_NAME = 'onehop_p95'
  
  # Path
  projects_path = 'saves/projects/'
  path = projects_path + PROJECT_NAME + '/'
    
  # Get the directory name from the specified path
  dirname = os.path.dirname(path)
  
  # create the dir
  os.makedirs(dirname, exist_ok=True)
  
  """ load training data """
  
  FILE_NAME = 'traindata_1hop_p95.npz'
  
  try:
      npzfile = np.load(path + FILE_NAME)
      train_data = npzfile['arr_0']
      meta_info = npzfile['arr_1']
      batch_size = meta_info[0]
      ndim_x = meta_info[1]
  
      print('training data loaded from .npz file. Rows: %d ' % len(train_data), ' Columns: %d ' % len(train_data[0]), 'Batch_size: %d' % batch_size, 'ndim_x: %d' % ndim_x)
  except:
      print('train data .npz file does not exist!')
      exit()
  
  
  """ import the test dataset into Numpy array """
  
  FILE_NAME = 'testdata_onehop_p95.npz'
  
  try:
      npzfile = np.load(projects_path + FILE_NAME)
      test_data = npzfile['arr_0']
      meta_info = npzfile['arr_1']
      ndim_x_test = meta_info[0]
  
      print('test data loaded from .npz file. Rows: %d ' % len(test_data), ' Columns: %d ' % len(test_data[0]), 'ndim_x: %d' % ndim_x_test)
  except:
      print('test data .npz file does not exist, import and create the test dataset into Numpy array')
  
      file_addrs = ['../../data/onehop_records_p95.mat']
      content_keys = ['records']
      select_cols = [0,1]
      # define the test packet stream
  
      # 130 seconds each, 15 minutes total
      for i in range(len(file_addrs)):
          cond_matds = MatlabDatasetH5(file_address=file_addrs[i],content_key=content_keys[i],select_cols=select_cols)
          if i is 0:
              test_data = cond_matds.dataset
          else:
              test_data = np.append(test_data,cond_matds.dataset,axis=0)
  
      ndim_x_test = len(test_data[0])-1
  
      meta_info = np.array([ndim_x_test])
      np.savez(projects_path + FILE_NAME, test_data, meta_info)
  
      print('test data loaded from .mat files. Rows: %d ' % len(test_data), ' Columns: %d ' % len(test_data[0]), 'ndim_x: %d' % ndim_x_test)
  
  
  """ load trained models """
  
  FILE_NAME = 'gmm_onehop_p95.pkl'
  if not os.path.isfile(path + FILE_NAME):
      print('No trained model found.')
      exit()
  
  with open(path+FILE_NAME, 'rb') as input:
      model = NoNaNGPDExtremeValueMixtureDensityNetwork(name="", ndim_x=ndim_x, ndim_y=1)
      model._setup_inference_and_initialize()
      model = pickle.load(input)
  
  n_epoch = model.n_training_epochs
  
  print(model)
  print('n_epoch: %d'%n_epoch)
  
  """ Benchmark models on single states """
  
  warnings.filterwarnings('ignore')
  
  plt.style.use('plot_style.txt')
  #evaluate_models_save_plots(models=[model],model_names=["EMM predictions"],train_data=train_data,cond_state=[15],test_dataset=test_data,quantiles=[1-1e-1,1-1e-2,1-1e-3,1-1e-5],save_fig_addr=path)
  evaluate_models_save_plots(models=[model],model_names=["GMM predictions"],train_data=train_data,cond_state=[15],test_dataset=test_data,quantiles=[1-1e-1,1-1e-2,1-1e-3,1-1e-5],save_fig_addr=path+'gmm_')
  
  #evaluate_models_singlestate(models=[model],model_names=["EMM"],train_data=train_data,cond_state=[1],test_dataset=test_data,quantiles=[1-1e-1,1-1e-2,1-1e-3,1-1e-5])
  #evaluate_models_singlestate(models=[model],model_names=["EMM"],train_data=train_data,cond_state=[2],test_dataset=test_data,quantiles=[1-1e-1,1-1e-2,1-1e-3,1-1e-5])
  #evaluate_models_singlestate(models=[model],model_names=["EMM"],train_data=train_data,cond_state=[10],test_dataset=test_data,quantiles=[1-1e-1,1-1e-2,1-1e-3,1-1e-5])
  
  #unique_states,_,_ = get_most_common_unique_states(test_data[1000000:5000000,:],ndim_x=1,N=30,plot=True,save_fig_addr=path)
  