Skip to content
Snippets Groups Projects
regression_target.py 1.2 KiB
Newer Older
# Copyright (c) 2016. Mount Sinai School of Medicine
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Tim O'Donnell's avatar
Tim O'Donnell committed
import numpy
Tim O'Donnell's avatar
Tim O'Donnell committed
def from_ic50(ic50):
Tim O'Donnell's avatar
Tim O'Donnell committed
    Convert ic50s to regression targets in the range [0.0, 1.0].
    
Tim O'Donnell's avatar
Tim O'Donnell committed
    ic50 : numpy.array of float

    Returns
    -------
    numpy.array of float
Tim O'Donnell's avatar
Tim O'Donnell committed
    x = 1.0 - (numpy.log(ic50) / numpy.log(50000))
    return numpy.minimum(
        1.0,
        numpy.maximum(0.0, x))
Tim O'Donnell's avatar
Tim O'Donnell committed

def to_ic50(x):
    """
    Convert regression targets in the range [0.0, 1.0] to ic50s in the range
    [0, 50000.0].
    
Tim O'Donnell's avatar
Tim O'Donnell committed
    x : numpy.array of float
Tim O'Donnell's avatar
Tim O'Donnell committed
    Returns
    -------
    numpy.array of float
Tim O'Donnell's avatar
Tim O'Donnell committed
    return 50000.0 ** (1.0 - x)