2 # -*- coding: utf-8 -*-
7 def penalty_lookup_new(penalty_struct
, value
):
9 limits
= penalty_struct
.limits
10 penalties
= penalty_struct
.penalties
12 if penalty_struct
.transform
== 'log':
13 value
= math
.log(value
)
15 elif penalty_struct
.transform
== 'log(+3)':
16 value
= math
.log(value
+3)
18 elif penalty_struct
.transform
== 'log(+1)':
19 value
= math
.log(value
+1)
21 elif penalty_struct
.transform
== '':
24 elif penalty_struct
.transform
== '(+3)':
27 elif penalty_struct
.transform
== 'mod3':
31 assert False,'unknown penalty transform'
33 count
= len([elem
for elem
in limits
if elem
<= value
])
37 elif count
== len(limits
):
40 pen
= (penalties
[count
]*(value
-limits
[count
-1]) + penalties
[count
-1]\
41 *(limits
[count
]-value
)) / (limits
[count
]-limits
[count
-1])