Class RandomFunctions

java.lang.Object
edu.cmu.tetrad.search.utils.RandomFunctions

public class RandomFunctions extends Object
A utility class for generating and evaluating random mathematical functions, including polynomials, Fourier series, piecewise linear functions, radial basis functions, and sampled Gaussian processes. Provides control over specific properties such as scaling and ensuring the function passes through the origin.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Executes a series of demonstrations of random mathematical function generators.
    static double
    randomFourier(double x, int numTerms, double scale, boolean passThroughOrigin)
    Generates a random Fourier series and evaluates it at a given input value x.
    static double
    randomPiecewiseLinear(double x, double min, double max, int numPoints, boolean passThroughOrigin)
    Generates a random piecewise linear function and evaluates it at a specified input value x.
    static double
    randomPolynomial(double x, int degree, double scale, boolean passThroughOrigin)
    Generates a random polynomial function and evaluates it at a specified input value.
    static double
    randomRBF(double x, double min, double max, int numCenters, double sigma, boolean passThroughOrigin)
    Generates a random Radial Basis Function (RBF) and evaluates it at a given input value x.
    static double[]
    sampleGaussianProcess(double[] x, double lengthScale, double jitter, boolean passThroughOrigin)
    Samples values from a Gaussian Process defined by an RBF kernel with the given parameters.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • randomPolynomial

      public static double randomPolynomial(double x, int degree, double scale, boolean passThroughOrigin)
      Generates a random polynomial function and evaluates it at a specified input value. The polynomial is constructed using random coefficients for each term, up to the specified degree. Optionally ensures that the polynomial passes through the origin.
      Parameters:
      x - the input value at which the polynomial is evaluated.
      degree - the degree of the polynomial.
      scale - a scaling factor for the random coefficients.
      passThroughOrigin - a boolean indicating whether the polynomial should be adjusted to pass through the origin.
      Returns:
      the evaluated value of the random polynomial at the given input x.
    • randomFourier

      public static double randomFourier(double x, int numTerms, double scale, boolean passThroughOrigin)
      Generates a random Fourier series and evaluates it at a given input value x. The series is composed of a specified number of terms, with random coefficients for sine and cosine components. Optionally ensures that the resulted function passes through the origin.
      Parameters:
      x - the input value at which the Fourier series is evaluated.
      numTerms - the number of terms in the Fourier series.
      scale - a scaling factor for the random coefficients.
      passThroughOrigin - a boolean indicating whether the Fourier series should be adjusted to pass through (0, 0).
      Returns:
      the evaluated value of the random Fourier series at the given input x.
    • randomPiecewiseLinear

      public static double randomPiecewiseLinear(double x, double min, double max, int numPoints, boolean passThroughOrigin)
      Generates a random piecewise linear function and evaluates it at a specified input value x. The function is constructed using random points within a defined range and optionally passes through the origin.
      Parameters:
      x - the input value at which the piecewise linear function is evaluated.
      min - the minimum value for the range of x-coordinates of the random points.
      max - the maximum value for the range of x-coordinates of the random points.
      numPoints - the number of random points used to construct the piecewise linear function.
      passThroughOrigin - a boolean indicating whether the piecewise linear function should be adjusted to pass through (0, 0).
      Returns:
      the evaluated value of the piecewise linear function at the given input x.
    • randomRBF

      public static double randomRBF(double x, double min, double max, int numCenters, double sigma, boolean passThroughOrigin)
      Generates a random Radial Basis Function (RBF) and evaluates it at a given input value x. The RBF is constructed using a specified number of centers, with each center assigned a random position and amplitude. Optionally adjusts the function to pass through the origin.
      Parameters:
      x - the point at which the RBF is evaluated.
      min - the minimum value for the range of the RBF centers.
      max - the maximum value for the range of the RBF centers.
      numCenters - the number of RBF centers to generate.
      sigma - the standard deviation parameter defining the width of each RBF (Gaussian).
      passThroughOrigin - a boolean indicating whether the RBF should be adjusted to pass through the origin.
      Returns:
      the evaluated value of the RBF at the given input point x.
    • sampleGaussianProcess

      public static double[] sampleGaussianProcess(double[] x, double lengthScale, double jitter, boolean passThroughOrigin)
      Samples values from a Gaussian Process defined by an RBF kernel with the given parameters.
      Parameters:
      x - an array of input values representing the points at which to sample the Gaussian Process.
      lengthScale - the length scale parameter of the RBF kernel, controlling the smoothness of the function.
      jitter - a small positive value added to the diagonal of the covariance matrix to ensure numerical stability.
      passThroughOrigin - a boolean indicating whether the sampled values should be adjusted to pass through (0, 0).
      Returns:
      an array of sampled values corresponding to the input points, representing the Gaussian Process realization.
    • main

      public static void main(String[] args)
      Executes a series of demonstrations of random mathematical function generators. The program generates and evaluates random polynomial, Fourier series, piecewise linear, and radial basis function (RBF) at specific points. It also samples a Gaussian Process function and outputs the results.
      Parameters:
      args - the command-line arguments (not used in this implementation).