1 // Copyright ©2017 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "gonum.org/v1/gonum/mat"
16 // Perform a GSVD factorization on food production/consumption data for the
17 // three years 1990, 2000 and 2014, for Africa and Latin America/Caribbean.
19 // See Lee et al. doi:10.1371/journal.pone.0030098 and
20 // Alter at al. doi:10.1073/pnas.0530258100 for more details.
22 ok := gsvd.Factorize(FAO.Africa, FAO.LatinAmericaCaribbean, mat.GSVDU|mat.GSVDV|mat.GSVDQ)
24 log.Fatal("GSVD factorization failed")
30 s1 := gsvd.ValuesA(nil)
31 s2 := gsvd.ValuesB(nil)
33 fmt.Printf("Africa\n\ts1 = %.4f\n\n\tU = %.4f\n\n",
34 s1, mat.Formatted(u, mat.Prefix("\t "), mat.Excerpt(2)))
35 fmt.Printf("Latin America/Caribbean\n\ts2 = %.4f\n\n\tV = %.4f\n",
36 s2, mat.Formatted(v, mat.Prefix("\t "), mat.Excerpt(2)))
39 q.Mul(gsvd.ZeroRTo(nil), gsvd.QTo(nil))
40 fmt.Printf("\nCommon basis vectors\n\n\tQ^T = %.4f\n",
41 mat.Formatted(q.T(), mat.Prefix("\t ")))
43 // Calculate the antisymmetric angular distances for each eigenvariable.
44 fmt.Println("\nSignificance:")
45 for i := 0; i < 3; i++ {
46 fmt.Printf("\teigenvar_%d: %+.4f\n", i, math.Atan(s1[i]/s2[i])-math.Pi/4)
52 // s1 = [1.0000 0.9344 0.5118]
55 // ⎡-0.0005 0.0142 ... ... -0.0060 -0.0055⎤
56 // ⎢-0.0010 0.0019 0.0071 0.0075⎥
60 // ⎢-0.0007 -0.0024 0.9999 -0.0001⎥
61 // ⎣-0.0010 -0.0016 ... ... -0.0001 0.9999⎦
63 // Latin America/Caribbean
64 // s2 = [0.0047 0.3563 0.8591]
67 // ⎡ 0.1362 0.0008 ... ... 0.0700 0.2636⎤
68 // ⎢ 0.1830 -0.0040 0.2908 0.7834⎥
72 // ⎢-0.2598 -0.0324 0.9339 -0.2170⎥
73 // ⎣-0.8386 0.1494 ... ... -0.1639 0.4121⎦
75 // Common basis vectors
77 // Q^T = ⎡ -8172.4084 -4524.2933 4813.9616⎤
78 // ⎢ 22581.8020 12397.1070 -16364.8933⎥
79 // ⎣ -8910.8462 -10902.1488 15762.8719⎦
82 // eigenvar_0: +0.7807
83 // eigenvar_1: +0.4211
84 // eigenvar_2: -0.2482