-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Optimizing More than one Param #569
Comments
Even the example in this link failed with this error. Any ideas?
|
Hello, In your code you have The example works for me:
Modifying the code inside the example to take your function also worked for me:
Code: use argmin::{
core::{observers::ObserverMode, CostFunction, Error, Executor},
solver::neldermead::NelderMead,
};
use argmin_observer_slog::SlogLogger;
struct MyStruct {}
impl CostFunction for MyStruct {
type Param = Vec<f64>;
type Output = f64;
fn cost(&self, input: &Self::Param) -> Result<Self::Output, Error> {
let out = input[0].cos() + input[0].sin() * (input[1] / 100.0);
Ok(out)
}
}
fn run() -> Result<(), Error> {
// Define cost function
let cost = MyStruct {};
let solver = NelderMead::new(vec![
vec![0_f64, 70.0],
vec![1_f64, 80.0],
vec![2_f64, 90.0],
])
.with_sd_tolerance(0.0001)?;
// Run solver
let res = Executor::new(cost, solver)
.configure(|state| state.max_iters(100))
.add_observer(SlogLogger::term(), ObserverMode::Always)
.run()?;
// Print result
println!("{res}");
Ok(())
}
fn main() {
if let Err(ref e) = run() {
println!("{e}");
std::process::exit(1);
}
} In my [dependencies]
argmin = { version = "0.10.0" }
argmin-math = { version = "0.4.0", features = ["ndarray_latest-nolinalg"] }
argmin-observer-slog = { version = "*" }
argmin_testfunctions = { version = "*" }
ndarray = "0.15.6" # Only useful for the example, not your problem Could you check if that works for you? |
When I updated the code and run, it still return the following errors.
Then I updated the dependencies from the details mentioned below to your dependencies.
And now it works. Thank you so much. |
What were your previous dependencies? |
I’ve added my previous dependencies in the previous comment. |
Oh, sorry, I didn't read that right. |
I'm using NelderMead for my optimizing problem. I wanted to use the struct below.
Then I tried to define my solver like the code below. despite the documents of NelderMead for optimizing 2 parameters I should define 3 initial points.
after running this code I got errors mentioned here:
What do you recommend me to do? Is it even possible for your CostFunction Trait to accept more than one parameter? Because vector doesn't implement ArgminMul, ...
Even when I copy the example in the document I got these errors.
The text was updated successfully, but these errors were encountered: