contrib/gel/pop/pop_graph_cost_function.cxx

Go to the documentation of this file.
00001 // This is gel/pop/pop_graph_cost_function.cxx
00002 #include "pop_graph_cost_function.h"
00003 //:
00004 // \file
00005 
00006 //: constructor
00007 //  We send in the parameters that can change,
00008 //  the residuals that would be evaluated and the pop manager
00009 //  that is responsible for updating the graph based on the
00010 //  current parameter values.
00011 pop_graph_cost_function::pop_graph_cost_function(vcl_vector<pop_parameter*> &params,
00012                                                  vcl_vector<pop_geometric_cost_function*> &cfs,
00013                                                  pop_manager *manager):
00014   vnl_least_squares_function(params.size(),cfs.size(),no_gradient)
00015 {
00016   params_ = params;
00017   cfs_ = cfs;
00018   manager_ = manager;
00019 }
00020 
00021 
00022 //: destructor
00023 pop_graph_cost_function::~pop_graph_cost_function()
00024 {
00025 }
00026 
00027 
00028 //: the method for evaluating the cost of the parameter values (x) and getting the residuals (fx)
00029 void pop_graph_cost_function::f(vnl_vector<double> const &x, vnl_vector<double> &fx)
00030 {
00031   // step 1: update the parameters
00032   for (int i=0;i<params_.size();i++) {
00033     params_[i]->value_ = x[i];
00034   }
00035 
00036   // step 2: update the graph
00037   manager_->update();
00038 
00039   // step 3: collect the residuals
00040   for (int i=0;i<cfs_.size();i++) {
00041     fx(i) = cfs_[i]->cost();
00042   }
00043 }
00044 
00045 
00046 //: get the current parameter value
00047 vnl_vector<double> pop_graph_cost_function::get_parameter_values()
00048 {
00049   vnl_vector<double> x(params_.size());
00050   for (int i=0;i<params_.size();i++)
00051     x[i] = params_[i]->value_;
00052   return x;
00053 }
00054 
00055 //: get the current costs
00056 vnl_vector<double> pop_graph_cost_function::get_current_costs()
00057 {
00058   vnl_vector<double> costs(cfs_.size());
00059   vnl_vector<double> params = this->get_parameter_values();
00060 
00061   this->f(params,costs);
00062 
00063   return costs;
00064 }
00065 

Generated on Sun Sep 7 05:15:06 2008 for contrib/gel/pop by  doxygen 1.5.1