{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Simple Kriging\n\nSimple kriging assumes a known mean of the data.\nFor simplicity we assume a mean of 0,\nwhich can be achieved by subtracting the mean from the observed values and\nsubsequently adding it to the resulting data.\n\nThe resulting equation system for $W$ is given by:\n\n\\begin{align}W = \\begin{pmatrix}c(x_1,x_1) & \\cdots & c(x_1,x_n) \\\\\n   \\vdots & \\ddots & \\vdots  \\\\\n   c(x_n,x_1) & \\cdots & c(x_n,x_n)\n   \\end{pmatrix}^{-1}\n   \\begin{pmatrix}c(x_1,x_0) \\\\ \\vdots \\\\ c(x_n,x_0) \\end{pmatrix}\\end{align}\n\nThereby $c(x_i,x_j)$ is the covariance of the given observations.\n\n\n## Example\n\nHere we use simple kriging in 1D (for plotting reasons) with 5 given observations/conditions.\nThe mean of the field has to be given beforehand.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nfrom gstools import Gaussian, krige\n\n# condtions\ncond_pos = [0.3, 1.9, 1.1, 3.3, 4.7]\ncond_val = [0.47, 0.56, 0.74, 1.47, 1.74]\n# resulting grid\ngridx = np.linspace(0.0, 15.0, 151)\n# spatial random field class\nmodel = Gaussian(dim=1, var=0.5, len_scale=2)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "krig = krige.Simple(model, mean=1, cond_pos=cond_pos, cond_val=cond_val)\nkrig(gridx)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ax = krig.plot()\nax.scatter(cond_pos, cond_val, color=\"k\", zorder=10, label=\"Conditions\")\nax.legend()"
      ]
    }
  ],
  "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.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}