10 using namespace Eigen;
11 using namespace SeamStress;
17 Seamstress::init_vector(numthreads,
vss);
19 vssp =
new vector<Seamstress*>();
20 for(
unsigned long int i=0;i<
vss.size();i++){
vssp->push_back(&(
vss[i]));}
26 pthread_mutexattr_init(&
mattr);
27 pthread_mutexattr_settype(&
mattr, PTHREAD_MUTEX_NORMAL);
30 vector<vector<double> >* tempvec = NULL;
32 vector<double>* tempvec2 = NULL;
49 for(
unsigned long int i=0;i<
nthreads;i++)
60 if(POINTS.size() == 0){
return;}
71 unsigned long int w = (*((
unsigned long int *)arg));
74 unsigned long int start = 0;
75 unsigned long int end = 0;
84 start += (part*(w-rem));
85 end = start + part - 1;
89 vector<double> tempvec;
90 tempvec.assign((*
points)[0].size(), 0.);
91 for(
unsigned long int i=(start);i<=(end);i++)
104 if(ERROR.size() == 0){
return;}
115 unsigned long int w = (*((
unsigned long int *)arg));
118 unsigned long int start = 0;
119 unsigned long int end = 0;
127 start = (part+1)*rem;
128 start += (part*(w-rem));
129 end = start + part - 1;
134 for(
unsigned long int i=(start);i<=(end);i++)
143 if(DATA.size() == 0){
return;}
154 unsigned long int w = (*((
unsigned long int *)arg));
157 unsigned long int start = 0;
158 unsigned long int end = 0;
166 start = (part+1)*rem;
167 start += (part*(w-rem));
168 end = start + part - 1;
173 for(
unsigned long int i=(start);i<=(end);i++)
200 double temp = 1./((*data_errors)[i]);temp*=temp;
219 grad = VectorXd::Zero(
npars);
226 if(
points == NULL){
return true;}
239 double temp = 1./((*data_errors)[i]);temp*=temp;
252 unsigned long int w = (*((
unsigned long int *)arg));
255 VectorXd temp_grad = VectorXd::Zero(
npars);
256 MatrixXd temp_hessian = MatrixXd::Zero(
npars,
npars);
260 VectorXd temp_grad2 = VectorXd::Zero(
npars);
261 MatrixXd temp_hessian2 = MatrixXd::Zero(
npars,
npars);
263 VectorXd cur_grad = VectorXd::Zero(
npars);
278 double inv_variance = 1.;
282 double temp2 = -exp(-temp1*temp1*0.5*inv_sig2);
284 temp_val += temp2*inv_variance;
286 for(
unsigned int j=0;j<
npars;j++)
288 cur_grad(j) = -temp2*inv_sig2*temp1*temp_grad2(j)*inv_variance;
289 temp_grad(j) += cur_grad(j);
294 for(
unsigned int j=0;j<
npars;j++)
296 temp_hessian(j,
k) += -inv_sig2*( cur_grad(
k)*temp1*temp_grad2(j) + temp2*temp_grad2(
k)*temp_grad2(j) + temp2*temp1*temp_hessian2(j,
k) )*inv_variance;
302 pthread_mutex_lock(&
mutex);
303 (*val_output) += temp_val;
304 (*grad_output) += temp_grad;
305 (*hessian_output) += temp_hessian;
306 pthread_mutex_unlock(&
mutex);
310 delete func_instance;