1 #include "../include/uncal_date.h" 15 std::cout <<
"name: " << _name <<
"\n";
16 std::cout <<
"bp: " << _bp <<
"\n";
17 std::cout <<
"std: " << _std <<
"\n";
18 std::cout << std::endl;
25 vector<int> full_bp(num_elements);
26 vector<int> full_c14_bp(num_elements);
27 vector<int> full_error(num_elements);
29 generate_date_grid(full_bp, full_c14_bp, full_error, calcurve);
31 vector<double> probs = compute_probs(full_error, full_c14_bp);
32 vector<double> probs_return;
33 vector<int> bp_return;
34 for (
unsigned i=0; i < probs.size(); i++)
36 if (probs[i] > 1.0e-05)
38 probs_return.push_back(probs[i]);
39 bp_return.push_back(full_bp[i]);
43 return CalDate(_name, probs_return, bp_return, _bp, _std, full_bp, probs);
47 vector<double> UncalDate::compute_probs(vector<int> &error_cal_curve, vector<int> &full_c14_bp){
48 using boost::math::students_t;
50 std::vector<double> prob_return_value;
53 int stdsq = pow(_std,2);
54 while (t < error_cal_curve.size()){
55 double this_tau = stdsq + error_cal_curve[t];
56 double this_value = (_bp - full_c14_bp[t]) / sqrt(this_tau);
58 this_prob = pdf(dist, this_value);
59 prob_return_value.push_back(this_prob);
60 prob_sum += this_prob;
63 for(
double& f : prob_return_value) f/=prob_sum*5;
64 return prob_return_value;
67 void UncalDate::generate_date_grid(std::vector<int>& full_bp, std::vector<int>& full_c14_bp, std::vector<int>& full_error,
CalCurve& calcurve){
69 vector<int> cal_bp = calcurve.
get_bp();
77 vector<int> working_bp = cal_bp;
78 vector<int> working_c14_bp = c14_bp;
79 vector<int> working_error = error;
81 std::reverse(working_bp.begin(), working_bp.end());
82 std::reverse(working_c14_bp.begin(), working_c14_bp.end());
83 std::reverse(working_error.begin(), working_error.end());
85 while (i < num_elements) {
86 int this_bp = max_bp - i * 5;
87 vector<int>::iterator it=find(cal_bp.begin(), cal_bp.end(), this_bp);
89 int pos = it - cal_bp.begin();
93 this_c14 = c14_bp[pos];
94 this_error = error[pos];
97 auto const upper_it = std::upper_bound(working_bp.begin(), working_bp.end(), this_bp);
98 int upper_pos = upper_it - working_bp.begin();
99 int upper_bp = working_bp[upper_pos];
100 int lower_bp = working_bp[upper_pos-1];
101 int upper_c14 = working_c14_bp[upper_pos];
102 int lower_c14 = working_c14_bp[upper_pos-1];
103 int upper_error = working_error[upper_pos];
104 int lower_error = working_error[upper_pos-1];
105 double mu = (double)(this_bp-lower_bp) / (double)(upper_bp - lower_bp);
106 this_c14 = LinearInterpolateInt(lower_c14, upper_c14,mu);
107 this_error = LinearInterpolateInt(lower_error, upper_error,mu);
109 full_bp[i] = this_bp;
110 full_c14_bp[i] = this_c14;
111 full_error[i] = this_error;
116 int UncalDate::LinearInterpolateInt(
int y1,
int y2,
double mu){
117 return (
int)round(y1*(1-mu)+y2*mu);
vector< int > get_error()
CalDate calibrate(CalCurve &calcurve)
Represents a calibrated date.
Represents the calibration curve.
vector< int > get_c14_bp()