001/* 002 * Java Genetic Algorithm Library (jenetics-7.0.0). 003 * Copyright (c) 2007-2022 Franz Wilhelmstötter 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 * Author: 018 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 019 */ 020package io.jenetics.prog.regression; 021 022import static java.util.Objects.requireNonNull; 023 024import io.jenetics.ext.util.Tree; 025 026import io.jenetics.prog.op.Op; 027 028/** 029 * This interface represents a set of sample points, which can be evaluated with 030 * a given evolved <em>program</em>. 031 * 032 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a> 033 * @version 6.0 034 * @since 6.0 035 */ 036@FunctionalInterface 037public interface Sampling<T> { 038 039 /** 040 * This class represents the result of a sample calculation, which contains 041 * the array of calculated values and a corresponding array with expected 042 * sample values. This two arrays can then be used for calculating the 043 * error between modeled regression function and actual sample values. 044 * 045 * @param <T> the sample result type 046 */ 047 record Result<T>(T[] calculated, T[] expected) { 048 /** 049 * @param calculated the calculated result values 050 * @param expected the expected sample result values 051 * @throws NullPointerException if one of the arguments is {@code null} 052 */ 053 public Result { 054 calculated = calculated.clone(); 055 expected = expected.clone(); 056 } 057 } 058 059 /** 060 * Evaluates the given {@code program} tree with its sample points. The 061 * returned result object may be {@code null} if no sample point has been 062 * added to the <em>sampling</em> when calling the {@code eval} method. 063 * 064 * @param program the program to evaluate 065 * @return the evaluated sample result. May be {@code null} if the sampling 066 * is empty and contains no sample points. 067 */ 068 Result<T> eval(final Tree<? extends Op<T>, ?> program); 069 070}