SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
RatioFunction.java
1/*
2 * Class: RatioFunction
3 * Description: Represents a function computing a ratio of two values.
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.util;
26
32public class RatioFunction implements MultivariateFunction {
33 private double zeroOverZero = Double.NaN;
34
38 public RatioFunction() {
39 }
40
48 public RatioFunction(double zeroOverZero) {
49 this.zeroOverZero = zeroOverZero;
50 }
51
71 public double getZeroOverZeroValue() {
72 return zeroOverZero;
73 }
74
81 public void setZeroOverZeroValue(double zeroOverZero) {
82 this.zeroOverZero = zeroOverZero;
83 }
84
85 public int getDimension() {
86 return 2;
87 }
88
89 public double evaluate(double... x) {
90 if (x.length != 2)
91 throw new IllegalArgumentException("Invalid length of x");
92 if (x[0] == 0 && x[1] == 0)
93 return zeroOverZero;
94 return x[0] / x[1];
95 }
96
97 public double evaluateGradient(int i, double... x) {
98 if (x.length != 2)
99 throw new IllegalArgumentException("Invalid length of x");
100 switch (i) {
101 case 0:
102 return 1.0 / x[1];
103 case 1:
104 return -x[0] / (x[1] * x[1]);
105 default:
106 throw new IndexOutOfBoundsException("Invalid value of i: " + i);
107 }
108 }
109}
void setZeroOverZeroValue(double zeroOverZero)
Sets the value returned by evaluate for the undefined function to zeroOverZero.
double evaluateGradient(int i, double... x)
Computes , the derivative of with respect to .
RatioFunction()
Constructs a new ratio function.
double getZeroOverZeroValue()
Returns the value returned by evaluate in the case where the function is calculated.
RatioFunction(double zeroOverZero)
Constructs a new ratio function that returns zeroOverZero for the special case of .
double evaluate(double... x)
Computes the function for the vector x.
int getDimension()
Returns , the dimension of the function computed by this implementation.
Represents a function of multiple variables.