-
Notifications
You must be signed in to change notification settings - Fork 0
/
warp_score_function_ell.py
33 lines (25 loc) · 1.07 KB
/
warp_score_function_ell.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
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 12 14:03:09 2019
@author: pasca
"""
import numpy as np
import ellipsoid_fun
def remap_score_function_ell(score_function, force_matrix, equilibrium_point, noise):
"""
This function warps the score function so that the target set is the 0.95-confidence ellipsoid.
return the score function and the associated threshold
"""
C, quad_form, spectral_radius, level, bound = ellipsoid_fun.ingredients_score_function(force_matrix, equilibrium_point, noise, confidence = 0.95, warning_threshold = 1e-3)
ellipsoid_array = ellipsoid_fun.get_ellipsoid_array(equilibrium_point, quad_form, level, bound)
score_level = np.min(np.apply_along_axis(score_function, 1, ellipsoid_array))
def remapped_score_function(v):
score = score_function(v)
if score>=score_level:
if ellipsoid_fun.ellipsoid_test(v, quad_form, level):
return 1
else:
return score_level
else:
return score
return remapped_score_function, (1-score_level)/2