def test_train(self, init):
     init.return_value = None
     p = factor_analysis.FactorAnalysisPreprocessor()
     p.nfactors = 5
     d = np.random.normal(size=(500, 50))
     p._train(d)
     assert p.fa_node
 def test_call(self, init):
     init.return_value = None
     p = factor_analysis.FactorAnalysisPreprocessor()
     p.fa_node = Mock()
     rv = object()
     p.fa_node.execute.return_value = rv
     d = object()
     r = p(d)
     assert r == rv
     p.fa_node.execute.assert_called_once_with(d)
 def test_get_variable_selector(self, init, nvariables):
     init.return_value = None
     nvariables.__get__ = Mock(return_value=4)
     p = factor_analysis.FactorAnalysisPreprocessor()
     # 4 variables, 3 factors
     p.fa_node = Mock()
     p.fa_node.E_y_mtx = np.array([[2, 1, 0], [1, 0, 0], [0, 0, 1],
                                   [0, 0, 2]])
     p.input_variables = ['f1', 'f2', 'f3', 'f4']
     sel = p.get_variable_selector()
     data = np.array([0, 1, 2, 3], dtype='i4')
     assert np.array_equal(sel(data), np.array([0, 3]))
 def test_nvariables(self, init):
     init.return_value = None
     p = factor_analysis.FactorAnalysisPreprocessor()
     p.fa_node = Mock()
     p.fa_node.E_y_mtx = np.zeros((3, 2))
     assert p.nvariables == 3
 def test_init_too_many_factors(self):
     d = np.random.normal(size=(500, 5))
     variables = ['f%d' % (i + 1) for i in range(5)]
     self.assertRaises(
         ValueError, lambda: factor_analysis.FactorAnalysisPreprocessor(
             d, variables, 6))
 def test_init(self, train):
     d = np.random.normal(size=(500, 50))
     variables = ['f%d' % (i + 1) for i in range(50)]
     p = factor_analysis.FactorAnalysisPreprocessor(d, variables, 5)
     p._train.assert_called_once_with(d)