DecodeAI
← Question Bank

Mathematics & Statistics

Calculus and Algorithmic Differentiation

Interview questions on Calculus and Algorithmic Differentiation.

41 questions

General

Q1. Differentiable functions

Sign in to bookmark
  1. What does it mean when a function is differentiable?
  2. Give an example of when a function doesn’t have a derivative at a point.
  3. Give an example of non-differentiable functions that are frequently used in machine learning. How do we do backpropagation if those functions aren’t differentiable?

General

Q2. Convexity

Sign in to bookmark
  1. What does it mean for a function to be convex or concave? Draw it.
  2. Why is convexity desirable in an optimization problem?
  3. Show that the cross-entropy loss function is convex.

General

Q3. 1. Write the formulae for the finite difference rule used in numerical differentiation.

Sign in to bookmark
  1. What is the main problem with this formulae?
  2. Indicate one problem with software tools which utilize numerical differentiation and successive operations on floating point numbers.

General

Q4. 1. Given a function $f(x)$ and a point a, define the instantaneous rate of change of $f(x)$ at $a$.

Sign in to bookmark
  1. What other commonly used alternative name does the instantaneous rate of change have?
  2. Given a function f(x)f (x) and a point a, define the tangent line of f(x)f (x) at a.

General

Q5. 1. State the definition of the derivative $f(c)$ of a function $f(x)$ at $x = c$.

Sign in to bookmark
  1. With respect to the DAG depicted in 5.3:

General

Q6. 1. With respect to the expression graph depicted in 5.4, traverse the graph and find the function g(x) it represents.

Sign in to bookmark

General

Q7. 1. The chain rule is key concept in differentiation. Define it.

Sign in to bookmark
  1. Elaborate how the chain rule is utilized in the context of neural networks.

General

Q8. Find the Taylor series expansion for:

Sign in to bookmark
  1. 11x\frac{1}{1-x}2.exe^x3.sin(x) sin(x)4.cos(x) cos(x)

General

Q9. Find the Taylor series expansion for: (Part 2)

Sign in to bookmark

log(x)\log(x)

General

Q10. Find the Taylor series expansion centered at $x = −3$ for:

Sign in to bookmark

f(x)=5x211x+1f(x) = 5x^2 − 11x + 1

General

Q11. Find the $101th$ degree Taylor polynomial centered at $x = 0$ for:

Sign in to bookmark

f(x)=cos(x)f(x) = cos(x)

General

Q12. At $x = 1 $, compute the first$7$ terms of the Taylor series expansion of:

Sign in to bookmark

f(x)=ln3x.f (x) = ln 3x.

General

Q13. Find the following limits:

Sign in to bookmark
  1. limx3ex3e273x9\lim_{{x \to 3}}\frac{e^{x^3} - e^{27}}{3x - 9}2. limx0ex2x13cosxx3\lim_{{x \to 0}}\frac{e^{x^2} - x - 1}{3\cos x-x - 3}3. limxinfxlnxx1/100+4\lim_{{x \to \inf}}\frac{x - ln x}{x^{1/100} + 4}

General

Q14. 1. True or false: When applying a partial derivative, there are two variables considered constants - the dependent and independent variable.

Sign in to bookmark
  1. Given g(x,y)g(x, y), find its partial derivative with respect to x: g(x,y)=x2y+yx+8yg(x,y) = x^2y + yx + 8y

General

Q15. How can we use the Hessian (second derivative matrix) to test for critical points?

Sign in to bookmark

General

Q16. The gradient of a two-dimensional function is given by

Sign in to bookmark

f(x,y)=fxi+fyj∇f (x, y) = \frac{∂f}{∂x} i + \frac{∂f}{∂y}j

  1. Find the gradient of the function:f(x,y)=xy2y2+x3f(x, y) = xy^2 - y^2 + x^32. Given the function: g(x,y)=xy2y1g(x, y) = xy^2 − y − 1 evaluate it at (1,0)(−1, 0), directed at (1,1)(1, 1).

General

Q17. Find the partial derivatives of:

Sign in to bookmark

f(x,y)=3sin2(xy)f(x, y) = 3 sin^2(x − y)

General

Q18. Find the partial derivatives of: (Part 2)

Sign in to bookmark

z=2sin(x)sin(y)z = 2 sin(x) sin(y)

General

Q19. Consider $f(x) = \frac{x^2 + 1}{(x+2)^2}$1. Where is$ f(x)$ well defined?

Sign in to bookmark
  1. Where is f(x)f(x) increasing and decreasing? 3. Where is f(x)f(x) reaching minimum and maximum values.

General

Q20. Consider $f(x) = 2x^3 − x $1. Derive$ f (x)$ and conclude on its behavior.

Sign in to bookmark
  1. Derive once again and discuss the concavity of the function f(x)f (x).

General

Q21. Consider the function

Sign in to bookmark

f(x,y)=2x2xy+y2f(x,y)=2x^2 −xy + y^2 and find maximum, minimum, and saddle points.

General

Q22. The gradient descent algorithm can be utilized for the minimization of convex functions.

Sign in to bookmark

Stationary points are required in order to minimize a convex function. A very simple approach for finding stationary points is to start at an arbitrary point, and move along the gradient at that point towards the next point, and repeat until converging to a stationary point.

  1. What is the term used to describe the vector of all partial derivatives for a function f(x)f(x)?
  2. Complete the sentence: when searching for a minima, if the derivative is positive, the function is increasing/decreasing.
  3. The function x2x^2 as depicted in 5.5, has a derivative of f(x)=2xf′(x) = 2x. Evaluated atx=1x = −1, the derivative equalsf(x=1)=2f′(x = −1) = −2.Atx=1At x = −1, the function is decreasing asxxgets larger. We will happen if we wish to find a minima using gradient descent, and increase (decrease)x x by the size of the gradient, and then again repeatedly keep jumping?

General

Q24. Let $x∈R_n $,$ L=cross entropy(softmax(x),y)$in which$ y $is a one-hot vector. Take the derivative of$ L $with respect to$ x$.

Sign in to bookmark

General

Q25. Given the function $f(x,y)=4x^2−y$ with the constraint $x^2+y^2=1$. Find the function’s maximum and minimum values.

Sign in to bookmark

General

Q26. Given a logistic discriminant classifier:

Sign in to bookmark

p(y=1x)=σ(wTx)p(y=1|x)=σ(w^Tx) where the sigmoid function is given by: σ(z)=(1+exp(z))1σ(z)=(1+exp(−z))^{−1} The logistic loss for a training sample xix_i with class label yiy_i is given by L(yi,xi;w)=logp(yixi)L(yi,xi;w)=−logp(y_i|x_i)1. Show thatp(y=1x)=σ(wTx) p(y=−1|x)=σ(−w^Tx).

  1. Show that ΔwL(yi,xi;w)=yi(1p(yixi))xiΔ_wL(y_i,x_i;w)=−y_i(1−p(y_i|x_i))x_i.
  2. Show that ΔwL(yi,xi;w)Δ_wL(y_i,x_i;w) is convex.

General

Q27. Most ML algorithms we use nowadays use first-order derivatives (gradients) to construct the next training iteration.

Sign in to bookmark
  1. How can we use second-order derivatives for training models?
  2. Pros and cons of second-order optimization.
  3. Why don’t we see more second-order optimization in practice?

General

Q28. 1. During the training of an ANN, a sigmoid layer applies the sigmoid function to every element in the forward pass, while in the backward pass the chain rule is being utilized as part of the backpropagation algorithm. With respect to the backpropagation algorithm, given a sigmoid $σ(x) = \frac{e^x}{1+e^x}$ activation function, and a J as the cost function, annotate each part of equation (5.21):

Sign in to bookmark

dZ=dJdσ(x)dσ(x)dx=dAσ(x).(1σ(x))dZ = \frac{dJ}{dσ(x)}\frac{dσ(x)}{dx} = dA·σ(x).(1−σ(x)) 2. Code snippet 5.6 provides a pure Python-based (e.g. not using Autograd) implementation of the forward pass for the sigmoid function. Complete the backward pass that directly computes the analytical gradients. python class Sigmoid: def forward(self,x): self.x = x return 1/(1+np.exp(-x)) def backward(self, grad): grad_input = [???] return grad_input

General

Q29. This question deals with the effect of customized transfer functions. Consider a neural network with hidden units that use $x^3$ and output units that use $sin(2x)$ as transfer functions. Using the chain rule, starting from $∂E/∂yk$, derive the formulas for the weight updates $∆w_{jk}$ and $∆w_{ij}$. Notice - do not include partial derivatives in your final answer.

Sign in to bookmark

General

Q30. 1. **True or false**: InAutograd if any input tensor of an operation has *requires_grad=True*, the computation will be tracked. After computing the backward pass, a gradient w.r.t. this tensor is accumulated into *.grad* attribute

Sign in to bookmark
  1. True or false: In Autograd, multiple calls to backward will sum up previously computed gradients if they are not zeroed.

General

Q31. Your friend, a veteran of the DL community wants to use logistic regression and implement custom activation functions using Autograd. Logistic regression is used when the variable y that we want to predict can only take on discrete values (i.e. classification). Considering a binary classification problem (y = 0 or y = 1), the hypothesis function could be defined so that it is bounded between [0, 1] in which we use some form of logistic function, such as the sigmoid function. Other, more efficient functions exist such as the ReLU (Rectified Linear Unit) which we discussed later. Note: The weights in (5.8) are only meant for illustration purposes and are not part of the solution.

Sign in to bookmark

General

Q32. For real values, $−1 < x < 1$ the hyperbolic tangent function is defined as:

Sign in to bookmark

tanh1(x)=12[ln(1+x)ln(1x)]\tanh^{-1}(x) = \frac{1}{2}[\ln(1+x) - ln(1-x)] On the other hand, the artanhartanh function, which returns the inverse hyperbolic tangent of its argument x, is implemented in numpy as arctanh()arctanh(). Its derivative is given by: (arctanh(x))=11x2(arctanh(x))′ = \frac{1}{1 − x^2} Your friend, a veteran of the DL community wants to implement a custom activation function for the arctanharctanh function using Autograd. Help him in realize the method.

  1. Use this numpy array as an input [[0.37,0.192,0.571]][[0.37, 0.192, 0.571]] and evaluate the result using pure Python.
  2. Use the PyTorch based torch.autograd.Functiontorch.autograd.Function class to implement a custom Function that implements the forward pass for the arctanh function in Python.
  3. Use the PyTorch based torch.autograd.Functiontorch.autograd.Function class to implement a custom Function that implements the backward pass for the arctanh function in Python.
  4. Name the class ArtanhFunction,and using the grad check method from torch.autogradtorch.autograd , verify that your numerical values equate the analytical values calculated by gradcheck. Remember you must implement a method entitled.apply(x).apply(x) so that the function can be invoked by Autograd.

General

Q33. 1. Explain how AD uses floating point numerical rather than symbolic expressions.

Sign in to bookmark
  1. Explain the notion of DN as introduced by ([2]).
  2. What arithmetic operations are possible on DN?.
  3. Explain the relationship between a Taylor series and DN.

General

Q34. 1. Expand the following function using DN:

Sign in to bookmark

sin(x+x˙d)\sin(x + \dot{x}d) 2. With respect to the expression graph depicted in 5.9:

General

Q35. With respect to the expression graph depicted in 5.10:

Sign in to bookmark

General

Q36. When differentiating a function using forward-mode AD, the computation of such an expression can be computed from its corresponding directed a-cyclical graph by propagating the numerical values.

Sign in to bookmark
  1. Find the function, g(A,B,C)g(A, B, C) represented by the expression graph in 5.11.

General

Q37. Answer the following given that a computational graph of a function has N inputs and

Sign in to bookmark

M outputs.

  1. True or False? (a) Forward and reverse mode AD always yield the same result. (b) In reverse mode AD there are fewer operations (time) and less space for intermediates (memory). (c) The cost for forward mode grows with N. (d) The cost for reverse mode grows with M.

General

Q38. 1. Given the function:

Sign in to bookmark

f(x1,x2)=x1x2+ln(x1)f (x1, x2) = x1x2 + ln (x1) and the graph 5.1, annotate each vertex (edge) of the graph with the partial derivatives that would be propagated in forward mode AD. 2. Transform the graph into a table that computes the function: g(x1,x2)g(x1, x2) evaluated at (x1;x2)=(e2;π)(x1; x2) = (e^2; π) using forward-mode AD. 3. Write and run a Python code snippet to prove your results are correct. 4. Describe the role of seed values in forward-mode AD. 5. Transform the graph into a table that computes the derivative of g(x1,x2)g(x1,x2) evaluated at (x1;x2)=(e2;π)(x1; x2) = (e^2; π) using forward-mode AD for x1x1 as the chosen independent variable. 6. Write and run a Python code snippet to prove your results are correct.

General

Q39. Answer the following questions:

Sign in to bookmark
  1. Which differentiation method is inherently prone to rounding errors?
  2. Define the term symbolic differentiation.

General

Q40. Answer the following questions: (Part 2)

Sign in to bookmark
  1. Implement the sigmoid function σ(x)=1σ(x) = 1 symbolically using a Python based 1+e−x SymPy program.
  2. Differentiate the sigmoid function using SymPy and compare it with the analytical derivation σ(x)=σ(x)(1σ(x))σ′(x) = σ(x)(1 − σ(x)) .
  3. Using SymPy, evaluate the gradient of the sigmoid function at x=0x = 0.
  4. Using SymPy, plot the resulting gradient of the sigmoid function.

General

Q41. You will most likely not be given such a long programming task during a face-to-face interview. Nevertheless, an extensive home programming assignment is typically given at many of the start-ups I am familiar with. You should allocate around approximately four to six hours to completely answer all questions in this problem.

Sign in to bookmark

We discussed the Beta-Binomial model extensively in chapter 3. Recall that the Beta- Binomial distribution is frequently used in Bayesian statistics to model the number of suc- cesses in n trials. We now employ SymPy to do the same; demonstrate computationally how a prior distribution is updated to develop into a posterior distribution after observing the data via the relationship of the Beta-Binomial distribution. Provided the probability of success, the number of successes after n trials follows a binomial distribution. Note that the beta distribution is a conjugate prior for the parameter of the binomial distribution. In this case, the likelihood function is binomial, and a beta prior distribution yields a beta posterior distribution. Recall that for the Beta-Binomial distribution the following relationships exist: (5.27)