1 /* 2 * Copyright (C) 2023 Alberto Irurueta Carro (alberto@irurueta.com) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.irurueta.numerical.interpolation; 17 18 /** 19 * Gaussian Radial Basis Function implementation. 20 */ 21 public class GaussianRadialBasisFunction implements RadialBasisFunction { 22 23 /** 24 * Scale factor. 25 */ 26 private final double r0; 27 28 /** 29 * Constructor. 30 * 31 * @param scale scale factor. 32 */ 33 public GaussianRadialBasisFunction(final double scale) { 34 r0 = scale; 35 } 36 37 /** 38 * Constructor. 39 * Uses default scale factor, which is 1.0. 40 */ 41 public GaussianRadialBasisFunction() { 42 this(1.0); 43 } 44 45 /** 46 * Evaluates RBF at provided distance between two points. 47 * 48 * @param r distance between two points. 49 * @return result of evaluating RBF. 50 */ 51 @Override 52 public double evaluate(double r) { 53 final var value = r / r0; 54 return Math.exp(-0.5 * value * value); 55 } 56 }