View Javadoc
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   * Inverse Multi-quadric Radial Function Basis implementation.
20   */
21  public class InverseMultiQuadricRadialBasisFunction implements RadialBasisFunction {
22  
23      /**
24       * Squared r0 value, which is a scale factor.
25       */
26      private final double r02;
27  
28      /**
29       * Constructor.
30       *
31       * @param scale scale factor.
32       */
33      public InverseMultiQuadricRadialBasisFunction(final double scale) {
34          r02 = scale * scale;
35      }
36  
37      /**
38       * Constructor.
39       * Uses default scale factor, which is 1.0.
40       */
41      public InverseMultiQuadricRadialBasisFunction() {
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          return 1.0 / Math.sqrt((r * r) + r02);
54      }
55  }