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

passing varargs to my objective function? #85

Closed
floswald opened this issue Sep 29, 2014 · 5 comments
Closed

passing varargs to my objective function? #85

floswald opened this issue Sep 29, 2014 · 5 comments

Comments

@floswald
Copy link

is there a way to have an objective function

f(x,a,b)

where x is the variable I want to minimize over, and a,b are parameters that are set somewhere else in the program? asked differently: can we have?

optimize(f::Function,vargs...)
@johnmyleswhite
Copy link
Contributor

Use a closure instead

-- John

On Sep 29, 2014, at 9:52 AM, Florian Oswald notifications@github.com wrote:

is there a way to have an objective function

f(x,a,b)
where x is the variable I want to minimize over, and a,b are parameters that are set somewhere else in the program? asked differently: can we have?

optimize(f::Function,vargs...)

Reply to this email directly or view it on GitHub.

@timholy
Copy link
Contributor

timholy commented Sep 29, 2014

I think the docs call these "anonymous functions" rather than closures.

If performance becomes a concern (which seems a bit unlikely, but who knows), see also FastAnonymous.jl.

@floswald
Copy link
Author

wouldn't have made it without the anonymous function pointer. thanks both!

y = 1.1
z = 8.4
optimize((x)->2x^2+3x+y-z, -2.0, 1.0)

@floswald
Copy link
Author

can i just say that this is awesome? first time i see this. compared to R's environment() or worrying about the ordering in the varargs to the objective, that beats the lot of them.

@johnmyleswhite
Copy link
Contributor

Glad this helped. Closures are possible in R as well. The R community is just not very sophisticated about programming, so basic CS concepts tend not to talked about in public.

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

No branches or pull requests

3 participants