Lecture 5ii
This presentation is the property of its rightful owner.
Sponsored Links
1 / 40

Lecture 5II PowerPoint PPT Presentation


  • 69 Views
  • Uploaded on
  • Presentation posted in: General

Lecture 5II. Roots of nonlinear functions Nested FOR loops. Nonlinear system. A set of nonlinear functions. Function evaluation. function F = myfun(x) F(1) = x(1).^2 + x(2)^2-4; F(2) = x(1) - x(2); return. x=linspace(-2,2); plot(x,x); hold on; plot(x,sqrt(4-x.^2))

Download Presentation

Lecture 5II

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Lecture 5ii

Lecture 5II

  • Roots of nonlinear functions

  • Nested FOR loops

軟體實作與計算實驗


Nonlinear system

Nonlinear system

軟體實作與計算實驗


A set of nonlinear functions

A set of nonlinear functions

軟體實作與計算實驗


Function evaluation

Function evaluation

function F = myfun(x)

F(1) = x(1).^2 + x(2)^2-4;

F(2) = x(1) - x(2);

return

軟體實作與計算實驗


Lecture 5ii

x=linspace(-2,2);

plot(x,x); hold on;

plot(x,sqrt(4-x.^2))

plot(x,-sqrt(4-x.^2))

軟體實作與計算實驗


Least square of nonlinear functions

Least square of nonlinear functions

軟體實作與計算實驗


Find a zero

Find a zero

x0= ones(1,2)*2;

x = lsqnonlin(@myfun,x0)

y=myfun(x);

sum(y.^2)

CHECKING

軟體實作與計算實驗


Multiple roots

Multiple roots

v=[]

demo_lsq.m

for i=1:n

x0= ones(1,2)*2;

x = lsqnonlin(@myfun,x0)

v=[v;x];

plot(x(1),x(2),'o');

軟體實作與計算實驗


Lecture 5ii

軟體實作與計算實驗


Function evaluation1

Function evaluation

function F = myfun2(x)

F(1) = 2*x(1).^2 + x(2)^2-24;

F(2) = x(1).^2 - x(2).^2+12;

return

軟體實作與計算實驗


Find a zero1

Find a zero

x0= ones(1,2)*2;

x = lsqnonlin(@myfun2,x0)

y=myfun2(x);

sum(y.^2)

CHECKING

軟體實作與計算實驗


Multiple roots1

Multiple roots

v=[]

for i=1:n

x0= ones(1,2)*2;

x = lsqnonlin(@myfun2,x0)

v=[v;x];

plot(x(1),x(2),'o');

軟體實作與計算實驗


Lecture 5ii

x=linspace(-5,5);

plot(x,sqrt(24-2*x.^2),'r');hold on;

plot(x,-sqrt(24-2*x.^2),'r')

plot(x,sqrt(12+x.^2),'b')

plot(x,-sqrt(12+x.^2),'b')

軟體實作與計算實驗


Demo lsq 2c

Demo_lsq_2c

source code

軟體實作與計算實驗


Lecture 5ii

軟體實作與計算實驗


Function evaluation2

Function evaluation

function F = myfun3(x)

F(1) = x(1).^2 -2* x(2)^2-2;

F(2) = x(1).*x(2) -2;

return

軟體實作與計算實驗


Lecture 5ii

x=linspace(-3,3);

x=x(find(abs(x) > 0.1));

plot(x,sqrt((x.^2-2)/2),'r');hold on;

plot(x,-sqrt((x.^2-2)/),'r')

x=linspace(0.5,3);

plot(x,2./x,'b');

x=linspace(-0.5,-3);

plot(x,2./x,'b')

軟體實作與計算實驗


Find a zero2

Find a zero

x0= ones(1,2)*2;

x = lsqnonlin(@myfun3,x0)

y=myfun3(x);

sum(y.^2)

CHECKING

軟體實作與計算實驗


Multiple roots2

Multiple roots

v=[]

for i=1:n

x0= ones(1,2)*2;

x = lsqnonlin(@myfun3,x0)

v=[v;x];

plot(x(1),x(2),'o');

軟體實作與計算實驗


Lecture 5ii

demo_lsq_hyperbola.txt

two_hyperbola.txt

軟體實作與計算實驗


Matrix multiplication

Matrix Multiplication

  • C=A*B

  • C(i,j)=A(i,:) *B(:,j) for all i,j

軟體實作與計算實驗


Nested for loops

Nested FOR Loops

[n,d1]=size(A);[d2,m]=size(B)

for i=1:n

for j=1:m

C(i,j)=A(i,:) *B(:,j)

軟體實作與計算實驗


Lecture 5ii

[n,d1]=size(A);[d2,m]=size(B);

for i=1:n

for j=1:m

C(i,j)=A(i, :) *B(:,j);

end

end

軟體實作與計算實驗


Constrained optimization

Constrained optimization

Inequality constraint

Nonlinear equality

軟體實作與計算實驗


Constrained optimization1

Constrained optimization

軟體實作與計算實驗


Constraints

Constraints

  • Lower bound and upper bound

  • Equality constraint

  • Inequality constraint

軟體實作與計算實驗


Lecture 5ii

Constraints

Lower bound

Upper bound

Inequality constraints

軟體實作與計算實驗


Demo conop2

Demo_conop2

demo_conop2.m

function demo_conop2()

lb =[-2 0];

ub =[10,10];

Aeq=[-1 1];beq=[0];

A=[];b=[];

x = fmincon(@fun,[1 1],A,b,Aeq,beq,lb,ub)

x(1).^2+x(2).^2

return

function y = fun(x)

y = (x(1).^2+x(2).^2-13).^2;

return

軟體實作與計算實驗


Objective function

Objective function

function y = fun(x)

y = (x(1).^2+x(2).^2-13).^2;

return

軟體實作與計算實驗


Calling fmincon

Calling fmincon

x = fmincon(@fun,[1 1],A,b,Aeq,beq,lb,ub)

objective

function

initial

guess

linear

equality

inequality

Lower and upper

bound

軟體實作與計算實驗


Random variable

Random variable

  • Sample space S={A,T,C,G}

  • X is a discrete random variable with sample space S.

軟體實作與計算實驗


Generative model

Flip-flop

pa

pt

pg

pc

T

C

G

A

Generative model

gatcacaggt

軟體實作與計算實驗


Partition

Partition

0

1

Knots partition [0,1]

into four intervals respectively with lengths,

軟體實作與計算實驗


Lecture 5ii

r=rand;

Tag= (r<=c(1))+ 2*(r<=c(2) & r > c(1))+3*(r<=c(3) & r > c(2))+4*(r<=c(4) & r > c(3))

switch Tag

case 1

s=[s 'A'];

case 2

s=[s 'T'];

case 3

s=[s 'C'];

case 4

s=[s 'G'];

end

軟體實作與計算實驗


Sequence generation

Sequence generation

  • Emulation of a generative model for creation of an atcg sequence

軟體實作與計算實驗


For loops

FOR Loops

input p,m

n=length(p)

p_sum=0;s=[];

for j=1:m

for i=1:n

r=rand;

switch r

end

p_sum=p_sum+p(i);

c(i)=p_sum;

軟體實作與計算實驗


Mixture model

Flip-flop

Flip-flop

pa

pa

pt

pt

pg

pg

pc

pc

T

T

C

C

G

G

A

A

Mixture model

軟體實作與計算實驗


Mixture model1

Mixture model

  • According to probabilities, and

    each time one of two joined models is selected to generate a character

  • Created characters are collected to form an atcg sequence

軟體實作與計算實驗


Hidden markov model

pa

pa

pt

pt

pg

pg

pc

pc

T

T

C

C

G

G

A

A

Hidden Markov model

1

2

軟體實作與計算實驗


Transition probability

Transition probability

軟體實作與計算實驗


  • Login