L i-VdZddlZddlmZddlmZddlmZm Z m Z dgZ GddZ y)a{rbf - Radial basis functions for interpolation/smoothing scattered N-D data. Written by John Travers , February 2007 Based closely on Matlab code by Alex Chirokov Additional, large, improvements by Robert Hetland Some additional alterations by Travis Oliphant Interpolation with multi-dimensional target domain by Josua Sassen Permission to use, modify, and distribute this software is given under the terms of the SciPy (BSD style) license. See LICENSE.txt that came with this distribution for specifics. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. Copyright (c) 2006-2007, Robert Hetland Copyright (c) 2007, John Travers Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Robert Hetland nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. N)linalgxlogy)cdistpdist squareformRbfcbeZdZdZdZdZdZdZdZdZ dZ d Z d Z e d Zd Zd Zy)r a Rbf(*args, **kwargs) Class for radial basis function interpolation of functions from N-D scattered data to an M-D domain (legacy). .. legacy:: class `Rbf` is legacy code, for new usage please use `RBFInterpolator` instead. Parameters ---------- *args : arrays x, y, z, ..., d, where x, y, z, ... are the coordinates of the nodes and d is the array of values at the nodes function : str or callable, optional The radial basis function, based on the radius, r, given by the norm (default is Euclidean distance); the default is 'multiquadric':: 'multiquadric': sqrt((r/self.epsilon)**2 + 1) 'inverse': 1.0/sqrt((r/self.epsilon)**2 + 1) 'gaussian': exp(-(r/self.epsilon)**2) 'linear': r 'cubic': r**3 'quintic': r**5 'thin_plate': r**2 * log(r) If callable, then it must take 2 arguments (self, r). The epsilon parameter will be available as self.epsilon. Other keyword arguments passed in will be available as well. epsilon : float, optional Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start). smooth : float, optional Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points in this case. norm : str, callable, optional A function that returns the 'distance' between two points, with inputs as arrays of positions (x, y, z, ...), and an output as an array of distance. E.g., the default: 'euclidean', such that the result is a matrix of the distances from each point in ``x1`` to each point in ``x2``. For more options, see documentation of `scipy.spatial.distances.cdist`. mode : str, optional Mode of the interpolation, can be '1-D' (default) or 'N-D'. When it is '1-D' the data `d` will be considered as 1-D and flattened internally. When it is 'N-D' the data `d` is assumed to be an array of shape (n_samples, m), where m is the dimension of the target domain. Attributes ---------- N : int The number of data points (as determined by the input arrays). di : ndarray The 1-D array of data values at each of the data coordinates `xi`. xi : ndarray The 2-D array of data coordinates. function : str or callable The radial basis function. See description under Parameters. epsilon : float Parameter used by gaussian or multiquadrics functions. See Parameters. smooth : float Smoothing parameter. See description under Parameters. norm : str or callable The distance function. See description under Parameters. mode : str Mode of the interpolation. See description under Parameters. nodes : ndarray A 1-D array of node values for the interpolation. A : internal property, do not use See Also -------- RBFInterpolator Examples -------- >>> import numpy as np >>> from scipy.interpolate import Rbf >>> rng = np.random.default_rng() >>> x, y, z, d = rng.random((4, 50)) >>> rbfi = Rbf(x, y, z, d) # radial basis function interpolator instance >>> xi = yi = zi = np.linspace(0, 1, 20) >>> di = rbfi(xi, yi, zi) # interpolated values >>> di.shape (20,) cXtjd|jz |zdzdzSN?npsqrtepsilonselfrs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/interpolate/_rbf.py_h_multiquadriczRbf._h_multiquadrics)wwDLL(*Q.233c^dtjd|jz |zdzdzz Sr rrs r_h_inverse_multiquadriczRbf._h_inverse_multiquadrics.277C ,Q.2Q6777rcTtjd|jz |zdz S)Nr r)rexprrs r _h_gaussianzRbf._h_gaussians'vvDLL(*Q..//rc|SNrs r _h_linearz Rbf._h_linearsrc |dzS)Nr!rs r_h_cubicz Rbf._h_cubic !t rc |dzS)Nr!rs r _h_quinticzRbf._h_quinticr&rc t|dz|S)Nrrrs r _h_thin_platezRbf._h_thin_platesQT1~rcXt|jtr|jj|_dddd}|j|vr||j|_d|jz}t ||rt |||_nIt|Dcgc]}|jdr|dd}}tddj|zt |d|jz|_nt|jrd}t |jd st |jd r|j}d }nBt |jd r!|jjj}n td |jj}|r|dk(r|j|_n6|dk(r&|jj!|t"|_n td|j |} | j$|j$k7r td| Scc}w)Ninverse_multiquadric thin_plate)inversezinverse multiquadricz thin-plate_h_r$z&function must be a callable or one of z, F func_code__code__T__call__z0Cannot determine number of arguments to functionrrz-Function argument must take 1 or 2 arguments.z;Callable must take array and return array of the same shape) isinstancefunctionstrlowerhasattrgetattr _functiondir startswith ValueErrorjoincallabler3__func__r2 co_argcount__get__r shape) rr_mapped func_namex functionlist allow_onevalargcounta0s r_init_functionzRbf._init_functions dmmS ) MM//1DM"8/E%13G}}' ' 6  -ItY'!(y!9/24y 8!#$<<#6!"!" 8  8 !I!%?DN dmm $It}}k2t}}j1mm  3mm,,55 ",--||//HX]!%Q!%!6!6tS!A ".//^^A  88qww ./ / = 8sH'c ltj|ddDcgc]5}tj|tjj7c}|_|jj d|_|jdd|_|jdk(r3tj|dj|_ d|_ nV|jdk(ryt9jB|j<|j|_ycc}wcc}w)Ndtypemodez1-DrzN-DzMode has to be 1-D or N-D.rz All arrays must be equal length.norm euclideanr)axisr smoothgr5 multiquadric)"rasarrayfloat64flattenxirCNpoprQdi _target_dimr=allsizerRramaxaminnonzeropowerprodrUr5itemssetattrzerosrPnodesr lu_factorArangelu_solvesolve) rargskwargsarFximaxximinedgesitemvaluelupivis r__init__z Rbf.__init__s **'+CRy2"#!jj"**=EEG23r"JJvu- 99 jjb*224DG D  YY% jjb*DG#ww}}R0D 9: :@1AFFdggmmA..@A?@ @JJv{3 zz)T2 << GGDGG!,EGGDGG!,EEME"**U+,E88BGGEN466$93uzz>JDLjj3/  :~> "<<> 'KD% D$ & '   a 4664+;+;"'E 6E N)__name__ __module__ __qualname____doc__rrrr"r%r)r+rLrzpropertyrkrr3r!rrr r 7sY\~480+Z27hCC , Br) rnumpyrscipyr scipy.specialrscipy.spatial.distancerrr__all__r r!rrrs1,Z;; 'kBkBr