capaulson / pykriging Goto Github PK
View Code? Open in Web Editor NEWWelcome to the User Friendly Python Kriging Toolbox!
Home Page: http://www.pykriging.com
License: MIT License
Welcome to the User Friendly Python Kriging Toolbox!
Home Page: http://www.pykriging.com
License: MIT License
I have trained a Kriging model with my own data, and want to call it for optimization through my own optimization program. How do I save and recall the trained Kriging model?
Hello!
I've been using pyKriging in my MSc project to manually optimise a design, but I haven't found any function to search the final trained surrogate for the location of a minimum. I have hacked together a new type of infill point in krige.py called "minimum" that uses the GA to search for a minimum.
Would you like me to issue a pull request on this?
Regards,
Ignacio Vidal
Hello, let's say I have set-up and trained my model,
k = kriging(np.array(X),np.array(y))
k.train(optimizer=optimizer)
where X has 50rows and 13 columns.
I now want to use it to predict new outputs, where the input vector, X_new, is 100 x 12 (list, array, dataframe, ??). Is there a way to predice all 100 rows at the same time or do we need to loop.
I can't get this to work, but would like it too
prediction = k.predict(X_new)
Any suggestions?
Thanks.
_I've recently tried initialising a pyKriging object with a 2D sampling plan of 100 points (generated using the package's optimallhc method). However, a "bad params" error was raised by the model's updatePsi method during training despite it having worked just fine for most other sampling plans (for example, a 74 point optimal LHC produced a good model, but failed with a 75 point LHC).
Am I missing something fundamental to the mathematics here, or is this an idiosyncrasy of the code itself?
Thanks very much for developing pyKriging by the way - it's a brilliant toolbox!_
EDIT:
I managed to track down the issue - it turns out it was the mathematics after all. It seems that when the model initially calls its "updatePsi" method, it runs a Cholesky decomposition using NumPy's linalg.cholesky function. If this method is not supplied with a definite positive matrix as its input, it fails, resulting in an overall failure to build the pyKriging object.
Have you come up against this issue in the past? If so, do you know of any ways to generate an optimal LHS while ensuring that Psi will be positive definite when processed by pyKriging?
Can anyone share how to use CoKriging using this package.
I have one target variable and one auxillary variable along with X,Y coordinates i.e. latitude and longitude.
How can i use CoKriging for this?
When trying to create an optimal LHC sampling plan for k>2, I am getting an IndexError from numpy in the samplingplan.perturb function. Upon closed inspection, this seems to be happening because math.floor returns a float instead of an int. Wrapping m.floor in int() seems to solve the problem.
Does pykriging support python 3? I'm using 3.4 and get the following when trying to do the demo:
Traceback (most recent call last):
File "D:/MRSE/apdl-submodels/krige.py", line 1, in
import pyKriging
File "C:\Anaconda\envs\full-py3\lib\site-packages\pyKriging__init__.py", line 2, in
from .krige import *
File "C:\Anaconda\envs\full-py3\lib\site-packages\pyKriging\krige.py", line 142
except Exception, err:
^
SyntaxError: invalid syntax
If its not supported, is python 3 support planned?
I am using the pyKriging package to build a surrogate model. And I find that when I input the same training data, the predict values are not the same for different trials. And I use the simplest kriging function, that is : k = kriging(X, y,) and k.train(). The randomness of the kriging is unexpected for me, so could I eliminate it?
Hi, sorry for bothering you.
I have been dealing with the following problem for 3 months, hence I decided to try to share it.
I am training kriging and xgboost on sets of increasing sample number ( say from 100 samples to 1000 samples) of 15 inputs and 1 output each sample and I use the trained functions to predict a test set (that is always the same).
Whilst I haven't ever had any problem with xgboost prediction, when I predict the test set with kriging, I have no problems up to 400ish samples training; the more I increase from say around 400 samples to train, the more the last values of the test set which I predict equal the same value.
Have you got any idea about that?
Thanks!
Matteo
I could not open this URL (http://www.pykriging.com/), does anyone have the same problem as me ?
I think there might be a bug in the kriging or MSE estimate if the problem is compressed to 2-D (ie, one input and one output). If you run the x*sin(x) test function with only a few points (2-4) and plot the error estimate, it doesn't look correct.
Is the smoothness factor "p" getting optimized on as well as the theta values? If not, that might cause this issue. I believe this bug also exists in the Matlab code, so that won't be a great resource to compare against.
Hello,
It's not really an issue but I wonder what are the models used in your implementation.
Is there any where I can read the mathematical theory behind your models?
And what are the models supported by this library?
For example, I'm using the following code:
k = kriging(train_coors, train_z, name='simple')
k.train()
print('predicting...')
predicted_z = np.array([k.predict([row[0], row[1]]) for row in coordinates])
What is the mathematical behind? What options available for name
?
The last question is: What's the difference between this lib and PyKrige?
I've checked your website, but I couldn't find that information.
Hi, it's not really an issue. I'm just wondering if is it possible to get the formula of the meta model (used in the predict function) ?
I didn't find any solution to my problem by my own so i'm calling for some help.
Thanks
I've read the documentation published in http://pykriging.com/, but I didn't find the semivariogram function used by the method. Providing it is there, could I change the function?
Thanks.
k.plot() Generate three graphs, but I want to get only the fitting diagram of the kriging model. how to use it?
Hello all,
when trying to run pyKriging the first time, I got the following error on import:
File "C:\Users\xxxxx\Anaconda3\lib\site-packages\pyKriging\krige.py", line 142
except Exception, err:
^
SyntaxError: invalid syntax
I am running a Jupyter notebook using python 3.6.1. My pyKriging version is 0.1.0, installed via pip. Is there another version of pyKriging to be used?
First of all, thank you for your package! Apart from 2 issues I found (of which this is one), everything works very well!
I was getting a IOError when generating an optimal LHC sampling plan using the samplingplan class, because it was trying to write the LHC pickled cache to its installation directory (I'm running Anaconda2 on Windows), to which I didn't have writing rights. I think that in general it can be assumed, especially for large corporate system architectures, that Python has no admin rights and thus cannot write to the installation directory of the package. It would be nice if the path could be supplied as a parameter to the init function to solve this issue.
Just a suggestion: if you could write this code using google tensorflow (or maybe theano), it would be possible to make use of many processors, the gpu and in the near future, several machines. What do you think?
How do I save the trained model so that I can load the model directly the next time and generate predictions for new points?
I hope to get your help. Thank you very much.
Hi, Can it support the calculation of average regression kriging variance for multiple targets?
Hi, I'm sorry for bothering you. But I have a question for the predicted array.
I've trained a model, and then I want to output the result as a numpy array(because I want to save the array as a raster image by using gdal). Just like the kriging module in ArcGIS. How could I?
Thanks very much.
@capaulson
Hello, I am trying to perform a simple kriging prediction. My training data are of form:
X
2.0, 10.0
3.0, 10.0
5.0, 15.0
..
and
Y
67.8
79.6
89.3
..
the simple code I run is the following:
k = kriging(X, y, testPoints=10)
k.train()
k_predictions = k.predict(X)
print k_predictions
I keep getting the following errors:
krige.py:85: RuntimeWarning: invalid value encountered in double_scalars
X[i] = (X[i] - self.normRange[i][0]) / float(self.normRange[i][1] - self.normRange[i][0])
matrixops.py:46: RuntimeWarning: invalid value encountered in absolute
self.LnDetPsi=2*np.sum(np.log(np.abs(np.diag(self.U))))
krige.py:85: RuntimeWarning: divide by zero encountered in true_divide
X[i] = (X[i] - self.normRange[i][0]) / float(self.normRange[i][1] - self.normRange[i][0])
and naturally, k_predictions is nan.
Can someone help or point me to the right direction?
Thank you in advance
Hi, I am using pyKriging to train a set of input(100 rows and 3 columns) and output(100 rows and 400 columns) data, but it shows that there is a problem: index 1 is out of bounds for axis 0 with size 1.
Below is the simple code I wrote:
import math
import random
import numpy as np
import matplotlib.pyplot as plt
from pyKriging.krige import kriging
import scipy.io as scio
path_1 = 'hb114_00_bywz.mat'
data_1 = scio.loadmat(path_1)
X = data_1['params'] #100 rows and 3 columns
Y = data_1['Cp_M'] #100 rows and 400 columns
X = np.mat(X)
Y = np.mat(Y)
k0 = kriging(X, Y)
k0.train()
a = [0.1065, 0.062, 0.353]
YX = k0.predict(a)
These codes can't run, hope to get help, thanks in advance.
Hi, I wanna know if you can help me figure out how this package works. I have the coordinates of each point where magnetometry data was taken but I need to know how to use it in the code. What is sp, X, y and testfun in the code?
This isn't a bug report, just some information for anyone looking to accelerate pyKriging. I profiled running one of the examples (2d_leave_n_out.py
) to see which parts of the code take most time. This was run after my changes in #16 which reduced the time spent in pyKriging.samplingplan
code.
As you can see below, most of the time is in the fittingObjective
method, and the calls it makes to neglikelihood
and updateModel
. So if anyone's working on performance, these are places to focus. I couldn't see any obvious changes like those I made in #16, but I don't understand the maths the code is implementing.
(The visualisation is by snakeviz
)
The example demonstrates two-dimensional and three-dimensional.Now there is a group of 5-Dimensional data with 5 columns and 100 rows, and 3 columns and 100 rows are output. How to establish Kriging model.Can you give sample code? Thanks
Actually I want to save the model so that I can use it whenever i want.
But it seems that there is no API for this?
Hi,
A quick question on the calculation of predicted error in the "predicterr_normalized" function. After digging into the code a bit, I am still a bit hazy on exactly what this function is returning. As far as I can tell it seems to be returning the normalized root mean squared error. Is this correct?
Thanks! And, nice work!
Hi guys, I'm new to all this. I am trying to evaluate pyKriging for mechanical design optimisation. I can run the 2D examples fine, however, when running the 3D example I get a signal 11 python crash. I presume this is just me not having enough memory?
If you need more info I am more than happy oblige.
Many thanks,
Darren
Hello! Pretty happy with the package so far. Any chance the gradient enhanced kriging from the textbook can get added to the package?
https://optimizationcodes.wordpress.com/
Hello
Where can I find the pyKriging documentation that explains how this module works and what features it has. So far I have come across the following website: http://www.pykriging.com/ I have also come across this GitHub page and the examples here but I can't seem to find documentation that explains all the features and how to use them. I am sorry if this seems like a silly question.
Kind regards,
Tessa
I tried to call pyKriging from MATLAB. I used the following code in MATLAB to call pyKriging function.
krigObj = py.pyKriging.regressionkrige.regression_kriging(npxSamples,npySamples);
krigObj.train(pyargs('optimizer','ga')); #optimizer='pso' or 'ga'
The function is called successfully but I am getting the following error
エラー: regressionkrige>train (line 399)
Python エラー: UnboundLocalError: local variable 'final_pop' referenced before assignment
I understood that neither of the 'if' conditions gets executed and the 'final_pop' variable is empty. Hence I tried with default options assuming it should execute with 'pso'
krigObj.train()
It ran successfully without any error and I got the model.
I tried the same method with krige.py
krigObj = py.pyKriging.krige.kriging(npxSamples,npySamples);
krigObj.train(pyargs('optimizer','so'));
But this time I didn't get any error and the model was generated successfully.
The difference; in regressionkrige.py 'is' is used to check the condition whereas in krige.py '==' is used. If there is a type mismatch even-if the value is same, the condition 'is' will return a False.
Note : I executed directly from Python and I didn't get any error. I am using Python 3.5 version.
Could you replace the 'is' with '==' and update the code ?
It appears that there is an array dimension mismatch in the regression Kriging model.
Hi. I noticed that both krige and regressionkrige can choose optimizer. Both PSO and GA works fine in my code when using krige. But when using regressionkrige, GA and no optimizer can give a good result while PSO always give me a result with big difference from GA.
Here is the code using regressionkriging and pso, it's just a simple try. The precise value of d should be 90, when using pso, the value can be numbers like 175, or -1735, etc.
`
import pyKriging
import numpy as np
from pyKriging.regressionkrige import regression_kriging
a = np.loadtxt('dataA.txt', dtype = np.float32)
b = np.loadtxt('dataB.txt', dtype = np.float32)
c = regression_kriging(a, b)
c.train('pso')
d = c.predict([9, 3])
print(d)
`
when i run 4 process krig.train and krig.predict under linux(redhat2.6.32, 32 CPU(s)),it is very slowl,it is 50 times slow than run it one by one.
and on windows it works well.
Hi, I would like to know what are the variables Xe, Xc, yc and ye.
Thanks!
Is there any algorithm example like Kriging?
Hi there, I'm new to this lovely tool and had run some surrogate model optimization to validate this, all 2 dimension benchmark functions(Brainin, Rastrigin, Rosenbrock2D) showed relatively good perfomance. However, when I'm tring to test a 10 dimensions Rosenbrock function, the performance may need some optimization to make it more practical.
I've just modified the 2D_model_convergence.py in example a little to do this validation.
In detail:
Planform:
Windows 10, intel CPU 8 cores with 2.7GHz each, 16G RAM
Running State:
Some questions:
Hi, I am trying to use the co-kriging module in Anaconda python 3.5. However, there is an error that "Matrix is not positive definite". I tried the co-kriging example, I failed either.
line 172, in
print a.zhou98([[1,1,1],[2,2,2]])
AttributeError: testfunctions instance has no attribute 'zhou98'
Not really an issue, Just can't follow the examples and see how to implement this library for my own simple task.
Do you have an example similar to the ones at this website http://hackersome.com/p/bsmurphy/PyKrige.
It could be that I am missing the point of the library.
Sincerely,
Michael Wallace, P.Geo., PGp
I installed pyKriging via pip, i.e. the command "pip install pykriging" and all installations (some dependencies were resolved) were done successfully. Then I tried to validate the installation via the suggested command, i.e.:
> python -c 'import pyKriging'
File "<string>", line 1
'import
^
SyntaxError: EOL while scanning string literal
Sadly that did not work out. Then I slightly altered the command to
>python -c "import pyKriging"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "E:\...\lib\site-packages\pyKriging\__init__.py", line 2, in <module>
from .krige import *
File "E:\...\lib\site-packages\pyKriging\krige.py", line 142
except Exception, err:
^
SyntaxError: invalid syntax
That showed that the problem was related to that I was using Python 3 while the project uses Python 2. On this specific topic there is this helpful link: https://www.python.org/dev/peps/pep-3110/
So after having this debugging process, I thought it could be nice to be informed on the first page that this project is Python 2 only. If it could be changed to be also compliant to Python 3, that would be great, too!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.