### Math fundamentals and Katex

It was really tough for me to understand many articles about data science due to the requirements of understanding mathematics (especially linear algebra). I’ve started to gain some basic knowledges about Math by reading a book first.

The great tool Typora and stackedit with supporting Katex syntax simply helps me to display Math-related symbols.

Let’s start!

The fundamental ideas of mathematics: “doing math” with numbers and functions. Linear algebra: “doing math” with vectors and linear transformations.

### 1. Solving equations

Solving equations means finding the value of the unknown in the equation. To find the solution, we must break the problem down into simpler steps. E.g:

\begin{aligned} x^2 - 4 &= 45\\ x^2 - 4 + 4 &= 45 + 4\\ x^2 &= 49\\ \sqrt{x}&=\sqrt{49}\\ |x| &= 7\\ x=7 &\text{ or } x=-7 \end{aligned}

### 2. Numbers

Definitions
Mathematicians like to classify the different kinds of number-like objects into sets:

• The natural numbers: $N$ = {$0, 1, 2, 3, 4, 5, 6, 7$, … }
• The integer: $Z$ = { … , $-3, -2, -1, 0, 1, 2, 3$, … }
• The rational numbers: $Q$ = {${5}\over{3}$, ${22}\over{7}$, $1.5, 0.125, -7$, … }
• The real numbers: $R$ = {$-1, 0, 1, \sqrt{2}, e, \pi, 4.94...$, … }
• The complex numbers: $C$ = {$-1, 0, 1, i, 1 + i, 2 + 3i$, … }

Operations on numbers

• Addition is commutative and associative. That means:
$a + b = b+ a$
$a + b + c = (a + b) + c = a + (b + c)$
• Subtraction is the inverse operation of addition.
• Multiplication is also commutative and associative.
$ab = \underbrace{a + a + a + ... + a}_{\text{b times}} = \underbrace{b + b + b + ... + b}_{\text{a times}}$
$ab = ba$
$abc = (ab)c = a(bc)$
• Division is the inverse operation of multiplication. You cannot divide by 0.
• Exponentiation is multiplying a number by itself many times.
$a^b = \underbrace{aaa...a}_{\text{b times}}$
$a^{-b} = {{1}\over{a^b}}$
$\sqrt[n]{a} \equiv a^{{1}\over{n}}$

The symbol “$\equiv$” stands for “is equivalent to” and is used when two mathematical object are identical.

### 3. Variables

Variables are placeholder names for any number or unknown. Variable substitution: we can often change variables and replace one unknown variable with another to simplify an equation. For example:

\begin{aligned} {6 \over{5 - \sqrt{x}}} = \sqrt{x}\\ u = \sqrt{x}\\ {6 \over{5 - u}} = u \end{aligned}

### 4. Functions and their inverses

The inverse function $f^{-1}$ performs the opposite action of the function $f$ so together the two functions cancel each other out. For example:

1. $f(x) = c$
2. $f^{-1}(f(x)) = x = f^{-1}(c)$
3. $x=f^{-1}(c)$

Common functions and their inverses:
\begin{aligned} function f(x) &\Leftrightarrow inverse f^{-1}(x)\\ x+2 &\Leftrightarrow x-2\\ 2x &\Leftrightarrow {1\over2}x\\ x^2 &\Leftrightarrow \pm{\sqrt{x}}\\ 2^x &\Leftrightarrow log{_2}(x)\\ 3x + 5 &\Leftrightarrow {1\over 3}(x-5)\\ a^x &\Leftrightarrow log{_a}(x)\\ exp(x) \equiv e^x &\Leftrightarrow ln(x) \equiv log{_e}(x)\\ sin(x) &\Leftrightarrow sin^{-1}(x) \equiv arcsin(x)\\ cos(x) &\Leftrightarrow cos^{-1}(x) \equiv arccos(x) \end{aligned}
The principle of “digging” (Bruce Lee-style) toward the unknown by applying inverse functions is the key for solving all these types of equations, so be sure to practice using it.

### 5. Basic rules of algebra

Given any three numbers a, b, and c we can apply the following algebraic properties:

• Associative property: $a + b + c = (a + b) + c = a + (b+ c)$ and $abc = (ab)c = a(bc)$
• Commutative property: $a + b = b + a$ and $ab = ba$
• Distributive property: $a(b + c)$ = $ab + ac$

Some algebraic tricks are useful when solving equations

• Expanding brackets: $(x + 3)(x +2) = x^2 + 5x + 6$
• Factoring: $2x^2y + 2x + 4x = 2x(xy + 1 + 2) = 2x(xy + 3)$
• Quadratic factoring: $x^2-5x+6=(x-2)(x-3)$
• Completing the square: $Ax^2 + Bx + C = A(x- h)^2 + k$ e.g: $x^2 + 4x + 1 = (x + 2)^2-3$

The solutions to the equation $ax^2 + bx + c =0$ are
$x_1 = {{-b + \sqrt{b^2 - 4ac}}\over{2a}} \quad and \quad x_2 = {{-b -\sqrt{b^2-4ac}}\over{2a}}$
Actually, we can use the technique completing the square to explain this formula.

### 7. The Cartesian plane

Vectors and points

• Point: $P = (P_x, P_y)$. To find this point, start from the origin and move a distance $P_x$ on the x-axis, then move a distance $P_y$ on the y-axis.
• Vector: $\overrightarrow{v} = (v_x, v_y)$. Unlike points, we don’t necessarily start from the plane’s origin when mapping vectors.

Graphs of functions

The Cartesian plane is great for visualizing functions, $f: {R} \rightarrow {R}$

A function as a set of input-output pairs $(x, y) = (x, f(x))$

### 8. Functions

We use functions to describe the relationship between variables.

To “know” a function, you must be able to understand and connect several of its aspects including definition, graph, values and relations.

Definition: $f: A \rightarrow B$. Function is a mapping from numbers to numbers.

• Function composition: $fog(x)\equiv f(g(x)) = z$
• Inverse function: $f^{-1}(f(x)) \equiv f^{-1}o f(x) = x$
• Table of values: $\{(x1, f(x1)), (x2, f(x2)), ...\}$
• Function graph: using the Cartesian plane
• Relations: e.g: $sin^2x + cos^2x = 1$

### 9. Function references

- Line

The equation of a line: $f(x) = mx + b$ and $f^{-1} (x) = {{1\over m} (x-b)}$
The general equation: $Ax + By = C$

- Square/Quadratic: $f(x) = x^2$

- Square root: $f(x) = \sqrt x \equiv x ^{1\over2}$

- Absolute value: $f(x) = |x| = \begin{cases} x &\text{if } x \ge 0, \\ c &\text{if } x \lt 0.\end{cases}$

- Polynomial functions: $f(x) = a_0 + a_1x + a_2x^2 + a_3x^3 + ... + a_nx^n$

- Sine: $f(x) = sin(x)$

- Consine: $f(x) = cos(x) = sin(x + {\pi\over2})$

- Tangent: $f(x) = tan(x) \equiv {sin(x)\over{cos(x)}}$

- Exponential: $f(x) = e^x \equiv exp(x)$

- Natural logarithm: $f(x) = ln(x) = log_e(x)$

- Function transformation

Vertical translation: $g(x) = f(x) + k$

Horizontal translation: $g(x) = f(x-h)$

Veritcal scaling: $g(x) = Af(x)$

Horizontal scaling: $g(x) = f(ax)$

- General quadratic function: $f(x) = A(x-h)^2 + k$

- General sine function: $f(x) = Asin({2\pi\over\lambda}x - \phi)$

### 10. Polynomials

In general, a polynomial of degree $n$ has the equation

$f(x) = a_nx^n + a_{n-1}x^{n-1} + ...+ a_2x^2 + a_1x + a_0 \equiv \displaystyle\sum_{k=0}^na_kx^k$

### 11. Trigonometry

Pythagoras’ theorem
\begin{aligned} |adj|^2 + |opp|^2 &= |hyp|^2\\ {{|adj|^2}\over{|hyp|^2}} + {{|opp|^2}\over{|hyp|^2}} &= 1\\ sin^2(\theta) + cos^2(\theta) &= 1 \end{aligned}

### 12. Trigonometric identities

$sin^2(\theta) + cos^2(\theta) = 1$

$sin(a+ b) = sin(a)cos(b) + sin(b)cos(a)$

$cos(a+b) = cos(a)cos(b) - sin(a)sin(b)$

And, more …

### 13. Geometry

A: area, P: perimeter, V: volume

Triangles: $A = {1\over2}ah_a$, $P = a + b + c$

Sphere: $A=4\pi r^2$, $V={{4\over3}\pi r^3}$

Cylinder: $A = 2(\pi r^2) + (2\pi r)h$, $V = (\pi r^2)h$

### 14. Circle

Radians: $2\pi [rad] = 360^0$

### 15. Sovling systems of linear equations

\begin{aligned} a_1x + b_1y = c1\\ a_2x + b_2y=c_2 \end{aligned}
There are some approaches to sovling it:

• Solving by substitution
• Solving by substraction
• Solving by equating

Reference:
[1]. Ivan Savov, “No bullshit guide to linear algebra”.

1. I like your blog, I read this blog please update more content on python, further check it once at python online training

### Generating PDF/A From HTML in Meteor

My live-chat app was a folk of project Rocket.Chat which was built with Meteor. The app had a feature that administrative users were able to export the conversations into PDF files. And, they wanted to archive these files for a long time.

I happened to know that PDF/A documents were good for this purpose. It was really frustrated to find a solution with free libraries. Actually, it took me more than two weeks to find a possible approach.

TL, DR;
Using Puppeteer to generate a normal PDF and using PDFBox to load and converting the generated PDF into PDF/A compliance.
What is PDF/A? Here is a definition from Wikipedia:
PDF/A is an ISO-standardized version of the Portable Document Format (PDF) specialized for use in the archiving and long-term preservation of electronic documents. PDF/A differs from PDF by prohibiting features unsuitable for long-term archiving, such as font linking (as opposed to font embedding) and encryption. The ISO requirements for PDF/A file viewers include color man…

### Creating a Chatbot with RiveScript in Java

Motivation"Artificial Intelligence (AI) is considered a major innovation that could disrupt many things. Some people even compare it to the Internet. A large investor firm predicted that some AI startups could become the next Apple, Google or Amazon within five years"
- Prof. John Vu, Carnegie Mellon University.

Using chatbots to support our daily tasks is super useful and interesting. In fact, "Jenkins CI, Jira Cloud, and Bitbucket" have been becoming must-have apps in Slack of my team these days.

There are some existing approaches for chatbots including pattern matching, algorithms, and neutral networks. RiveScript is a scripting language using "pattern matching" as a simple and powerful approach for building up a Chabot.
Architecture Actually, it was flexible to choose a programming language for the used Rivescript interpreter like Java, Go, Javascript, Python, and Perl. I went with Java.

Used Technologies and ToolsOracle JDK 1.8.0_151Apache Maven 3.5…

### How to convert time between timezone in Java, Primefaces?

I use the calendar Primefacescomponent with timeOnly and timeZone attributes for using only hour format (HH:mm). Like this:
<p:calendar id="xabsOvertimeTimeFrom" pattern="HH:mm" timeOnly="true" value="#{data.dateFrom}" timeZone="#{data.timeZone}"/> We can convert the value of #{data.dateFrom} from GMT/UTC time zone to local, conversely, from local time zone to GMT/UTC time zone. Here is my functions:
package vn.nvanhuong.timezoneconverter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class TimeZoneConverter { /** * convert a date with hour format (HH:mm) from local time zone to UTC time zone */ public static Date convertHourToUTCTimeZone(Date inputDate) throws ParseException { if(inputDate == null){ return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(inputDate); int hours…

### AngularJS - Build a custom validation directive for using multiple emails in textarea

AngularJS already supports the built-in validation with text input with type email. Something simple likes the following:
<input name="input" ng-model="email.text" required="" type="email" /> <span class="error" ng-show="myForm.input.$error.email"> Not valid email!</span> However, I used a text area and I wanted to enter some email addresses that's saparated by a comma (,). I had a short research and it looked like AngualarJS has not supported this functionality so far. Therefore, I needed to build a custom directive that I could add my own validation functions. My validation was done only on client side, so I used the$validators object.

Note that, there is the $asyncValidators object which handles asynchronous validation, such as making an$http request to the backend.

This is just my implementation on my project. In order to understand that, I supposed you already had experiences with Angular…

### Applying pipeline “tensorflow_embedding” of Rasa NLU

According to this nice article, there was a new pipeline released using a different approach from the standard one (spacy_sklearn). I wanted to give it a try to see whether it can help with improving bot’s accuracy.

After applying done, I gave an evaluation of “tensorflow_embedding”. It seemed to work better a bit. For example, I defined intents “greet” and “goodbye” with some following messages in my training data.
## intent:greet- Hey! How are you? - Hi! How can I help you? - Good to see you! - Nice to see you! - Hi - Hello - Hi there ## intent:goodbye- Bye - Bye Bye - See you later - Take care - Peace In order to play around with Rasa NLU, I created a project here. You can have a look at this change from this pull request. Yay!

When I entered message “hi bot”, then bot with “tensorflow_embedding” could detect intent “greet” with better confidence scores rather than bot with “spacy_sklearn”. The following are responses after executing curl -X POST localhost:5000/parse -d '{&qu…