How to compute the partial derivative

2 visualizzazioni (ultimi 30 giorni)
Kumar Thapa
Kumar Thapa il 22 Ott 2019
Commentato: Kumar Thapa il 22 Ott 2019
Compute the partial derivative of the following loss function with respect to θj:
J(θ0, θ1, θ2) = -1/m sum_{i = 1}^m [y(i) * log(hθ(x(i))) + (1 - y(i)) log(1 - hθ(x(i)))],
where hθ(x) = 1/(1 + exp(-(θ0 + θ1 x1 + θ2 x2)).
  2 Commenti
KALYAN ACHARJYA
KALYAN ACHARJYA il 22 Ott 2019
Define variables as syms and do diff respectively
Kumar Thapa
Kumar Thapa il 22 Ott 2019
sysm x1 x2 theta0 theta1 theta2 y
h(theta0, theta1, theta2) = 1/(1+exp(-(theta0 + theta1*x1 + theta2*x2)));
I dont know how to differentiate it using this :
diff(function, var).

Accedi per commentare.

Risposta accettata

Jon
Jon il 22 Ott 2019
As @Kalyan suggested you could use the symbolic toolbox if you have it. Otherwise you could just go to the definition of a partial derivative. Evaluate your function to quantify how much it changes when you make small perturbations to the variable you are taking the derivative with respect to. Then the partial derivative is the small change in the function divided by the small change to the input variable. You have to be careful though on the size of the perturbation, too small and the round off causes problems, too big and it isn't a very good approximation. Maybe plot your estimate of your derivative versus perturbation size to get an idea of the behavior. Hopefully has a relatively stable plateau between too small and too big.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by