A python implementation of spatial entropy
Project description
SpatialEntropy
This is a python implementation of spatial entropy, inspired by the R package spatentropy. For now, two spatial entropy methods has been implemented:
- Leibovici’s entropy
- Altieri's entropy
Usage
Let's generated some fake data first:
import numpy as np
points = 100 * np.random.randn(10000, 2) + 1000
types = np.random.choice(range(30), 10000)
Here we have 10,000 points and then we assigned each point with a category from 30 categories.
To calculate the libovici entropy, we need to set up a distance to define the co-occurrences.
from spatialentropy import leibovici_entropy
# here we set the distance d into 5
e = leibovici_entropy(points, types, 5)
e.entropy # to get the entropy value
e.adj_matrix # to get the adjacency matrix
e.pairs_counts # to get the counts for each pair of co-occurrences
To calculate the latieri entropy, we need to set up a distance to define the co-occurrences.
from spatialentropy import altieri_entropy
# if the cut is set as a number, it means how many times to cut evenly from [0,max]
# there for it will generate cut + 1 intervals
# if the cut is an array, it lets you define your own intervals
# e = leibovici_entropy(points, types, cut=[0,4,10])
e = leibovici_entropy(points, types, cut=2)
e.entropy # to get the entropy value, e.entropy = e.mutual_info + e.residue
e.mutual_info # the spatial mutual information
e.residue # the spatial residue entropy
e.adj_matrix # to get the adjacency matrix
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
spatialentropy-0.0.1.tar.gz
(8.4 kB
view hashes)
Built Distribution
Close
Hashes for spatialentropy-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23719639e0b7578226de615343b0b2502c866df7be98164d74269c822bcd368 |
|
MD5 | f058d3898dc600d9f80a8b7b24f2832d |
|
BLAKE2b-256 | bb79948e0d98195352dd82b04894a2be5e6a07adf33f51331a17254eca0376a5 |