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

com.expleague.ml.loss.DSSumFunc Maven / Gradle / Ivy

package com.expleague.ml.loss;

import com.expleague.commons.math.Func;
import com.expleague.commons.math.vectors.Vec;
import com.expleague.ml.TargetFunc;
import com.expleague.ml.data.set.DataSet;

/**
 * User: solar
 * Date: 01.06.15
 * Time: 12:52
 */
public abstract class DSSumFunc extends Func.Stub implements TargetFunc {
  protected final DataSet ds;

  public DSSumFunc(DataSet ds) {
    this.ds = ds;
  }

  public abstract Func component(int index);

  public Item item(int index) {
    return ds.at(index);
  }

  public int length() {
    return ds.length();
  }

  @Override
  public double value(Vec x) {
    final int length = length();
    double result = 0;
    for (int i = 0; i < length; i++) {
      result += component(i).value(x);
    }
    return result;
  }

  @Override
  public int dim() {
    return component(0).dim();
  }


  @Override
  public DataSet owner() {
    return ds;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy