- Google Colab - Discussion
- Google Colab - Useful Resources
- Google Colab - Quick Guide
- Google Colab - Conclusion
- Google Colab - Using Free GPU
- Google Colab - Installing ML Libraries
- Google Colab - Adding Forms
- Google Colab - Magics
- Google Colab - Code Editing Help
- Google Colab - Graphical Outputs
- Executing External Python Files
- Invoking System Commands
- Google Colab - Sharing Notebook
- Google Colab - Saving Your Work
- Documenting Your Code
- Your First Colab Notebook
- What is Google Colab?
- Google Colab - Introduction
- Google Colab - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Google Colab - Documenting Your Code
As the code cell supports full Python syntax, you may use Python comments in the code window to describe your code. However, many a time you need more than a simple text based comments to illustrate the ML algorithms. ML heavily uses mathematics and to explain those terms and equations to your readers you need an editor that supports LaTex - a language for mathematical representations. Colab provides Text Cells for this purpose.
A text cell containing few mathematical equations typically used in ML is shown in the screenshot below −
As we move ahead in this chapter, we will see the code for generating the above output.
Text Cells are formatted using markdown - a simple markup language. Let us now see you how to add text cells to your notebook and add to it some text containing mathematical equations.
Markdown Examples
Let us look into few examples of markup language syntax to demonstrate its capabipties.
Type in the following text in the Text cell.
This is **bold**. This is *itapc*. This is ~strikethrough~.
The output of the above commands is rendered on the right hand side of the Cell as shown here.
Mathematical Equations
Add a Text Cell to your notebook and enter the following markdown syntax in the text window −
$sqrt{3x-1}+(1+x)^2$
You will see the immediate rendering of the markdown code in the right hand side panel of the text cell. This is shown in the screenshot below −
Hit Enter and the markdown code disappears from the text cell and only the rendered output is shown.
Let us try another more comppcated equation as shown here −
$e^x = sum_{i = 0}^infty frac{1}{i!}x^i$
The rendered output is shown here for your quick reference.
Code for Sample Equations
Here is the code for the sample equations shown in an earper screenshot −
Constraints are - $3x_1 + 6x_2 + x_3 =< 28$ - $7x_1 + 3x_2 + 2x_3 =< 37$ - $4x_1 + 5x_2 + 2x_3 =< 19$ - $x_1,x_2,x_3 >=0 $ The trial vector is calculated as follows: - $u_i(t) = x_i(t) + eta(hat{x}(t) − x_i(t)) + eta sum_{k = 1}^{n_v}(x_{i1,k}(t) − x_{i2,k}(t))$ $f(x_1, x_2) = 20 + e - 20exp(-0.2 sqrt {frac {1}{n} (x_1^2 + x_2^2)}) - exp (frac {1}{n}(cos(2pi x_1) + cos(2pi x_2))$ $x ∈ [-5, 5]$ >$A_{m,n} = egin{pmatrix} a_{1,1} > a_{1,2} > cdots > a_{1,n} \ a_{2,1} > a_{2,2} > cdots > a_{2,n} \ vdots > vdots > ddots > vdots \ a_{m,1} > a_{m,2} > cdots > a_{m,n} end{pmatrix}$
Describing full markup syntax is beyond the scope of this tutorial. In the next chapter, we will see how to save your work.
Advertisements