Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3022-FastFunctionExtraction/FFX/ProductBaseFunction.cs @ 17779

Last change on this file since 17779 was 17779, checked in by gkronber, 4 years ago

#3022: made a few changes while reviewing the code.

File size: 1.1 KB
Line 
1using HeuristicLab.Problems.DataAnalysis;
2using System;
3using System.Linq;
4
5namespace HeuristicLab.Algorithms.DataAnalysis.FastFunctionExtraction {
6    internal struct ProductBaseFunction : IBasisFunction {
7        public IBasisFunction B1 { get; set; }
8        public IBasisFunction B2 { get; set; }
9
10        public int Complexity => 1 + B1.Complexity + B2.Complexity;
11
12        public bool IsDenominator { get; set; }
13
14        public ProductBaseFunction(IBasisFunction b1, IBasisFunction b2, bool isDenominator) {
15            B1 = b1 ?? throw new ArgumentNullException(nameof(b1));
16            B2 = b2 ?? throw new ArgumentNullException(nameof(b2));
17            IsDenominator = isDenominator;
18        }
19
20        public double[] Evaluate(IRegressionProblemData data) {
21            return B1.Evaluate(data).Zip(B2.Evaluate(data), (a, b) => a * b).ToArray();
22        }
23
24        public override string ToString() {
25            return $"{B1} * {B2}";
26        }
27
28        public IBasisFunction DeepCopy() {
29            return new ProductBaseFunction(B1, B2, IsDenominator);
30        }
31    }
32}
Note: See TracBrowser for help on using the repository browser.