def test_analyze_linreg(self): X, y = gen_regression_data() solver = linReg.LinearRegressionSolver() with CapturedStdout(): analyzerResults = analyze( solver, X, y, optimizationParams={ "nnTopology": "", "Lambda": 0.1, "functions": [lambda x: x[0]**2, lambda x: x[1]**2, lambda x: x[2]**2] }, iterations=40, bins=3, tries=4, sample_iterations=40) npt.assert_equal(analyzerResults.sampleCountAnalyzis.sampleCount, [ 1, 4, 7, 10, 19, 28, 54, 80, 159, 238, 475, 712, 1423, 2134, 4267, 6400 ]) npt.assert_almost_equal( analyzerResults.sampleCountAnalyzis.errorTrain, [ 0.00000000e+00, 2.33847837e+01, 3.00222512e+01, 7.96243961e+00, 1.37056787e+00, 5.14152946e-01, 1.26362331e-01, 6.45051925e-02, 1.46205243e-02, 7.25704802e-03, 1.67555343e-03, 7.51420424e-04, 1.82472270e-04, 8.16512666e-05, 2.04713359e-05, 9.08089772e-06 ], 5) npt.assert_almost_equal(analyzerResults.sampleCountAnalyzis.errorCV, [ 4.99885725e+04, 1.75878006e+04, 4.13273401e+03, 4.01030109e+01, 3.82169238e+00, 6.81074172e-01, 1.43006176e-01, 7.01556101e-02, 1.44597141e-02, 8.57240292e-03, 1.67551231e-03, 7.42103605e-04, 1.73911141e-04, 7.83993282e-05, 1.98093851e-05, 8.65960541e-06 ], 3) npt.assert_equal(analyzerResults.iterationCountAnalyzis.iterationCount, [2, 4, 6, 10, 14, 27, 40]) npt.assert_almost_equal( analyzerResults.iterationCountAnalyzis.errorTrain, [ 2.18325422e-01, 1.04552670e-05, 2.27461723e-06, 2.27461723e-06, 2.27461723e-06, 2.27461723e-06, 2.27461723e-06 ], 5) npt.assert_almost_equal( analyzerResults.iterationCountAnalyzis.errorCV, [ 2.14481838e-01, 1.01920583e-05, 2.16874107e-06, 2.16874107e-06, 2.16874107e-06, 2.16874107e-06, 2.16874107e-06 ], 5)
def test_find_solution(self): X, y = gen_regression_data() solver = linReg.LinearRegressionSolver() with CapturedStdout(): optimizationResults = find_solution( solver, X, y, showFailureRateTrain=True, optimizationParams={ "nnTopology": "", "Lambda": [0.01, 0.1, 1], "functions": [[], [lambda x: x[0]**2, lambda x: x[1]**2], [lambda x: x[0]**2, lambda x: x[1]**2, lambda x: x[2]**2]] }, files=[], log={ "log_dir": "out", "log_file_name": "mlak" }) self.assertAlmostEqual(optimizationResults.failureRateTest, 1e-07, 6)