derivative

Is there a vectorized way to calculate the gradient in sympy?

自古美人都是妖i 提交于 2019-12-22 04:04:14
问题 How does one calculate the (symbolic) gradient of a multivariate function in sympy? Obviously I could calculate separately the derivative for each variable, but is there a vectorized operation that does this? For example m=sympy.Matrix(sympy.symbols('a b c d')) Now for i=0..3 I can do: sympy.diff(np.sum(m*m.T),m[i]) which will work, but I rather do something like: sympy.diff(np.sum(m*m.T),m) Which does not work ("AttributeError: ImmutableMatrix has no attribute _diff_wrt"). 回答1: Just use a

Calculate the derivative of a data-function in r

不想你离开。 提交于 2019-12-21 05:30:29
问题 Is there an easy way to calculate the derivative of non-liner functions that are give by data? for example: x = 1 / c(1000:1) y = x^-1.5 ycs = cumsum(y) plot (x, ycs, log="xy") How can I calculate the derivative function from the function given by ´x´ and ´ycs´? 回答1: Was also going to suggest an example of a smoothed spline fit followed by prediction of the derivative. In this case, the results are very similar to the diff calculation described by @dbaupp: spl <- smooth.spline(x, y=ycs) pred

calculating the Gradient and the Hessian in R

烈酒焚心 提交于 2019-12-21 02:50:06
问题 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

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

最后都变了- 提交于 2019-12-20 12:19:14
问题 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

List of activation functions in C#

↘锁芯ラ 提交于 2019-12-20 10:49:09
问题 I can find a list of activation functions in math but not in code. So i guess this would be the right place for such a list in code if there ever should be one. starting with the translation of the algorithms in these 2 links: https://en.wikipedia.org/wiki/Activation_function https://stats.stackexchange.com/questions/115258/comprehensive-list-of-activation-functions-in-neural-networks-with-pros-cons the goal is to have an Activation class (with the functions and their derivative) with easy

Saving derivative values in ode45 in Matlab

╄→гoц情女王★ 提交于 2019-12-19 10:26:34
问题 I'm simulating equations of motion for a (somewhat odd) system with mass-springs and double pendulum, for which I have a mass matrix and function f(x), and call ode45 to solve M*x' = f(x,t); I have 5 state variables, q= [ QDot, phi, phiDot, r, rDot]'; (removed Q because nothing depends on it, QDot is current.) Now, to calculate some forces, I would like to also save the calculated values of rDotDot, which ode45 calculates for each integration step, however ode45 doesn't give this back. I've

Explanation of dFdx

江枫思渺然 提交于 2019-12-18 10:19:50
问题 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

Function for polynomials of arbitrary order (symbolic method preferred)

ぃ、小莉子 提交于 2019-12-17 20:14:22
问题 I've found polynomial coefficients from my data: R <- c(0.256,0.512,0.768,1.024,1.28,1.437,1.594,1.72,1.846,1.972,2.098,2.4029) Ic <- c(1.78,1.71,1.57,1.44,1.25,1.02,0.87,0.68,0.54,0.38,0.26,0.17) NN <- 3 ft <- lm(Ic ~ poly(R, NN, raw = TRUE)) pc <- coef(ft) So I can create a polynomial function: f1 <- function(x) pc[1] + pc[2] * x + pc[3] * x ^ 2 + pc[4] * x ^ 3 And for example, take a derivative: g1 <- Deriv(f1) How to create a universal function so that it doesn't have to be rewritten for

How does the sgolay function work in Matlab R2013a?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 02:07:32
问题 I have a question about the sgolay function in Matlab R2013a. My database has 165 spectra with 2884 variables and I would like to take the first and second derivatives of them. How might I define the inputs K and F to sgolay ? Below is an example: sgolay is used to smooth a noisy sinusoid and compare the resulting first and second derivatives to the first and second derivatives computed using diff . Notice how using diff amplifies the noise and generates useless results. K = 4; % Order of

Derivative in MATLAB gui?

柔情痞子 提交于 2019-12-13 05:08:46
问题 I'm trying to calculate the derivative of a an edit text box (edit1) and display the answer in a static text box (text1). But it is just displaying numbers. What am I doing wrong? % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) x=-10:.1:10; equation = get(handles