derivative

`numpy.diff` and `scipy.fftpack.diff` giving different results when differentiating

谁说我不能喝 提交于 2019-12-24 00:42:27
问题 I am trying to compute the derivative of some data and I was trying to compare the output of a finite difference and a spectral method output. But the results are very different and I can't figure out exactly why. Consider the example code below import numpy as np from scipy import fftpack as sp from matplotlib import pyplot as plt x = np.arange(-100,100,1) y = np.sin(x) plt.plot(np.diff(y)/np.diff(x)) plt.plot(sp.diff(y)) plt.show() This outputs the following result The orange output being

symbolic derivative and integral

只愿长相守 提交于 2019-12-23 20:58:52
问题 I would like to integrate function f4 with respect to x and then find the derivative of the new function with respect to t . I can calculate the integral numerically. Is there any way to calculate this integral and derivative symbolically in R? lambda=1 ci=1 aa <- function(u,k,t){ f4 <- function(x){ f1 <- function(x){ lambda*exp(2*sqrt(lambda)*ci*t*cos(x)- (1+lambda)*ci*t +u*(sqrt(lambda)*cos(x)-1)) } f2 <- function(x){cos(u*sqrt(lambda)*sin(x)) - cos(u*sqrt(lambda)*sin(x) + 2*x) } f3 <-

Tensorflow: Compute Hessian matrix (only diagonal part) with respect to a high rank tensor

我的未来我决定 提交于 2019-12-23 05:16:03
问题 I would like to compute the first and the second derivatives(diagonal part of Hessian) of my specified Loss with respect to each feature map of a vgg16 conv4_3 layer's kernel which is a 3x3x512x512 dimensional matrix. I know how to compute derivatives if it is respected to a low-rank one according to How to compute all second derivatives (only the diagonal of the Hessian matrix) in Tensorflow? However, when it turns to higher-rank, I got completed lost. # Inspecting variables under Ipython

How to get special derivative from an interpolated function

烈酒焚心 提交于 2019-12-23 04:50:13
问题 I have created a h5 file for a simple cube and then read it by python and finally use RegularGridInterpolator function to interpolate. Everything works perfectly for me. But, I want to know how can I change my code so that, I can get derivative from this interpolated function? For your kind information, I have given here my code: code for creating h5 file import numpy as np import h5py def f(x,y,z): return 2 * x**3 + 3 * y**2 - z x = np.linspace(-1, 1, 2) y = np.linspace(-1, 1, 2) z = np

Deriving a mathematical function in python [closed]

偶尔善良 提交于 2019-12-23 04:26:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Beginner programmer here looking to write a function that can simply derive a mathematical function. The function should run like this: f(x) = x ** 2 + 2 * x <--- user input f'(x) = 2 * x + 2 I know there's

Represent a first order differential equation in numpy

心不动则不痛 提交于 2019-12-22 18:42:39
问题 I have an equation dy/dx = x + y/5 and an initial value, y(0) = -3 . I would like to know how to plot the exact graph of this function using pyplot. I also have a x = np.linspace(0, interval, steps+1) which I would like to use as the x axis. So I'm only looking for the y axis values. Thanks in advance. 回答1: Just for completeness, this kind of equation can easily be integrated numerically, using scipy.integrate.odeint . import numpy as np from scipy.integrate import odeint import matplotlib

How do you evaluate a derivative in python?

浪子不回头ぞ 提交于 2019-12-22 07:23:33
问题 I'm a beginner in python. I've recently learned about Sympy and its symbolic manipulation capabilities, in particular, differentiation. I am trying to do the following in the easiest way possible: Define f(x,y) = x^2 + xy^2. Differentiate f with respect to x. So f'(x,y) = 2x + xy^2. Evaluate the derivative, e.g., f'(1,1) = 2 + 1 = 3. I know how to do 1 and 2. The problem is, when I try to evaluate the derivative in step 3, I get an error that python can't calculate the derivative. Here is a

How do you evaluate a derivative in python?

旧街凉风 提交于 2019-12-22 07:22:51
问题 I'm a beginner in python. I've recently learned about Sympy and its symbolic manipulation capabilities, in particular, differentiation. I am trying to do the following in the easiest way possible: Define f(x,y) = x^2 + xy^2. Differentiate f with respect to x. So f'(x,y) = 2x + xy^2. Evaluate the derivative, e.g., f'(1,1) = 2 + 1 = 3. I know how to do 1 and 2. The problem is, when I try to evaluate the derivative in step 3, I get an error that python can't calculate the derivative. Here is a

How do you evaluate a derivative in python?

只谈情不闲聊 提交于 2019-12-22 07:22:09
问题 I'm a beginner in python. I've recently learned about Sympy and its symbolic manipulation capabilities, in particular, differentiation. I am trying to do the following in the easiest way possible: Define f(x,y) = x^2 + xy^2. Differentiate f with respect to x. So f'(x,y) = 2x + xy^2. Evaluate the derivative, e.g., f'(1,1) = 2 + 1 = 3. I know how to do 1 and 2. The problem is, when I try to evaluate the derivative in step 3, I get an error that python can't calculate the derivative. Here is a

How is the gradient and hessian of logarithmic loss computed in the custom objective function example script in xgboost's github repository?

[亡魂溺海] 提交于 2019-12-22 05:48:18
问题 I would like to understand how the gradient and hessian of the logloss function are computed in an xgboost sample script. I've simplified the function to take numpy arrays, and generated y_hat and y_true which are a sample of the values used in the script. Here is a simplified example: import numpy as np def loglikelihoodloss(y_hat, y_true): prob = 1.0 / (1.0 + np.exp(-y_hat)) grad = prob - y_true hess = prob * (1.0 - prob) return grad, hess y_hat = np.array([1.80087972, -1.82414818, -1