{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial 4: Data with errors\n", "\n", "This tutorial will talk about how to treat data with errors.\n", "\n", "**NOTE FOR CONTRIBUTORS: Always clear all output before committing (``Cell`` > ``All Output`` > ``Clear``)**!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Magic\n", "%matplotlib inline\n", "# Reload modules whenever they change\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "# Make clusterking package available even without installation\n", "import sys\n", "sys.path = [\"../../\"] + sys.path" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import clusterking as ck\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Loading the data created in Tutorial 1, this time as a ``DataWithErrors`` object (which has additional methods to add errors)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe = ck.DataWithErrors(\"output/tutorial_basics.sql\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Adding errors" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.add_err_poisson(500)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Warning: Do not run the dwe.add_err_... (or dwe.add_rel_err_...) cells more than once, or the error gets added multiple times!\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a relative error of 10% to all the bin contents (without any correlation between the bins):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.add_rel_err_uncorr(0.1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similar, if you want to give individual errors per bin (e.g. an additional 10% error to the first bin):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.add_rel_err_uncorr([0.1, 0, 0, 0, 0, 0, 0, 0, 0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly you can also add absolute errors, e.g.:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.add_err_uncorr(0.001)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To add normalization errors, which are maximally correlated across bin, there is the shortcut:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.add_rel_err_maxcorr(0.05) # Add a 5% normalization error" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#corr = np.ones(9)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#add_err(relative=True/False, corr=\"max\", None, cov=None, err=None, )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also add an error together with a custom correlation matrix: For a trivial example, the following errors will also be uncorrelated:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corr = np.eye(9) # Unit matrix\n", "dwe.add_rel_err_corr(0.01, corr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plots\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.plot_dist_err();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Preview" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.err()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.corr()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.cov()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwe.data(decorrelate=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }