derivative

scipy.misc.derivative for multiple argument function

不想你离开。 提交于 2019-11-30 03:30:10
It is straightforward to compute the partial derivatives of a function at a point with respect to the first argument using the SciPy function scipy.misc.derivative . Here is an example: def foo(x, y): return(x**2 + y**3) from scipy.misc import derivative derivative(foo, 1, dx = 1e-6, args = (3, )) But how would I go about taking the derivative of the function foo with respect to the second argument? One way I can think of is to generate a lambda function that rejigs the arguments around, but that can quickly get cumbersome. Also, is there a way to generate an array of partial derivatives with

3D Perlin noise analytical derivative

早过忘川 提交于 2019-11-30 02:22:50
I am currently implementing a 3D Perlin noise bump mapping using Shader Model 4 (DirectX 10 HLSL). Generating the noise itself is not a big problem (there are tons of tutorials and codes around) but what I have not found are analytical derivatives of 3D Perlin noise. The only sites taking the derivatives into account are Ińigo Quilez's site and a related GameDev.net discussion . The problem is that in the first link the noise is value based, not gradient based (which is a requirement for me), in the second link, there's only 2D gradient noise derivative. Note that I'm not looking for numerical

numpy second derivative of a ndimensional array

泪湿孤枕 提交于 2019-11-30 01:57:22
I have a set of simulation data where I would like to find the lowest slope in n dimensions. The spacing of the data is constant along each dimension, but not all the same (I could change that for the sake of simplicity). I can live with some numerical inaccuracy, especially towards the edges. I would heavily prefer not to generate a spline and use that derivative; just on the raw values would be sufficient. It is possible to calculate the first derivative with numpy using the numpy.gradient() function. import numpy as np data = np.random.rand(30,50,40,20) first_derivative = np.gradient(data)

Derivative of an array in python?

╄→гoц情女王★ 提交于 2019-11-29 21:51:33
问题 Currently I have two numpy arrays: x and y of the same size. I would like to write a function (possibly calling numpy/scipy... functions if they exist): def derivative(x, y, n = 1): # something return result where result is a numpy array of the same size of x and containing the value of the n -th derivative of y regarding to x (I would like the derivative to be evaluated using several values of y in order to avoid non-smooth results). 回答1: This is not a simple problem, but there are a lot of

Explanation of dFdx

断了今生、忘了曾经 提交于 2019-11-29 20:51:17
I am trying to understand the dFdx and dFdy functions in GLSL. I understand the following: The derivative is the rate of change The partial derivative of a function with two parameters is when you differentiate the function while keeping one of the parameters constant. dFdx and dFdy find the rate that a value changes between the current fragment and a neighboring fragment. I don't understand what the rate of change is referring to. Is it the rate of change of fragment coordinates? Could it possibly be that you can find the rate of change of an arbitrary variable between two invokations of the

Java - Computation of Derivations with Apache Commons Mathematic Library

做~自己de王妃 提交于 2019-11-29 15:50:06
问题 I have a problem in using the apache commons math library. I just want to create functions like f(x) = 4x^2 + 2x and I want to compute the derivative of this function --> f'(x) = 8x + 2 I read the article about Differentiation (http://commons.apache.org/proper/commons-math/userguide/analysis.html, section 4.7). There is an example which I don't understand: int params = 1; int order = 3; double xRealValue = 2.5; DerivativeStructure x = new DerivativeStructure(params, order, 0, xRealValue);

Python differentiation using numpy not producing expected output

孤人 提交于 2019-11-29 15:10:44
So, I am working on some numerical computation. I have calculated some 100,000 points of a function ( return_times ) only computable numerically, and now want to take it's derivate using numpy.gradient . As I understand ( doc ), for an f(x)I can give the following arguments: numpy.gradient(arr_of_fx_datapoints, arr_of_their_x_values) to make it work. And that's what I (intended to) do. Except that it doesn't work. The result is almost (but not exactly) zero everywhere. The bug is reproduced by this abstract of my code below (sin^2(x) has a shape alike to my original function): import

scipy.misc.derivative for multiple argument function

大憨熊 提交于 2019-11-29 01:10:03
问题 It is straightforward to compute the partial derivatives of a function at a point with respect to the first argument using the SciPy function scipy.misc.derivative . Here is an example: def foo(x, y): return(x**2 + y**3) from scipy.misc import derivative derivative(foo, 1, dx = 1e-6, args = (3, )) But how would I go about taking the derivative of the function foo with respect to the second argument? One way I can think of is to generate a lambda function that rejigs the arguments around, but

In pyomo how can one extract the second derivative from the objective function

Deadly 提交于 2019-11-28 14:28:44
I'm working with pyomo and already have a model defined, with an objective function to go with it. After the model is solved, the objective function has certain parameters attached to it. So if i had a multi index variable [x1, x2, x3] , my quadratic objective function would suppose look something like this: (x1^2 + 13*x2^2 + 10*x3^2) + (2*x1 +......) . My question is: given that i can actually access this expression in string format from the objective, is there any way to obtain the second derivative of this function with respect to all the variables? There are two ways to get derivative

Matlab gradient equivalent in opencv

大城市里の小女人 提交于 2019-11-28 12:59:16
I am trying to migrate some code from Matlab to Opencv and need an exact replica of the gradient function. I have tried the cv::Sobel function but for some reason the values in the resulting cv::Mat are not the same as the values in the Matlab version. I need the X and Y gradient in separate matrices for further calculations. Any workaround that could achieve this would be great Pei Guo Sobel can only compute the second derivative of the image pixel which is not what we want. (f(i+1,j) + f(i-1,j) - 2f(i,j)) / 2 What we want is (f(i+i,j)-f(i-1,j)) / 2 So we need to apply Mat kernelx = (Mat_