-
Notifications
You must be signed in to change notification settings - Fork 10
/
evt_fitting.py
56 lines (33 loc) · 1.56 KB
/
evt_fitting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os, sys, pickle, glob
import os.path as path
import argparse
import scipy.spatial.distance as spd
import scipy as sp
from scipy.io import loadmat
from openmax_utils import *
import numpy as np
import libmr
#---------------------------------------------------------------------------------
def weibull_tailfitting(meanfiles_path, distancefiles_path,
tailsize = 20,
distance_type = 'eucos'):
weibull_model = {}
for filename in os.listdir(meanfiles_path):
category = filename.split(".")[0]
weibull_model[category] = {}
distance_scores = np.load(os.path.join(distancefiles_path,category+".npy"))[()][distance_type]
meantrain_vec = np.load(os.path.join(meanfiles_path,category+".npy"))
weibull_model[category]['distances_%s'%distance_type] = distance_scores
weibull_model[category]['mean_vec'] = meantrain_vec
distance_scores = distance_scores.tolist()
mr = libmr.MR()
tailtofit = sorted(distance_scores)[-tailsize:]
mr.fit_high(tailtofit, len(tailtofit))
weibull_model[category]['weibull_model'] = mr
return weibull_model
def query_weibull(category_name, weibull_model, distance_type = 'eucos'):
category_weibull = []
category_weibull += [weibull_model[category_name]['mean_vec']]
category_weibull += [weibull_model[category_name]['distances_%s' %distance_type]]
category_weibull += [weibull_model[category_name]['weibull_model']]
return category_weibull