Interesting, when I substitute the initial values in my cost functions, they all evaluate to zeros (or values e-18). Rechecked this. Not sure why the log shows initial cost as e9. Here is my code again, am I missing something?
struct Zreal {
Zreal(double x, double y)
: x_(x), y_(y) {}
template <typename T> bool operator()(const T* const R1, const T* const R2, const T* const C1, T* residual) const {
residual[0] = T(y_) + (T(y_) * (4.0 * Pisq * pow(10,T(x_)) * pow(10,T(x_)) * R2[0] * R2[0] * C1[0] * C1[0])) - R1[0] -
(R1[0] * (4.0 * Pisq * pow(10, T(x_)) * pow(10, T(x_)) * R2[0] * R2[0] * C1[0] * C1[0])) - R2[0];
return true;
}
private:
const double x_; const double y_;
};
struct Zimag {
Zimag(double x, double y)
: x_(x), y_(y) {}
template <typename T> bool operator()(const T* const R1, const T* const R2, const T* const C1, T* residual) const {
residual[0] = T(y_) + (T(y_) * (4.0 * Pisq * pow(10, T(x_)) * pow(10, T(x_)) * R2[0] * R2[0] * C1[0] * C1[0]))
- (R2[0] * R2[0] * 2.0 * Pi * C1[0] * pow(10, T(x_)));
return true;
}
private:
const double x_; const double y_;
};
DEFINE_string(minimizer, "trust_region",
"Minimizer type to use, choices are: line_search & trust_region");
int main(int argc, char** argv) {
CERES_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
//Initial Values
double initialR1 = 10.0;
double initialR2 = 90.0;
double initialC1 = 1E-06;
double R1 = initialR1;
double R2 = initialR2;
double C1 = initialC1;
//reading the input data file1
readinputFile(logf_val, Zr_val, Zi_val);
Problem problem;
for (int i = 0; i < logf_val.size(); ++i) {
problem.AddResidualBlock(new AutoDiffCostFunction<Zreal, 1, 1, 1, 1>(new Zreal(logf_val[i], Zr_val[i])),
NULL,
&R1, &R2, &C1);
problem.AddResidualBlock(new AutoDiffCostFunction<Zimag, 1, 1, 1, 1>(new Zimag(logf_val[i], Zi_val[i])),
NULL,
&R1, &R2, &C1);
}
problem.SetParameterLowerBound(&R1, 0, 0.001);
problem.SetParameterUpperBound(&R1, 0, 1E+6);
problem.SetParameterLowerBound(&C1, 0, 10E-15);
problem.SetParameterUpperBound(&C1, 0, 10E-6);
problem.SetParameterLowerBound(&R2, 0, 0.001);
problem.SetParameterUpperBound(&R2, 0, 1E+6);
Solver::Options options;
LOG_IF(FATAL, !ceres::StringToMinimizerType(FLAGS_minimizer,
&options.minimizer_type))
<< "Invalid minimizer: " << FLAGS_minimizer
<< ", valid options are: trust_region and line_search.";
options.trust_region_strategy_type = ceres::LEVENBERG_MARQUARDT;
options.max_num_iterations = 500;
options.linear_solver_type = ceres::DENSE_QR;
options.minimizer_progress_to_stdout = true;
Thank you.