Ordinary Kriging Complexity #203
Replies: 5 comments
-
Independently of the theoretical complexity the most reliable apporach I think is to measure it. For instance on randomly distributed data, changing the number of samples and running krigging on a 100x100 grid the script below produces,
so the time complexity is roughly O(n_samples²) both for the Overall there should be room for improvement I think. benchmark.py (run with import numpy as np
import pykrige.kriging_tools as kt
from pykrige.ok import OrdinaryKriging
from neurtu import Benchmark, delayed
rng = np.random.RandomState(0)
max_samples = 100000
data = 10*rng.rand(max_samples, 2)
z = rng.rand(max_samples)
gridx = np.linspace(0, 10, 100)
gridy = np.linspace(0, 10, 100)
kwargs = dict(variogram_model='linear',
verbose=False, enable_plotting=False)
def bench_cases():
for n_samples in [2000, 4000, 8000]:
tags = {'n_samples': n_samples, 'method': '__init__'}
ok = delayed(OrdinaryKriging, tags=tags)(
data[:n_samples, 0], data[:n_samples, 1], z[:n_samples])
yield ok
tags = {'n_samples': n_samples, 'method': 'execute'}
ok = OrdinaryKriging(data[:n_samples, 0], data[:n_samples, 1], z[:n_samples])
yield delayed(ok, tags=tags).execute('grid', gridx, gridy)
res = Benchmark(wall_time=True, peak_memory=True)(bench_cases())
print(res.unstack(-1).round(2)) you can adapt this script to evaluate the complexity with respect to other parameter (e.g. grid size etc). |
Beta Was this translation helpful? Give feedback.
-
Thank you @rth, this script helped a lot! I had an issue printing the output but I did a workaround, so my outputs are not cool like yours. Follow the error.
I did some simple experiments that I would like to share. TIME COMPLEXITYSamples time complexityChecking time variation between 50 to 6400 samples
If we plot this in a chart and compare to a chart for O(n2) we can see that it's a little bit complexy than O(n2), but almost the same thing. (This isn't a controlled experiment) So, I think we can say samples time complexity is O(n2). Grid time complexityChecking the time variation between 625 (25 x 25) to 160000 (400 x 400) grid cells 25 x 25 grid (625 cells), 50 to 1600 samples
50 x 50 grid (2500 cells), 50 to 1600 samples
100 x 100 grid (10000 cells, 4x bigger than the previous one), 50 to 1600 samples
200 x 200 grid (40000 cells, 4x bigger than the previous one), 50 to 1600 samples
400 x 400 grid (160000 cells, 4x bigger than the previous one), 50 to 1600 samples
If get all results for 100 samples for example and plot in a chart, we can see a linear grow. ConclusionIf we say samples is n and number of grid cells is m, can we say that the complexity time for grid and samples is O(mn2)? ### Memory Usage Complexity Is this correct? Thanks for the help! |
Beta Was this translation helpful? Give feedback.
-
You need to install pandas, then the output will be a pandas.DataFrame instead of a list of dict. Yes, O(m n²) for both time and memory complexity sounds plausible to me. Obviously O(n²) is not great, and we should try to reduce it if possible (also see #74) |
Beta Was this translation helpful? Give feedback.
-
I did a couple of tests. For C backend, the memory usage decreases but time execution increases a lot. When using NORMAL
BACKEND C
BACKEND C with
|
Beta Was this translation helpful? Give feedback.
-
Cython pre-build wheels are now provided for |
Beta Was this translation helpful? Give feedback.
-
What's the ordinary kriging complexity?
I've been searching for the ordinary kriging algorithm complexity but couldn't find it. I found a lot of papers and academic stuff, but I don't have the background to understand it. Big O notations it's something that I can actually understand before studying the kriging process deeply!
The complexities of the other kriging types is usefull as well.
I appreciate if anyone can help me
Beta Was this translation helpful? Give feedback.
All reactions