示例#1
0
func TestSimpleLinearNew(t *testing.T) {
	x := []float64{
		3.181500e+02,
		3.281500e+02,
		3.381500e+02,
		3.481500e+02,
		3.581500e+02,
		3.681500e+02,
		3.781500e+02,
		3.881500e+02,
		3.981500e+02,
	}
	y := []float64{
		5.459861e-01,
		6.303621e-01,
		7.325854e-01,
		8.549895e-01,
		1.000000e+00,
		1.171091e+00,
		1.373428e+00,
		1.606733e+00,
		1.873658e+00,
	}

	model := NewSimpleLinear(x, y)

	assert.EqualWithin(model.α, -4.7845715178610932e+00, 1e-12, t)
	assert.EqualWithin(model.β, +1.6395978333333290e-02, 1e-12, t)
}
示例#2
0
func TestListDelay(t *testing.T) {
	platform, application, _ := system.Load(findFixture("002_040"))
	profile := system.NewProfile(platform, application)

	list := NewList(platform, application)
	schedule := list.Compute(profile.Mobility)

	delay := []float64{
		0.0352, 0.0831, 0.0585, 0.0550, 0.0917, 0.0286, 0.0757, 0.0754,
		0.0380, 0.0568, 0.0076, 0.0054, 0.0531, 0.0779, 0.0934, 0.0130,
		0.0569, 0.0469, 0.0012, 0.0337, 0.0162, 0.0794, 0.0311, 0.0529,
		0.0166, 0.0602, 0.0263, 0.0654, 0.0689, 0.0748, 0.0451, 0.0084,
		0.0229, 0.0913, 0.0152, 0.0826, 0.0538, 0.0996, 0.0078, 0.0443,
	}

	start := []float64{
		0.0000, 0.0582, 0.1533, 0.4349, 0.2238, 0.3855, 1.7419, 0.3365,
		0.3365, 0.5019, 0.6554, 0.4251, 0.6820, 1.2139, 1.6966, 0.5727,
		1.3128, 0.7837, 0.9856, 0.6067, 0.6554, 0.9998, 0.8456, 1.3128,
		0.7481, 1.4890, 1.1766, 1.0992, 0.8917, 0.9856, 0.7837, 1.3847,
		1.8648, 1.3847, 1.1766, 1.6373, 1.8010, 1.5810, 1.5622, 1.5810,
	}

	finish := make([]float64, len(start))
	for i := range finish {
		finish[i] = start[i] + (schedule.Finish[i] - schedule.Start[i]) + delay[i]
	}

	schedule = list.Delay(schedule, delay)

	assert.EqualWithin(schedule.Start, start, 1e-15, t)
	assert.EqualWithin(schedule.Finish, finish, 2e-15, t)
}
示例#3
0
func TestKolmogorovSmirnovGaussian(t *testing.T) {
	data1 := []float64{
		+1.8368909586194213e-01, -4.7615301661907383e-01,
		+8.6202161155692203e-01, -1.3616944708707543e+00,
		+4.5502955644433435e-01, -8.4870937993365902e-01,
		-3.3488693896404770e-01, +5.5278334594455014e-01,
		+1.0390906535049560e+00, -1.1176386832652081e+00,
		+1.2606587091208963e+00, +6.6014314104697769e-01,
		-6.7865553542687335e-02, -1.9522119789875436e-01,
		-2.1760635014319193e-01, -3.0310762135174091e-01,
		+2.3045624425105282e-02, +5.1290355848774699e-02,
		+8.2606279021159545e-01, +1.5269766867333727e+00,
	}

	data2 := []float64{
		+4.6691443568470004e-01, -2.0971333838873671e-01,
		+6.2519035708762571e-01, +1.8322726300143696e-01,
		-1.0297675435666211e+00, +9.4922183113102254e-01,
		+3.0706191914670344e-01, +1.3517494209945566e-01,
		+5.1524633552484855e-01, +2.6140632405538267e-01,
		-9.4148577095543373e-01, -1.6233767280382774e-01,
		-1.4605463433152618e-01, -5.3201137680882071e-01,
		+1.6821035946631788e+00, -8.7572934616001730e-01,
		-4.8381505011012110e-01, -7.1200454902742250e-01,
		-1.1742123314568162e+00, -1.9223951753927476e-01,
	}

	rejected, pvalue, statistic := KolmogorovSmirnov(data1, data2, 0.05)

	assert.Equal(rejected, false, t)
	assert.EqualWithin(pvalue, 7.7095294467658659e-01, 1e-15, t)
	assert.EqualWithin(statistic, 2.0000000000000007e-01, 1e-15, t)
}
示例#4
0
func TestParabola(t *testing.T) {
	fixture := &fixtureParabola
	algorithm, strategy := prepare(fixture)

	surrogate := algorithm.Compute(fixture.target, strategy)
	assert.Equal(surrogate.Nodes, fixture.surrogate.Nodes, t)
	assert.EqualWithin(surrogate.Integral, fixture.surrogate.Integral, 1e-6, t)
	assert.Equal(interpolation.Validate(surrogate.Indices, surrogate.Inputs,
		fixture.grid), true, t)

	values := algorithm.Evaluate(surrogate, fixture.points)
	assert.EqualWithin(values, fixture.values, 1e-6, t)
}
示例#5
0
func TestListCompute(t *testing.T) {
	platform, application, _ := system.Load(findFixture("002_040"))
	profile := system.NewProfile(platform, application)

	list := NewList(platform, application)
	schedule := list.Compute(profile.Mobility)

	mapping := []uint{
		0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0,
		1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0,
	}

	order := []uint{
		0, 1, 2, 4, 7, 8, 5, 11, 3, 9, 15, 19, 20, 10, 12, 24, 30, 17, 22, 28, 29,
		18, 21, 27, 34, 26, 13, 16, 23, 31, 33, 25, 38, 39, 37, 35, 14, 36, 6, 32,
	}

	start := []float64{
		0.0000, 0.0230, 0.0350, 0.0910, 0.0470, 0.0790, 0.4220, 0.0680,
		0.0680, 0.1030, 0.1530, 0.0900, 0.1720, 0.3150, 0.4040, 0.1170,
		0.3360, 0.2040, 0.2590, 0.1380, 0.1530, 0.2720, 0.2190, 0.3360,
		0.1850, 0.3640, 0.3040, 0.2920, 0.2340, 0.2590, 0.2040, 0.3510,
		0.4250, 0.3510, 0.3040, 0.4000, 0.4150, 0.3880, 0.3770, 0.3880,
	}

	duration := []float64{
		0.0230, 0.0120, 0.0120, 0.0120, 0.0210, 0.0110, 0.0180, 0.0230,
		0.0110, 0.0140, 0.0190, 0.0150, 0.0130, 0.0210, 0.0110, 0.0210,
		0.0150, 0.0150, 0.0130, 0.0150, 0.0210, 0.0200, 0.0150, 0.0100,
		0.0190, 0.0130, 0.0110, 0.0120, 0.0250, 0.0150, 0.0180, 0.0190,
		0.0140, 0.0130, 0.0260, 0.0220, 0.0100, 0.0160, 0.0110, 0.0120,
	}

	finish := make([]float64, len(start))
	span := 0.0
	for i := range start {
		finish[i] = start[i] + duration[i]
		if span < finish[i] {
			span = finish[i]
		}
	}

	assert.Equal(schedule.Cores, uint(2), t)
	assert.Equal(schedule.Tasks, uint(40), t)
	assert.EqualWithin(schedule.Span, span, 1e-15, t)

	assert.Equal(schedule.Mapping, mapping, t)
	assert.Equal(schedule.Order, order, t)
	assert.EqualWithin(schedule.Start, start, 1e-15, t)
	assert.EqualWithin(schedule.Finish, finish, 1e-15, t)
}
示例#6
0
func TestParseRealIndex(t *testing.T) {
	cases := []struct {
		line   string
		min    float64
		max    float64
		result []float64
	}{
		{"", 0, 1, nil},
		{"[]", 0, 1, []float64{}},
		{"[0, 0.1, 0.9, 1]", 0, 1, []float64{0.0, 0.1, 0.9, 1.0}},
		{"[0, 0.1, 1.1]", 0, 1, nil},
		{"[0:1]", 0, 1, []float64{0, 1}},
		{"[0.1:0.2:1]", 0, 1, []float64{0.1, 0.3, 0.5, 0.7, 0.9}},
		{"[0:0.2:1]", 0, 1, []float64{0.0, 0.2, 0.4, 0.6, 0.8, 1.0}},
		{"[0:0.5:1.5]", 0, 1, nil},
		{"[0, 0.2, end]", 0, 1, []float64{0.0, 0.2, 1.0}},
		{"[0:0.2:end]", 0, 1, []float64{0.0, 0.2, 0.4, 0.6, 0.8, 1.0}},
		{"[0:end]", 0, 1, []float64{0, 1}},
	}

	for _, c := range cases {
		result, err := ParseRealIndex(c.line, c.min, c.max)
		if c.result != nil {
			assert.Success(err, t)
		}
		assert.EqualWithin(result, c.result, 1e-15, t)
	}
}
示例#7
0
func TestSolutionCompute(t *testing.T) {
	config, _ := config.New("fixtures/002_020.json")
	system, _ := system.New(&config.System)
	uncertainty, _ := uncertainty.NewEpistemic(system, &config.Uncertainty)

	quantity, _ := quantity.New(system, uncertainty, &config.Quantity)
	ni, no := quantity.Dimensions()

	solution, _ := New(ni, no, &config.Solution)
	surrogate := solution.Compute(quantity, quantity)

	nn := surrogate.Surrogate.Nodes

	assert.Equal(nn, uint(841), t)

	grid := grid.NewClosed(ni)
	nodes := grid.Compute(surrogate.Surrogate.Indices)

	values := make([]float64, nn*no)
	for i := uint(0); i < nn; i++ {
		quantity.Compute(nodes[i*ni:(i+1)*ni], values[i*no:(i+1)*no])
	}

	assert.EqualWithin(values, solution.Evaluate(surrogate, nodes), 1e-15, t)
}
示例#8
0
func TestCompute(t *testing.T) {
	Q := []float64{318.15, 328.15, 338.15, 348.15, 358.15, 368.15, 378.15, 388.15, 398.15}
	C := []float64{0.5460, 0.6304, 0.7326, 0.8550, 1.0000, 1.1711, 1.3734, 1.6067, 1.8737}
	power := New(1.0, Q, C)

	assert.EqualWithin(power.Compute(358.15), 1.088, 0.001, t)
}
示例#9
0
func TestHat(t *testing.T) {
	fixture := &fixtureHat
	algorithm, strategy := prepare(fixture)

	surrogate := algorithm.Compute(fixture.target, strategy)
	assert.Equal(surrogate, fixture.surrogate, t)

	values := algorithm.Evaluate(surrogate, fixture.points)
	assert.EqualWithin(values, fixture.values, 1e-15, t)
}
示例#10
0
func TestExpectation(t *testing.T) {
	data := []float64{
		+5.3766713954610001e-01, +1.8338850145950865e+00,
		-2.2588468610036481e+00, +8.6217332036812055e-01,
		+3.1876523985898081e-01, -1.3076882963052734e+00,
		-4.3359202230568356e-01, +3.4262446653864992e-01,
		+3.5783969397257605e+00, +2.7694370298848772e+00,
	}

	assert.EqualWithin(Expectation(data), 6.2428219709029698e-01, 1e-15, t)
}
示例#11
0
func TestVariance(t *testing.T) {
	data := []float64{
		+5.3766713954610001e-01, +1.8338850145950865e+00,
		-2.2588468610036481e+00, +8.6217332036812055e-01,
		+3.1876523985898081e-01, -1.3076882963052734e+00,
		-4.3359202230568356e-01, +3.4262446653864992e-01,
		+3.5783969397257605e+00, +2.7694370298848772e+00,
	}

	assert.EqualWithin(Variance(data), 3.1324921339484746e+00, 1e-15, t)
}
示例#12
0
func TestQuadrature(t *testing.T) {
	const (
		a = -6.0
		b = +6.0
	)

	nodes := uint(math.Ceil((float64(3) + 1.0) / 2.0))
	value := quadrature(a, b, nodes, f)

	assert.EqualWithin(value, F(b)-F(a), 1e-12, t)
}
示例#13
0
func TestBaseForwardInvert(t *testing.T) {
	uncertainty := &base{
		tasks: []uint{0, 1, 2},
		lower: []float64{10.0, 20.0, 30.0},
		upper: []float64{20.0, 30.0, 40.0},

		nt: 3,
		nu: 3,
		nz: 2,

		copula: &copula{
			C: []float64{
				1.0, 2.0, 3.0,
				4.0, 5.0, 6.0,
			},
			D: []float64{
				6.0, 5.0,
				4.0, 3.0,
				2.0, 1.0,
			},
		},
		marginals: []distribution.Continuous{
			distribution.NewUniform(0.0, 1.0),
			distribution.NewUniform(0.0, 1.0),
			distribution.NewUniform(0.0, 1.0),
		},
	}

	forward := uncertainty.Forward([]float64{18.0, 21.0, 36.0})
	assert.EqualWithin(forward, []float64{
		6.664804998759882e-01,
		7.313162037785672e-01,
	}, 1e-14, t)

	backward := uncertainty.Backward([]float64{0.45, 0.65})
	assert.EqualWithin(backward, []float64{
		1.921556679782504e+01,
		2.953060310728164e+01,
		3.973501094321997e+01,
	}, 1e-14, t)
}
示例#14
0
func TestPartition(t *testing.T) {
	const (
		n = 10
		ε = 1e-14
	)

	power, schedule := prepare("002_040")
	P, ΔT := power.Partition(schedule, ε)

	assert.Equal(P, fixturePartition.P, t)
	assert.EqualWithin(ΔT, fixturePartition.ΔT, 1e-15, t)
}
示例#15
0
func TestInvert(t *testing.T) {
	n := uint(3)
	a := []float64{1.0, -1.0, 0.0, 0.0, 5.0, 3.0, 2.0, 0.0, -9.0}

	expectedA := []float64{
		+8.823529411764706e-01, +1.764705882352941e-01, +5.882352941176472e-02,
		-1.176470588235294e-01, +1.764705882352941e-01, +5.882352941176472e-02,
		+1.960784313725490e-01, +3.921568627450981e-02, -9.803921568627452e-02,
	}

	assert.Equal(Invert(a, n), nil, t)
	assert.EqualWithin(a, expectedA, 1e-15, t)
}
示例#16
0
func TestNew(t *testing.T) {
	config, _ := config.New("fixtures/002_020.json")

	system, _ := New(&config.System)
	assert.Equal(system.Platform.Len(), 2, t)
	assert.Equal(system.Application.Len(), 20, t)

	schedule := system.schedule
	assert.Equal(schedule.Mapping, []uint{
		0, 1, 0, 0, 1, 1, 1, 0, 0, 1,
		1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
	}, t)
	assert.Equal(schedule.Order, []uint{
		0, 1, 2, 9, 12, 16, 18, 14, 17, 13,
		15, 3, 5, 11, 19, 8, 7, 6, 4, 10,
	}, t)
	assert.EqualWithin(schedule.Start, []float64{
		0.000, 0.010, 0.013, 0.187, 0.265, 0.218, 0.262, 0.260, 0.242, 0.051,
		0.267, 0.237, 0.079, 0.152, 0.113, 0.170, 0.079, 0.141, 0.113, 0.242,
	}, 1e-15, t)
	assert.EqualWithin(schedule.Span, 0.291, 1e-15, t)
}
示例#17
0
func TestComputeTridiagonal1D(t *testing.T) {
	a := []float64{
		4.8075817741978699e-01, 1.2692671000342037e-01, 4.9831340044932859e-01,
		3.9611537773884853e-01, 8.4803219799756557e-01, 3.8361564524640535e-01,
		4.2271936732562421e-01, 2.9871494846480506e-01, 6.0343086813946123e-01,
		6.5050309033626463e-01, 6.2611305300575382e-01, 4.9016643252911518e-01,
		6.3228557723272305e-01, 8.0881918292978749e-03, 9.8142184023407009e-01,
		3.0011820727343141e-01, 1.0221196095348672e-01, 1.7152991176879773e-01,
		6.3234800301520455e-01, 6.4222978064709224e-01,
	}
	b := []float64{
		1.4305400424536181e+00, 1.1546425268361689e+00, 1.5528249265311795e+00,
		1.5046909633814507e+00, 1.3106321971636674e+00, 1.7723433981144341e+00,
		1.0930877721506009e+00, 1.8067166712036105e+00, 1.4064057825267366e+00,
		1.2810478325153505e+00, 1.9576080656029342e+00, 1.6020009934522998e+00,
		1.9283873223117676e+00, 1.5668820259614546e+00, 1.4354500051833838e+00,
		1.2600111255480502e+00, 1.4573886219153447e+00, 1.0769003298984701e+00,
		1.2457299327768727e+00, 1.7477107763931770e+00,
	}
	c := []float64{
		2.8548654494460557e-01, 5.8540758620217703e-01, 2.6850381977534676e-01,
		6.9258609074529653e-01, 3.1247923637358188e-01, 9.0156663656333069e-01,
		6.1005182073414899e-01, 3.7766783517906743e-01, 9.3237166831823881e-01,
		5.8777963759554253e-01, 4.6097285394375520e-01, 2.1253215171767503e-01,
		2.8937226325800802e-01, 1.2110782971154588e-01, 7.6345100838619318e-01,
		9.4948181851599811e-01, 9.2046644452877935e-01, 9.4207843361454224e-01,
		5.5613288144227369e-01, 3.2889132147476241e-01,
	}
	d := []float64{
		5.4345703792352307e-01, 2.5206603256969351e-01, 6.7212010426701829e-01,
		5.5742791550815585e-01, 1.5338438683979383e-01, 1.3141853627070477e-01,
		2.1725351445739172e-01, 3.0696424588099869e-01, 6.5854065921020499e-01,
		5.4972430745083167e-01, 6.8185426479854760e-01, 6.4746979094442436e-01,
		3.7339166209360886e-01, 5.5263882037533685e-01, 4.5130602770887251e-01,
		5.3739081485328155e-01, 3.0980792962149784e-01, 1.1107555117435641e-01,
		7.5049154682465413e-01, 3.4499665786432776e-01,
	}
	x := []float64{
		+3.8743269018574988e-01, -1.8416124759605874e-02, +3.2427337332838657e-01,
		+2.4678206444367387e-01, +7.8428909904907917e-02, -5.2310318986601989e-02,
		+2.5837172936714375e-01, -1.1942347907589732e-01, +4.4350329009194173e-01,
		+1.1988956633676386e-01, +2.7879399381445569e-01, +2.7335327852770996e-01,
		+1.2095495317582093e-01, +5.0822993667190834e-02, +5.1938776470139614e-01,
		-3.1033791506044228e-01, +4.5485802026695138e-01, -2.7594190219192083e-01,
		+6.5046602806975073e-01, -3.7949205847255349e-02,
	}

	assert.EqualWithin(ComputeTridiagonal(a, b, c, d), x, 1e-15, t)
}
示例#18
0
func TestNewProfile(t *testing.T) {
	platform, application, _ := Load(findFixture("002_040"))

	profile := NewProfile(platform, application)

	mobility := []float64{
		0.0000, 0.0000, 0.0000, 0.0445, 0.0000, 0.0140, 0.1145, 0.0000,
		0.0095, 0.0000, 0.0145, 0.0140, 0.0140, 0.0280, 0.0740, 0.0000,
		0.0280, 0.0140, 0.0225, 0.0000, 0.0000, 0.0225, 0.0140, 0.0310,
		0.0000, 0.0380, 0.0260, 0.0225, 0.0140, 0.0140, 0.0000, 0.0280,
		0.1490, 0.0340, 0.0225, 0.0520, 0.0280, 0.0435, 0.0380, 0.0380,
	}

	assert.EqualWithin(profile.Mobility, mobility, 1e-15, t)
}
示例#19
0
func TestInverse(t *testing.T) {
	m := uint(3)

	A := []float64{
		1.0, 2.0, 3.0,
		2.0, 4.0, 5.0,
		3.0, 5.0, 6.0,
	}
	U := make([]float64, m*m)
	Λ := make([]float64, m)

	err := decomposition.SymmetricEigen(A, U, Λ, m)
	assert.Equal(err, nil, t)

	err = matrix.Invert(A, m)
	assert.Equal(err, nil, t)

	I, err := invert(U, Λ, m)
	assert.Equal(err, nil, t)
	assert.EqualWithin(A, I, 1e-14, t)
}
示例#20
0
func TestNewEpistemic(t *testing.T) {
	const (
		nt = 10
		σ  = 0.2
	)

	config, _ := config.New("fixtures/001_010.json")
	system, _ := system.New(&config.System)
	reference := system.ReferenceTime()
	uncertainty, _ := NewEpistemic(system, &config.Uncertainty)

	point := make([]float64, nt)
	value := make([]float64, nt)
	for i := 0; i < nt; i++ {
		α := float64(i) / (nt - 1)
		point[i] = α
		value[i] = (1.0 - σ + 2.0*σ*α) * reference[i]
	}

	assert.EqualWithin(uncertainty.Backward(point), value, 1e-15, t)
}
示例#21
0
func TestComputeTridiagonal2D(t *testing.T) {
	a := []float64{
		4.1702200470257400e-01, 7.2032449344215810e-01, 1.1437481734488664e-04,
		3.0233257263183977e-01, 1.4675589081711304e-01, 9.2338594768797799e-02,
		1.8626021137767090e-01, 3.4556072704304774e-01, 3.9676747423066994e-01,
		5.3881673400335695e-01,
	}
	b := []float64{
		1.4191945144032947e+00, 1.6852195003967596e+00, 1.2044522497315175e+00,
		1.8781174363909454e+00, 1.0273875931979262e+00, 1.6704675101784021e+00,
		1.4173048023671271e+00, 1.5586898284457518e+00, 1.1403869385952339e+00,
		1.1981014890848787e+00,
	}
	c := []float64{
		8.0074456867553667e-01, 9.6826157571939753e-01, 3.1342417815924284e-01,
		6.9232261566931408e-01, 8.7638915229603831e-01, 8.9460666350384732e-01,
		8.5044211369777911e-02, 3.9054783232882362e-02, 1.6983041956456890e-01,
		8.7814250342941313e-01,
	}
	d := []float64{
		9.8886108890649471e-01, 7.4816565437983940e-01, 2.8044399206440518e-01,
		7.8927932845148852e-01, 1.0322600657764203e-01, 4.4789352617590517e-01,
		9.0859550309309556e-01, 2.9361414837367950e-01, 2.8777533858634874e-01,
		1.3002857211827767e-01, 1.9366957870297075e-02, 6.7883553293989096e-01,
		2.1162811600005904e-01, 2.6554665937222621e-01, 4.9157315928033829e-01,
		5.3362545117080384e-02, 5.7411760549201307e-01, 1.4672857490581015e-01,
		5.8930553690328424e-01, 6.9975836002093117e-01,
	}
	x := []float64{
		+4.2413660994635355e-01, +3.9961178716148082e-01, -3.2589132682920774e-01,
		+5.5626432959857730e-01, -2.9143803729175111e-01, +2.6209172590772878e-01,
		+6.2141868670421718e-01, +9.3577077457946675e-02, +1.8848763199672364e-01,
		+4.6108623476807969e-02, -3.2256530997806154e-01, +4.9279026276907484e-01,
		-5.4582244963076967e-02, -1.1208513329599634e-01, +5.4320839567983115e-01,
		-3.6469011007728362e-02, +4.0642167843987542e-01, +3.7427069391596034e-02,
		+7.4728631269099247e-02, +5.5930860268891813e-01,
	}

	assert.EqualWithin(ComputeTridiagonal(a, b, c, d), x, 1e-15, t)
}
示例#22
0
func TestNewAleatory(t *testing.T) {
	const (
		nt = 10
		σ  = 0.2
	)

	config, _ := config.New("fixtures/001_010.json")
	system, _ := system.New(&config.System)
	uncertainty, _ := NewAleatory(system, &config.Uncertainty)

	point := make([]float64, nt)
	for i := 0; i < nt; i++ {
		point[i] = 0.5
	}

	assert.EqualWithin(uncertainty.Backward(point), []float64{
		3.1402438661763954e-02, 1.7325483399593899e-02,
		2.7071067811865485e-02, 3.1402438661763954e-02,
		4.0065180361560912e-02, 3.2485281374238568e-02,
		1.7325483399593888e-02, 2.5988225099390850e-02,
		1.6242640687119302e-02, 3.2485281374238568e-02,
	}, 1e-15, t)
}
示例#23
0
func TestLegendre(t *testing.T) {
	x, w := Legendre(42, -1.0, 1.0)
	assert.EqualWithin(x, fixtureLegendre42X, 1e-14, t)
	assert.EqualWithin(w, fixtureLegendre42W, 1e-14, t)
}
示例#24
0
func TestClosedCompute1D3P(t *testing.T) {
	const (
		nd = 1
		np = 3
		nb = 4
		nn = 101
	)

	basis := NewClosed(nd, np)

	indices := internal.Compose(
		[]uint64{3, 3, 3, 3, 3, 3, 3, 3},
		[]uint64{1, 3, 5, 7, 9, 11, 13, 15},
	)

	points := make([]float64, nn)
	for i := range points {
		points[i] = float64(i) / (nn - 1)
	}

	values := make([]float64, nn)
	for i := range values {
		for j := 0; j < nb; j++ {
			values[i] += basis.Compute(indices[j:j+1], points[i:i+1])
		}
	}

	assert.EqualWithin(values, []float64{
		0.0000000000000000e+00, 2.0070399999999997e-01, 3.7683200000000000e-01,
		5.2940799999999999e-01, 6.5945600000000004e-01, 7.6800000000000013e-01,
		8.5606400000000005e-01, 9.2467200000000005e-01, 9.7484799999999983e-01,
		1.0076160000000001e+00, 1.0240000000000000e+00, 1.0250240000000002e+00,
		1.0117119999999999e+00, 9.8508799999999996e-01, 9.4617599999999991e-01,
		8.9599999999999991e-01, 8.3558399999999988e-01, 7.6595199999999986e-01,
		6.8812800000000007e-01, 6.0313600000000001e-01, 5.1199999999999990e-01,
		4.1574400000000011e-01, 3.1539200000000001e-01, 2.1196799999999993e-01,
		1.0649600000000009e-01, 0.0000000000000000e+00, 1.0649600000000009e-01,
		2.1196800000000018e-01, 3.1539200000000028e-01, 4.1574399999999978e-01,
		5.1199999999999990e-01, 6.0313600000000001e-01, 6.8812800000000007e-01,
		7.6595200000000008e-01, 8.3558400000000010e-01, 8.9599999999999991e-01,
		9.4617599999999991e-01, 9.8508799999999996e-01, 1.0117119999999999e+00,
		1.0250239999999999e+00, 1.0240000000000000e+00, 1.0076160000000001e+00,
		9.7484799999999994e-01, 9.2467200000000005e-01, 8.5606400000000005e-01,
		7.6799999999999990e-01, 6.5945599999999971e-01, 5.2940800000000032e-01,
		3.7683200000000028e-01, 2.0070400000000016e-01, 0.0000000000000000e+00,
		2.0070400000000016e-01, 3.7683200000000028e-01, 5.2940800000000032e-01,
		6.5945600000000049e-01, 7.6800000000000057e-01, 8.5606400000000038e-01,
		9.2467199999999972e-01, 9.7484799999999983e-01, 1.0076160000000001e+00,
		1.0240000000000000e+00, 1.0250239999999999e+00, 1.0117119999999999e+00,
		9.8508799999999996e-01, 9.4617599999999991e-01, 8.9599999999999991e-01,
		8.3558399999999988e-01, 7.6595199999999963e-01, 6.8812799999999963e-01,
		6.0313600000000045e-01, 5.1200000000000045e-01, 4.1574400000000039e-01,
		3.1539200000000028e-01, 2.1196800000000018e-01, 1.0649600000000009e-01,
		0.0000000000000000e+00, 1.0649600000000009e-01, 2.1196800000000018e-01,
		3.1539200000000028e-01, 4.1574400000000039e-01, 5.1200000000000045e-01,
		6.0313600000000045e-01, 6.8812799999999963e-01, 7.6595199999999963e-01,
		8.3558399999999988e-01, 8.9599999999999991e-01, 9.4617599999999991e-01,
		9.8508799999999996e-01, 1.0117119999999999e+00, 1.0250239999999999e+00,
		1.0240000000000000e+00, 1.0076160000000001e+00, 9.7484799999999983e-01,
		9.2467199999999972e-01, 8.5606400000000038e-01, 7.6800000000000057e-01,
		6.5945600000000049e-01, 5.2940800000000032e-01, 3.7683200000000028e-01,
		2.0070400000000016e-01, 0.0000000000000000e+00,
	}, 1e-15, t)
}
示例#25
0
func TestOpenCompute(t *testing.T) {
	basis := NewOpen(1, 1)

	compute := func(level, order uint64, point float64) float64 {
		return basis.Compute(internal.Compose([]uint64{level}, []uint64{order}), []float64{point})
	}

	points := []float64{
		0.00, 0.04, 0.08, 0.12, 0.16, 0.20, 0.24, 0.28, 0.32, 0.36, 0.40, 0.44, 0.48,
		0.52, 0.56, 0.60, 0.64, 0.68, 0.72, 0.76, 0.80, 0.84, 0.88, 0.92, 0.96, 1.00,
	}

	cases := []struct {
		level  uint64
		order  uint64
		values []float64
	}{
		{0, 0, []float64{
			1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00,
			1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00,
		}},
		{1, 0, []float64{
			2.00, 1.84, 1.68, 1.52, 1.36, 1.20, 1.04, 0.88, 0.72, 0.56, 0.40, 0.24, 0.08,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{1, 2, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.08, 0.24, 0.40, 0.56, 0.72, 0.88, 1.04, 1.20, 1.36, 1.52, 1.68, 1.84, 2.00,
		}},
		{2, 0, []float64{
			2.00, 1.68, 1.36, 1.04, 0.72, 0.40, 0.08, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{2, 2, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.24, 0.56, 0.88, 0.80, 0.48, 0.16,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{2, 4, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.16, 0.48, 0.80, 0.88, 0.56, 0.24, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{2, 6, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.08, 0.40, 0.72, 1.04, 1.36, 1.68, 2.00,
		}},
		{3, 0, []float64{
			2.00, 1.36, 0.72, 0.08, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 2, []float64{
			0.00, 0.00, 0.00, 0.00, 0.56, 0.80, 0.16, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 4, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.48, 0.88, 0.24, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 6, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.40, 0.96, 0.32,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 8, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.32, 0.96, 0.40, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 10, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.24, 0.88, 0.48, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 12, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.16, 0.80, 0.56, 0.00, 0.00, 0.00, 0.00,
		}},
		{3, 14, []float64{
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
			0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.08, 0.72, 1.36, 2.00,
		}},
	}

	values := make([]float64, len(points))

	for i := range cases {
		for j := range values {
			values[j] = compute(cases[i].level, cases[i].order, points[j])
		}
		assert.EqualWithin(values, cases[i].values, 1e-15, t)
	}
}
示例#26
0
func TestEvaluate3D(t *testing.T) {
	interpolant := New(trainPoints, trainValues)
	values := interpolant.Evaluate(testPoints)
	assert.EqualWithin(values, testValues, 1e-15, t)
}
示例#27
0
func TestKolmogorovSmirnovWeibull(t *testing.T) {
	data1 := []float64{
		8.7461628950465320e-01, 3.2805348316383787e-01,
		9.0760296313544622e+00, 1.1962276336402389e+00,
		1.9189846792253313e+00, 2.3822930800308089e+00,
		1.6806105970365317e+00, 1.0625868855376310e+00,
		9.2440487711596209e-01, 6.1837977701552593e-01,
		8.6942023193092821e-01, 3.7801605351395895e-01,
		1.5874208284094915e+00, 1.2997493985974612e-01,
		3.5976651711297412e+00, 3.9978003354420455e-01,
		8.7393838326219087e-01, 5.8216082843584527e-01,
		1.9633528216664577e+00, 1.6189758084715631e+00,
		2.2221327331258003e-01, 3.2253005358561328e-02,
		1.1601978041124075e+00, 3.6770322439085690e-01,
		1.3194504890926964e-01, 1.1137113942645817e-01,
		2.4645840239524057e+00, 3.2427899202391495e+00,
		1.7729548717711372e+00, 1.2994639392767643e-01,
		2.3192549275168197e+00, 8.6486683662826902e-01,
		4.3022820655631802e-02, 6.2892379974946411e-01,
		3.6834692013026532e-01, 1.1535470546272795e+00,
		3.7614770245443635e-01, 1.8077195177537575e-01,
		4.0014950066798560e+00, 2.8748967103549722e-01,
		1.1201413335031433e-02, 2.9013086245233494e-01,
		1.2713812457411025e+00, 2.3663499233392407e-01,
		2.2708344559604376e+00, 8.0319973959982871e-01,
		9.5855274939282600e-02, 1.2254887941191932e+00,
		1.2455751776154669e+00, 2.0400010671506421e+00,
	}

	data2 := []float64{
		2.3831972409571311e+00, 7.4687483316870418e-01,
		1.4953967997990596e+00, 1.3818064935457834e+00,
		1.0112408625687035e+00, 2.0542956216762875e+00,
		8.9391625059996016e-01, 1.6624096945581250e+00,
		8.7263228664338210e-01, 7.1701401175000756e-01,
		1.8117651960300805e+00, 1.1268211359176015e+00,
		7.2469160298066559e-01, 1.1266309014978020e+00,
		2.0773048597848836e+00, 9.4778307072697676e-01,
		7.6817102463234821e-01, 9.7768980447137177e-01,
		2.8649424647995436e-01, 8.7648378662405579e-01,
		3.8247397215059686e-01, 1.6903887428782887e+00,
		1.6848338500054207e+00, 5.5505268065669600e-01,
		1.1523221867552904e+00, 1.6098193245119850e+00,
		3.2918787364845276e-01, 1.2332741840978334e+00,
		6.4242025954586868e-01, 6.7904313293871110e-01,
		4.2270583693329028e-01, 8.2454091183641387e-01,
		6.4222569780367744e-01, 1.2313746559990257e+00,
		1.3732532939676521e+00, 3.9788978659375451e-01,
		1.1053159845638993e+00, 2.2702828394384506e-01,
		7.6866964666838733e-01, 8.2730797319419624e-01,
		1.7656867546746680e+00, 2.7319723346979158e-01,
		1.0724422049099485e+00, 8.8792504877824741e-01,
		1.1359842068648212e+00, 1.4397906365994388e+00,
		3.8252063532077912e-01, 8.9453092224749142e-01,
		2.9032385714734148e+00, 8.3367741780056803e-01,
	}

	rejected, pvalue, statistic := KolmogorovSmirnov(data1, data2, 0.01)

	assert.Equal(rejected, false, t)
	assert.EqualWithin(pvalue, 3.1660846051790786e-02, 1e-15, t)
	assert.EqualWithin(statistic, 2.7999999999999997e-01, 1e-15, t)
}
示例#28
0
func TestCovPCA(t *testing.T) {
	Σ := []float64{
		+1.000000000000000e+00,
		+1.154127058177033e-01,
		+3.134709671301593e-01,
		-2.624605475789556e-01,
		-2.675628902376415e-01,
		+1.154127058177033e-01,
		+1.000000000000000e+00,
		+1.487775664601468e-01,
		+8.251722261621278e-01,
		+6.471493243665016e-01,
		+3.134709671301593e-01,
		+1.487775664601468e-01,
		+1.000000000000000e+00,
		+2.188948568766876e-01,
		-4.746506616202846e-01,
		-2.624605475789556e-01,
		+8.251722261621278e-01,
		+2.188948568766876e-01,
		+1.000000000000000e+00,
		+7.047860759340304e-01,
		-2.675628902376415e-01,
		+6.471493243665017e-01,
		-4.746506616202846e-01,
		+7.047860759340304e-01,
		+1.000000000000000e+00,
	}

	expectedU := []float64{
		-1.777008675251867e-01,
		+5.456098595844089e-01,
		-7.679302728419535e-02,
		+5.862167305996994e-01,
		+5.667319106337718e-01,
		+5.274851240801810e-01,
		+3.209998200695767e-01,
		+7.174077977724287e-01,
		+1.998699259327777e-01,
		-2.531731103264220e-01,
		+7.655128668903998e-01,
		+1.936393917712877e-01,
		-4.774829578033630e-01,
		-2.733383132570983e-01,
		+2.716431999752671e-01,
		-2.541030814371850e-01,
		+7.277625876615521e-01,
		-2.402296315689612e-01,
		-2.880993167658167e-01,
		-5.148609014089138e-01,
		+1.990063320205669e-01,
		-1.792607000828338e-01,
		-4.401461482047020e-01,
		+6.772642819885449e-01,
		-5.252109497950679e-01,
	}

	expectedΛ := []float64{
		2.500258665819985e+00,
		1.525542276483301e+00,
		8.324395052148045e-01,
		1.261010747114109e-01,
		1.565847777049709e-02,
	}

	U, Λ, err := CovPCA(Σ, 5, 0.0)

	assert.Success(err, t)
	assert.EqualWithin(Λ, expectedΛ, 1e-14, t)
	assert.EqualWithin(abs(U), abs(expectedU), 1e-14, t)
}
示例#29
0
func TestSymmetricEigen(t *testing.T) {
	m := uint(5)

	A := []float64{
		0.814723686393179,
		0.097540404999410,
		0.157613081677548,
		0.141886338627215,
		0.655740699156587,
		0.097540404999410,
		0.278498218867048,
		0.970592781760616,
		0.421761282626275,
		0.035711678574190,
		0.157613081677548,
		0.970592781760616,
		0.957166948242946,
		0.915735525189067,
		0.849129305868777,
		0.141886338627215,
		0.421761282626275,
		0.915735525189067,
		0.792207329559554,
		0.933993247757551,
		0.655740699156587,
		0.035711678574190,
		0.849129305868777,
		0.933993247757551,
		0.678735154857773,
	}

	eigenVectors := []float64{
		+0.200767588469279,
		-0.613521879994358,
		+0.529492579537623,
		+0.161735212201923,
		-0.526082320114459,
		-0.241005628008408,
		-0.272281143378657,
		+0.443280672960843,
		-0.675165120368165,
		+0.464148221418878,
		+0.509762909240926,
		+0.555609456752178,
		+0.244072927029371,
		-0.492754485897426,
		-0.359251069377747,
		-0.766321363493223,
		+0.386556170387878,
		+0.341170928524320,
		+0.084643789583352,
		-0.373849864790357,
		+0.233456648876442,
		+0.302202482503382,
		+0.589211894835079,
		+0.517708631263932,
		+0.488854547655902,
	}

	eigenValues := []float64{
		-0.671640666831794,
		-0.230366398529950,
		+0.397221322493687,
		+0.999582068576074,
		+3.026535012212483,
	}

	U := make([]float64, m*m)
	Λ := make([]float64, m)

	SymmetricEigen(A, U, Λ, m)

	assert.EqualWithin(U, eigenVectors, 2e-15, t)
	assert.EqualWithin(Λ, eigenValues, 1e-15, t)
}
示例#30
0
func TestDecompose(t *testing.T) {
	m := uint(5)
	ε := math.Sqrt(math.Nextafter(1.0, 2.0) - 1.0)

	Σ := []float64{
		+1.000000000000000e+00,
		+1.154127058177033e-01,
		+3.134709671301593e-01,
		-2.624605475789556e-01,
		-2.675628902376415e-01,
		+1.154127058177033e-01,
		+1.000000000000000e+00,
		+1.487775664601468e-01,
		+8.251722261621278e-01,
		+6.471493243665016e-01,
		+3.134709671301593e-01,
		+1.487775664601468e-01,
		+1.000000000000000e+00,
		+2.188948568766876e-01,
		-4.746506616202846e-01,
		-2.624605475789556e-01,
		+8.251722261621278e-01,
		+2.188948568766876e-01,
		+1.000000000000000e+00,
		+7.047860759340304e-01,
		-2.675628902376415e-01,
		+6.471493243665017e-01,
		-4.746506616202846e-01,
		+7.047860759340304e-01,
		+1.000000000000000e+00,
	}

	expectedC := []float64{
		-2.809842768614861e-01,
		+8.627295633325639e-01,
		-1.214267186196807e-01,
		+9.269379853101427e-01,
		+8.961281861000945e-01,
		+6.515118812441264e-01,
		+3.964760087163447e-01,
		+8.860907779360867e-01,
		+2.468650308871921e-01,
		-3.127013101588838e-01,
		+6.984395695466264e-01,
		+1.766729460543113e-01,
		-4.356464873918021e-01,
		-2.493887459101609e-01,
		+2.478421563724771e-01,
		-9.023381630769038e-02,
		+2.584336847835331e-01,
		-8.530725532353041e-02,
		-1.023061219107812e-01,
		-1.828307777260400e-01,
		+2.490242639661812e-02,
		-2.243157966027762e-02,
		-5.507717743518731e-02,
		+8.474867991403982e-02,
		-6.572166265854235e-02,
	}

	expectedD := []float64{
		-1.123820829831357e-01,
		+4.270690437671776e-01,
		+8.390274190151508e-01,
		-7.155673852439032e-01,
		+1.590347846170451e+00,
		+3.450561236429604e-01,
		+2.598918527714004e-01,
		+2.122351773883221e-01,
		+2.049416988514750e+00,
		-1.432551745390084e+00,
		-4.856566253710289e-02,
		+5.808365927286619e-01,
		-5.233371129826270e-01,
		-6.764990347525633e-01,
		-3.517403047885066e+00,
		+3.707368353450518e-01,
		+1.618211666059287e-01,
		-2.995878311251075e-01,
		-8.113025376263803e-01,
		+5.412319202171648e+00,
		+3.584141906398315e-01,
		-2.049771513902104e-01,
		+2.977299309077400e-01,
		-1.449874857486012e+00,
		-4.197193598369533e+00,
	}

	C, D, _, _, _ := Decompose(Σ, m, 1.0, ε)

	assert.EqualWithin(abs(C), abs(expectedC), 1e-14, t)
	assert.EqualWithin(abs(D), abs(expectedD), 1e-13, t)

	C, D, _, _, _ = Decompose(Σ, m, 0.75, ε)

	assert.EqualWithin(abs(C), abs(expectedC[:m*2]), 1e-14, t)
	assert.EqualWithin(abs(D), abs(slice(expectedD, m, m, 2)), 1e-13, t)
}