Completed
Push — master ( 2bc047...202252 )
by Rich
01:16
created

skchem.bedroc_score()   B

Complexity

Conditions 3

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 38
rs 8.8571
1
#! /usr/bin/env python
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
#
3
# Copyright (C) 2007-2009 Rich Lewis <[email protected]>
4
# License: 3-clause BSD
5
6
def bedroc_score(y_true, y_pred, decreasing=True, alpha=20.0):
7
8
    """ BEDROC metric implemented according to Truchon and Bayley
9
     (10.1021/ci600426e).
10
11
     @param y_true      class labels, 1 for positive class, 0 otherwise
12
     @param y_pred      prediction values
13
     @param decreasing  :boolean: if high metric correlates to positive class
14
     @param alpha       early recognition parameter
15
16
     @returns float between 0 and 1, indicating degree to which the predictive
17
     technique employed detects (early) the positive class.
18
     """
19
20
    assert len(y_true) == len(y_pred), \
21
     'The number of scores must be equal to the number of labels'
22
23
    N = len(y_true)
0 ignored issues
show
Coding Style Naming introduced by
The name N does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
24
    n = sum(y_true == 1)
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
25
26
    if decreasing:
27
        order = np.argsort(-y_pred)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'np'
Loading history...
28
    else:
29
        order = np.argsort(y_pred)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'np'
Loading history...
30
31
    m_rank = (y_true[order] == 1).nonzero()[0]
32
33
    s = np.sum(np.exp(-alpha * m_rank / N))
0 ignored issues
show
Coding Style Naming introduced by
The name s does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'np'
Loading history...
34
35
    r_a = n / N
36
37
    rand_sum = r_a * (1 - np.exp(-alpha))/(np.exp(alpha/N) - 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'np'
Loading history...
38
39
    fac = r_a * np.sinh(alpha / 2) / (np.cosh(alpha / 2) - np.cosh(alpha/2 - alpha * r_a))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'np'
Loading history...
40
41
    cte = 1 / (1 - np.exp(alpha * (1 - r_a)))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'np'
Loading history...
42
43
    return s * fac / rand_sum + cte
44