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);
63 double temp = 1./((*data_errors)[i]);temp*=temp;
82 for(
unsigned int j=0;j<(*points)[0].size();j++){func_instance->
setFixedPar(j, (*
points)[0][j]);}
88 grad = VectorXd::Zero(
npars);
107 unsigned long int w = (*((
unsigned long int *)arg));
110 unsigned long int start = 0;
111 unsigned long int end = 0;
119 start = (part+1)*rem;
120 start += (part*(w-rem));
121 end = start + part - 1;
126 VectorXd temp_grad = VectorXd::Zero(
npars);
127 MatrixXd temp_hessian = MatrixXd::Zero(
npars,
npars);
131 VectorXd temp_grad2 = VectorXd::Zero(
npars);
132 MatrixXd temp_hessian2 = MatrixXd::Zero(
npars,
npars);
134 VectorXd cur_grad = VectorXd::Zero(
npars);
142 for(
unsigned long int i=(start);i<=(end);i++)
144 for(
unsigned int j=0;j<(*points)[i].size();j++){func_instance->
setFixedPar(j, (*
points)[i][j]);}
146 double inv_variance = 1.;
147 if(
data_has_errors==
true){inv_variance = 1./(*data_errors)[i];inv_variance*=inv_variance;}
149 double temp1 = (temp_val2 - (*data)[i]);
150 temp_val += temp1*temp1*inv_variance;
152 for(
unsigned int j=0;j<
npars;j++)
154 cur_grad(j) = 2.*temp1*temp_grad2(j)*inv_variance;
155 temp_grad(j) += cur_grad(j);
160 for(
unsigned int j=0;j<
npars;j++)
162 temp_hessian(j,
k) += 2.*inv_variance*(temp_grad2(j)*temp_grad2(
k) + temp1*temp_hessian2(j,
k));
168 pthread_mutex_lock(&
mutex);
169 (*val_output) += temp_val;
170 (*grad_output) += temp_grad;
171 (*hessian_output) += temp_hessian;
172 pthread_mutex_unlock(&
mutex);
176 delete func_instance;
185 for(
unsigned int j=0;j<(*points)[0].size();j++){func_instance->
setFixedPar(j, (*
points)[0][j]);}
187 delete func_instance;
190 grad = VectorXd::Zero(
npars);
205 unsigned long int w = (*((
unsigned long int *)arg));
208 unsigned long int start = 0;
209 unsigned long int end = 0;
217 start = (part+1)*rem;
218 start += (part*(w-rem));
219 end = start + part - 1;
224 VectorXd temp_grad = VectorXd::Zero(
npars);
228 VectorXd temp_grad2 = VectorXd::Zero(
npars);
230 VectorXd cur_grad = VectorXd::Zero(
npars);
238 for(
unsigned long int i=(start);i<=(end);i++)
240 for(
unsigned int j=0;j<(*points)[i].size();j++){func_instance->
setFixedPar(j, (*
points)[i][j]);}
242 double inv_variance = 1.;
243 if(
data_has_errors==
true){inv_variance = 1./(*data_errors)[i];inv_variance*=inv_variance;}
245 double temp1 = (temp_val2 - (*data)[i]);
246 temp_val += temp1*temp1*inv_variance;
248 for(
unsigned int j=0;j<
npars;j++)
250 cur_grad(j) = 2.*temp1*temp_grad2(j)*inv_variance;
251 temp_grad(j) += cur_grad(j);
256 pthread_mutex_lock(&
mutex);
257 (*val_output) += temp_val;
258 (*grad_output) += temp_grad;
259 pthread_mutex_unlock(&
mutex);
263 delete func_instance;