Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-129

Performance improvement for UnitSphereSampler

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.3
    • 1.4
    • sampling
    • None

    Description

      The UnitSphereSampler accepts a dimension argument and creates the sample using iteration over an array of the given dimension creating n Gaussian samples. This can be optimised for low order dimensions to remove the use of array iteration, e.g.

      final double[] v = new double[dimension];
      double sum = 0;
      for (int i = 0; i < dimension; i++) {
          final double x = sampler.sample();
          v[i] = x;
          sum += x * x;
      }
      

      becomes for 3D:

      final double x = sampler.sample();
      final double y = sampler.sample();
      final double z = sampler.sample();
      final double sum = x * x + y * y + z * z;
      

      The special case of 1D sampling can be handled by returning either 1 or -1 in a vector based on a single bit of the random source.

      Optimised versions can be created by adding a factory method to the class:

      public static UnitSphereSampler of(int dimension, UniformRandomProvider rng) {
          // ...
      }
      

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m