polytex.kriging

polytex.kriging.curve2D

Implementation of 2D Curve Kriging.

Bin Yang 2021-9-2

polytex.kriging.curve2D.addPoints(coordinate, threshold=0.03)[source]

Linearly interpolate the points between each of two points that further than the threshold.

Parameters
coordinatenumpy array

The coordinates of the points. [normalized distance, X, Y, Z]

thresholdfloat, optional

The distance between two points. The default is 0.03.

Returns
coordinatenumpy array

The coordinates of the points after linear interpolation. [normalized distance, X, Y, Z]

polytex.kriging.curve2D.bd_Deriv_kriging_func(x, y, xDeriv, yDeriv, choixDerive, choixCov, plot_x_pts, nugg)[source]

Derivative kriging function.

Parameters
xarray

x points

yarray

y points

xDerivarray

x points for derivative

yDerivarray

the derivative of xDeriv points

choixDerivestring

the name of the derivative function. Possible values are ‘cst’, ‘lin’ or ‘quad’.

choixCovstring

the name of the covariance function. Possible values are ‘lin’ or ‘cub’.

plot_x_pts: array

number of points for plot

nugg: float

nugget effect (variance)

Returns
kringFunctionStr: string

String of the kriging function.

x_var_sym: string

string of the x variable

polytex.kriging.curve2D.buildKrigFunc_deriv(x, xKnown, xKnown_deriv, B, deriveFuncs, covFuncs, covFuncs_deriv)[source]
polytex.kriging.curve2D.buildM_deriv(x, x_deriv, name_drift, name_cov, covFuncs_deriv, covFuncs_deriv2, nugg)[source]

Build the matrix M for the derivative kriging system

Parameters
xarray

x points

xDerivarray

x points for derivative

name_driftfunction

derivative functions

name_covfunction

covariance functions

covFuncs_derivfunction

derivative of covariance functions

covFuncs_deriv2function

second derivative of covariance functions

nuggfloat

nugget effect (variance)

polytex.kriging.curve2D.buildU_deriv(y, y_deriv, deriveFuncs)[source]
polytex.kriging.curve2D.curve_krig_2D(dataset, name_drift, name_cov, nugget_effect=0)[source]
Parameters
dataset: numpy array

X-Y.

name_driftString

Name of drift.

name_covString

Name of covariance.

nugget_effectFloat
Returns
exprExpression

The kriging expression.

polytex.kriging.curve2D.func_select(drift_name, cov_name)[source]

This is the function for definition of drift function and covariance function in dictionary drif_funcs and cov_funcs.

Parameters
drift_namestring

The name of the drift function. Possible values are: “const”, “lin”, and “quad” for “constant”, “linear”, “quadratic”, respectively.

cov_namestring

The name of the covariance function. Possible values are: “lin”, “cub”, and “log” for “linear”, “cubic”, “logarithmic”, respectively.

Returns
drift_funcfunction

The drift function.

cov_funcfunction

The covariance function.

polytex.kriging.curve2D.func_var(X, K_h, lambda_, nugget_effect=0)[source]

Calculate the variance of the prediction.

Parameters
Xnumpy array

The locations where function values are unknown and to be predicted.

K_hnumpy array

The kriging matrix.

lambda_numpy array

The weight of gloabl combination. Note that it is different from the vector_ba in dual Kriging formulation.

nugget_effectfloat

The nugget effect. Default is 0.

Returns
std_predictionnumpy array

the standard deviation of the prediction

polytex.kriging.curve2D.h(x1, x2)[source]

The function h(x1, x2) = abs(x1 - x2).

Parameters
x1float

The first point.

x2float

The second point.

Returns
hfloat
polytex.kriging.curve2D.interpolate(dataset, name_drift, name_cov, nugget_effect=0, interp=' ', return_std=False)[source]
Parameters
datasetnumpy array

X-Y.

name_driftString

Name of drift.

name_covString

Name of covariance.

nugget_effectFloat

smoothing strength control

interp: Numpy array

The points that need to be interpolated, 1D numpy array. If interp is not given, the x-coordinate of the sample points is used.

Returns
exprExpression

The kriging expression.

polytex.kriging.curve2D.krig_expression(len_b, func_drift, func_cov, adef, dataset, vector_ba)[source]

return the Kriging function expression.

Parameters
len_bint

The length of the b vector (the coefficient of linear combination).

func_driftfunction

The drift function.

func_covfunction

The covariance function.

adefnumpy array

The coefficients of the drift function.

datasetnumpy array

The sample points. X-Y.

vector_banumpy array

The kriging vector.

Returns
exprsympy expression

The analytical expression of the function created by kriging.

polytex.kriging.curve2D.lambda_weight(X, X_train, func_drift, func_cov, mat_krig)[source]

Calculate the weight of the lambda matrix

Parameters
Xnumpy array

The locations where function values are unknown and to be predicted.

X_trainnumpy array

The training data. The locations where function values are known.

func_driftfunction

The drift function.

func_covfunction

The covariance function.

mat_krignumpy array

The kriging matrix.

Returns
K_hnumpy array

The kriging matrix.

lambda_numpy array

The weight of gloabl combination. Note that it is different from the vector_ba in dual Kriging formulation.

polytex.kriging.curve2D.solve(dataset, krig_len, mat_krig, inverse_type='inverse')[source]

Solve the kriging equation: [Matrix_kriging] [b_a] = [u.. 0..]

dataset: numpy array.

The sample points. X-Y.

krig_len: int.

The length of the kriging vector.

mat_krig: numpy array.

The kriging matrix.

inverse_type: String.

The type of the inverse matrix. “inverse” or “pseudoinverse”. “inverse” : inverse matrix “pseudoinverse” : generalized inverse/pseudoinverse

Returns
b_a: numpy array.

The kriging vector.

mat_krig_inv: numpy array.

The inverse matrix of the kriging matrix.

polytex.kriging.curve2D.solveB(M, U)[source]

Solve the linear equation system M * B = U TODO: check the comments

Parameters
Mnumpy array

The kriging matrix.

Unumpy array

The vector of the right hand side of the linear equation system.

Returns
Bnumpy array

The solution of the linear equation system.

polytex.kriging.intersect

1. the intersection of a curve with a plane def curve_plane()

2. the intersection of a plane with a plane def plane_plane()

3. the intersection of a line with a surface def line_surf()

4. the intersection of a curve with a surface def curve_surf()

5. the intersection of two surfaces def surf_surf()

polytex.kriging.intersect.ray_plane_intersect(plane_normal, plane_point, ray_direction, ray_point, epsilon=1e-06)[source]

Find the intersection between a plane and a ray.

Parameters
plane_normalarray-like

normal vector of the plane for defining the plane.

plane_pointarray-like

point on the plane for defining the plane.

ray_directionarray-like

direction of the ray.

ray_pointarray-like

The endpoint of the ray.

epsilonfloat

tolerance for determining if an intersection point exists.

Returns
Psi: array-like

intersection point.

polytex.kriging.mdKrig

polytex.kriging.mdKrig.buildKriging(xy, z, drift_name, cov_name, nugg=0)[source]

Build the kriging model and return the expression in string format.

Parameters
xy: array like. The coordinates of the points. The shape is (m, 2).
z: array like. The values of the target function. The shape is (m,).
drift_name: str. The name of the drift function.

The possible values are: ‘const’, ‘lin’, ‘cub’.

cov_name: str. The name of the covariance function.

The possible values are: ‘lin’, ‘cub’, ‘log’.

nugg: float. The nugget effect (variance).
Returns
return

The expression of kriging function in string format. ..

polytex.kriging.mdKrig.buildM(xy, drift_name, cov_name)[source]

Build the kriging matrix.

Parameters
xy: The coordinates of the points. The shape is (m, 2).
drift_name: str. The name of the drift function.

Possible values are: “const”, “lin”, “quad”.

cov_name: str. The name of the covariance function.

Possible values are: “lin”, “cub”, “log”.

Returns
drift_func: The drift function.
cov_func: The covariance function.
a_len: The length of the drift function.
M: The matrix of the kriging system. The shape is (n,n).
polytex.kriging.mdKrig.buildU(z, a_len)[source]

Build the result vector of the kriging linear system.

Parameters
z:

The values of the target function. The shape is (m,).

a_len:

The length of the drift function.

Returns
U: The result vector of the kriging linear system. The shape is (n,).
polytex.kriging.mdKrig.dist(xy, type='Euclidean')[source]

Calculate the distance between each pair of points.

Parameters
xy: numpy array. The coordinates of the points. The shape is (m, 2).
type: str. The type of the distance. The default is “Euclidean”.
Other possible values are:

“1-norm” : The 1-norm distance. “inf-norm” : The infinity-norm distance.

Returns
distancenumpy array

The distance between each pair of points. The shape is (m, m).

polytex.kriging.mdKrig.func_select(drift_name, cov_name)[source]

Function for definition of drift and covariance function in dictionary drif_funcs and cov_funcs.

Parameters
drift_name: str. The name of the drift function.

Possible values are: “const”, “lin”, “quad”.

cov_name: str. The name of the covariance function.

Possible values are: “lin”, “cub”, “log”.

Returns
drift_func: Function.

The drift function.

cov_func: Function.

The covariance function.

a_len: int.

The length of the drift function.

polytex.kriging.mdKrig.interp(xy, expr)[source]

TODO: add description

Parameters
xy: numpy array.

The coordinates of the points. The shape is (m, 2).

expr: String.

The expression of the target function.

Returns
yinter: The values of the kriging function. The shape is (m,).
polytex.kriging.mdKrig.nugget(M, nugg, b_len)[source]

Introduce the nugget effect to the kriging matrix.

Parameters
Mnumpy array.

The kriging matrix. The shape is (n,n).

nuggfloat.

The nugget effect.

Returns
M: numpy array.

The kriging matrix with nugget effect.

polytex.kriging.mdKrig.solveB(M, U)[source]

Solve the kriging linear system.

Parameters
M: numpy array.

The kriging matrix.

U: numpy array.

The result vector of the kriging linear system.

Returns
B: numpy array.

The solution of the kriging linear system (vector contains b_i and a_i).

polytex.kriging.paraSurface

polytex.kriging.paraSurface.buildKriging(s, t, x, drift_names, cov_names, nugg=[])[source]

Build the kriging model and return the expression in string format.

Parameters
s, t: numpy array.

The parameters of the two profiles for surface parametric kriging in S and T direction (1d array).

x: array like.

The known values of the variables in parametric space.

drift_names: list.

The name of the drift functions for profile 1 and profile 2 in the following format: [drift_name1, drift_name2]. The possible values are: ‘const’, ‘lin’, ‘cub’.

cov_names: list.

The name of the covariance functions in the following format: [covariance_name1, covariance_name2]. The possible values are: ‘lin’, ‘cub’, ‘log’.

nugg: list.

The nugget effects (variance) for each profile contained in a list.

Returns
expr: The expression of kriging function in string format.
polytex.kriging.paraSurface.buildM(x, drift_name, cov_name)[source]

Build the kriging matrix.

Parameters
x: The coordinates of the points. The shape is (m, 2).
drift_name: str. The name of the drift function.

Possible values are: “const”, “lin”, “quad”.

cov_name: str. The name of the covariance function.

Possible values are: “lin”, “cub”, “log”.

Returns
return drift_func

The drift function. ..

return cov_func

The covariance function. ..

return a_len

The length of the drift function. ..

return M

The matrix of the kriging system. The shape is (n,n). ..

polytex.kriging.paraSurface.buildP(x, a_lenS, a_lenT)[source]

Build the result matrix of the kriging linear system.

Parameters
x: numpy array.

The values of the target function. The shape is (m,n).

a_lenS: int.

The size of the result matrix in S direction.

a_lenT: int.

The length of the result matrix in T direction.

Returns
Pnumpy array.

The result vector of the kriging linear system. The shape is (n,).

polytex.kriging.paraSurface.dist1D(x)[source]

Calculate the distance between each pair of points.

Parameters
x: numpy array.

The coordinates in parametric space of the points. The shape is (m, 1).

Returns
numpy array.

The distance between each pair of points. The shape is (m, m).

polytex.kriging.paraSurface.func_select(drift_name, cov_name)[source]

This is the function for definition of drift function and covariance function in dictionary drif_funcs and cov_funcs.

Parameters
drift_name: str.

The name of the drift function. Possible values are: “const”, “lin”, “quad”.

cov_name: str.

The name of the covariance function. Possible values are: “lin”, “cub”, “log”.

Returns
drift_func:

The drift function.

cov_func:

The covariance function.

polytex.kriging.paraSurface.interp(s, t, expr, split_complexity=1)[source]

Interpolation (substitute the symbolic variables in the expression).

Parameters
s, t: numpy array.

The parameters of the two profiles for surface parametric kriging (1d array). s has size that same as the number of rows and t the same as the number of columns.

expr: String.

The expression of the target function.

Returns
xinterp: numpy array.

The values of the kriging function. The shape is (s.size,t.size).

polytex.kriging.paraSurface.kVector(x, symVar, drift_name, cov_name)[source]

Calculate the kriging matrix.

Parameters
x: numpy array.

The coordinates in parametric space of the points. The shape is (m, 1).

symVar: String.

The variable in parametric space.

cov_name: String.

The name of covariance function.

Returns
return

numpy array. The kriging matrix. The shape is (m, 1).

polytex.kriging.paraSurface.nugget(M, nugg, b_len)[source]

Introduce the nugget effect to the kriging matrix.

Parameters
Mnumpy array.

The kriging matrix.

nugg: float.

The nugget effect.

Returns
Mnumpy array.

The kriging matrix with nugget effect.

polytex.kriging.paraSurface.surface3Dinterp(x, y, z, name_drift, name_cov, nug, return_dict=None, label=None)[source]

Build the kriging model and interpolate the results

Parameters
x: numpy array.

The coordinates in parametric space of the points. The shape is (m, 1).

y: numpy array.

The coordinates in parametric space of the points. The shape is (n, 1).

z: numpy array.

The coordinates in parametric space of the points. The shape is (m, n).

name_drift: String.

The name of drift function.

name_cov: String.

The name of covariance function.

nug: float.

The nugget effect.

return_dict: dict.

The dictionary to store the results. It is used for multiprocessing purpose.

label: String.

The label of the result.

Returns
z_krig: numpy array.

The interpolated results. The shape is (m, n). It is the return value if return_dict is None (namely, the function is not used in parallel).

return_dict: dict.

The dictionary to store the results. It is used for multiprocessing purpose.

polytex.kriging.projection

This will be an implementation of Kriging: Chapter 15.

The following functions will be included:

1. orthogonal projection of a point onto a curve def point_curve()

2. orthogonal projection of a point onto a surface def point_surf()

polytex.kriging.tool

polytex.kriging.tool.data_compr(matXC, data_norm, max_err, skip_comp)[source]

Data compression by kriging using linear drift and linear covariance.

Parameters
data_normnumpy array

Time-Temperature-Alpha-dadt

max_errfloat

The criterion for data compression, which is the maximum local error.

skip_compint

skip (skip_comp-1) data point for data compression. skip_comp >=1.

Returns
data_norm_compTYPE

Data points .

extrenumpy array

Index of data_norm_comp or extrema choosed according to kriging compression.

polytex.kriging.tool.fun_crva(data_norm, drift_para, cov_para)[source]
Parameters
data_normnumpy array

Time-Temperature-Alpha-dadt.

drift_paralist

List of string elements.

cov_paralist

List of string elements.

Returns
exprExpression

The kriging expression.

polytex.kriging.tool.norm(data_krig, norm_type='axial')[source]

This is the normalization function. After input the data of DSC test, this function will normalize temperature, degree of cure and rate of cure.

Parameters
data_krignumpy array

Time-Temperature-Alpha-dadt

norm_typestring, optional

The type of normalization. The default is ‘axial’. The other option is ‘global’ (TODO).

polytex.kriging.volumeKrig