diff --git a/S13_math.ipynb b/S13_math.ipynb index 1fcd313d..b0c633d5 100644 --- a/S13_math.ipynb +++ b/S13_math.ipynb @@ -123,9 +123,9 @@ "*Optimization* is the process of finding extremal values of performance criteria, all of which, in this book, will be expressed as scalar-valued functions of a finite number of inputs. In some cases, we search for the single, scalar input that will minimize a cost function, such as when choosing the best action for a trash sorting robot in Chapter 2. In other cases, we might search for a sequence of input commands that will yield an ideal system trajectory, such as for drone flight in Chapter 7. In still other cases, we might try to find millions of weights for a neural network to minimize recognition error of our computer vision system, such as the Convolutional Neural Nets (CNNs) of Chapter 5. \n", "\n", "In general, we can express such problems as\n", - "\n", - "$$\\max_x f(x)$$\n", - "\n", + "$$\n", + "\\max_x f(x)\n", + "$$\n", "in which $x$ is called the optimization variable (or variables in the case where $x$ is a vector) and $f(\\cdot)$ is called the objective function. For this formulation, when maximizing, $f(\\cdot)$ can be thought of as a reward. We could have framed the problem as a minimization, $\\min_x f(x)$, in which case $f(\\cdot)$ should be thought of as a cost to be minimized. It is easy to convert between these two forms (e.g., simply multiply the objective function by $-1$), but it is often helpful to express problems specifically as either minimizing cost or maximizing reward, based on the semantics of the problem." ] }, @@ -134,23 +134,23 @@ "metadata": {}, "source": [ "Many optimization problems can be solved using the method of gradient descent. Such methods construct a sequence of estimates, $x^1, x^2, \\dots$ until a minimal value of cost is found. The incremental update rule for the estimates is given by\n", - "\n", - "$$ x^{k+1} = x^k + \\alpha \\nabla f(x) $$\n", - "\n", + "$$ \n", + "x^{k+1} = x^k + \\alpha \\nabla f(x)\n", + "$$\n", "in which $\\alpha$ is a step-size parameter.\n", "In some cases, the gradient $\\nabla f(x) $ can be computed in closed form, while for more complex functions it may be necessary to use numerical approximations of the gradient.\n", "When working with neural networks, the cost function can be written as a sum\n", - "\n", - "$$ f(x,S) = \\sum_{s\\in S} f_k(x; s) $$\n", - "\n", + "$$\n", + "f(x,S) = \\sum_{s\\in S} f_k(x; s)\n", + "$$\n", "Here, $x$ denotes the weights assigned to the connections in the network, and $s$ denotes a specific example in the data set $S$. Since differentiation is linear, the gradient of this functional can be expressed as \n", - "\n", - "$$ \\nabla_x f(x,S) = \\sum_{s\\in S} \\nabla_x f_k(x; s)$$\n", + "$$ \\nabla_x f(x,S) = \\sum_{s\\in S} \\nabla_x f_k(x; s)\n", + "$$\n", "\n", "If the data set is very large, computing $|S|$ gradients will be prohibitive. The method of stochastic gradient descent deals with this problem by randomly selecting a few samples from the data set, $S' \\subset S$, and using the approximation\n", - "\n", - "$$ \\nabla_x f(x,S) \\approx \\sum_{s \\in S'} \\nabla_x f_k(x; s)$$\n", - "\n", + "$$\n", + "\\nabla_x f(x,S) \\approx \\sum_{s \\in S'} \\nabla_x f_k(x; s)\n", + "$$\n", "We use stochastic gradient descent in chapter 5 to optimize the weights in a deep neural network.\n", "\n", "Quite often in robotics, the optimization variables can be written as $x_1, x_2, \\dots x_n$, in which the subscripts denote discrete instants in time. In this case, there are typically well-defined relationships between each $x_k$ and $x_{k+1}$. This is true, for example, when a robot moves through the world, at each step $k$ executing command $u_k$ and collecting data $z_k$. Estimating the state trajectory $x_1, \\dots, x_n$ can be formulated as an optimization problem in which the value of $u_k$ acts as a kind of constraint on the relationship between $x_k$ and $x_{k+1}$, as we will see in Chapter 4 when we solve the localization problem. Similarly, if we wish to optimize the trajectory of a drone (as in Chapter 7), the optimization problem begins by finding a sequence of states $x_1, \\dots, x_n$ that maximize performance criteria. In this case, in order to ensure smooth flight, $x_k$ and $x_{k+1}$ should not be too far apart. For problems of this sort, when there are specific relationships between the optimization variables, and especially when they enjoy this kind of sequential structure, we can solve the optimization using factor graphs, which are extremely computationally efficient when the graph that encodes variable interdependence is sparse. " diff --git a/S42_logistics_actions.ipynb b/S42_logistics_actions.ipynb index 6d8ce141..f94358c4 100644 --- a/S42_logistics_actions.ipynb +++ b/S42_logistics_actions.ipynb @@ -358,35 +358,25 @@ "\n", "On the other hand, the contact of each wheel must move exactly opposite to the parallel or **driving direction** of the velocity, because it cannot slide in that direction. As a consequence, if the radius of each wheel is $r$, the wheel's angular velocity $\\omega^i$ (i.e., the angular rate at which the wheel spins about its axle)\n", "must satisfy\n", - "\n", - "$$\\omega^i = \\frac{v^i_\\parallel}{r} = \n", + "$$\n", + "\\omega^i = \\frac{v^i_\\parallel}{r} = \n", "\\frac{1}{r} (-\\sin \\theta^i, \\cos \\theta^i) \\begin{pmatrix}v_x \\\\ v_y \\end{pmatrix}\n", "$$\n", - "\n", "Because we have three wheels, we can stack three instances of the above equation\n", "to obtain a matrix equation\n", "that maps a desired robot velocity $v=(v_x,v_y)$ to the appropriate commanded wheel velocities:\n", - "\n", - "\n", "$$\n", "\\begin{pmatrix}\\omega^1 \\\\ \\omega^2 \\\\ \\omega^3 \\end{pmatrix} \n", - "= \\frac{1}{r}\n", - "\\begin{pmatrix}- \\sin\\theta^1 & \\cos\\theta^1 \\\\ - \\sin\\theta^2 & \\cos\\theta^2 \\\\ - \\sin\\theta^3 & \\cos\\theta^3 \n", - "\\end{pmatrix}\n", + "= \\frac{1}{r} \\begin{pmatrix}- \\sin\\theta^1 & \\cos\\theta^1 \\\\ - \\sin\\theta^2 & \\cos\\theta^2 \\\\ - \\sin\\theta^3 & \\cos\\theta^3 \\end{pmatrix}\n", "\\begin{pmatrix}v_x \\\\ v_y \\end{pmatrix}\n", "$$\n", - "\n", "in which the $3\\times2$ matrix is called the **Jacobian matrix**.\n", "\n", "For the three regularly arranged omni wheels with $\\theta^1=0$, $\\theta^2=2\\pi/3$, and $\\theta^3=4\\pi/3$ this becomes\n", - "\n", - "\n", "$$\n", "\\begin{pmatrix}\\omega^1 \\\\ \\omega^2 \\\\ \\omega^3 \\end{pmatrix} \n", - "= \\frac{1}{r}\n", - "\\begin{pmatrix}0 & 1 \\\\ -0.866 & -0.5 \\\\ 0.866 & -0.5 \n", - "\\end{pmatrix}\n", - "\\begin{pmatrix}v_x \\\\ v_y \\end{pmatrix}\n", + "= \\frac{1}{r} \\begin{pmatrix}0 & 1 \\\\ -0.866 & -0.5 \\\\ 0.866 & -0.5 \\end{pmatrix}\n", + "\\begin{pmatrix}v_x \\\\ v_y \\end{pmatrix}.\n", "$$" ] }, diff --git a/S52_diffdrive_actions.ipynb b/S52_diffdrive_actions.ipynb index 580f5ec9..8c064813 100644 --- a/S52_diffdrive_actions.ipynb +++ b/S52_diffdrive_actions.ipynb @@ -252,6 +252,7 @@ "and with respect to the world frame\n", "\n", "$$\n", + "\\begin{align}\n", "v^{\\mathrm{body}}=\n", "\\begin{bmatrix} v_x \\\\ 0 \\\\ \\dot{\\theta} \\end{bmatrix}\n", "=\n", @@ -260,7 +261,7 @@ "v^{\\mathrm{world}}=\n", "\\begin{bmatrix} v_x \\cos \\theta \\\\ v_x \\sin \\theta \\\\ \\dot{\\theta} \\end{bmatrix}\n", "=\\begin{bmatrix} \\frac{r}{2} (\\dot{\\phi}_R + \\dot{\\phi}_L) \\cos\\theta \\\\ \\frac{r}{2} (\\dot{\\phi}_R + \\dot{\\phi}_L) \\sin\\theta \\\\ \\frac{r}{L} (\\dot{\\phi}_R - \\dot{\\phi}_L)\\end{bmatrix}\n", - "\n", + "\\end{align}\n", "$$\n" ] },