{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Additional Parameters\n\nLet's pimp our self-defined model ``Gau`` from the introductory example\nby setting the exponent as an additional parameter:\n\n\\begin{align}\\rho(r) := \\exp\\left(-\\left(\\frac{r}{\\ell}\\right)^{\\alpha}\\right)\\end{align}\n\nThis leads to the so called **stable** covariance model and we can define it by\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport gstools as gs\n\n\nclass Stab(gs.CovModel):\n    def default_opt_arg(self):\n        return {\"alpha\": 1.5}\n\n    def cor(self, h):\n        return np.exp(-(h ** self.alpha))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "As you can see, we override the method :any:`CovModel.default_opt_arg`\nto provide a standard value for the optional argument ``alpha``.\nWe can access it in the correlation function by ``self.alpha``\n\nNow we can instantiate this model by either setting alpha implicitly with\nthe default value or explicitly:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "model1 = Stab(dim=2, var=2.0, len_scale=10)\nmodel2 = Stab(dim=2, var=2.0, len_scale=10, alpha=0.5)\nax = model1.plot()\nmodel2.plot(ax=ax)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Apparently, the parameter alpha controls the slope of the variogram\nand consequently the roughness of a generated random field.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>You don't have to override the :any:`CovModel.default_opt_arg`,\n   but you will get a ValueError if you don't set it on creation.</p></div>\n\n"
      ]
    }
  ],
  "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
}