Ejemplo n.º 1
0
func TestGcvRodrigues(t *testing.T) {
	rvec := mat64.NewDense(3, 1, []float64{
		-0.98405029,
		-0.93443411,
		-0.26304667,
	})
	rmat := GcvRodrigues(rvec)

	assert.InDeltaSlice(t, []float64{0.59922526, 0.57799222, -0.55394411}, rmat.Row(nil, 0), DELTA)
	assert.InDeltaSlice(t, []float64{0.20413818, 0.558743, 0.80382452}, rmat.Row(nil, 1), DELTA)
	assert.InDeltaSlice(t, []float64{0.77411672, -0.5947531, 0.21682264}, rmat.Row(nil, 2), DELTA)
}
Ejemplo n.º 2
0
func TestComputeCentroidDistanceMatrix1(t *testing.T) {
	model := NewTriangleKMeans(4, 2, circles)

	// now assign centroids to certain values
	// so we can test distance computation
	model.Centroids = [][]float64{
		[]float64{0, 0},
		[]float64{-6, 6},
		[]float64{100, 0},
		[]float64{10, 10},
	}

	// should is the distances such that
	// should[i][j] is the correct
	// distances from centroid[i] to
	// centroid[j]
	//
	// also note that these distances are
	// the *SQUARED* Euclidean distances
	// because it's faster to compute and
	// relative comparison is the same
	should := [][]float64{
		[]float64{0, 36, 5000, 100},
		[]float64{36, 0, 5636, 136},
		[]float64{5000, 5636, 0, 4100},
		[]float64{100, 136, 4100, 0},
	}

	mins := []float64{
		36,
		36,
		4100,
		100,
	}

	model.computeCentroidDistanceMatrix()

	// test matrix similarities from expected
	for i := range should {
		assert.InDeltaSlice(t, should[i], model.centroidDist[i], 1e-6, "Centroid distances should match")
	}

	// now test min similarities
	assert.InDeltaSlice(t, mins, model.minCentroidDist, 1e-6, "Differences in min centroid dist from expected should be small")
}
Ejemplo n.º 3
0
func TestGcvCalibrateCamera(t *testing.T) {
	objPts := mat64.NewDense(10, 3, []float64{
		-1.482676, -1.419348, 1.166475,
		-0.043819, -0.729445, 1.212821,
		0.960825, 1.147328, 0.485541,
		1.738245, 0.597865, 1.026016,
		-0.430206, -1.281281, 0.870726,
		-1.627323, -2.203264, -0.381758,
		0.166347, -0.571246, 0.428893,
		0.376266, 0.213996, -0.299131,
		-0.226950, 0.942377, -0.899869,
		-1.148912, 0.093725, 0.634745,
	})
	objPts.TCopy(objPts)

	imgPts := mat64.NewDense(10, 2, []float64{
		-0.384281, -0.299055,
		0.361833, 0.087737,
		1.370253, 1.753933,
		1.421390, 0.853312,
		0.107177, -0.443076,
		3.773328, 5.437829,
		0.624914, -0.280949,
		-0.825577, -0.245594,
		0.631444, -0.340257,
		-0.647580, 0.502113,
	})
	imgPts.TCopy(imgPts)

	camMat := GcvInitCameraMatrix2D(objPts, imgPts, [2]int{1920, 1080}, 1)

	distCoeffs := mat64.NewDense(5, 1, []float64{0, 0, 0, 0, 0})

	camMat, rvec, tvec := GcvCalibrateCamera(
		objPts, imgPts, camMat, distCoeffs, [2]int{1920, 1080}, 14575)

	assert.InDeltaSlice(t, []float64{-46.15296606, 0., 959.5}, camMat.Row(nil, 0), DELTA)
	assert.InDeltaSlice(t, []float64{0., -46.15296606, 539.5}, camMat.Row(nil, 1), DELTA)
	assert.InDeltaSlice(t, []float64{0., 0., 1.}, camMat.Row(nil, 2), DELTA)

	assert.InDeltaSlice(t, []float64{-0.98405029, -0.93443411, -0.26304667}, rvec.Col(nil, 0), DELTA)
	assert.InDeltaSlice(t, []float64{0.6804739, 0.47530207, -0.04833094}, tvec.Col(nil, 0), DELTA)
}
Ejemplo n.º 4
0
func TestGcvInitCameraMatrix2D(t *testing.T) {
	objPts := mat64.NewDense(10, 3, []float64{
		-1.482676, -1.419348, 1.166475,
		-0.043819, -0.729445, 1.212821,
		0.960825, 1.147328, 0.485541,
		1.738245, 0.597865, 1.026016,
		-0.430206, -1.281281, 0.870726,
		-1.627323, -2.203264, -0.381758,
		0.166347, -0.571246, 0.428893,
		0.376266, 0.213996, -0.299131,
		-0.226950, 0.942377, -0.899869,
		-1.148912, 0.093725, 0.634745,
	})
	objPts.TCopy(objPts)

	imgPts := mat64.NewDense(10, 2, []float64{
		-0.384281, -0.299055,
		0.361833, 0.087737,
		1.370253, 1.753933,
		1.421390, 0.853312,
		0.107177, -0.443076,
		3.773328, 5.437829,
		0.624914, -0.280949,
		-0.825577, -0.245594,
		0.631444, -0.340257,
		-0.647580, 0.502113,
	})
	imgPts.TCopy(imgPts)

	camMat := GcvInitCameraMatrix2D(objPts, imgPts, [2]int{1920, 1080}, 1)
	assert.InDeltaSlice(t, []float64{1.47219772e+03, 0.00000000e+00, 9.59500000e+02},
		camMat.Row(nil, 0), DELTA)
	assert.InDeltaSlice(t, []float64{0.00000000e+00, 1.47219772e+03, 5.39500000e+02},
		camMat.Row(nil, 1), DELTA)
	assert.InDeltaSlice(t, []float64{0.00000000e+00, 0.00000000e+00, 1.00000000e+00},
		camMat.Row(nil, 2), DELTA)
}
Ejemplo n.º 5
0
func TestIwt53Fwt53(t *testing.T) {

	xn := make([]float64, 32)

	for i := 0; i < 32; i++ {
		xn[i] = 5.0 + float64(i) + 0.4*float64(i*i) - 0.02*float64(i*i*i)
	}
	yn := make([]float64, 32)
	copy(yn, xn)

	fmt.Printf("xn is %v\n.", xn)

	Fwt53(xn)
	fmt.Printf("Fwt53(xn) is %v\n.", xn)

	Iwt53(xn)
	fmt.Printf("Iwt53(Fwt53(xn)) is %v\n.", xn)

	assert.InDeltaSlice(t, yn, xn, 0.0000000001, "Iwt53(Fwt53(xn)) != xn")
}
Ejemplo n.º 6
0
func TestGenerateThetas(t *testing.T) {
	var examples = []struct {
		start  float64
		end    float64
		step   float64
		thetas []float64
	}{
		{0, 1, 0.1, []float64{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}},
		{0, 1, 0.3, []float64{0, 0.3, 0.6, 0.9}},
		{0, 1, 1, []float64{0, 1}},
		{-1, 1, 1, []float64{-1, 0, 1}},
		{1, 0, -0.5, []float64{1, 0.5, 0}},
		{1, 2, 0.3, []float64{1, 1.3, 1.6, 1.9}},
	}

	for _, tt := range examples {
		thetas := generateThetas(tt.start, tt.end, tt.step)
		if !assert.InDeltaSlice(t, tt.thetas, thetas, 0.01) {
			t.Logf("For theta: %v, %v, %v", tt.start, tt.end, tt.step)
		}
	}
}
Ejemplo n.º 7
0
// InDeltaSlice is the same as InDelta, except it compares two slices.
func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
	if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
		t.FailNow()
	}
}