Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-226

CorrelatedRandomVectorGenerator generates invariant samples

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      WIN32

      Description

      For the following code sample, the output is:
      1.0,3.9432161557722925,16.66859790068678,1.0743673824292688,
      1.0,-1.4103098147521094,-2.670854139636077,1.8368602953644368,
      1.0,0.230029048125738,12.67864233710285,0.1124537698401884,

      Why is the first column of each row fixed at 1.0?

      Here is the code that generated this:

      import org.apache.commons.math.linear.RealMatrix;
      import org.apache.commons.math.linear.RealMatrixImpl;
      import org.apache.commons.math.random.CorrelatedRandomVectorGenerator;
      import org.apache.commons.math.random.GaussianRandomGenerator;
      import org.apache.commons.math.random.JDKRandomGenerator;

      public class TestMath {

      public static void sampler(double[] mean, double[][] cov, double[][] s) {
      RealMatrix covRM = new RealMatrixImpl(cov);
      try {
      CorrelatedRandomVectorGenerator sg = new CorrelatedRandomVectorGenerator(
      mean, covRM, 0.00001, new GaussianRandomGenerator(
      new JDKRandomGenerator()));

      for (int i = 0; i < s.length; i++)

      { s[i] = sg.nextVector(); }

      } catch (Exception e)

      { e.printStackTrace(); System.exit(-1); }

      }

      static void print(double[][] s) {
      for (int r = 0; r < s.length; r++)

      { for (int c = 0; c < s[r].length; c++) System.out.print(s[r][c] + ","); System.out.println(); }

      }

      public static void main(String[] args) {
      double[] mean =

      { 1, 1, 10, 1 }

      ;
      double[][] cov = {

      { 1, 3, 2, 6 }

      ,

      { 3, 13, 16, 2 }

      ,

      { 2, 16, 38, -1 }

      ,

      { 6, 2, -1, 197 }

      };

      double[][] s = new double[3][4];

      TestMath.sampler(mean, cov, s);
      TestMath.print(s);

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ssiegel95 Stuart Siegel
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: