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

Fix files format #2

Merged
merged 2 commits into from
Nov 6, 2023
Merged

Fix files format #2

merged 2 commits into from
Nov 6, 2023

Conversation

datejada
Copy link
Member

@datejada datejada commented Nov 3, 2023

Pull request details

Describe the changes made in this pull request

Fixing files format according to the pre-commit hooks

List of related issues or pull requests

Closes #1

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)
  • [NA] Tests are passing
  • Lint is passing

Copy link

codecov bot commented Nov 3, 2023

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@datejada
Copy link
Member Author

datejada commented Nov 3, 2023

@abelsiqueira would you mind double-checking that all is in place for this package? I think after fixing the formats, the basic set up is there, but just to double-check. Thanks!

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.

Looks right to me. I made a small comment on the equation, but that is a separate issue.

@NLobjective(
model,
Min,
(sum((profile_values[i])^x for i = 1:total_hours) - target_mean * total_hours)^2
Copy link
Member

Choose a reason for hiding this comment

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

It would be useful to write the math for this in the docs. Something like

$$\min \qquad \bigg(\mu h - \sum_{i = 1}^h p_i^x\bigg)^2$$

It would also make it easier to read with less parenthesis, that's why I moved things around.
I had the impression the problem was

$$\min \qquad \sum_{i=1}^h (\mu - p_i^x)^2,$$

i.e., you want each p_i^x to be close to \mu.

Copy link
Member

Choose a reason for hiding this comment

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

Never mind my comment, I read that you are just worried about the mean of the new p_i^x, not the individual p_i^x value, so the first definition is correct. I would maybe write as

$$\min \qquad \frac{1}{2}\bigg(\mu - \frac{1}{h}\sum_{i=1}^h p_i^x\bigg)^2$$

Copy link
Member

Choose a reason for hiding this comment

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

I realized something about the problem. You are doing nonlinear least squares of a single variable with a single equation. So it makes sense to ask whether the equation already has a solution. Under conditions on the profile values and the target_mean, it has, and in that case it would be simpler to use a root-finding algorithm.
For instance:

using Roots
profile_values = [0.2, 0.5, 0.9, 1.0, 0.4, 0.1, 0.0] 
target_mean = 0.5
find_zero(
	x -> sum(profile_values .^ x .- target_mean),
	[1e-2, 1.0],
)

Depending on what you want, and the assumptions that you can make, this can be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

@abelsiqueira Thanks for the proposal. German and I have reviewed it and we think it makes sense to have the solution from the find_zero function. We believe that in most cases, there will be a solution to the equation. However, in the unlikely event that there is no solution, we want to at least have the coefficient that minimizes the error. Therefore, we want to modify the function to start with the "find_zero" function and if it cannot find a solution, then go for the optimization. What do you think? In any case, I will create an issue for it. 😄

@datejada datejada merged commit 6638d26 into TulipaEnergy:main Nov 6, 2023
12 checks passed
@datejada datejada deleted the 1-fix-files-format branch November 6, 2023 15:09
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.

Fix files format to match the pre-commit requisites
2 participants