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))
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))
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))
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))