|
68 | 68 | (a,b) = hcat(fill!(similar(Height), 1), Height) \ Age
|
69 | 69 | model_ages = a .+ b .* collect(model_heights)
|
70 | 70 |
|
| 71 | + # Select sidedness method |
| 72 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 73 | + FastSidedness(Age_Sidedness) |
| 74 | + else |
| 75 | + CDFSidedness(Age_Sidedness) |
| 76 | + end |
| 77 | + |
71 | 78 | # Run the Markov chain
|
72 | 79 | ages = Normal.(Age, Age_sigma)
|
73 |
| - agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, Age_Sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, Chronometer, systematic) |
| 80 | + agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, Chronometer, systematic) |
74 | 81 |
|
75 | 82 | # Crop the result
|
76 | 83 | agedist = agedist[active_height_t,:]
|
|
124 | 131 | (a,b) = hcat(fill!(similar(Height), 1), Height) \ Age
|
125 | 132 | model_ages = a .+ b .* collect(model_heights)
|
126 | 133 |
|
| 134 | + # Select sidedness method |
| 135 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 136 | + FastSidedness(Age_Sidedness) |
| 137 | + else |
| 138 | + CDFSidedness(Age_Sidedness) |
| 139 | + end |
| 140 | + |
127 | 141 | # Run the Markov chain
|
128 | 142 | ages = Normal.(Age, Age_sigma)
|
129 |
| - agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, Age_Sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
| 143 | + agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
130 | 144 |
|
131 | 145 | # Crop the result
|
132 | 146 | agedist = agedist[active_height_t,:]
|
|
210 | 224 | (a,b) = hcat(fill!(similar(Height), 1), Height) \ Age
|
211 | 225 | model_ages = a .+ b .* collect(model_heights)
|
212 | 226 |
|
| 227 | + # Select sidedness method |
| 228 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 229 | + FastSidedness(Age_Sidedness) |
| 230 | + else |
| 231 | + CDFSidedness(Age_Sidedness) |
| 232 | + end |
| 233 | + |
213 | 234 | # Run the Markov chain
|
214 | 235 | ages = BilinearExponential.(eachcol(p))
|
215 |
| - agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, Age_Sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, Chronometer, systematic) |
| 236 | + agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, Chronometer, systematic) |
216 | 237 |
|
217 | 238 | # Crop the result
|
218 | 239 | agedist = agedist[active_height_t,:]
|
|
270 | 291 | (a,b) = hcat(fill!(similar(Height), 1), Height) \ Age
|
271 | 292 | model_ages = a .+ b .* collect(model_heights)
|
272 | 293 |
|
| 294 | + # Select sidedness method |
| 295 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 296 | + FastSidedness(Age_Sidedness) |
| 297 | + else |
| 298 | + CDFSidedness(Age_Sidedness) |
| 299 | + end |
| 300 | + |
273 | 301 | # Run the Markov chain
|
274 | 302 | ages = BilinearExponential.(eachcol(p))
|
275 |
| - agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, Age_Sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
| 303 | + agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
276 | 304 |
|
277 | 305 | # Crop the result
|
278 | 306 | agedist = agedist[active_height_t,:]
|
|
355 | 383 | (a,b) = hcat(fill!(similar(Height), 1), Height) \ Age
|
356 | 384 | model_ages = a .+ b .* collect(model_heights)
|
357 | 385 |
|
| 386 | + # Select sidedness method |
| 387 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 388 | + FastSidedness(Age_Sidedness) |
| 389 | + else |
| 390 | + CDFSidedness(Age_Sidedness) |
| 391 | + end |
| 392 | + |
358 | 393 | # Run the Markov chain
|
359 | 394 | ages = Radiocarbon.(Age, Age_sigma, (collect(c) for c in eachcol(p)))
|
360 |
| - agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, Age_Sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
| 395 | + agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
361 | 396 |
|
362 | 397 | # Crop the result
|
363 | 398 | agedist = agedist[active_height_t,:]
|
|
419 | 454 | (a,b) = hcat(fill!(similar(Height), 1), Height) \ Age
|
420 | 455 | model_ages = a .+ b .* collect(model_heights)
|
421 | 456 |
|
| 457 | + # Select sidedness method |
| 458 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 459 | + FastSidedness(Age_Sidedness) |
| 460 | + else |
| 461 | + CDFSidedness(Age_Sidedness) |
| 462 | + end |
| 463 | + |
422 | 464 | # Run the Markov chain
|
423 | 465 | ages = Radiocarbon.(Age, Age_sigma, (collect(c) for c in eachcol(p)))
|
424 |
| - agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, Age_Sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
| 466 | + agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
425 | 467 |
|
426 | 468 | # Crop the result
|
427 | 469 | agedist = agedist[active_height_t,:]
|
|
438 | 480 | npoints = length(model_heights)
|
439 | 481 |
|
440 | 482 | # Calculate log likelihood of initial proposal
|
441 |
| - # Proposals younger than age constraint are given a pass if Age_Sidedness is -1 (maximum age) |
442 |
| - # proposals older than age constraint are given a pass if Age_Sidedness is +1 (minimum age) |
| 483 | + |
443 | 484 | sample_height = copy(Height)
|
444 | 485 | closest = findclosest(sample_height, model_heights)
|
445 | 486 | closest_model_ages = model_ages[closest]
|
446 |
| - @inbounds for i ∈ eachindex(ages,closest_model_ages) |
447 |
| - if Age_Sidedness[i] == sign(closest_model_ages[i] - ages[i].μ) |
448 |
| - closest_model_ages[i] = ages[i].μ |
449 |
| - end |
450 |
| - end |
451 |
| - ll = strat_ll(closest_model_ages, ages) |
| 487 | + ll = strat_ll(closest_model_ages, ages, Age_Sidedness) |
452 | 488 | ll += normpdf_ll(Height, Height_sigma, sample_height)
|
453 | 489 |
|
454 | 490 | # Preallocate variables for MCMC proposals
|
|
473 | 509 |
|
474 | 510 | if rand() < 0.1
|
475 | 511 | # Adjust heights
|
476 |
| - @inbounds for i ∈ eachindex(sample_heightₚ) |
| 512 | + @inbounds for i ∈ eachindex(sample_heightₚ, closestₚ) |
477 | 513 | sample_heightₚ[i] += randn() * Height_sigma[i]
|
478 |
| - closestₚ[i] = round(Int,(sample_heightₚ[i] - model_heights[1])/resolution)+1 |
479 |
| - if closestₚ[i] < 1 # Check we're still within bounds |
480 |
| - closestₚ[i] = 1 |
481 |
| - elseif closestₚ[i] > npoints |
482 |
| - closestₚ[i] = npoints |
483 |
| - end |
| 514 | + closestₚ[i] = round(Int,(sample_heightₚ[i] - first(model_heights))/resolution)+1 |
| 515 | + closestₚ[i] = max(min(closestₚ[i], lastindex(model_agesₚ)), firstindex(model_agesₚ)) |
484 | 516 | end
|
485 | 517 | else
|
486 | 518 | # Adjust one point at a time then resolve conflicts
|
|
505 | 537 |
|
506 | 538 |
|
507 | 539 | # Calculate log likelihood of proposal
|
508 |
| - # Proposals younger than age constraint are given a pass if Age_Sidedness is -1 (maximum age) |
509 |
| - # proposal older than age constraint are given a pass if Age_Sidedness is +1 (minimum age) |
510 |
| - @inbounds for i ∈ eachindex(ages, closest_model_agesₚ) |
| 540 | + adjust!(agesₚ, Chronometer, systematic) |
| 541 | + @inbounds for i ∈ eachindex(closest_model_agesₚ, closestₚ) |
511 | 542 | closest_model_agesₚ[i] = model_agesₚ[closestₚ[i]]
|
512 |
| - if Age_Sidedness[i] == sign(closest_model_agesₚ[i] - ages[i].μ) |
513 |
| - closest_model_agesₚ[i] = ages[i].μ |
514 |
| - end |
515 | 543 | end
|
516 |
| - adjust!(agesₚ, Chronometer, systematic) |
517 |
| - llₚ = strat_ll(closest_model_agesₚ, agesₚ) |
| 544 | + llₚ = strat_ll(closest_model_agesₚ, agesₚ, Age_Sidedness) |
518 | 545 | llₚ += normpdf_ll(Height, Height_sigma, sample_heightₚ)
|
519 | 546 |
|
520 | 547 | # Accept or reject proposal based on likelihood
|
|
549 | 576 |
|
550 | 577 | if rand() < 0.1
|
551 | 578 | # Adjust heights
|
552 |
| - @inbounds for i ∈ eachindex(sample_heightₚ) |
| 579 | + @inbounds for i ∈ eachindex(sample_heightₚ, closestₚ) |
553 | 580 | sample_heightₚ[i] += randn() * Height_sigma[i]
|
554 |
| - closestₚ[i] = round(Int,(sample_heightₚ[i] - model_heights[1])/resolution)+1 |
555 |
| - if closestₚ[i] < 1 # Check we're still within bounds |
556 |
| - closestₚ[i] = 1 |
557 |
| - elseif closestₚ[i] > npoints |
558 |
| - closestₚ[i] = npoints |
559 |
| - end |
| 581 | + closestₚ[i] = round(Int,(sample_heightₚ[i] - first(model_heights))/resolution)+1 |
| 582 | + closestₚ[i] = max(min(closestₚ[i], lastindex(model_agesₚ)), firstindex(model_agesₚ)) |
560 | 583 | end
|
561 | 584 | else
|
562 | 585 | # Adjust one point at a time then resolve conflicts
|
|
580 | 603 | end
|
581 | 604 |
|
582 | 605 | # Calculate log likelihood of proposal
|
583 |
| - # Proposals younger than age constraint are given a pass if Age_Sidedness is -1 (maximum age) |
584 |
| - # proposal older than age constraint are given a pass if Age_Sidedness is +1 (minimum age) |
585 |
| - @inbounds for i ∈ eachindex(ages, closest_model_agesₚ) |
| 606 | + adjust!(agesₚ, Chronometer, systematic) |
| 607 | + @inbounds for i ∈ eachindex(closest_model_agesₚ, closestₚ) |
586 | 608 | closest_model_agesₚ[i] = model_agesₚ[closestₚ[i]]
|
587 |
| - if Age_Sidedness[i] == sign(closest_model_agesₚ[i] - ages[i].μ) |
588 |
| - closest_model_agesₚ[i] = ages[i].μ |
589 |
| - end |
590 | 609 | end
|
591 |
| - adjust!(agesₚ, Chronometer, systematic) |
592 |
| - llₚ = strat_ll(closest_model_agesₚ, agesₚ) |
| 610 | + llₚ = strat_ll(closest_model_agesₚ, agesₚ, Age_Sidedness) |
593 | 611 | llₚ += normpdf_ll(Height, Height_sigma, sample_heightₚ)
|
594 | 612 |
|
595 | 613 | # Accept or reject proposal based on likelihood
|
|
619 | 637 | npoints = length(model_heights)
|
620 | 638 |
|
621 | 639 | # Calculate log likelihood of initial proposal
|
622 |
| - # Proposals younger than age constraint are given a pass if Age_Sidedness is -1 (maximum age) |
623 |
| - # proposals older than age constraint are given a pass if Age_Sidedness is +1 (minimum age) |
624 | 640 | sample_height = copy(Height)
|
625 | 641 | closest = findclosest(sample_height, model_heights)
|
626 | 642 | closest_model_ages = model_ages[closest]
|
627 |
| - @inbounds for i ∈ eachindex(ages) |
628 |
| - if Age_Sidedness[i] == sign(closest_model_ages[i] - ages[i].μ) |
629 |
| - closest_model_ages[i] = ages[i].μ |
630 |
| - end |
631 |
| - end |
632 |
| - ll = strat_ll(closest_model_ages, ages) |
| 643 | + ll = strat_ll(closest_model_ages, ages, Age_Sidedness) |
633 | 644 | ll += normpdf_ll(Height, Height_sigma, sample_height)
|
634 | 645 |
|
635 | 646 | # Ensure there is only one effective hiatus at most for each height node
|
|
673 | 684 |
|
674 | 685 | if rand() < 0.1
|
675 | 686 | # Adjust heights
|
676 |
| - @inbounds for i ∈ eachindex(sample_heightₚ) |
| 687 | + @inbounds for i ∈ eachindex(sample_heightₚ, closestₚ) |
677 | 688 | sample_heightₚ[i] += randn() * Height_sigma[i]
|
678 |
| - closestₚ[i] = round(Int,(sample_heightₚ[i] - model_heights[1])/resolution)+1 |
679 |
| - if closestₚ[i] < 1 # Check we're still within bounds |
680 |
| - closestₚ[i] = 1 |
681 |
| - elseif closestₚ[i] > npoints |
682 |
| - closestₚ[i] = npoints |
683 |
| - end |
| 689 | + closestₚ[i] = round(Int,(sample_heightₚ[i] - first(model_heights))/resolution)+1 |
| 690 | + closestₚ[i] = max(min(closestₚ[i], lastindex(model_agesₚ)), firstindex(model_agesₚ)) |
684 | 691 | end
|
685 | 692 | else
|
686 | 693 | # Adjust one point at a time then resolve conflicts
|
|
718 | 725 |
|
719 | 726 |
|
720 | 727 | # Calculate log likelihood of proposal
|
721 |
| - # Proposals younger than age constraint are given a pass if Age_Sidedness is -1 (maximum age) |
722 |
| - # proposal older than age constraint are given a pass if Age_Sidedness is +1 (minimum age) |
723 |
| - @inbounds for i ∈ eachindex(ages) |
| 728 | + adjust!(agesₚ, Chronometer, systematic) |
| 729 | + @inbounds for i ∈ eachindex(closest_model_agesₚ, closestₚ) |
724 | 730 | closest_model_agesₚ[i] = model_agesₚ[closestₚ[i]]
|
725 |
| - if Age_Sidedness[i] == sign(closest_model_agesₚ[i] - ages[i].μ) |
726 |
| - closest_model_agesₚ[i] = ages[i].μ |
727 |
| - end |
728 | 731 | end
|
729 |
| - adjust!(agesₚ, Chronometer, systematic) |
730 |
| - llₚ = strat_ll(closest_model_agesₚ, agesₚ) |
| 732 | + llₚ = strat_ll(closest_model_agesₚ, agesₚ, Age_Sidedness) |
731 | 733 | llₚ += normpdf_ll(Height, Height_sigma, sample_heightₚ)
|
732 | 734 |
|
733 | 735 | # Add log likelihood for hiatus duration
|
|
767 | 769 |
|
768 | 770 | if rand() < 0.1
|
769 | 771 | # Adjust heights
|
770 |
| - @inbounds for i ∈ eachindex(sample_heightₚ) |
| 772 | + @inbounds for i ∈ eachindex(sample_heightₚ, closestₚ) |
771 | 773 | sample_heightₚ[i] += randn() * Height_sigma[i]
|
772 |
| - closestₚ[i] = round(Int,(sample_heightₚ[i] - model_heights[1])/resolution)+1 |
773 |
| - if closestₚ[i] < 1 # Check we're still within bounds |
774 |
| - closestₚ[i] = 1 |
775 |
| - elseif closestₚ[i] > npoints |
776 |
| - closestₚ[i] = npoints |
777 |
| - end |
| 774 | + closestₚ[i] = round(Int,(sample_heightₚ[i] - first(model_heights))/resolution)+1 |
| 775 | + closestₚ[i] = max(min(closestₚ[i], lastindex(model_agesₚ)), firstindex(model_agesₚ)) |
778 | 776 | end
|
779 | 777 | else
|
780 | 778 | # Adjust one point at a time then resolve conflicts
|
|
811 | 809 | end
|
812 | 810 |
|
813 | 811 | # Calculate log likelihood of proposal
|
814 |
| - # Proposals younger than age constraint are given a pass if Age_Sidedness is -1 (maximum age) |
815 |
| - # proposal older than age constraint are given a pass if Age_Sidedness is +1 (minimum age) |
816 |
| - @inbounds for i ∈ eachindex(ages) |
| 812 | + adjust!(agesₚ, Chronometer, systematic) |
| 813 | + @inbounds for i ∈ eachindex(closest_model_agesₚ, closestₚ) |
817 | 814 | closest_model_agesₚ[i] = model_agesₚ[closestₚ[i]]
|
818 |
| - if Age_Sidedness[i] == sign(closest_model_agesₚ[i] - ages[i].μ) |
819 |
| - closest_model_agesₚ[i] = ages[i].μ |
820 |
| - end |
821 | 815 | end
|
822 |
| - adjust!(agesₚ, Chronometer, systematic) |
823 |
| - llₚ = strat_ll(closest_model_agesₚ, agesₚ) |
| 816 | + llₚ = strat_ll(closest_model_agesₚ, agesₚ, Age_Sidedness) |
824 | 817 | llₚ += normpdf_ll(Height, Height_sigma, sample_heightₚ)
|
825 | 818 |
|
826 | 819 | # Add log likelihood for hiatus duration
|
|
0 commit comments