Artificial Intelligence in Advance 2019 Lecturer: September 2019

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 77

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/335684104

Artificial Intelligence in Advance 2019 lecturer

Presentation · September 2019


DOI: 10.13140/RG.2.2.14210.02240

CITATIONS READS

0 166

1 author:

nguyen dinh Cuong


Nha Trang University
35 PUBLICATIONS   17 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Vingroup and Nha Trang University View project

All content following this page was uploaded by nguyen dinh Cuong on 08 September 2019.

The user has requested enhancement of the downloaded file.


Artificial Intelligence in Advance

Prolog – Web knowledge


Programming Computer
NGUYEN DINH CUONG
BIG NUMBER

25 ! = 15,511,210,043,330,985,984,000,000 very large

unsigned long long 264 − 1 , ℎ𝑎𝑣𝑒 𝑛𝑜 𝑖𝑛 𝐶/𝐶 + +

Import java.util.Scanner;
Import java.math.Bignumber;
Class Main {
public static void main (String[] args) {
BigInteger fac = BigInteger.ONE;
for (int i=2 ; I <=25 ; i++)
fac =fac.multiply (BigInteger.ValueOf(i));
System.out.println(fac);
}
}
Nếu mỗi viên gạch là 1mx1mx1m 264 − 1 𝑣𝑖ê𝑛 𝑔ạ𝑐ℎ 𝑐ó 𝑙ấ𝑝 đượ𝑐 𝑏𝑖ể𝑛 𝑘ℎô𝑛𝑔
BIG NUMBER

#include <cstdio>
using namespace std;
int N;
char x[100];

int main() {
scanf(“%d\n”, &N);
while (N--) {
scanf(“0..%[0..9]...\n”, &x);
}
printf(“the digits number are 0.%s\n”,x);
}
Parallel OpenMP

#include <omp.h>
#include <stdio.h>
int main (int argc, char *argv[]) #pragma omp parallel for
{
/* sequencetial code */ for ( i = 0; i < N ; i ++ ) {
#pragma omp parallel c[i] = a [i] + b [i];
{ }
printf(“ I am a parallel region.”);
}
/* sequence code */
return 0;
}
#include <pthread.h>
#include <stdio.h>

int value=0; void *runner(void *param) {


void *runner (void *param) ; /* the thread */ value=5;
pthread_exit(0);
int main (int argc, char *argv[]) }
{
pid_t pid; 7, 12, 19, 3, 18, 4, 2, 6, 15,8
pthread_t tid;
pthread_attr_t attr; Sorting Thread 1
Sorting Thread 0
pid = fork();
if (pid ==0) { /* child process */ 7, 12, 19, 3, 18 4, 2, 6, 15, 8
pthread_attr_init(&attr);
pthread_create(&tid, &attr, runner, NULL);
pthread_join(tid, NULL);
printf(“CHILD: value =%d”, value); /* LINE P */
} 2, 3, 4, 6, 7, 8, 12, 15, 18, 19
else if (pid >0) {/* parent process */
wait (NULL); Sorted List (Merge)
printf (“ PARENT : value=%d”, value); /* LINE P */
}
}
Java Multithread
New Sleep done , I/O, complete clock available,
resume, notify

Non-runnable
Runable
Block

Sleep, block on I/O, wait for clock, suspend, wait


Running

Terminated

Method Meaning
getname Obtain thread’s name
getPriority Obtain thread’s priority
isAlive Determine if a thread is still running
join Wait for a thread to terminate
run Entry point for the thread
sleep Suspend a thread for a period of time

start Start a thread by calling its run method


Java Multithread

public void run()

public class MyClass implements Runable{


public void run(){
System.out.println(“MyClass running”);
}
}

Thread t1=new Thread(new MyClass());


t1.start();

public class Myclass extends Thread{


public void run(){
System.out.println(“MyClass running”);
}
}

MyClass t1= new MyClass();


T1.start();
class RunableDemo implements Runable {
private Thread t;
private String theadName;

RunnableDemo(String name) {
threadName name;
System.out.println(“Creating” + threadName);
}

public void run() {

System.out.println(“Running “ + threadName);
try {
for (int i=4; i>0; i--) {
System.out.println(“Thread:” + threadName + “, “ + i);
// Let the thread sleeo for a while
Thread.sleep(50);
}
}
} catch (InterruptedException e) { public class TestThread{
System.out.println(“thread” + threadName + “ interrupted.”); public static void main (String args[]) {
}
RunnableDemo R1 = new RunnableDemo(“Thread -1 “);
System.out.println(“Thread “ + threadName + “exiting.”);
R1.start();
}

Public void start() { RunnableDemo R2 =new RunnableDemo(“Thread -2”);


System.out.println(“Starting “ + threadName); R2.start();
If (t== null) { }
t= new Thread (this, threadName); }
t.start();
}
}
}
ĐỊNH LÝ FERMAT

𝑥𝑛 + 𝑦𝑛 = 𝑧𝑛, 𝑛 > 2

for(x=minint; x ≤maxint ; x++ )


for (y=minint; y ≤ maxint; y++)
for (n=minint; n ≤ maxint; n++)
if (𝑥 𝑛 + 𝑦 𝑛 = 𝑧 𝑛 ) 𝑡ℎ𝑒𝑛 𝑝𝑟𝑜𝑏 = 𝑜𝑘
JIProlog
father(terach,abraham).
father(terach,nachor).
father(terach,haran).
father(abraham,isaac).
father(haran,lot):-!.
father(haran,milcah).
mother(sara,isaac).
male(terach). Prolog Machine Web environment
male(abraham).
male(nachor).
male(haran). JAVA
male(isaac).
male(lot).
female(sarah).
female(milcah).
female(yiscah).
Prolog files, SQL, Oracle
likes(X,pome).
son(X,Y):-father(Y,X),male(X).
daughter(X,Z):-father(Z,X),female(X).
granfather(X,Z):-father(X,Y),father(Y,Z).
<HTML>
<HEAD><TITLE>
Sample JSP
</TITLE></HEAD>

<%@ page language="java" import="java.util.Vector" %>


<%@ page import="com.ugos.JIProlog.engine.*" %>

<%
// New instance of prolog engine
JIPEngine jip = new JIPEngine();
JIPTerm queryTerm = null;
// collector for solution
Vector vect = new Vector();
// parse query
try
{
// consult file
// files are searched in the search path
jip.consultFile("bible.pl");
queryTerm = jip.getTermParser().parseTerm("father(X, Y).");
}
catch(JIPSyntaxErrorException ex)
{
ex.printStackTrace();
}
catch(IOException ex)
{
ex.printStackTrace();
}
// open Query
JIPQuery jipQuery = jip.openSynchronousQuery(queryTerm);
JIPTerm solution;
try
{
// Collect solutions
// Loop while there is another solution
while ((solution = jipQuery.nextSolution()) != null)
{
vect.addElement(solution);
}
}
catch(JIPRuntimeException ex)
{
System.out.println(ex.getMessage());
}
%>
<BODY BGCOLOR="white">
<B> Solutions: </B>
<ul>
<%
// print solutions
for(int i = 0; i < vect.size(); i++)
{
%>
<li> <%= vect.elementAt(i) %>
<%
}
%>
</ul>
</BODY>
</HTML>
SPARQL – Web Semantic
SPARQL

package jena.examples.rdf ;

import org.apache.jena.rdf.model.*;
import org.apache.jena.vocabulary.*;

/** Tutorial 1 creating a simple model


*/

public class Tutorial01 extends Object {


// some definitions
static String personURI =
"http://somewhere/JohnSmith";
static String fullName = "John Smith";
public static void main (String args[]) {
// create an empty model
Model model = ModelFactory.createDefaultModel();

// create the resource


Resource johnSmith =
model.createResource(personURI);

// add the property


johnSmith.addProperty(VCARD.FN, fullName);
}
}
# filename: ex003.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#>

SELECT ?craigEmail
WHERE { ab:craig ab:email ?craigEmail . }
# filename: ex002.ttl

# filename: ex001.rq @prefix ab: <http://learningsparql.com/ns/addressbook#> .

PREFIX d: <http://learningsparql.com/ns/demo#> ab:richard ab:homeTel "(229) 276-5135" .


SELECT ?person ab:richard ab:email "richard49@hotmail.com" .
WHERE { ?person d:homeTel "(229) 276-5135" . }
ab:cindy ab:homeTel "(245) 646-5488" .
ab:cindy ab:email "cindym@gmail.com" .

ab:craig ab:homeTel "(194) 966-1505" .


ab:craig ab:email "craigellis@yahoo.com" .
ab:craig ab:email "c.ellis@usairwaysgroup.com" .
# filename: ex012.ttl
# filename: ex010.rq
@prefix ab: <http://learningsparql.com/ns/addressbook#> .
PREFIX ab: <http://learningsparql.com/ns/addressbook#> @prefix d: <http://learningsparql.com/ns/data#> .

SELECT ?propertyName ?propertyValue d:i0432 ab:firstName "Richard" .


WHERE d:i0432 ab:lastName "Mutt" .
{ ab:cindy ?propertyName ?propertyValue . } d:i0432 ab:homeTel "(229) 276-5135" .
d:i0432 ab:email "richard49@hotmail.com" .
# filename: ex015.rq
d:i9771 ab:firstName "Cindy" .
PREFIX ab: d:i9771 ab:lastName "Marshall" .
<http://learningsparql.com/ns/addressbook#> d:i9771 ab:homeTel "(245) 646-5488" .
d:i9771 ab:email "cindym@gmail.com" .
SELECT ?craigEmail
WHERE d:i8301 ab:firstName "Craig" .
{ d:i8301 ab:lastName "Ellis" .
?person ab:firstName "Craig" . d:i8301 ab:email "craigellis@yahoo.com" .
?person ab:lastName "Ellis" . ------------------------------------- d:i8301 ab:email "c.ellis@usairwaysgroup.com" .
?person ab:email ?craigEmail . | propertyName | propertyValue |
} =====================================
| ab:email | "cindym@gmail.com" |
| ab:homeTel | "(245) 646-5488" |
-------------------------------------
Speech recognition

MFCCs features
s(n)
windows DFT | |2 Filterbank Log

𝑁−1
2𝜋𝑗
𝑥 𝑘 = ෎ 𝑥 𝑚 exp − 𝑘𝑚
N Discrete
𝑚=0 Cosine
DFT Transform
𝑘
𝑧 = exp 2𝛱𝑗
𝑁

Energy
X 𝑧 = σ𝑁−1
𝑚=0 𝑥 𝑚 𝑧
−𝑚
Mel
Filterbank d/dt
spectrum - cepstrum

Log
d2/dt2

HTK FrontEnd FrontEnd


Aurora
Dynamic Program
A=XXXXPPPPAAAAPCCCCCAAAAAAAAA
B=XXXXBBBBBBCCPPPPPPAAAACCCCCC
𝜙𝑗 𝑡 = 𝑚𝑎𝑥𝑖 𝜙𝑖 𝑡 − 1 𝑎𝑖𝑗 𝑏𝑗 𝑜𝑡

𝜑1 1 = 1

𝜑𝑖 1 = 𝑎1𝑗 𝑏𝑗 𝑜1

1≤𝑗≤N The maximum likelihood 𝑃෠ Oȁ𝑀

𝜙𝑁 𝑇 = 𝑚𝑎𝑥𝑖 {𝜙𝑖 𝑇 𝑎𝑖𝑁 }

𝜑𝑗 𝑡 = 𝑚𝑎𝑥𝑖 𝜑𝑗 𝑡 − 1 +log(𝑎𝑖𝑗 ) + 𝑙𝑜𝑔( 𝑏𝑗 𝑜𝑡 )


D[i, j] khoảng cách ngắn nhất của chuỗi S độ dài i, so với chuỗi T độ dài j

1. D[i, j] = D[i-1, j-1] Nếu Siሶ = Tiሶ

Ngược lại D[i, j] = D[i-1, j-1] +1

2. D[i, j] = D[i-1, j] +1 cho trường hợp chèn một kí tự vào chuỗi S tại vị trí i.

3. D[i, j] = D[i, j-1] +1 cho trường hợp xóa kí tự ở chuỗi P tại vị trí j.
from gtts import gTTS
tts = gTTS(text='Xin chào các bạn em hát bài diễm xưa', lang='vi')
tts.save("chao.mp3")

Xin chào các bạn em hát bài Diễm Xưa

Đánh trọng số lại transcription


// xinchao.cpp : Defines the entry point for the console application.
Language Model //

#include "stdafx.h"

#include <iostream>
#include <io.h>
#include <fcntl.h>
#include <string>
#include <windows.h>
#include <fstream>

int main()
{
_setmode(_fileno(stdin), _O_U16TEXT);
_setmode(_fileno(stdout), _O_U16TEXT);
SetConsoleTitleW(L"Việt Nam Vô Địch!");
HANDLE hdlConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX consoleFont;
consoleFont.cbSize = sizeof(consoleFont);
GetCurrentConsoleFontEx(hdlConsole, FALSE, &consoleFont);
memcpy(consoleFont.FaceName, L"Consolas", sizeof(consoleFont.FaceName));
SetCurrentConsoleFontEx(hdlConsole, FALSE, &consoleFont);

std::wcout << L"Tiếng Việt có dấu" << std::endl;


std::wstring test;
std::wcout << L"Hãy nhập vào một chuỗi ký tự:" << std::endl;
std::getline(std::wcin, test);
std::wcout << L"Chuỗi ký tự mà bạn vừa mới nhập:" << std::endl;
n-gram language models std::wcout << test << std::endl;
𝑚
FILE *f;
𝑃෠ 𝑤1 , 𝑤2 , ⋯ 𝑤m = ෑ 𝑃෠ 𝑤𝑖 ȁ𝑤1 , ⋯ , 𝑤i−1
f = fopen("output.txt","w,ccs=UTF-16LE");
𝑖=1
fwprintf(f, L"%ws",(wchar_t*) test.c_str());

fclose(f);

//std::wofstream f(L"ketqua.txt");
𝐶 𝑤𝑖−𝑛+1 … , 𝑤𝑖 //f << test.c_str() << std::endl;
𝑃෠ 𝑤𝑖 ȁ𝑤1 , ⋯ , 𝑤i−1 = //f.close();
𝐶 𝑤𝑖−𝑛+1 , ⋯ , 𝑤𝑖−1 system("pause");
return 0;
}
Speech synthesis
Multimedia
Bảng tần số

Nốt nhạc Bát độ 3 Bát độ 4 Bát độ 5 Bát độ 6
C 131 262 523 1047
C# 139 277 554 1109
D 147 294 587 1175
D# 156 311 622 1245
E 165 330 659 1319
F 175 349 698 1397
F# 185 370 740 1480
G 196 392 784 1568
G# 208 415 831 1661
A 220 440 880 1760
A# 233 466 932 1865
B 247 494 988 1976
Harmonica Effects
C (Đồ) D (Rê) E (Mi) F (Fa) G (Sol) A (La) B (si) C (Đô)
Why using cosin distance for this

What is no people see…

Chiều nay còn mưa sao em không lại

Đo khoảng cách và gắn nốt nhạc tương ứng


Là Đô Là Si Đô Đô Si Là

Tranlation Machine
Using dictionary and Grammer

ĐỀ CÁT
JAVA and OpenCV
1. javac -classpath .;opencv-400.jar EqualizeHistDemo.java
2. java -classpath .;opencv-400.jar EqualizeHistDemo lena.jpg Using java for opencv
NetBean IDE

Copy Opencv-400.jar to your project and


opencv_java400.dll -> bin
import java3d lib, copy *.dll ->bin JAVA 3D
ant run
ASM Features
Handwritting and speech

Hand writting model

Combine model

Speech model
BÀI TOÁN CÁI TÚI
Mỗi con vật được vẽ bởi một tiến trình

Làm sao nhét con voi qua lỗ kim


Python Scipy
Adruino
FUZZY LOGIC
‫ 𝑦 𝑆׬‬d𝑦
defuzzy =
‫ 𝑆׬‬d𝑦

S = {𝑦𝑚 ∈ 𝑅, 𝜇 𝑦𝑛 = 𝑆𝑈𝑃𝑦𝜖𝑅 (𝜇 𝑦 )}

Turn over

‫𝑦 𝑆׬‬. 𝜇 𝑢 d𝑦
defuzzy =
‫ 𝑢 𝜇 𝑆׬‬d𝑦
Rule 1: IF e=ZE AND delta =ZE THEN output =ZE
mu(1) = MIN (0.7, 0.3)=0.3
output(1)=0

Rule 2: IF e=ZE AND delta =SP THEN output =SN


mu(2)=MIN (0.7,1)=0.7
output(2)=-0.5

Rule 3: IF e=SN AND delta =SN THEN output =LP


mu(3) = MIN (0.0, 0.0 )=0
output(3)=1
e=0.25, delta=0.5
Rule 4: IF e=LP OR delta =LP THEN output = LN
E Delta mu(4) = MAX (0.0,0.3)=0.3
mu(LP) 0 0.3 output(4)=-1
mu(SP) 0.7 1
mu(ZE) 0.7 0.3
mu(SN) 0 0
mu(LN) 0 0
Fuzzy
Database
Analyzier

DeFuzzier

Fuzzy question

𝑚 1 ⋅ 𝑜𝑢𝑡𝑝𝑢𝑡 1 + 𝑚𝑢 2 . 𝑜𝑢𝑡𝑝𝑢𝑡 2 + 𝑚𝑢 3 . 𝑜𝑢𝑡𝑝𝑢𝑡 3 + 𝑚𝑢 4 . 𝑜𝑢𝑡𝑝𝑢𝑡(4)


=
𝑚𝑢 1 + 𝑚𝑢 2 + 𝑚𝑢 3 + 𝑚𝑢(4)

0.3⋅0+0.7.(−0.5)+0.1+0.3.(−1)
= =-0.5
0.3+0.7+0+0.3
Robotics wireless communication
MIMO

Correlation caculate

d
SIMO

Noise, echo, reverberant, diffuse,distortion…


PCA

Những người con trai của đất nam kì lục tỉnh
Viterbi algorithm

𝜙𝑗 𝑡 = 𝑚𝑎𝑥𝑖 𝜙𝑖 𝑡 − 1 𝑎𝑖𝑗 𝑏𝑗 𝑜𝑡

𝜑1 1 = 1

𝜑𝑖 1 = 𝑎1𝑗 𝑏𝑗 𝑜1

1≤𝑗≤N The maximum likelihood 𝑃෠ Oȁ𝑀

𝜙𝑁 𝑇 = 𝑚𝑎𝑥𝑖 {𝜙𝑖 𝑇 𝑎𝑖𝑁 }

𝜑𝑗 𝑡 = 𝑚𝑎𝑥𝑖 𝜑𝑗 𝑡 − 1 +log(𝑎𝑖𝑗 ) + 𝑙𝑜𝑔( 𝑏𝑗 𝑜𝑡 )


𝐴𝑖𝑗
𝑎ො𝑖𝑗 = 𝑁
𝛴𝑘=2 𝐴𝑖𝑘

𝑟
σ𝑅𝑟=1 σ𝑇𝑟 𝑟
𝑡=1 𝜓𝑗𝑠𝑚 (𝑡)𝑜𝑠𝑡
𝜇Ƹ 𝑖𝑗 = R 𝑇𝑟 𝑟
𝛴𝛤=1 𝛴𝑡=1 𝜓𝑗𝑠𝑚 𝑡

𝑅 𝑇 𝑟 𝑟 𝑟
𝛴𝑟=1 𝑟
𝛴𝑡=1 𝜓𝑗𝑠𝑚 𝑡 (𝑂𝑠𝑡 − 𝜇Ƹ 𝑗𝑠𝑚 )(𝑂𝑠𝑡 − 𝜇Ƹ 𝑗𝑠𝑚 )𝑇
𝛴෠𝑗𝑠𝑚 =
σ𝑅𝑟=1 σ𝑇𝑡=1
𝑟 𝑟
𝜓𝑗𝑠𝑚 (𝑡)

𝑟
σ𝑅𝑟=1 σ𝑇𝑟
𝑡=1 𝜓𝑗𝑠𝑚 (𝑡)
𝑐𝑗𝑠𝑚 = R 𝑇𝑟 𝑀 𝑠 𝑟
𝛴𝛤=1 𝛴𝑡=1 𝛴𝑡=1 𝜓𝑗𝑠𝑚 𝑡
Markov Chains

𝑁−1

𝛼𝑗 𝑡 = ෍ 𝛼𝑖 𝑡 − 1 𝑎𝑖𝑗 𝑏𝑗 𝑜𝑡
𝑖=2

𝛼1 1 = 1

𝛼𝑗 1 = 𝑎1𝑗 𝑏𝑗 𝑜1

1≤𝑗≤𝑁 1≤t≤T

𝑁−1

𝛼𝑁 𝑇 = ෍ 𝛼𝑖 𝑇 𝑎𝑖𝑁
𝑖=2
Forward algorithm

Terminal: 𝑃 0ȁ𝜆 = σ𝑁
𝑖=1 𝛼 𝑇 𝑖
Markov Chains

Backward algorithm
Forward algorithm
𝛽𝑡 i = 𝑃(𝑂𝑡+1 , 𝑂𝑡+2 , … , 𝑂𝑇 ȁ𝑞𝑡 = 𝑖, 𝜆)
1. Initialization
1. Initialization
𝑣1 𝑗 = 𝜋𝑗 𝑏𝑗 (𝑂1 ) 1≤𝑗≤𝑁
1≤𝑗≤𝑁 𝛽𝑇 i = 1 1≤i ≤𝑁
𝑏𝑡1 𝑗 = 0
2. Recursion 2. Recursion 𝑁
𝑁
𝑣𝑡 𝑗 = 𝑚𝑎𝑥𝑖=1 𝑣𝑡−1 (𝑖)𝑎𝑖𝑗 𝑏𝑗 (𝑂𝑡 ) 1 ≤ 𝑗 ≤ 𝑁, 1<t ≤ 𝑁 𝛽𝑡 i = ෍ 𝑎𝑖𝑗 𝑏𝑗 𝑜𝑡+1 𝛽𝑡+1 j 1 ≤ 𝑗 ≤ 𝑁, 1<t ≤ T
𝑗=1
𝑁
𝑏𝑡1 𝑗 = 𝑎𝑟𝑔𝑚𝑎𝑥𝑖=1 𝑣𝑡−1 (𝑖)𝑎𝑖𝑗 𝑏𝑗 (𝑂𝑡 ) 1 ≤ 𝑗 ≤ 𝑁, 1<t ≤ 𝑁 3. Termination
3. Termination 𝑁
𝑁 P Oȁ𝜆 = ෍ 𝜋𝑗 𝑏𝑗 𝑜1 𝛽1 j
The best score 𝑃 ∗ = 𝑚𝑎𝑥𝑖=1 𝑣𝑇 (𝑖) 𝑗=1
𝑁
The start of backtrace 𝑞 𝑇 ∗ = 𝑎𝑟𝑔𝑚𝑎𝑥𝑖=1 𝑣𝑇 (𝑖)
E - step
𝛼𝑡 𝑗 𝛽𝑡 𝑗
𝛾𝑡 𝑗 = ∀𝑡 and 𝑗
𝛼 𝑇 𝑞𝐹

𝛼𝑡 𝑗 𝑎𝑖𝑗 𝑏𝑗 (𝑂𝑡+1 )𝛽𝑡+1 𝑗


ξ𝑡 𝑖, 𝑗 = ∀𝑡, 𝑖 and 𝑗
𝛼 𝑇 𝑞𝐹

𝑁
M - step
𝑃 0ȁ𝜆 = ෍ 𝛼 𝑇 𝑖
σ𝑇−1
𝑡=1 𝜉𝑡 𝑖, 𝑗 𝑖=1
𝑎ො𝑖𝑗 = 𝑇−1 𝑁
σ𝑡=1 σ𝑡=1 𝜉𝑡 𝑖, 𝑗 Chuỗi trạng thái tối ưu

σ𝑇𝑡=1,𝑠,𝑡,𝑂𝑡=𝑣𝑘 𝛾𝑡 𝑗
𝑏෠𝑗 (𝑣𝑘 ) =
σ𝑇𝑡=1 𝛾𝑡 𝑗
Implementation Hmm Model
Có ông vua trẻ xuất quân qua rừng dẹp quân xâm lấn

Quân vương giữa hoa rừng lòng bàng hoàng nhớ người thương
THANK YOU

View publication stats

You might also like