2 # -*- coding: utf-8 -*-
6 def penalty_lookup_new(penalty_struct
, value
):
8 limits
= penalty_struct
.limits
9 penalties
= penalty_struct
.penalties
11 if penalty_struct
.transform
== 'log':
12 value
= math
.log(value
)
14 elif penalty_struct
.transform
== 'log(+3)':
15 value
= math
.log(value
+3)
17 elif penalty_struct
.transform
== 'log(+1)':
18 value
= math
.log(value
+1)
20 elif penalty_struct
.transform
== '' or\
21 penalty_struct
.transform
== '(+3)':
24 elif penalty_struct
.transform
== 'mod3':
28 assert False,'unknown penalty transform'
30 count
= len([elem
for elem
in limits
if elem
<= value
])
34 elif count
== length(limits
):
37 pen
= (penalties
[count
+1]*(value
-limits
[count
]) + penalties
[count
]\
38 *(limits
[count
+1]-value
)) / (limits
[count
+1]-limits
[count
])