All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chen0040.glm.links.LogitLinkFunction Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.github.chen0040.glm.links;

/**
 * Created by xschen on 14/8/15.
 */
/// 
/// For the logistic link function:
/// Constraint interval : [0, 1]
///
/// The logistic link function maps constraint interval {b | b \in [0, 1]} to the real line {a | a \in R } by:
/// a = f(b) = log(b / (1-b))
///
/// The inverse link function maps the real line {a | a \in R} to constraint interval {b | b \in [0, 1] } by:
/// b = g(a) = 1 / (1 + exp(-a))
///
/// This is generally applicable to the following distribution (logistic regressions):
///   1. Binomial: count of # of "yes" occurrence out of N yes/no occurrences
///   2. Bernouli: count of single yes/no occurrence
///   3. Categorical: outcome of single K-way occurrence
///   4. Multinomial: cout of occurrences of different types (1 .. K) out of N total K-way occurrences
/// 
public class LogitLinkFunction extends AbstractLinkFunction {

    @Override
    public LinkFunction makeCopy(){
        return new LogitLinkFunction();
    }

    /// 
    /// The logistic link function maps constraint interval {b | b \in [0, 1]} to the real line {a | a \in R } by:
    /// a = f(b) = log(b / (1-b))
    /// 
    /// The constraint interval value
    /// The mapped linear line value
    @Override
    public double GetLink(double b) {
        return Math.log(b / (1 - b));
    }

    /// 
    /// The inverse link function maps the real line {a | a \in R} to constraint interval {b | b \in [0, 1] } by:
    /// b = g(a) = 1 / (1 + exp(-a))
    /// 
    /// the real line value
    /// the mapped constraint interval value
    @Override
    public double GetInvLink(double a) {
        return 1.0 / (1.0 + Math.exp(-a));
    }

    @Override
    public double GetInvLinkDerivative(double a) {
        //double g_a = GetInvLink(a);
        //return g_a * (1 - g_a);

        double t = Math.exp(-a);
        return t / ((1 + t) * (1 + t));
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy