Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.anhth12.lambda.ml.param; import com.google.common.base.Preconditions; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * * @author Tong Hoang Anh */ final class ContinuousAround implements HyperParamValues<Double>, Serializable { private final double around; private final double step; ContinuousAround(double around, double step) { Preconditions.checkArgument(step > 0.0); this.around = around; this.step = step; } @Override public List<Double> getTrialValues(int num) { Preconditions.checkArgument(num > 0); if (num == 1) { return Collections.singletonList(around); } List<Double> values = new ArrayList<>(num); double value = around - ((num - 1.0) / 2.0) * step; for (int i = 0; i < num; i++) { values.add(value); value += step; } // Make sure middle value is exact if (num % 2 != 0) { values.set(num / 2, around); } return values; } @Override public String toString() { return "ContinuousAround[..." + getTrialValues(3) + "...]"; } }