Exemplo n.º 1
0
 def test_CF(self):
     # quartimax
     out = self.get_quartimax_example_derivative_free()
     A, table_required, L_required = out
     vgQ = lambda L=None, A=None, T=None: CF_objective(
         L=L, A=A, T=T, kappa=0, rotation_method='orthogonal',
         return_gradient=True)
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     # quartimax derivative free
     ff = lambda L=None, A=None, T=None: CF_objective(
         L=L, A=A, T=T, kappa=0, rotation_method='orthogonal',
         return_gradient=False)
     L, phi, T, table = GPA(A, ff=ff, rotation_method='orthogonal')
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     # varimax
     p, k = A.shape
     vgQ = lambda L=None, A=None, T=None: orthomax_objective(
         L=L, A=A, T=T, gamma=1, return_gradient=True)
     L_vm, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     vgQ = lambda L=None, A=None, T=None: CF_objective(
         L=L, A=A, T=T, kappa=1/p, rotation_method='orthogonal',
         return_gradient=True)
     L_CF, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     ff = lambda L=None, A=None, T=None: CF_objective(
         L=L, A=A, T=T, kappa=1/p, rotation_method='orthogonal',
         return_gradient=False)
     L_CF_df, phi, T, table = GPA(A, ff=ff, rotation_method='orthogonal')
     self.assertTrue(np.allclose(L_vm, L_CF, atol=1e-05))
     self.assertTrue(np.allclose(L_CF, L_CF_df, atol=1e-05))
Exemplo n.º 2
0
 def test_oblimin(self):
     # quartimin
     A, table_required, L_required = self.get_quartimin_example()
     vgQ = lambda L=None, A=None, T=None: oblimin_objective(
         L=L, A=A, T=T, gamma=0, rotation_method='oblique')
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='oblique')
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     # quartimin derivative free
     ff = lambda L=None, A=None, T=None: oblimin_objective(
         L=L, A=A, T=T, gamma=0, rotation_method='oblique',
         return_gradient=False)
     L, phi, T, table = GPA(A, ff=ff, rotation_method='oblique')
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     # biquartimin
     A, table_required, L_required = self.get_biquartimin_example()
     vgQ = lambda L=None, A=None, T=None: oblimin_objective(
         L=L, A=A, T=T, gamma=1/2, rotation_method='oblique')
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='oblique')
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     # quartimin derivative free
     out = self.get_biquartimin_example_derivative_free()
     A, table_required, L_required = out
     ff = lambda L=None, A=None, T=None: oblimin_objective(
         L=L, A=A, T=T, gamma=1/2, rotation_method='oblique',
         return_gradient=False)
     L, phi, T, table = GPA(A, ff=ff, rotation_method='oblique')
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
Exemplo n.º 3
0
 def test_equivalence_orthomax_oblimin(self):
     """
     These criteria should be equivalent when restricted to orthogonal
     rotation.
     See Hartman 1976 page 299.
     """
     A = self.get_A()
     gamma = 0  # quartimax
     vgQ = lambda L=None, A=None, T=None: orthomax_objective(
         L=L, A=A, T=T, gamma=gamma, return_gradient=True)
     L_orthomax, phi, T, table = GPA(
         A, vgQ=vgQ, rotation_method='orthogonal')
     vgQ = lambda L=None, A=None, T=None: oblimin_objective(
         L=L, A=A, T=T, gamma=gamma, rotation_method='orthogonal',
         return_gradient=True)
     L_oblimin, phi2, T2, table2 = GPA(A, vgQ=vgQ,
                                       rotation_method='orthogonal')
     self.assertTrue(np.allclose(L_orthomax, L_oblimin, atol=1e-05))
     gamma = 1  # varimax
     vgQ = lambda L=None, A=None, T=None: orthomax_objective(
         L=L, A=A, T=T, gamma=gamma, return_gradient=True)
     L_orthomax, phi, T, table = GPA(
         A, vgQ=vgQ, rotation_method='orthogonal')
     vgQ = lambda L=None, A=None, T=None: oblimin_objective(
         L=L, A=A, T=T, gamma=gamma, rotation_method='orthogonal',
         return_gradient=True)
     L_oblimin, phi2, T2, table2 = GPA(
         A, vgQ=vgQ, rotation_method='orthogonal')
     self.assertTrue(np.allclose(L_orthomax, L_oblimin, atol=1e-05))
Exemplo n.º 4
0
 def test_orthogonal_partial_target(self):
     """
     Rotation towards target matrix example
     http://www.stat.ucla.edu/research/gpa
     """
     A = self.get_A()
     H = self.str2matrix("""
       .8 -.3
       .8 -.4
       .7 -.4
       .9 -.4
       .8  .5
       .6  .4
       .5  .4
       .6  .3
     """)
     W = self.str2matrix("""
     1 0
     0 1
     0 0
     1 1
     1 0
     1 0
     0 1
     1 0
     """)
     vgQ = lambda L=None, A=None, T=None: vgQ_partial_target(
         H, W, L=L, A=A, T=T)
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     table_required = self.str2matrix("""
      0.00000    0.02559   -0.84194    1.00000
      1.00000    0.02203   -1.27116    0.25000
      2.00000    0.02154   -1.71198    0.25000
      3.00000    0.02148   -2.15713    0.25000
      4.00000    0.02147   -2.60385    0.25000
      5.00000    0.02147   -3.05114    0.25000
      6.00000    0.02147   -3.49863    0.25000
      7.00000    0.02147   -3.94619    0.25000
      8.00000    0.02147   -4.39377    0.25000
      9.00000    0.02147   -4.84137    0.25000
     10.00000    0.02147   -5.28897    0.25000
     """)
     L_required = self.str2matrix("""
     0.84526  -0.36228
     0.83621  -0.43571
     0.79528  -0.43836
     0.81349  -0.36857
     0.76525   0.53122
     0.65303   0.48467
     0.57565   0.46754
     0.63308   0.35876
     """)
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     ff = lambda L=None, A=None, T=None: ff_partial_target(
         H, W, L=L, A=A, T=T)
     L2, phi, T2, table = GPA(A, ff=ff, rotation_method='orthogonal')
     self.assertTrue(np.allclose(L, L2, atol=1e-05))
     self.assertTrue(np.allclose(T, T2, atol=1e-05))
Exemplo n.º 5
0
 def test_orthomax(self):
     """
     Quartimax example
     http://www.stat.ucla.edu/research/gpa
     """
     A = self.get_A()
     vgQ = lambda L=None, A=None, T=None: orthomax_objective(
         L=L, A=A, T=T, gamma=0, return_gradient=True)
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     table_required = self.str2matrix("""
      0.00000   -0.72073   -0.65498    1.00000
      1.00000   -0.88561   -0.34614    2.00000
      2.00000   -1.01992   -1.07152    1.00000
      3.00000   -1.02237   -1.51373    0.50000
      4.00000   -1.02269   -1.96205    0.50000
      5.00000   -1.02273   -2.41116    0.50000
      6.00000   -1.02273   -2.86037    0.50000
      7.00000   -1.02273   -3.30959    0.50000
      8.00000   -1.02273   -3.75881    0.50000
      9.00000   -1.02273   -4.20804    0.50000
     10.00000   -1.02273   -4.65726    0.50000
     11.00000   -1.02273   -5.10648    0.50000
     """)
     L_required = self.str2matrix("""
     0.89876   0.19482
     0.93394   0.12974
     0.90213   0.10386
     0.87651   0.17128
     0.31558   0.87647
     0.25113   0.77349
     0.19801   0.71468
     0.30786   0.65933
     """)
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     # oblimin criterion gives same result
     vgQ = lambda L=None, A=None, T=None: oblimin_objective(
         L=L,
         A=A,
         T=T,
         gamma=0,
         rotation_method='orthogonal',
         return_gradient=True)
     L_oblimin, phi2, T2, table2 = GPA(A,
                                       vgQ=vgQ,
                                       rotation_method='orthogonal')
     self.assertTrue(np.allclose(L, L_oblimin, atol=1e-05))
     # derivative free quartimax
     out = self.get_quartimax_example_derivative_free()
     A, table_required, L_required = out
     ff = lambda L=None, A=None, T=None: orthomax_objective(
         L=L, A=A, T=T, gamma=0, return_gradient=False)
     L, phi, T, table = GPA(A, ff=ff, rotation_method='orthogonal')
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
Exemplo n.º 6
0
 def test_orthogonal_target(self):
     """
     Rotation towards target matrix example
     http://www.stat.ucla.edu/research/gpa
     """
     A = self.get_A()
     H = self.str2matrix("""
       .8 -.3
       .8 -.4
       .7 -.4
       .9 -.4
       .8  .5
       .6  .4
       .5  .4
       .6  .3
     """)
     vgQ = lambda L=None, A=None, T=None: vgQ_target(H, L=L, A=A, T=T)
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     table_required = self.str2matrix("""
     0.00000   0.05925  -0.61244   1.00000
     1.00000   0.05444  -1.14701   0.12500
     2.00000   0.05403  -1.68194   0.12500
     3.00000   0.05399  -2.21689   0.12500
     4.00000   0.05399  -2.75185   0.12500
     5.00000   0.05399  -3.28681   0.12500
     6.00000   0.05399  -3.82176   0.12500
     7.00000   0.05399  -4.35672   0.12500
     8.00000   0.05399  -4.89168   0.12500
     9.00000   0.05399  -5.42664   0.12500
     """)
     L_required = self.str2matrix("""
     0.84168  -0.37053
     0.83191  -0.44386
     0.79096  -0.44611
     0.80985  -0.37650
     0.77040   0.52371
     0.65774   0.47826
     0.58020   0.46189
     0.63656   0.35255
     """)
     self.assertTrue(np.allclose(table, table_required, atol=1e-05))
     self.assertTrue(np.allclose(L, L_required, atol=1e-05))
     ff = lambda L=None, A=None, T=None: ff_target(H, L=L, A=A, T=T)
     L2, phi, T2, table = GPA(A, ff=ff, rotation_method='orthogonal')
     self.assertTrue(np.allclose(L, L2, atol=1e-05))
     self.assertTrue(np.allclose(T, T2, atol=1e-05))
     vgQ = lambda L=None, A=None, T=None: vgQ_target(
         H, L=L, A=A, T=T, rotation_method='oblique')
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='oblique')
     ff = lambda L=None, A=None, T=None: ff_target(
         H, L=L, A=A, T=T, rotation_method='oblique')
     L2, phi, T2, table = GPA(A, ff=ff, rotation_method='oblique')
     self.assertTrue(np.allclose(L, L2, atol=1e-05))
     self.assertTrue(np.allclose(T, T2, atol=1e-05))
Exemplo n.º 7
0
 def test_orthogonal_target(self):
     """
     Rotation towards target matrix example
     http://www.stat.ucla.edu/research/gpa
     """
     A = self.str2matrix("""
      .830 -.396
      .818 -.469
      .777 -.470
      .798 -.401
      .786  .500
      .672  .458
      .594  .444
      .647  .333
     """)
     H = self.str2matrix("""
       .8 -.3
       .8 -.4
       .7 -.4
       .9 -.4
       .8  .5
       .6  .4
       .5  .4
       .6  .3
     """)
     vgQ = lambda L=None, A=None, T=None: vgQ_target(H, L=L, A=A, T=T)
     L, phi, T, table = GPA(A, vgQ=vgQ, rotation_method='orthogonal')
     T_analytic = target_rotation(A, H)
     self.assertTrue(np.allclose(T, T_analytic, atol=1e-05))