Package edu.cmu.tetrad.search.utils
Class RandomFourier
java.lang.Object
edu.cmu.tetrad.search.utils.RandomFourier
The RandomFourier class generates a random Fourier series with specified cosine and sine amplitudes and frequency
terms. The series is defined as:
f(x) = Σ [a_i * cos(b_i * x) + c_i * sin(b_i * x)]
where: - a_i and c_i are randomly chosen amplitudes in the range [-2, 2], - b_i are randomly chosen frequencies scaled by a given factor.
This class also provides functionality to adjust the series so that its value at x = 0 is zero.
-
Constructor Summary
ConstructorsConstructorDescriptionRandomFourier(int numTerms, double frequencyScale) Initializes a RandomFourier instance with the specified number of terms and frequency scale. -
Method Summary
Modifier and TypeMethodDescriptiondoublecompute(double x) Computes the value of the Fourier series at a given input x.doublecomputeAdjusted(double x) Computes the adjusted value of the Fourier series at the given input x.static voidThe main method demonstrates the usage of the RandomFourier class.
-
Constructor Details
-
RandomFourier
public RandomFourier(int numTerms, double frequencyScale) Initializes a RandomFourier instance with the specified number of terms and frequency scale.- Parameters:
numTerms- The number of terms in the Fourier series.frequencyScale- The scale factor applied to the randomly generated frequencies.
-
-
Method Details
-
main
The main method demonstrates the usage of the RandomFourier class. It creates an instance of RandomFourier, evaluates the adjusted Fourier series over a given range of x values, and verifies that the series is adjusted such that its value at x = 0 is approximately zero.- Parameters:
args- Command-line arguments (not used in this implementation).
-
compute
public double compute(double x) Computes the value of the Fourier series at a given input x.- Parameters:
x- The input value for which the Fourier series is evaluated.- Returns:
- The calculated result of the Fourier series at the given input x.
-
computeAdjusted
public double computeAdjusted(double x) Computes the adjusted value of the Fourier series at the given input x. The adjustment ensures that the computed value is shifted such that the Fourier series value at x = 0 is zero.- Parameters:
x- The input value for which the adjusted Fourier series is evaluated.- Returns:
- The adjusted result of the Fourier series at the given input x.
-