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

The example to use the constrained function #345

Closed
ZulunZhu opened this issue May 28, 2022 · 4 comments
Closed

The example to use the constrained function #345

ZulunZhu opened this issue May 28, 2022 · 4 comments
Labels

Comments

@ZulunZhu
Copy link

I am a beginner in C++, and I am curious about the template of the constrained function. Because the examples only show how to solve the square function, I don't know what should I return in the constrained function. Can anyone provide some examples? Thank you very much.
image

@zoq
Copy link
Member

zoq commented May 30, 2022

Hello, what you want to return is the f(x), so the function f at x, in the example above it's x but without the surrounding {}. You can find another example here - https://github.com/mlpack/ensmallen/blob/master/include/ensmallen_bits/problems/aug_lagrangian_test_functions_impl.hpp#L55-L64

Let me know if you like me to clarify anything further.

@ZulunZhu
Copy link
Author

Thanks for your reply. I think I might have formulated the code well. But another question is, when the function is too complex, the gradient is almost can not be obtained. So I use the approximation function (f'(x) = (f(x+eps)-f(x))/eps). After the optimization, I found the gradient is not close to zero. It is really strange. Do you have other ideas to get the gradient easily?

@zoq
Copy link
Member

zoq commented Jun 27, 2022

If you have matlab or a similair toolbox you can use that to return the gradient -- https://www.mathworks.com/help/matlab/ref/gradient.html is just one example.

@mlpack-bot
Copy link

mlpack-bot bot commented Jul 27, 2022

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍

@mlpack-bot mlpack-bot bot added the s: stale label Jul 27, 2022
@mlpack-bot mlpack-bot bot closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants