In this post we describe important characteristics of the hyperplane including the concept of the direction of steepest ascent. These concepts are fundamental to the notion of mult-input derivatives (the gradient), gradient descent, as well as linear regression and classification schemes.
Press the button 'Toggle code' below to toggle code on and off for entire this presentation.
from IPython.display import display
from IPython.display import HTML
import IPython.core.display as di # Example: di.display_html('<h3>%s:</h3>' % str, raw=True)
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
In this Section we describe how to construct complex hyperplanes from relatively simple parts. Along the way we will also see several important concepts - most notably the idea of the direction of steepest ascent arisess naturally from the notion of slope.
The formula for a line
\begin{equation} g(w) = a + bw \end{equation}$a$ = point at which it strikes or intersects the vertical axis
$b$ = and the steepness or slope of that line
# create two quadratic functions
func1 = lambda w: 2*w
func2 = lambda w: -w + 2
# use custom plotter to show both functions
title1 = '$g(w)=$2 + 3w$'; title2 = '$g(w)=$-w$';
callib.plotter.double_2d_plot(func1 = func1, func2 = func2,title1 = title1,title2=title2,fontsize = 13,color = 'lime')
# animate 2d slope visualizer
func = lambda w: 2 + 3*w
callib.slope_visualizer.animate_visualize2d(func = func,num_frames = 50)
# plot a single input quadratic in both two and three dimensions
func1 = lambda w: 2-2*w
func2 = lambda w: 2-2*w[0]
# use custom plotter to show both functions
title1 = '$g(w)=$2-2w$'; title2 = '$g(w_1,w_2)=2-2w_1$';
callib.plotter.double_2d3d_plot(func1 = func1, func2 = func2,title1 = title1,title2=title2,fontsize = 18,color = 'lime')
# define hyperplane
func = lambda w: 2-2*w[0]
# animate 2d slope visualizer
callib.slope_visualizer.animate_visualize3d(func=func,num_frames=50)
one along each input dimension.
For example, below we plot the following single input hyperplanes
\begin{array} \ g_1(w_1,w_2) = 1-2w_1 \\ g_2(w_1,w_2) = 1 + 2w_2 \\ \end{array}as well as their sum $g(w_1,w_2) = 2 - 2w_1 + 2w_2$
# plot a single input quadratic in both two and three dimensions
func1 = lambda w: 1 + 2*w[0]
func2 = lambda w: 1 - 2*w[1]
func3 = lambda w: 2 + 2*w[0] -2*w[1]
# use custom plotter to show both functions
view = [25,-50]
callib.slope_visualizer.visualize3d(func1 = func1,func2=func2,func3=func3,view = view)
# define hyperplane
func = lambda w: 2 -2*w[0] - 2*w[1]
# animate 2d slope visualizer
callib.slope_visualizer.animate_visualize3d(func=func,num_frames=50)