derivative

calculating the Gradient and the Hessian in R

混江龙づ霸主 提交于 2019-12-03 08:55:49
As you know, the Gradient of a function is the following vector: and the Hessian is the following matrix: Now, I wonder, is there any way to calculate these in R for a user defined function at a given point? First, I've found a package named numDeriv , which seems to have the necessary functions grad and hessian but now I can't get the correct results... Thus, here's my workflow: Let's say that we are given the function f(x,y) = x^2 * x^3, and we need to calculate the Gradient and the Hessian at the point (x=1, y=2). That's been said, I define this function within R: dummy <- function(x,y) {

What's the best way to calculate a numerical derivative in MATLAB?

本秂侑毒 提交于 2019-12-03 08:50:34
问题 (Note: This is intended to be a community Wiki.) Suppose I have a set of points xi = { x0 , x1 , x2 ,... xn } and corresponding function values fi = f(xi) = { f0 , f1 , f2 ,..., fn }, where f ( x ) is, in general, an unknown function. (In some situations, we might know f ( x ) ahead of time, but we want to do this generally, since we often don't know f ( x ) in advance.) What's a good way to approximate the derivative of f ( x ) at each point xi ? That is, how can I estimate values of dfi ==

Why are dFdx/ddx and dFdy/ddy 2 dimension variables when quering a 2d texture?

谁说胖子不能爱 提交于 2019-12-03 08:41:37
I cannot seem to understand this, shouldn't the derivative/change along the U or V coordinate in a 2d texture/array be single dimension variable as we are checking it only along ddx (U coordinate) or ddy (V coordinate)? There are 4 distinct partial derivatives here: du/dx, dv/dx, du/dy, and dv/dy. None of those four values need be zero, unless the texture image coordinates happen to be perfectly aligned to the display screen axes. In general the texture coordinate axes need not be aligned to the screen display axes. X and Y (display viewport axes) are not the same directions as U and V

How to calculate first derivative of time series

眉间皱痕 提交于 2019-12-03 05:57:08
问题 I would calculate the first derivative (dpH/dtime) of time series using two variables, time and pH . Are there any kind of functions to do this in R or should I compute an extra function to do this? 回答1: Assuming pH and time are plain vectors try this: library(pspline) predict(sm.spline(time, pH), time, 1) 回答2: You might want to start with stats::deriv or diff.ts as Matt L suggested. Just keep in mind what a professor of mine used to tell all his students: numeric differentiation is known as

Implement Relu derivative in python numpy

纵然是瞬间 提交于 2019-12-03 03:24:30
This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 2 years ago . Learn more . I'm trying to implement a function that computes the Relu derivative for each element in a matrix, and then return the result in a matrix. I'm using Python and Numpy. Based on other Cross Validation posts, the Relu derivative for x is 1 when x > 0, 0 when x < 0, undefined or 0 when x == 0 Currently, I have the following code so far: def reluDerivative(self, x): return np.array([self.reluDerivativeSingleElement(xi) for xi in x]) def reluDerivativeSingleElement(self,

How to implement the Softmax derivative independently from any loss function?

前提是你 提交于 2019-12-03 02:26:52
For a neural networks library I implemented some activation functions and loss functions and their derivatives. They can be combined arbitrarily and the derivative at the output layers just becomes the product of the loss derivative and the activation derivative. However, I failed to implement the derivative of the Softmax activation function independently from any loss function. Due to the normalization i.e. the denominator in the equation, changing a single input activation changes all output activations and not just one. Here is my Softmax implementation where the derivative fails the

Scheme Derivative Function

拥有回忆 提交于 2019-12-02 08:05:55
问题 I wrote a simple derivative function in scheme today. I was asked to return a function such that g(x) = (f (x+h) -f(x))/h . Does this suffice to return a function or does this only return a value? (define (der f h) (lambda (x) (/ (- (f(+ x h)) (f x)) h))) 回答1: Yes, the code in the question is returning a function (that's what the lambda is for). If it were returning a value , it'd be missing the line with (lambda (x) and the corresponding closing parentheses. Also notice that although the

Directional Derivatives of a Matrix

荒凉一梦 提交于 2019-12-02 05:32:19
问题 I have 40 structures in my Workspace. I Need to write a script to calculate the directional derivatives of all the elements. Here is the code : [dx,dy] = gradient(Structure_element_1.value); dxlb = min(min(dx)); dxub = max(max(dx)); dylb = min(min(dy)); dyub = max(max(dy)); [ddx,ddy] = gradient(gradient(Structure_element_1.value)); ddxlb = min(min(ddx)); ddxub = max(max(ddx)); ddylb = min(min(ddy)); ddyub = max(max(ddy)); This is the code for one element. I Need to find out the same for all

Scheme Derivative Function

对着背影说爱祢 提交于 2019-12-02 04:26:14
I wrote a simple derivative function in scheme today. I was asked to return a function such that g(x) = (f (x+h) -f(x))/h . Does this suffice to return a function or does this only return a value? (define (der f h) (lambda (x) (/ (- (f(+ x h)) (f x)) h))) Yes, the code in the question is returning a function (that's what the lambda is for). If it were returning a value , it'd be missing the line with (lambda (x) and the corresponding closing parentheses. Also notice that although the procedure is correct, the formula stated in the question isn't right, it should be: g(x) = (f(x+h) - f(x))/h ;

LibGDX Path (CatmullRomSpline) Constant Speed

只谈情不闲聊 提交于 2019-12-01 20:40:15
问题 I’m trying to achieve constant speed on a path using the LibGDX CatmullRomSpline and I’m having problems getting it to work. I’ve tried researching on this topic a lot including reading the LibGDX wiki, but their explanation for achieving constant speed doesn’t really make sense and I wasn’t able to get their method to work. https://github.com/libgdx/libgdx/wiki/Path-interface-&-Splines In my case, the derivative values are very large (in the hundreds) so when dividing a number between 0-1 by