Functions
Why Use Functions?
- Explain how functions are analogous to data structures in terms of the “nouns” versus “verbs” of programming.
- Give situations when a block of code should be turned into a function.
Function Syntax in R
- State the syntax for defining a function in R using
function()
.
- Given a block of code to turn into a function, produce a function using
function()
.
- State the names for the inputs and outputs of a function in R.
Named Arguments and Default Values
- Include named arguments in a function to pass desired inputs into the function.
- State and use the appropriate operator to bind a function argument when calling a function.
- Include named arguments with default values in a function.
- Call a function using named and unnamed arguments.
- Determine the output of a given function with named or unnamed arguments.
- Use
stopifnot()
to check function arguments for desired / necessary characteristics.
Function Environments and Interfacing with Functions
- Explain the difference between a global environment and local / internal environment in R.
- Describe the rules for how the interval environment of a function interfaces with the global environment.
- Given a block of code including a function definition, describe the values stored in the global and internal environments before, during, and after a function call.
- State the best-practices for interfacing with a function.
Gradient / Steepest Descent
- Explain how to find the minima / maxima of a smooth function of a single variable using calculus.
- Describe the procedure for using gradient descent to find the minima of a function, and relate this to the analogy of walking down a hill when you can only see one step ahead of you at any given time.
- Explain why gradient descent may not find the global minimum of a function when multiple minima exist, and relate this to the hill analogy.
- Explain the rationale for the stopping criteria for gradient descent.
- Implement gradient descent, or some portion of the gradient descent algorithm, as a function in R.