Code Monkey home page Code Monkey logo

pykriging's People

Contributors

capaulson avatar dronecfd avatar merax avatar merlinkeller avatar npezolano avatar sjvrijn avatar takluyver avatar tsingqaq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pykriging's Issues

Searching the surrogate

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

Prediction with multiple inputs

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.

"bad params" error when initialising a model with certain sampling plans

_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?

CoKiging

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?

IndexError in samplingplan.perturb

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.

Python 3 Support

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?

How to eliminate the randomness of the kriging model?

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?

It starts to predict the same value as I increase sample number to predict

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

1-d infill error estimate

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.

Documentation for your library

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.

Get the meta model

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

the problem of k.plot()

k.plot() Generate three graphs, but I want to get only the fitting diagram of the kriging model. how to use it?

SyntaxError: invalid syntax in krige.py

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?

Option to specify path

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.

How do I save the trained model?

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.

Regression kringe

Hi, Can it support the calculation of average regression kriging variance for multiple targets?

How could I output the predicted array as a numpy array?

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

errors in simple kriging prediction attempt

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

n-dimensional Kriging

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.

How the code works? What is sp, X, y and testfun?

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?

Profiling results

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.

screenshot from 2017-04-27 11-33-01

(The visualisation is by snakeviz)

N dimension kriging model

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

predicterr_normalized calculation

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!

Signal 11 encountered when running 3d example

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

PyKriging Documentation

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

Regression Kriging not able to use the optimizer option when called from MATLAB

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 ?

Optimizer of krige and regressionkrige

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.

dataA.txt
dataB.txt

`
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)
`

linux muti process

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.

Unknown variables

Hi, I would like to know what are the variables Xe, Xc, yc and ye.
Thanks!

Long Time&Large Resources consumption on High-dimension(relatively) benchmark function trainning

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:

  1. I've used Lartin Hypersquare to generate 15 sample points.
  2. train the model and add two point each time if the Rsquare do not meet the requirments: 0.9999
  3. Opt according to train results and add more points if needed
    PS. No other changes in the builtin pyKriging code.

Planform:
Windows 10, intel CPU 8 cores with 2.7GHz each, 16G RAM

Running State:

  1. Adding points to converge time: 9 hours 48 min
  2. 233 points have been added
  3. The opt result using this model:
    [-0.63639733 -0.05997818 -0.28746121 -0.74832849 -0.40609548 -0.94673114
    -0.33373671 0.16122451 0.24220962 0.24609548]
    while the true one is : [1 1 1 1 1 1 1 1 1 1 1 ]

Some questions:

  1. The adding point and training the model process are quit slow compared to DACE toolbox(matlab),more than 2 minute of two points each time,this is quite long to prevent it useful and may need some acceleration to make it quicker, I wonder what to make it so slow, is that the optimization process?
  2. The CPU consumption is very high, more than 60% is taken by this python process, since there may be no multiprocess(seems that in the TODO list according to the official website), I wounder where does these consumptions come from.

co-Kriging problem

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.

Missing test function

line 172, in
print a.zhou98([[1,1,1],[2,2,2]])

AttributeError: testfunctions instance has no attribute 'zhou98'

Project is Python 2 only without (obvious) notice of that fact

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.