Non-integer numbers conversion - Computational mathematics - UoL

 

Non-integer numbers conversion



$ 17.375_{10} = 1 \cdot 10^1 + 7 \cdot 10^0 + 3 \cdot 10^{-1} + 7 \cdot 10^{-2} + 5 \cdot 10^{-3} \\
                         = 10 + 7 + \frac{3}{10} + \frac{7}{100} + \frac{5}{1000} $


As an Amazon Associate I earn from qualifying purchases.

Choosing between MacOS iMovie (free) and Final Cut Pro ($299)

Choosing between MacOS iMovie (free) and Final Cut Pro ($299) 










As an Amazon Associate I earn from qualifying purchases.

Set Theory - Discrete Mathematics

 

Set Theory - Introduction to discrete mathematics


integers, propositions, sets, relations, and functions, which are all discrete.


the fundamental concept of sets, functions, logic, graphs, trees, relations,
combinatorics, mathematical induction, and recursive relations.

Syllabus




Webinar

Review before the midterm and final exam!






What is the definition of Sets?



A set is a collection of distinct items. Sets are used to study a relation between object members in a particular domain. [reference 1]


Set theory is a branch of mathematics that deals with properties of well-defined
collection of objects. 

Mathematicians use, the term is set to refer to a well-defined, unorderedcollection of any kind of object, duplicates are allowed.

The empty set is a set that contains nothing.


Examples

vowels V = {a,e,i,o,u}
empty set E = {} = $ \emptyset $ or $ \varnothing $

Set notation
  • an element of a set
    • belongs in $ \in $
    • not belong in $ \notin $
  • the cardinality of a set
    • Definition: Given a set S, the cardinality of S is the number of elements contained in S. We write the cardinality of S as |S|.
    • Given V = {a,e,i,o,u}; |V| = 5
    • |E| = |{}| = $ | \emptyset | $  = $ | \varnothing | $ = 0

Subset


Definition:
    • A is a subset of B if every element of A also belongs to B.
      • A is also an element of B.  $ A \subseteq B $
      • subset \subset
      • not subset equal $ \not \subseteq$
      • subset not equal $ \subsetneqq $
      • subset not equal $ \subsetneq $
      • if V = {a,e,i,o,u} AND W={u,w}$ \implies W \subsetneq V $
$$ A \subseteq B \iff x \in A \ \implies \ x \in B $$
for any x of A
A is a subset of B if and only if any x belonging to A implies that x also belongs to B.


An empty set is a subset of ANY set A

Empty = {} = $ \emptyset $ or $ \varnothing $

$ \varnothing \subseteq A $ 
$ \varnothing \subseteq  \varnothing $

Any set is a subset of itself:

$ S \subseteq  S $

  • Special sets
    • N all natural numbers N = {1,2,3,..., \infty}
    • Z all integers $ \mathbb{Z} $ = {..., -3,-2,-1,0, 1,2,...}
      • The notation $ \mathbb{Z} $ for the set of integers comes from the German word Zahlen, which means "numbers".
      • positive integers < 4 = {2}
    • Q all rational numbers such as a/b where $ b \neq 0$
      • $ Q = \{ \frac{n}{m} | n,m \in \mathbb{R} \ and \  m \ne 0  \} $
    • R or $ \mathbb{R} $ all real numbers
In mathematics, a real number $ \mathbb{R} $ is a value of a continuous quantity that can represent a distance along a line (or alternatively, a quantity that can be represented as an infinite decimal expansion). [reference 2]

$$ \therefore N \subseteq Z \subseteq Q \subseteq \mathbb{R} $$







The listing method and rule of inclusion




  • Set representation
    • Listing method
      • list all elements of the set
        • V = {a,e,i,o,u}
    • Set builder notation
      • example $ Even = \{ 2n | n \in \mathbb{R} \} $ 
      • example $ Odd = \{ 2n+1 | n \in \mathbb{R} \} $ 
      • Q all rational numbers = $ Q = \{ \frac{n}{m} | n,m \in \mathbb{R} \ and \  m \ne 0  \} $



Examples

$ S_1 = \{ 3n | x \in \mathbb{N} \ and \ n < 6 \} \implies $ 
$ S_1 = \{ 3*1, 3*2, 3*3, 3*4, 3*5 \} \implies  $
$ S_1 = \{ 3, 6, 9, 12, 14 \}  $


$ S_2 = \{ 2^n | n \in \mathbb{Z} \ and \ 0 \le n \le 4 \} \implies $ 
$ S_2 = \{ 2^0, 2^1, 2^2, 2^3, 2^4 \} \implies  $
$ S_2 = \{ 1, 2, 4, 8, 16 \}  $

Important:
$ S_3 = \{ 2^{-n} | n \in \mathbb{Z} \ and \ 0 \le n < 5 \} \implies $ 
$ S_3 = \{ 2^0, 2^{-1}, 2^{-2}, 2^{-3}, 2^{-4} \} \implies  $
$ S_3 = \{ 1, \frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16} \}  $

$ S_4 = \{ \frac{1}{2}, \frac{1}{4}, \frac{1}{6}, \frac{1}{8},  \frac{1}{10} \}  \implies $
$ S_4 = \{ \frac{1}{2*1}, \frac{1}{2*2}, \frac{1}{2*3}, \frac{1}{2*4} , \frac{1}{2*5} \}  \implies $
$ S_3 = \{ \frac{1}{2*N} | n \in \mathbb{Z} \ and \ 1 \le n \le 5 \}  $ 













The powerset of a set









A = {1, 2, 3, 4, 5, 6, 7, 8, 9}
B = {
         {1, 2, 3, 4}
         {5, 6,} 
         {7, 8, 9}
}
X = {1, 2, 3, 4}
$ X \subseteq A, \ but \ X \in B $
Read: X is a subset of A, but it is an element of B.

Set S is not an element of S:
$ S = \{1\} \notin S $

An empty set is not an element of the empty set:
$ \varnothing \notin \{\} $
An empty set is a subset of the empty set:
$ \{\} = \varnothing \subseteq \varnothing $


  • The power set of the set
    • definition:
      • Given a set S, the powerset of S, written P(S),
        is the set containing ALL the subsets of S.
      • Given S = {1, 2, 3}
        • all subsets:
          • {}
          • {1}, {2},{3}
          • {1,2},{1,3},{2,3}
          • {1,2,3}
        • then P(S)={{},{1}, {2},{3},{1,2},{1,3},{2,3},{1,2,3}}






Cardinality

see reference #3

given a set S={1, 2, 3}, 
  • then P(S) = $ 2^{|S|} $
  • P(S)={{},{1}, {2},{3},{1,2},{1,3},{2,3},{1,2,3}}
  • |P(S)| = 2^{|S|} = $ 2^3 = 8  $


Given a set A, if |A| = n, find |P(P(P(A)))| :
  • $ |P(A)| = 2^{|A|} = 2^n $
  • $ |P(P(A))| = 2^{|P(A)|} = 2^{2^n} $
  • $ |P(P(P(A)))| = 2^{|P(P(A))|} = 2^{2^{2^{n}}} $


Powers of 2

$ 2^0 = 1 $
$ 2^1 = 2 $
$ 2^2 = 4 $
$ 2^3 = 8 $
$ 2^4 = 16 $
$ 2^5 = 32 $
$ 2^6 = 64 $
$ 2^7 = 128 $
$ 2^8 = 256 $
$ 2^9 = 512 $
$ 2^{10} = 1,024 $
$ 2^{11} = 2,048 $
$ 2^{12} = 4,096 $
$ 2^{13} = 8,192 $
$ 2^{14} = 16,384 $
$ 2^{15} = 32,768 $
$ 2^{16} = 65,536 $
$ 2^{17} = 131,072 $
$ 2^{18} = 262,144 $
$ 2^{19} = 524,288 $
$ 2^{20} = 1,048,576 $


Example: 
Given a set A with 12 elements( |A| ). 
What is the number of elements (cardinality) in a powerset P(A)?

n = 12
$ |P(A)| = 2^{|A|} = 2^n = 2^{12} = 4096 $


Set Operations


Disjointed Sets (nothing in common)


Definition: 

Two sets are disjointed if the intersection is zero.

$$ A \cap B = \varnothing $$ 


Set Union (all together)

Definition: 
Given two sets A and B,
the union of A and B, written $ A \cup B $,
contains all the elements in either A or B.

$$ A \cup B = \{x | x \in A \ or \ x \in B \} $$

A = {1, 3, 5}
B = {3, 4, 6}
$ A \cup B $ = {1, 2, 3, 4, 5, 6}


Set Intersection (common)


Definition:
Given two sets A and B,
the intersection of A and B, written $ A \cap B $,
contains all the elements in both A and B.

$$ A \cap B = \{ x | x \in A \ and \ x \in B \} $$

A = {1, 2, 3}
B = { 3, 5, 6}
$ A \cap B $ = {3}




Set Difference (one but not the other)

Definition:
Given two sets A and B,
the set difference, written $ A - B $,
contains all the elements that are in A, but not in B.

$$ A - B = \{ x | x \in A \ and \ x \notin B \} $$

A = {1, 2, 3}
B = { 3, 5, 6}
$ A \cap B $ = {1, 2}

LaTeX \setminus == "$ \setminus $" 

Symmetric difference (owned separately)


Definition:
Given two sets A and B,
the symmetric difference, written $ A \oplus B $,
contains all the elements that are in A or in B, but not in both.

$$ A \oplus B = \{ x | ( x \in A \ or \ x \in B ) \ and \ x \notin A \cap B  \} $$

$$ A \oplus B =  ( A \cup B ) - ( A \cap B ) $$

A = {1, 2, 3}
B = { 3, 5, 6}
$ A \cap B $ = {3}
$ A - B $ = {1, 2}
$ B - A $ = {5, 6}
$ A \oplus B $ = (A-B) + (B-A)
$ A \oplus B $ = {1, 2, 5, 6}


LaTeX symbol substitutes for symmetric difference (see reference 4):
  • A \oplus B == "$ A \oplus B $"
  • A \triangle B == "$ A \triangle B $"
  • A \Theta B == "$ A  \Theta B $"
  • A \triangledown B  == "$ A \triangledown B $"





Membership Table














Disjoint Sets

See reference 5.
In mathematics, two sets are said to be disjoint sets if they have no element in common.
Equivalently, two disjoint sets are sets whose intersection is the empty set

For example, 
A = {1, 2, 3} and 
B = {4, 5, 6} are disjoint sets, 
$ A \cup B = \{\} = \varnothing $

while {1, 2, 3} and {3, 4, 5} are not disjoint.






The representation of a set using Venn diagrams


See reference 6.





The universal set is marked as U.
The set A is a subset of U, or $ A \subseteq U $.

The complement of a set A, written $ \complement{A} \ or \ \bar{A} \ or \ \overline{A} $,
contains all the elements in the universal set U, but not in set A.

$$ \complement{A} = \overline{A} = U-A $$

$$ \overline{A} \cup A = U $$

$$   \overline{A} \cap A = \varnothing $$

Example:

U = {1, 2, 3, 4, 5, 6, 7, ...} positive integers
A = {2, 4, 6, 8, ...} positive even integers

then,
$ \overline{A} = \{1, 3, 5, 7, 9, ... \}$ positive odd numbers 





Example:

U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
A = {1, 2, 3, 4, 5}
B = {4, 5, 6, 7, 8, 9, 10}
$ A \cap B $ = {4, 5}
$ \overline{A \cap B} $  = {1, 2, 3, 6, 7, 8, 9, 10}


Example:

U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
A = {1, 2, 3, 4, 5}
B = {4, 5, 6, 7}
C = {3, 5, 7, 8}

$ D = B \cup C $ =  {4, 5, 6, 7, 3, 5, 7, 8} = {3, 4, 5, 6, 7, 8 }
$ A \cap D $ = {3, 4, 5}
$ \overline{A \cap (B \cup C)} $ = $ \overline{A \cap D} $ 
= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - {3, 4, 5} = 
= {1, 2, 6, 7, 8, 9, 10}

tip: Use LaTeX \overline{A} = $ \overline{A} $ = long \bar{A} = $ \bar{A} $





Augustus De Morgan's laws



See reference 7.

Definition:
The union of the sets is equal to the intersection of their complements.
$$ \overline{A \cup B} = \bar{A} \cap \bar{B} $$































Definition:
The complement of the intersection of two sets A and B
is equal to the union of their complements.
$$ \overline{ A \cap B } = \bar{A} \cup \bar{B} $$








Exercise:




U = {1, 2, 3, 4}
A = {1, 2}
B = {2, 3}
$ \overline{A} $ = {3, 4}
$ \overline{B} $ = {1, 4}
$ \overline{A} \cup \overline{B} $ = {1, 3, 4}

Compliment of the union of compliments:
$ \overline{ \overline{A} \cup \overline{B} } $ = {2}


Intersection, or $ A \cap B $ = {2}

ergo:

$$ \overline{ \overline{A} \cup \overline{ B} } = A \cap B $$


Exercise:



U = {1, 2, 3, 4}
A = {1, 2}
B = {2, 3}
$$ A \cap \overline{ \overline{A} \cup  \overline{B}}  = ? $$

$ \overline{A} $ = {3, 4}
$ \overline{B} $ = {1, 4}
$ \overline{A} \cup \overline{B} $ = {1, 3, 4}

$ \overline{ \overline{A} \cup  \overline{B}}  = \{2\} $

$  A \cap \overline{ \overline{A} \cup  \overline{B}}  =  A \cap \{2\} = \{1, 2\} \cap \{2\} = \{2\} $

$  \{2\} = A \cap B $

ergo:
$$ A \cap \overline{ \overline{A} \cup  \overline{B}}  = A \cap B $$




Exercise:
Given two sets A and B,
What is the complement of the union of their complements?

$$ \overline{ \overline{ A} \cup \overline{ B} } =  A \cap B $$


Proof with Vann diagram:

$ \overline{ \overline{ A} \cup \overline{ B} } = ? $

$ \overline{A} = \{3, 4\} $
$ \overline{B} = \{1, 4\} $
$  \overline{ A} \cup \overline{ B} =  \{1, 3, 4 \} $
$   \overline{ \{1, 3, 4 \} } = \{2 \}$
$ \overline{ \overline{ A} \cup \overline{ B} } = \{2\}  = A \cap B $






$ A - \overline{B} = \{1, 2 \} - \{ 1, 4 \} =  {4} = \overline{ A \cup B}$


Exercise:

Set difference of set differences

$$  \overline{ (A-B) - (B-C) } = ? $$

Venn diagram proof:
$ (A-B) = \{1, 3 \} $
$ (B-C) = \{2, 5 \} $
$ \{1, 3 \} - \{2, 5 \} = \{1, 3 \}$
$  \overline{ (A-B) - (B-C) } =  \overline{ \{1, 3 \} } = $


 









Laws of sets: Commutative, associative, and distributives

See reference 8.

Commutative

Definition:
order does not affect the outcome. 





Commutative:
  • addition 2+3 = 3+2
  • multiplication 2*3 = 3*2
  • union $ A \cup B = B \cup A $
  • intersection $ A \cap B = B \cap A $
  • symmetric difference $ A \oplus B = B \oplus A $


Not commutative:
  • Subtraction $ 3-1 \neq 1-3 $
  • Set difference $ A-B \neq B-A $

Associativity

Definition:
concerns the grouping of elements in an operation.






Associative:
  • addition (a+b)+c = a +(b+c)
  • multiplication (a*b)*c = a *(b*c)
  • union $ (A \cup B) \cup C = A \cup (B \cup C) $
  • intersection $ (A \cap B) \cap C = A \cap (B \cap C) $
  • symmetric difference $ (A \oplus B) \oplus C = A \oplus (B \oplus C) $
Not associative
  • set difference $ (A - B) - C \neq A - (B - C) $



Distributivity


Definition: 
multiplying a sum is equal to multiplying each number and adding the sum





$$ a(b+c) = ac + ac $$

3*(2+5) = 3*2 + 3*5 = 21 



$$ A \cup (B \cap C) = (A \cup B) \cap (A \cup C) $$









$$ A \cap (B \cup C) = (A \cap B) \cup (A \cap C) $$








Using set identities to simplify expressions














Prove


$$ \overline{(A \cap B) \cup \overline{B}} = B \cap  \overline{A}$$

$ \ \ \ \ \overline{(A \cap B) \cup \overline{B}} = $
$ =  \overline{ (A \cap B )} \cap \overline{\overline{B}} $ - De Morgan's law
$ =  \overline{ (A \cap B )} \cap B $
$ = ( \overline{A} \cup \overline{B} ) \cap B $ - De Morgan's law
$ = B \cap (\overline{A} \cup \overline{B}) $ - commutative
$ = (B \cap \overline{A}) \cup (B \cap \overline{B}) $ - distributive
$ = (B \cap \overline{A}) \cup \ \varnothing $
$ = B \cap \overline{A} $  



Exercise

$ A \cap ( B \cap \overline{A} ) = $
$ = (A \cap B) \cap ( A \cap \overline{A} ) $
$ = (A \cap B) \cap \varnothing =  \varnothing $ !

OR 

$ A \cap ( B \cap \overline{A} ) = $
$ = A \cap B \cap \overline{A} = $
$ = B \cap A \cap \overline{A} = $
$ = B \cap \varnothing = \varnothing $ !


Exercise


$ \overline{ \overline{A \cup B} \cup \overline{A} } $
$ \overline{A \cup B } = \{4\} $ - Vann diagram
$ \overline{ \{4\} \cup \overline{A} } = $ 
$ \overline{ \{4\} \cup \{3, 4\} } =  \{3, 4 \} = \overline{A}  $ !


Exercise
$ \overline{ (A - B) - (B-C)  } $


Exercise:

$ \overline{ \overline{A \cup B} \cup \overline{B} } $
$ \overline{A \cup B} = \{ 4 \} $
$ \overline{B} = \{1, 4 \} $
$ \overline{A \cup B} \cup \overline{B} = \{ 1, 4 \} =  \overline{B} $
$ \overline{ \overline{A \cup B} \cup \overline{B} }  =  B = \{2, 3 \} $ !

Exercise:



$ \overline{ A \cup \overline{B} \cup C } \cap  \overline{B} $
$  U = \{ 1, 2, 3, 4, 5, 6, 7, 8 \} $
$  \overline{B} = \{ 1, 3,  7, 8 \} $
$  A = \{ 1, 2, 3, 4 \} $
$  C = \{ 3, 4,  6, 7 \} $
$ \overline{ \{ 1, 2, 3, 4 \} \cup \{ 1, 3,  7, 8 \} \cup \{ 3, 4,  6, 7 \}} \cap  \{ 1, 3,  7, 8 \} $
$ \overline{ \{ 1, 2, 3, 4, 6, 7, 8 \} } \cap  \{ 1, 3,  7, 8 \} $
$ \{ 5, 6 \} \cap \{ 1, 3, 7, 8 \} = \varnothing  $

Exercise:

$ A \cup ( B \cup \overline{A}) = $
$ A \cup  B \cup \overline{A} = $
$ B \cup A \cup   \overline{A} = $
$ B \cup \varnothing  =  B$  
Q.E.D.


Tip: Q.E.D. QUOD ERAT DEMONSTRANDUM means "Which was to be demonstrated."


Partition of a set

See reference 9.


Definition:

A partition of set A,
is a set of subsets $ A_i $ of A such that:
all the subsets $ A_i $ are disjointed,
and the union of all subsets $ A_i $ is equal to A.


Exercise

Hint: Use the inclusion-exclusion principle (IEP):
$ | A \cup B | = | A | + | B | - | A \cap B | $
The formula expresses the fact that the sum of the sizes of the two sets may be too large since some elements may be counted twice. The double-counted elements are those in the intersection of the two sets and the count is corrected by subtracting the size of the intersection. 
https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle

Given three sets A, B, and C, prove that:

I could not find the use for associativity of the union, so I just show it here:
$  | C \cup (A \cup B) | = | A\cup B \cup C | = $
1. Using IEP, split above:
$ = | A\cup B | + | C | - | (A \cup B) \cap C | = $
2. Using IEP, split $ | A\cup B | $ above:
$ | A \cup B | = | A | + | B | - | A \cap B | $
3. Combine the two terms:
$ = | A | + | B | - | A \cap B | + | C | - | (A \cup B) \cap C | = $
4. Use associativity of addition for arranging the terms:
$ = \color{green}{ | A | + | B | + | C | - | A \cap B | } - | (A \cup B) \cap C | = $
5. Using distributivity of the intersection, split the last union:
$ | (A \cup B) \cap C | =  | ( A \cap C ) \cup ( A \cap B) | $
6. Using IEP, split the term
$ =  | ( A \cap C ) \cup ( A \cap B) |  =  | A \cap C | + | A \cap B | - | A \cap C) | \cap | A \cap B |$
7. Combine the terms 
$ = \color{green}{ | A | + | B | + | C | - | A \cap B |  -  | A \cap C | + | A \cap B | } - | A \cap C | \cap | A \cap B | $
8. Using commutativity of the intersection law (clearly proven by Vann diagram):
$ | A \cap C | \cap | A \cap B | =  | A \cap B \cap C | $
9. Combining the terms:
$ = \color{green}{| A | + | B | + | C | - | A \cap B |  -  | A \cap C | + | A \cap B | -  | A \cap B \cap C |  } $
Q.E.D.
 


Visual proof of the same:
$ | A\cup B \cup C | = $ using IEP, see Venn diagram below for reference
$ = | A | + | B | + | C | $ - accounts for all sets, but double counts subsets 2, 3, 6 and triple counts subset 4
resulting in:
$ = | S_1 | + | S_2 | + | S_2 | + | S_3 | + | S_3 | + | S_4 | + | S_4 | + | S_4 | +  | S_6 | + | S_6 | $
to correct that:
$ - | A \cap B | $ remove one double counted subsets 2, 4
$ - | A \cap C | $ remove one double counted subsets 3, 4
$ - | B \cap C | $ remove one double counted subsets 6, 4
but at this point, we removed all three $ S_4 $ so we have to add:
$ + | A \cap B \cap C |$ intersection of all set resulting in subset 4
$ = | A | + | B | + | C | - | A \cap B | - | A \cap C | - | B\cap C | + | A \cap B \cap C | $
E.Q.D.











Exercise:

Given A (even numbers) and B (odd numbers) which are subsets to the universal Integer set U,
$$ U = \{x: x \in \mathbb{Z} \ and \ 0 \leq x < 20 \} $$

Therefore: 
$ U = \{0, 1, 2, 3, ..., 18, 19 \} $
$ A = \{0, 2, 4, 6, 8, 10, 12, 14, 16, 18 \} $ assuming even numbers include zero 0
$ B = \{1, 3, 5, 7, 9, 11, 13, 15, 17, 19 \} $
$ A\cup B = U $ 
$ A\cap B = \varnothing $ empty set
$ \overline{B} = A $

Use the listing method to list the elements of the following sets:
$ A \cap \overline{B} = \{0, 2, 4, ..., 16, 18 \} \cap \{ 0, 2, 4, ..., 16, 18 \} = A = \{ 0, 2, 4, ..., 16, 18 \} $
$ \overline{A \cap B} =  \overline{ \varnothing } = \overline{ \{\} } = U = \{0, 1, 2, 3, ..., 18, 19 \} $
$ \overline{A \cup B } =  \overline{ U } = \overline{\{0, 1, 2, 3, ..., 18, 19 \}} = \{\} =  \varnothing $
$ \overline{A \oplus B} =  U - (A \cup B)  + ( A \cap B) = \{\} = \varnothing $






Peer reviews



Read Book


Discrete Mathematics with Applications
Thomas Koshy
https://ebookcentral.proquest.com/lib/londonww/detail.action?docID=294091#




pp.70-71, 71-73, and 78-86.

Please also complete the following exercises:

pp.93, exercises 5–14, 27-32, and 57-60.




Review Problem Sheet

TODO: review and document






Cartesian Product of A and B




Summative Quiz




TODO



Webinar


https://www.coursera.org/learn/uol-discrete-mathematics/lecture/B7F94/webinar









References





As an Amazon Associate I earn from qualifying purchases.

Computational Mathematics

 


https://www.coursera.org/learn/uol-cm1015-computational-mathematics/supplement/Ok8Zg/introduction-to-computational-mathematics-course


handle numbers in any base and perform operations with binary numbers. You will learn about sequences, recursion and series, basic trigonometry and geometry.

You will also be introduced to functions, their different types, how to plot them and how to study their properties through basic calculus, limits and derivatives. You will also be introduced to linear algebra, vector spaces and the basic concepts of combinatorics, statistics and probability.

How to pass?

https://www.coursera.org/learn/uol-cm1015-computational-mathematics/supplement/57Ggy/how-to-pass-the-course




Number Bases

https://www.coursera.org/learn/uol-cm1015-computational-mathematics/lecture/nPHpG/introduction-to-number-bases-conversion-to-decimal


For any number base b, written with positions n such as:

$$ a_n a_{n-1} a_{n-2} ... a_0 $$

the conversion to decimal will be:

$$ a_n * b^n +  a_{n-1}* b^{n-1} + ... +  a_0*b^0 $$

Binary


  • 0 - 00000000 
  • 1 - 00000001 
  • 2 - 00000010 
  • 3 - 00000011 
  • 4 - 00000100 
  • 5 - 00000101 
  • 6 - 00000110 
  • 7 - 00000111 
  • 8 - 00001000



$ 1001_2 \\ = 1*2^3 + 0*2^2 + 0*2^1 + 1*2^0  \\ = 8 + 0 + 0 + 1 \\ =  9_{10} $


$ 100 101 011_2 = \\
= 1*2^8 + 0*2^7 + 0*2^6 + 1*2^5 + 0*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 1*2^0 = \\
= 1*256 + 0*128 + 0*64 + 1*32 + 0*16 + 1*8 + 0*4 + 1*2 + 1*1 = \\
= 256 + 32 + 8 + 2 +1 = \\ = 299_{10} $




Decimal

count to 9, then zero add 1 in front to make 10. and so on

$ 127_{10} \\ = 100 + 20 + 7 \\ = 1*10^2 + 2*10^1 + 7*10^0 $


Hexadecimal (base 16)


0, 1, 2, ..., 9, A, B, C, D, E, F

$ 1F_{16} =  1*16^1 + 15*16^0 =  16 + 15 =  31_{10} $


Sexagesimal

 - Sumerians, Babylonians, angles, time, etc.


Method of repeated division









As an Amazon Associate I earn from qualifying purchases.

Logistic Regression - Machine Learning with Python - IBM AI Engineering certificate program on Coursera

 

Intro to Logistic Regression

https://www.coursera.org/learn/machine-learning-with-python/lecture/eySE4/intro-to-logistic-regression


  • Logistic Regression is a statistical and Machine Learning algorithm to classify data in the dataset.
  • it is similar to linear regression, but it takes categorical (discrete) target fields instead the numeric continuous values.
  • The classification can b binary (i.e. yes, no), or multi-class.
  • Logistic Regression gives the probability of a given class
  • The independent variables (features, x) should be continuous (i.e 0.0 .. 1.0)
  • The dependent variable (the label, y) should be categorical (i.e. TRUE, FALSE, MAYBE)

What are the applications of Logistic Regression?
  • a chance of mortality
  • a likelihood of propensity to purchase a product
  • a probability for the failure of a process or a product
  • a likelihood of default on a loan 
When should I use Logistic Regression?

  • If the data is binary (i.e. 0/1, Yes/No, True, False)
  • If you need probabilistic results
  • When you need a decision boundary (linear, polynomial, or more complex hyperplane)
  • if you need to understand the impact of the features





As an Amazon Associate I earn from qualifying purchases.

Decision Trees - Machine Learning with Python - IBM AI Engineering certificate program on Coursera

NOTE: This is a continuation of the:
"IBM AI Engineering certificate program on Coursera - Machine Learning with Python"



I am also maintaining a PRIVATE Jupyter notebook on GitHub:



Please note that the Mathematic formulas (LaTex script) DO NOT show on the MOBILE phone, to read this post please use the desktop Chrome browser.

All images, unless otherwise marked, are copyrighted by IBM Developer Skills Network.



Introduction to Decision Trees


It is built by splitting the training set into distinct nodes. One node in a Decision Tree contains all of, or most of, one category of the data.





  • internal node - the test
  • branch node - the result of the test
  • leaf node - the assigned classification


Building Decision Trees

How to create a decision tree?

Use recursive partitioning by using the most predictive feature:
  1. choose an attribute from the dataset
  2. calculate the significance of the attribute in splitting data
  3. split the data based on the value of the best attribute
  4. go back to step 1

The pure nodes are those that contain the same type of category.
The impurity of nodes is calculated by the entropy of the data.
The entropy is the amount of randomness or uncertainty, the lower the entropy, the less uniform the distribution, and the purer (homogenous) the node. Homogenous has entropy = 0.

Entropy in a node is the amount of information disorder calculated in each node.

Use the frequency table calculated by the entropy formula:

$$ entropy = - p(A) log_2(p(A)) - p(B) log_2(p(B)) $$

Where
  • p is the proportion or ratio of the category A or B

Which tree has less entropy after splitting?
Choose the tree with the higher information gain after splitting.

$$ information \ gain = (entropy \ before \ the \ split) - ( weighted \ entropy \ aftersplit) $$







As an Amazon Associate I earn from qualifying purchases.

How to write a Math or Data Science eBook?


When studying, I like to take notes, usually, I do it on my Blog, but often I use Jupyter notebooks which I commit to GitHub. If I am writing a paper I use Google Docs. Having my writing in 3 different places is not optimal. 
On top of that, using math formulas complicates things as it is not supported everywhere.

Example of a formula written using LaTeX:

$$ LogLoss = - \frac{1}{n} \sum_{i=1}^{n}
( y_i \cdot log(\hat{y_i}) + ( 1 - y_i ) \cdot \log(1 - \hat{y_i}) ) $$

So, how should I write a Math, or a Data Science, eBook?

First, publishing papers as PDF is most common, I read tons of them, but they are hard to digest unless you print them, or view them on a big screen. I do not want to sit in front of the computer any longer than I already do.  I like using Kindle reader, so an eBook format is much more user-friendly. I can set font sizes, and spacing, take notes, etc. The PDFs on Kindle are a really bad experience. Also, I would like to distribute my papers over the Amazon Kindle store (for free or not). Not everyone has a university or a work subscription to access papers on ieee.org, sciencedirect.com, proquest.com, etc.




Below, I will investigate different approaches and hopefully, come to a good conclusion.

How to send documents to Kindle:
  • Every Kindle account has an associated (secret) email, you can attach a file to it and it will show in your Kindle.
  • Make sure the file name is human-readable!
  • HTML (export from Jupyter Lab) sent to Kindle:
    • PRO:
      • it is readable, good for text-only pages
    • CON:
      • LaTeX is not converted to math formulas
      • Images are missing
  • PDF (of the same HTML) sent to Kindle:
    • PRO:
      • images show up
      • LaTeX formulas show up
      • good enough to publish a "paper"
    • CON:
      • still the problem with PDF in general -- no font size adjustment
  • ePUB (of the same HTML) sent to Kindle:
    • conversion is done with convertio.co
      • PRO
        • font adjustable
        • plots included
      • CONS:
        • missing images
        • LaTeX not converted to math formulas 
    • conversion with  calibre-ebook.com

Is Blogger (Blogspot) good for writing papers and articles?

Pro:
  • searchable 
  • easy to manage and edit
  • use of tags (labels) for finding related articles
  • support for LaTeX math notation
Cons: 
  • No good ways to "clean" export to ePub, PDF, or Markdown
    • I could write embedded JavaScript in Blogger that creates "print" version of article text only

Using Jupyter Notebook

Pro:

  • inline and current code (Julia, Python)
  • incline and current plots 
  • export to HTML, PDF, Markdown with pandoc.org/
Cons
  • no spellcheck while writing (Grammarly)
    • conda install -c conda-forge jupyterlab-spellchecker
  • GitHub Diff is garbage

How to install brew?

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

How to install pandoc? 

[see reference 5]
brew install pandoc


[see reference 1]


Using Markdown

Pros:

  • GitHub diff is readable


Using Google Docs

Pros:

  • Available on all devices, online and offline


[see reference 2]



References

  1. https://towardsdatascience.com/transform-jupyter-notebook-to-an-ebook-ef3a9d32ac4f
  2. https://workspace.google.com/marketplace/app/autolatex_equations/850293439076
  3. https://tug.org/mactex/mactex-download.html
  4. https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex
  5. https://pandoc.org/installing.html



As an Amazon Associate I earn from qualifying purchases.

Classification - Machine Learning with Python - IBM AI Engineering certificate program on Coursera

NOTE: This is a continuation of the: "IBM AI Engineering certificate program on Coursera - Machine Learning with Python"

https://uki.blogspot.com/2022/09/ibmaiengineering.html


Please note that the Mathematic formulas (LaTex script) DO NOT show on the MOBILE phone, to read this post please use the desktop Chrome browser.

All images are copyrighted by IBM Developer Skills Network.

Table of Contents



  • Classification is a supervised machine learning approach
  • Categorizing some unknown items into a discrete set of categories or "classes".
  • Relationship between "feature" variables and the target attribute which is a categorical variable.


What is multi-class classification?

Multi-class classification can predict the target attribute (a field) with multiple discrete values to choose from.

What are examples of Multi-class classification use cases?
  • category to which the person belongs
  • churn detection: person switching brand loyalty
  • detect if a person responds to a particular advertising campaign


What are the types of classification algorithms?

  • Decision Trees (ID3, C4.5, C5.0)
  • Naïve Bayes,
  • Linear Discriminant Analysis
  • k-Nearest Neighbor
  • Logistic Regression
  • Neural Networks (DNN)
  • Support Vector Machines (SVM)


k-Nearest Neighbors (kNN)



K-Nearest Neighbors is a supervised learning algorithm. Where the data is 'trained' with data points corresponding to their classification. To predict the class of a given data point, it takes into account the classes of the 'K' nearest data points and chooses the class to which the majority of the 'K' nearest data points belong as the predicted class.


  • The kNN algorithm is a classification algorithm
  • The kNN algorithm classifies classes on their similarity to other classes 
  • The kNN can work with Minkowski/Eucleadian distance, but it does not have to.
  • The large, or the small, size of k in kNN does guarantee a good model, rather the k value needs to be found empirically.
  • kNN can be used to compute a continuous value, for example, the price of a home
How to determine which class?

Find several nearest neighbors in the data (e.g. age, income, etc.) and determine (vote) to which class they should belong.




This can be done using Euclidean Distance [reference 1].







How does the k-Nearest Neighbor work?

  • pick a value for K
  • calculate the distance of the unknown case from all cases
  • select the k-observations in the training data that are "nearest" to the unknown data point
  • predict the response of the unknown data point the most popular response value from the K-nearest neighbors.
How to select the K-value?
  • too small of the k sample may capture the "noise" in the data (an outlier)
  • a low value of k makes for a very complex model which may result in overfitting of the model
  • too large of the k can make the model overgeneralized
  • reserve part of your data to test the distribution of accuracy of the model for various k= 1 to n

How to calculate the distance between k-neighbors?
  • We can use the Minkowski distance (aka Euclidean distance)
  • normalize the unites
$$
Minkowski \ distance (x_1, x_2) =
\sqrt{
  \sum_{i=0}^{n}
  \left(
    x_{1i} - x_{2i}
  \right)^2 

$$

Example (not normalized):
  • person 1
    • age 34
    • income 190
    • education 3
  • person 2
    • age 30
    • income 200
    • education 8

$$
Minkowski \ distance (x_1, x_2) =
\sqrt{
  \sum_{i=0}^{n}
  \left(
    x_{1i} - x_{2i}
  \right)^2 

$$

$$ = \sqrt{  \left( 34 - 30 \right)^2 + \left( 190 - 200 \right)^2 + \left( 3 - 8 \right)^2 }  \\ = 11.87 $$



Evaluation Metrics in Classification



Harmonic Mean [see references 2, 3 ]
$$ harmonic \ mean  = \frac{2*A*B}{A+B} $$


Classification Accuracy
compare the historical actual data $ y $ vs predicted values $ \hat{y} $
  • Jaccard index (similarity coefficient, intersection-over-union)


  • F1 score (Confusion matrix)
    • TP = True Positives
    • FN = False Negatives
    • FP = False Positives
    • TN = True Negatives
    • precision = TP / (TP + FP)
      • use when identifying positives is a priority
      • example: classify butterfly species
    • recall  = TP / (TP + FN) 
      • use when false negatives are a problem
      • example: identify non-existing obstacles at highway speed
    • F1 score is a harmonic mean of the precision and recall scores
      • F1 score = $ \frac{2 * precision * recall}{precision + recall} $ 
    • Finally, we can average multiple F1 score results




Logarithmic (Log) Loss

  • Sometimes the output is the probability of the class label
    • continuous values between 0 to 1 (or 0 to 100%, or NO to YES)
  • Log Loss measures the performance of the classifier where the output is a probability

$$ error = y \cdot log(\hat{y}) + ( 1 -y ) \cdot \log(1 - \hat{y}) $$
Where:
  • $ \hat{y} $ is a predicted result
  • y is the actual observed result
Then, we can calculate the Log Loss as an average across all observations (rows n):

$$ LogLoss = - \frac{1}{n} \sum_{i=1}^{n} ( error_i ) $$

The classifier with the lower Log Loss has better performance.





Lab: kNN










References














As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles