In C# I had this
List<Learner> Learners;
double learnerSum = this.Learners.Sum(learner => learner.Predicted * learner.Alpha);
I want to do the same in java 8. I get as far as
double learnerSum = this.Learners.stream()...
It seems i need a reduce but all the examples are on simple arrays of integers. what am i missing?
You can create a DoubleStream
from a Stream
, and use the method sum
to get the sum.
double learnerSum = Learners.stream()
.mapToDouble(l -> l.Predicted * l.Alpha).sum();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments