{ "cells": [ { "cell_type": "markdown", "id": "be5d3b4f", "metadata": {}, "source": [ "# Theory\n", "\n", "## Discrete spaces\n", "\n", "A discrete space is defined by a set of states and the connections between them, which we consider here finite for practical reasons.\n", "Here, we consider that each state $i$ has an associated scalar value $f_i$ e.g. potential energy, fitness or a phenotype of interest. \n", "\n", "The module `gpmap.space` contains general classes for a number of different discrete spaces for testing and use. These include, for instance, a multidimensional finite grid `GridSpace` or a `SequenceSpace`, which are subclasses of a `DiscreteSpace` class that can be arbitrarily defined by an adjacency matrix connecting a number of different discrete states and the vector $f$ with the phenotype associated to each state. " ] }, { "cell_type": "code", "execution_count": 12, "id": "6b281ef0", "metadata": {}, "outputs": [], "source": [ "# Import required libraries\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import gpmap.plot.mpl as plot\n", "\n", "from gpmap.space import GridSpace\n", "from gpmap.randwalk import WMWalk" ] }, { "cell_type": "markdown", "id": "af23cb8d", "metadata": {}, "source": [ "A very simple discrete space that we can visualize in a straight forward manner is a two-dimension grid.\n", "Among the predefined discrete spaces, we provide a class `GridSpace` that we will use here for illustrating the behavior of the visualization technique. \n", "This class allows us to define a space of this type by defining the number of dimensions `n_dim` and the length `length` of each dimension (number of different values along each axis)." ] }, { "cell_type": "code", "execution_count": 13, "id": "6f2f76f5", "metadata": {}, "outputs": [], "source": [ "space = GridSpace(length=20, ndim=2)" ] }, { "cell_type": "markdown", "id": "cbe140d9", "metadata": {}, "source": [ "by printing the newly created object, we can see a summary of the properties of the space, including the number of states, some of the labels associated to those states, and the total number of edges connecting pairs of states. " ] }, { "cell_type": "code", "execution_count": 14, "id": "6d7fb98c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Discrete Space:\n", "\tNumber of states: 400\n", "\tState labels: [0-0,0-1,0-2,...,19-17,19-18,19-19]\n", "\tStates function values: undefined\n", "\tNumber of edges: 1520.0\n" ] } ], "source": [ "print(space)\n" ] }, { "cell_type": "markdown", "id": "af26363c", "metadata": {}, "source": [ "We can now add a phenotype to each possible state. For illustration purposes, `GridSpace` has a method that places different peaks at specific locations of the two-dimensional grid. Lets add three different peaks. \n", "The `GridSpace` object contains a ``nodes_df`` attribute that stores a dataframe containing the `x,y` coordinates of the grid and the associated function at each point." ] }, { "cell_type": "code", "execution_count": 15, "id": "926944d8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | 1 | \n", "2 | \n", "function | \n", "
|---|---|---|---|
| 0-0 | \n", "0 | \n", "0 | \n", "0.652099 | \n", "
| 0-1 | \n", "0 | \n", "1 | \n", "0.752238 | \n", "
| 0-2 | \n", "0 | \n", "2 | \n", "0.867756 | \n", "
| 0-3 | \n", "0 | \n", "3 | \n", "0.785574 | \n", "
| 0-4 | \n", "0 | \n", "4 | \n", "0.690295 | \n", "
| \n", " | i | \n", "j | \n", "
|---|---|---|
| 0 | \n", "0 | \n", "1 | \n", "
| 1 | \n", "1 | \n", "0 | \n", "
| 2 | \n", "1 | \n", "2 | \n", "
| 3 | \n", "2 | \n", "1 | \n", "
| 4 | \n", "2 | \n", "3 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 1515 | \n", "397 | \n", "396 | \n", "
| 1516 | \n", "397 | \n", "398 | \n", "
| 1517 | \n", "398 | \n", "397 | \n", "
| 1518 | \n", "398 | \n", "399 | \n", "
| 1519 | \n", "399 | \n", "398 | \n", "
1520 rows × 2 columns
\n", "