Skip to main content

Bayesian Neural Networks methods for radiocarbon (14C) calibration

Project description

Bayesian Neural Network For Radiocarbon Calibration

Welcome to the bnn_for_14C_calibration Python library project.

Overview

This library implements algorithms based on Bayesian Neural Networks (BNN) for radiocarbon (14C) calibration.
Among available functionalities, we can find : the independent calibration of a conventional radiocarbon age (individual calibration), the joint calibration of several conventional radiocarbon ages (simultaneous calibration), the independent calibration using the IntCal20 curve for comparisons with BNN methods results or the plotting of calibration results and curves.

Installation

Python version and installation

This library requires Python 3.9.13 version to work.

If you do not have Python installed on your computer, you can install the Anaconda distribution (or Miniconda for a lightweight distribution).

Once the installation is complete, open a terminal (on Linux or macOS) or Anaconda Prompt (on Windows) and create a conda environment with the required Python version (3.9.13) and pip (the Python package manager) as follows:

conda create --name myenv python=3.9.13 pip

myenv is the name of of your environment.The command above creates an environement called myenv in which it installs pip and Python 3.9.13.

To learn more about managing Python environments with conda, please visit this page.

Installing bnn_for_14C_calibration

Before installing bnn_for_14C_calibration, you need to activate your conda environment as follows:

conda activate myenv

Then, the library can be installed using pip as follows:

pip install bnn-for-14C-calibration

If you wish, you can also install jupyter-notebook in your environment (myenv) to test the library:

pip install jupyter

You can then launch the notebook using the jupyter-notebook command in the terminal and conduct your experiments there.

Quick Start

Example usage :

import bnn_for_14C_calibration as bnn
import numpy as np

######## plotting calibration curves ########

# the global BNN curve
bnn.plot_bnn_calibration_curve()

# the global BNN curve estimated using covariates 
# in addition, reset extra margins
bnn.plot_bnn_calibration_curve(covariables = True, reset_margins=True)

# only a portion of the global BNN curve estimated using covariates
bnn.plot_bnn_calibration_curve(
    covariables = True,
    Max_x=12400,
    Min_x=12200,
    Max_y=260,
    Min_y=180
)

# only the recent part of the BNN curve
bnn.plot_individual_calibration_curve_part_1()

# only the older part of the BNN curve
bnn.plot_individual_calibration_curve_part_2()

# IntCal20 curve
bnn.plot_IntCal20_curve(reset_margins=True)

######## individual calibration ########

# radiocarbon data
c14age = 10400
c14sig = 18

# independent calibration using BNN curve
individual_calib_results = bnn.individual_calibration(
    c14age, c14sig, 
    sample_size=10000,
    compute_calage_posterior_mean_and_std=True
)
print(individual_calib_results)

# independent calibration using the BNN curve trained with covariates
individual_calib_results_with_covariables = bnn.individual_calibration(
    c14age, c14sig, 
    sample_size=10000,
    covariables=True,
    compute_calage_posterior_mean_and_std=True
)
print(individual_calib_results_with_covariables)

# independent calibration using IntCal20 curve
IntCal20_calib_results = bnn.IntCal20_calibration(
    c14age, c14sig,
    sample_size=10000,
    compute_calage_posterior_mean_and_std=True
)
print(IntCal20_calib_results)

# plotting result for independent calibration

cm = 1/2.54  # cm in inches
figsize=(17*cm, 17*cm)

bnn.plot_calib_results(
    figsize=figsize,
    calibration_results=individual_calib_results
)

bnn.plot_calib_results(
    figsize=figsize,
    add_grid=True,
    color_cal_date='green',
    eps=-1,
    calibration_results=individual_calib_results_with_covariables
)

# same function for plotting IntCal20 calibration results
bnn.plot_calib_results(
    figsize=figsize,
    calibration_results=IntCal20_calib_results
)

######## joint calibration ########

c14ages=np.array([4000, 10483])
c14sigs=np.array([10, 18])

joint_calib_results = bnn.joint_calibration(
    c14ages = c14ages, 
    c14sigs = c14sigs,
    compute_calage_posterior_mode=True,
    chaine_length=10000
)
print(joint_calib_results)


######## local cache management ########

# test of cache downloading
bnn.download_cache_lib_data()

# force cache downloading
bnn.download_cache_lib_data(overwrite = True)

# clear cache
bnn.clear_cache()

Reference

Refer to the pages on Calibration functions, Plotting functions and Local cache management in the User Guide of the documentation for detailed information on the inputs, outputs, and behaviour of each function.

For internal functions and more details on the implementation of all library functions, please refer to the Developer's Guide section of the documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bnn_for_14c_calibration-0.2.1.tar.gz (379.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bnn_for_14c_calibration-0.2.1-py3-none-any.whl (366.4 kB view details)

Uploaded Python 3

File details

Details for the file bnn_for_14c_calibration-0.2.1.tar.gz.

File metadata

  • Download URL: bnn_for_14c_calibration-0.2.1.tar.gz
  • Upload date:
  • Size: 379.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for bnn_for_14c_calibration-0.2.1.tar.gz
Algorithm Hash digest
SHA256 63e21da0ccd3e344a78425fa36e32609764d0339b4daaab9e76046a8fd5ebdd4
MD5 a3ad9ac9893ab01fff43153e0ab37c50
BLAKE2b-256 56b2daf9cf64b30a39b4d0d30d535f04535adc0dfcfdc4ff674c9118206d406b

See more details on using hashes here.

File details

Details for the file bnn_for_14c_calibration-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bnn_for_14c_calibration-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e1e6c365ffb5975445c8726c38ab670dee45742e3e00307cd657a73522ba943
MD5 d09fd27adf52d605651ef3ad232a33e6
BLAKE2b-256 e15543c79ef1cf840865a1ffcd53146b5dfa5a744f0d8a9b50b1419cc1c95ce2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page