com.qualizeal.community.DoubleSigmoid Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sigmoid Show documentation
Show all versions of sigmoid Show documentation
A simple java library to perform sigma function on list items
The newest version!
package com.qualizeal.community;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.IntStream;
public class DoubleSigmoid implements Sigmoid {
private static DoubleSigmoid instance;
private DoubleSigmoid() {
// Prevent Instantiation
}
public static DoubleSigmoid getInstance() {
if (Objects.isNull(instance)) {
instance = new DoubleSigmoid();
}
return instance;
}
@Override
public Double sumOfSeries(List series) {
return series.stream().mapToDouble(Double::doubleValue).sum();
}
@Override
public Double sumOfSquaresOfSeries(List series) {
return series.stream().map(s -> s * s).mapToDouble(Double::doubleValue).sum();
}
@SafeVarargs
@Override
public final Double sumOfProductsOfSeries(List... listOfSeries) {
if (!Arrays.stream(listOfSeries).allMatch(s -> s.size() == listOfSeries[0].size())) {
throw new SeriesSizeMismatchException();
}
return IntStream.range(0, listOfSeries[0].size()).mapToDouble(i -> {
double product = 1;
for (List series : listOfSeries) {
product *= series.get(i);
}
return product;
}).sum();
}
}