All problems
Varimax Step
Problem
Perform one varimax rotation step on a 2-factor loading matrix. With x_i = l1^2 - l2^2 and y_i = 2*l1*l2, the rotation angle is phi = 0.25*atan2(2*sum(x*y), sum(x^2 - y^2)); return the rotated loadings. Rows must have exactly two loadings, otherwise return [].
Hint
This single step sharpens the loading pattern toward simple structure.
Test cases
case 1
in: [[[0.8,0.6],[0.8,0.6]]]
expected: [[1,0],[1,0]]
case 2
in: [[[0.9,0.1],[0.1,0.9]]]
expected: [[0.9,0.1],[0.1,0.9]]
case 3
in: [[[0.7,0.7],[0.7,0.7]]]
expected: [[0.9899494936611665,1.1102230246251565e-16],[0.9899494936611665,1.1102230246251565e-16]]
case 4
in: [[[0.6,0.8],[0.6,0.8]]]
expected: [[0,1],[0,1]]
case 5
in: [[]]
expected: []
Starter codePython
import math
def varimax_step(loadings):
# Your code here
pass5 test cases · run your code against them in the editor