Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add find_zero function #8

Merged
merged 4 commits into from
Nov 8, 2023
Merged

Add find_zero function #8

merged 4 commits into from
Nov 8, 2023

Conversation

datejada
Copy link
Member

@datejada datejada commented Nov 7, 2023

Pull request details

Describe the changes made in this pull request

Changes to add the find_zero function to the fitting function

List of related issues or pull requests

Closes #4

Collaboration confirmation

As a contributor I confirm

  • I read and followed the instructions in README.dev.md
  • [NA] The documentation is up to date with the changes introduced in this Pull Request (or NA)
  • Tests are passing
  • Lint is passing

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
src/TulipaProfileFitting.jl 100.00% <ø> (ø)
src/model.jl 100.00% <100.00%> (ø)

📢 Thoughts on this report? Let us know!

test/runtests.jl Outdated
Comment on lines 12 to 15
# Test case 2: Using optimization method
target_mean = 1.0
expected_coefficient = 0.0
@test fit_profile(profile_values, target_mean) ≈ expected_coefficient atol = 1e-3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you're doing, and the code seems correct, but I don't know what you want to do, so I am not sure it this is the best approach.
This solution is to change all profile values to 1. Is that what you want in this situation?
Are the profiles always between 0.0 and 1.0? Is that why you use p^x?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you're doing, and the code seems correct, but I don't know what you want to do, so I am not sure it this is the best approach. This solution is to change all profile values to 1. Is that what you want in this situation? Are the profiles always between 0.0 and 1.0? Is that why you use p^x?

The idea is to test that part of the code that uses the optimization procedure. My problem is that I couldn't develop a naive set of values that don't use the find_zero function. So, I forced the use by just going for a target I knew would fail, even if the solution was trivial. I'm open to ideas to test the function better 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is fine. I am just not sure if this is what you want for your scaler because to me it doesn't make sense to "scale" all values to 1.0.

Copy link
Member Author

@datejada datejada Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the tests to make them more meaningful in our expected results. If the input data is in per unit ([0,1]) then you need either one method (find_zero) or the other (optimization) depending on the target value. If the target value is greater than the current mean, it uses find_zero, whereas if it is below, it uses the optimization. You can double-check in the new test the values that I proposed. Nevertheless, it is fair to say that most of our profiles will increase the mean, so we will mainly use the find_zero part.

Copy link
Member

@abelsiqueira abelsiqueira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a small comment, after that should be good to go.

Comment on lines +4 to +16
function test_fit_profile()

# Test case 1: Using root finding method
profile_values = [0.2, 0.5, 0.9, 1.0, 0.4, 0.1, 0.0]
target_mean = 0.5
coefficient = fit_profile(profile_values, target_mean)
@test coefficient ≈ 0.7491921789832345 atol = 0.01
expected_coefficient = 0.7491921797062476
@test fit_profile(profile_values, target_mean) ≈ expected_coefficient atol = 1e-3

# Test case 2: Using optimization method
target_mean = 0.4
expected_coefficient = 1.2550552057968192
@test fit_profile(profile_values, target_mean) ≈ expected_coefficient atol = 1e-3
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to move this inside the @testset. The scope will also be limited.

@datejada datejada merged commit 7972b4f into TulipaEnergy:main Nov 8, 2023
12 checks passed
@datejada datejada deleted the 4-add-find-zero-function branch November 8, 2023 16:28
datejada added a commit that referenced this pull request Nov 9, 2023
* Add find_zero function

* Update the test cases

* Update fit_profile function documentation
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.

Include the function find_zero in the calculation of the coefficient
2 participants