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

com.expleague.ml.func.generic.Logit Maven / Gradle / Ivy

There is a newer version: 1.4.9
Show newest version
package com.expleague.ml.func.generic;

import com.expleague.commons.math.FuncC1;
import com.expleague.commons.math.MathTools;
import com.expleague.commons.math.vectors.SingleValueVec;
import com.expleague.commons.math.vectors.Vec;

/**
* User: solar
* Date: 26.05.15
* Time: 11:45
*/
public class Logit extends FuncC1.Stub {
  private final double a, b;

  public Logit(double a, double b) {
    this.a = a;
    this.b = b;
  }

  @Override
  public Vec gradient(Vec x) {
    return new SingleValueVec(a * (prob(x) - 1));
  }

  @Override
  public double value(Vec x) {
    return Math.log(prob(x));
  }

  private double prob(Vec x) {
    return 1. / (1. + Math.exp(a * x.get(0) + b));
  }

  @Override
  public int dim() {
    return 1;
  }

  @Override
  public String toString() {
    return "-log(1+exp(" + a + "x" + (Math.abs(b) > MathTools.EPSILON ? " + " + b : "") + "))";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy