Skip to content

#43 Fix Polynomial.compute() and Exponential.compute() #44

Merged
pberkes merged 8 commits intopberkes:masterfrom
TheMatt2:master
Jul 28, 2022
Merged

#43 Fix Polynomial.compute() and Exponential.compute() #44
pberkes merged 8 commits intopberkes:masterfrom
TheMatt2:master

Conversation

@TheMatt2
Copy link
Contributor

The major fix in this PR is changes to the complexity classes to fix #43 and make sure Polynomial.compute() and Exponential.compute() return sensible values. Test cases are added for this and some other changes.

Major Fix: Compute() make aware of time transform

The compute() function on big_o.complexities.Polynomial() and big_o.complexities.Exponential() fail because
these classes implement custom _transform_time() functions that alter the coefficients as calculated.

big_O/big_o/complexities.py

Lines 176 to 177 in 82b8bb3

def _transform_time(self, t):
return np.log(t)

However, the compute() function does not seem to account for _transform_time().

This PR addresses the issue by introducing the _inverse_transform_time() function and calling it within compute() to correct the mathematical function.

Test Cases

The compute() function already has test cases, but they seem to miss this issue because only Linear is tested.

def test_compute(self):
x = np.linspace(10, 100, 100)
y = 3.0 * x + 2.0
linear = complexities.Linear()
linear.fit(x, y)
assert_array_almost_equal(linear.compute(x), y, 10)

This PR adds test cases for all of the included complexity classes.

This PR also replaces the numpy.testing.assert_array_almost_equal() with numpy.testing.assert_allclose().
The reason is assert_array_almost_equal() does not scale well for large floating point numbers, as is noted in Numpy's documentation.

If assert_array_almost_equal() where used with the new test cases, the tests would fail due to the lost in precision in large floating point numbers.

Other Changes

  • Expanded TestComplexities.test_not_fitted to test all complexity classes, not just Linear

  • Added coefficients() function to Polynomial classes to correct displaying the coefficients in there standard form, instead of the coefficient transformed by _transform_time() and _transform_n(). Previously printing a Polynomial or Exponential class would show incorrect coefficients.

  • Change printing behavior from "Polynomial: : not yet fitted" to "Polynomial: not yet fitted"

@pberkes
Copy link
Owner

pberkes commented Jul 28, 2022

Thank you! LGTM

@pberkes pberkes merged commit 0ed1e3d into pberkes:master Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polynomial.compute() and Exponential.compute() Return Incorrect Results

2 participants