Esempio n. 1
0
// test set 3
func Test_randist_3(t *testing.T) {

	// test bivariate gaussian distributions
	rng_type := Ranlxd2
	rng_state := Rng_alloc(rng_type)

	// bivariate gaussian
	tail := BivariateGaussianSlice(rng_state, 1, 1, 1, numSamples)

	first := stats.FloatSlice(make([]float64, numSamples))
	second := stats.FloatSlice(make([]float64, numSamples))
	for i, v := range tail {
		first[i], second[i] = v[0], v[1]
	}

	if first.Mean(1) > margin {
		t.Error("randist: Mean of 1st component of bivariate gaussian is not 0.")
	}

	if second.Mean(1) > margin {
		t.Error("randist: Mean of 2nd component of bivariate gaussian is not 0.")
	}

	if (first.Sd(1) - 1) > margin {
		t.Error("randist: Std of 1st component of bivariate gaussian is not 0.")
	}

	if (second.Sd(1) - 1) > margin {
		t.Error("randist: Std of 2nd component of bivariate gaussian is not 0.")
	}
}
Esempio n. 2
0
// test set 1
func Test_randist_1(t *testing.T) {

	// test gaussians
	rng_type := Ranlxd2
	rng_state := Rng_alloc(rng_type)

	// gaussian
	gaus := stats.FloatSlice(GaussianSlice(rng_state, 1, numSamples))
	if gaus.Mean(1) > margin {
		t.Error("randist: Mean of gaussian distribution is not 0.")
	}

	if (gaus.Sd(1) - 1.0) > margin {
		t.Error("randist: Stdev of gaussian distribution is not 1.")
	}

	// gaussian ziggurat
	gaus_zig := stats.FloatSlice(GaussianZigguratSlice(rng_state, 1, numSamples))
	if gaus_zig.Mean(1) > margin {
		t.Error("randist: Mean of gaussian_zig distribution is not 0.")
	}

	if (gaus_zig.Sd(1) - 1.0) > margin {
		t.Error("randist: Stdev of gaussian_zig distribution is not 1.")
	}

	// gaussian ratio method
	gaus_rat := stats.FloatSlice(GaussianRatioMethodSlice(rng_state, 1, numSamples))
	if gaus_rat.Mean(1) > margin {
		t.Error("randist: Mean of gaussian_rat distribution is not 0.")
	}

	if (gaus_rat.Sd(1) - 1.0) > margin {
		t.Error("randist: Stdev of gaussian_rat distribution is not 1.")
	}

	// unit gaussian
	ugaus := stats.FloatSlice(UgaussianSlice(rng_state, numSamples))
	if ugaus.Mean(1) > margin {
		t.Error("randist: Mean of ugaussian distribution is not 0.")
	}

	if (ugaus.Sd(1) - 1.0) > margin {
		t.Error("randist: Stdev of ugaussian distribution is not 1.", ugaus.Sd(1))
	}

	// unit gaussian ratio method
	ugaus_rat := stats.FloatSlice(UgaussianRatioMethodSlice(rng_state, numSamples))
	if ugaus_rat.Mean(1) > margin {
		t.Error("randist: Mean of ugaussian_rat distribution is not 0.")
	}

	if (ugaus_rat.Sd(1) - 1.0) > margin {
		t.Error("randist: Stdev of ugaussian_rat distribution is not 1.", ugaus_rat.Sd(1))
	}
}
Esempio n. 3
0
// test set 1
func Test_random_1(t *testing.T) {

  // test 1
  var rng_type RngType
  for k, v := range TypesSetup() {
    if k == "ranlxd2" {
      rng_type = v
    }
  }

  if rng_type.Name() != "ranlxd2" {
    t.Error("Test 1: Failed to select ranlxd2 rng type.")
  }
  rng_state := Rng_alloc(rng_type)

  // test 2
  nums1 := rng_state.GetSlice(100)
  nums1_slice := make(stats.FloatSlice, 100)
  for i := 0; i < 100; i++ {
    nums1_slice[i] = float64(nums1[i])
  }
  min, max := nums1_slice.MinMax(1)

  if min < float64(rng_state.Min()) || max > float64(rng_state.Max()) {
    t.Error("Test 2: Generated random numbers are out of range.")
  }

  // test 3
  nums2 := stats.FloatSlice(rng_state.UniformSlice(100))
  min, max = nums2.MinMax(1)

  if min < 0 || max >= 1 {
    t.Error("Test 3: Generated uniform random numbers are out of range.")
  }

  // test 4
  nums3 := rng_state.UniformIntSlice(900, 100)
  nums3_slice := make(stats.FloatSlice, 100)
  for i := 0; i < 100; i++ {
    nums3_slice[i] = float64(nums3[i])
  }
  min, max = nums3_slice.MinMax(1)

  if min < 0 || max >= 900 {
    t.Error("Test 4: Generated uniform int random numbers are out of range.")
  }

  // test 5
  rng_state_1 := rng_state.Clone()
  if rng_state_1.Get() != rng_state.Get() {
    t.Error("Test 5: Failed to clone rng state.")
  }

  // test 6
  rng_state_2 := Rng_alloc(rng_type)
  if rng_state_2.Get() == rng_state.Get() {
    t.Error("Test 6: Hmmm, this is very unlikely to happen.")
  }

  rng_state.Memcpy(rng_state_2)
  if rng_state_2.Get() != rng_state.Get() {
    t.Error("Test 6: Failed to memcpy rng state.")
  }
}