Ubuntu เสียงหาย

Jul 18 2010

ใช้งาน Ubuntu อยู่ดีๆแล้วเสียงก็หายไป กลายเป็นไม่ว่าจะเล่นเพลงอะไรก็ได้ยินแต่ noise ซ่าๆ วิธีแก้ให้ลองใช้คำสั่ง

sudo /etc/init.d/alsa-utils reset 

เพื่อ reset ALSA ซะ ทำได้โดยไม่ต้องปิดโปรแกรมที่กำลังใช้งานเสียงอยู่

ที่มา

No responses yet

การเรียนรู้ด้วยวิธี linear least squares

Jul 10 2010

ช่วงนี้ได้มีโอกาสเรียนรู้เรื่อง machine learning แบบลึกกว่าที่ผ่านมา ที่ผ่านมาต้องเรียกว่าไม่รู้อะไรเลยมากกว่า ได้แต่ใช้ tool ของชาวบ้าน ไหนๆ ก็เรียนมาแล้วก่อนที่จะลืมก็อยากเขียนเอาไว้ซะหน่อย เผื่อคนที่เพิ่งเริ่มเหมือนกันด้วย

เป้าหมายหนึ่งของงานในด้าน supervised learning หรือการเรียนรู้แบบมีผู้สอน ก็คือการประมาณค่าของ function (real-valued function) จริงจากข้อมูลที่สุ่มมาได้ (sample) จากภาพ (จาก http://en.wikipedia.org/wiki/Least_squares) จุดแดงคือข้อมูลที่สุ่มมา เส้นน้ำเงินคือ function ที่ประมาณขึ้นมาได้จากข้อมูล วิธีหนึ่งในการประมาณค่า function คือ Linear least-squares ไอเดียคือ พยายามหา function ที่ทำให้ผลรวมของระยะห่างจากจุดแต่ละจุดมายัง function นั้นน้อยที่สุด (จริงๆแล้วคือระยะห่างกำลังสอง) ระยะห่างแต่ละจุดมาถึง function พูดง่ายๆก็คือ error นั่นเอง ถ้าระยะห่างทุกจุดเป็น 0 ก็แปลว่า function เราผ่านทุกจุดเป๊ะๆ

สมมติว่าเรามี n จุด (ตัวอย่าง) กำหนดให้  (x_i, y_i) เป็นตัวอย่างที่ i เราพยายามจะหา function ในรูปของ

 \hat{f}(x) = \sum_{j=1}^b \alpha_j \varphi_j(x)

เมื่อ  \varphi_j(x) คือสิ่งที่เรียกว่า basis function ที่รับ x แล้วคืนค่าเป็นจำนวนจริง ซึ่งเราสามารถเลือกเป็นอะไรก็ได้ มีทั้งหมด b basis function จากไอเดียของ lineat least-squares เราอยากหา  \hat{f}(x) ที่ทำให้ผลรวม error น้อยสุด ในเมื่อ basis function ของเรากำหนดตายตัวไปแล้ว ปัญหาจึงลดลงไปเป็นการหา  \alpha_j ทั้งหมดที่ทำให้ผลรวม error น้อยสุด ดังนี้ (เรียก  \alpha_j ดังกล่าวว่า  \hat{\alpha}_j)

 \hat{\boldsymbol \alpha} = \arg \min_{\boldsymbol \alpha} \sum_{i=1}^n (\hat{f}(x_i) - y_i)^2

ในสมการข้างบน \arg \min_{\boldsymbol \alpha}  แปลว่า หา \boldsymbol \alpha ที่ทำให้สิ่งที่ตามมามีค่าน้อยที่สุด ในที่นี้ \boldsymbol \alpha = (\alpha_1, \alpha_2, \ldots, \alpha_b)^T เป็น vector ของ \alpha_j ทั้งหมด เขียนเป็น vector จะได้สะดวก ต่อมาจากข้างบนแทนนิยามของ function ลงไปเราจะได้

  \hat{\boldsymbol \alpha} = \arg \min_{\boldsymbol \alpha} \sum_{i=1}^n (\sum_{j=1}^b \alpha_j \varphi_j(x_i) - y_i)^2

ถ้าเรากำหนดให้  \boldsymbol X_{i,j} = \varphi_j(x_i) โดยที่  \boldsymbol X_{n \times b} เป็น matrix แล้วสมการข้างบนจะสามารถเขียนได้เป็น

  \hat{\boldsymbol \alpha} = \arg \min_{\boldsymbol \alpha} \| (\boldsymbol X \boldsymbol \alpha - \boldsymbol y) \|^2

โดยที่ \boldsymbol y = (y_1, y_2, \ldots, y_n)^T เป็น vector ของค่า y ทั้งหมด ต่อไปเราก็ diff ค่าข้างบนนั่นเทียบกับ \boldsymbol \alpha แล้วจับเท่ากับ 0 (การ diff เทียบกับ vector สามารถหาดูได้ที่ matrixcookbook.com) เราจะได้

  2\boldsymbol X^T (\boldsymbol X \boldsymbol \alpha - \boldsymbol y) = 0

จัดรูปไปมา เราจะได้

  \hat{\boldsymbol \alpha} = (\boldsymbol X^T \boldsymbol X)^{-1} \boldsymbol X^T \boldsymbol y

จะเห็นว่าเราสามารถหา parameter ที่ดีที่สุดในแง่ของ Least-squares ได้โดยการคูณ matrix เมื่อเราได้ \hat{\boldsymbol \alpha} แล้วที่เหลือก็แค่แทนลงไปในนิยามของ \hat{f}(x) ข้างบน เราก็ได้ function แล้ว สังเกตว่าถึงเราจะเรียกว่า linear least squares แต่ \varphi_j(x) จะเป็น function ที่ไม่ linear กับ x ก็ได้ เช่น log คำว่า linear least squares ในที่นี้คือ function ที่ได้นั้น linear เมื่อเทียบกับ parameter นั่นคือ \boldsymbol \alpha

ถ้าเลือก basis function ดีๆหลากหลายหน่อย เราสามารถประมาณค่า function ได้หลากหลายมาก วิธีนี้ดูเผินๆแล้วน่าจะดี แต่จริงๆแล้ว function ที่ได้มักจะมีปัญหาที่เรียกว่า overfit หรือประมาณค่าใกล้กับข้อมูลมากจนเกินไป (เกิดขึ้นเมื่อมี basis function เยอะ จนสามารถประมาณค่า function อะไรก็ได้) นั่นหมายความว่าถ้าข้อมูลที่เราได้มามี noise มาก เช่น ได้จากเครื่องมือวัดค่าที่เก่าแล้ว คลาดเคลื่อนบ่อย function ที่เราได้มันก็จะซิกแซกไปตามจุดพวกนั้นด้วย ซึ่งในความเป็นจริงเราไม่อยากได้

ตัวอย่างคือรูปนี้ http://upload.wikimedia.org/wikipedia/commons/5/5d/Overfit.png จะเห็นว่ามี 2 เส้น เส้นโค้งกับเส้นตรง ซึ่งได้จากข้อมูลชุดเดียวกันแต่ basis function ต่างกัน ในความเป็นจริงเราอยากได้เส้นตรง ถึงแม้เส้นโค้งจะผ่านทุกจุดเป๊ะ แต่เห็นได้ชัดว่าข้อมูลมีโครงสร้างเชิงเส้น ที่จุดพวกนั้นไม่เรียงเป็นแนวเส้นตรงน่าจะเกิดจาก noise มากกว่า ด้วยเหตุนี้เราจึงกล่าวว่าเส้นโค้งฟิตกับข้อมูลมากไปหรือ overfit นั่นเอง วันหลังจะมีพูดถึงวิธีแก้ปัญหา overfit

จบแล้ว หากผู้รู้จริงผ่านมาแล้วมีคำแนะนำก็เชิญ comment ครับ

\sum_{j=1}^b \alpha_i \varphi_j(x)[

5 responses so far

ncftp: FTP Client with Recursive Transfers

Jun 05 2010

I have searched for a FTP client with recursive transfers for a while. By recursive transfers, I mean transfering the whole directory at once. For many GUI clients, this feature is quite common. What I mean here is a FTP command-line client. FTP command-line clients rarely provide such feature. A good client I have come across which can do that is ncftp . If you use Ubuntu, you can get it by

sudo apt-get install ncftp

You can start ncftp with

ncftp -u <your_ftp_user> -p <your_ftp_password> <yourhostname.here.com> 

After you are in the ncftp interface, normal FTP commands work here. To transfer the whole folder, use

mget -R folder_name 

If you need more information, issue the command

help

to see all available commands.

No responses yet

Phrases I don’t like that are often used in text books

May 25 2010

I am sure that people who read technical books related to mathematics have come across the following phrases at least once.

  • “It is easy to show that … “
  • “The derivation of … is left as an exercise.”
  • “The blah blah problem therefore amounts to ….(some long formula) …”
  • “Clearly, blah blah of this is blah blah of that …”

There is nothing wrong about the mentioned phrases. The problem is that these phrases are often used without any justification or clear explanation. Around 80% of the time I found “It is easy to show that…”, it is NOT easy for me.  Around 90% of the time I found “The derivation of … is left as an exercise.”, I cannot derive the thing I want. Almost every time I found “The blah blah problem therefore amounts to ….(some long formula) …”, I do not know why the given formula is related to the original problem. Finally, every time I found “Clearly, ….”, it is NOT that obvious for me to figure out. It takes some time.

This post is just a complaint from a stupid man like me. Just think about it. If you can easily derive a long formula, what is the point of reading the book ? You are already able to do it by your own. This implies that many students read the book because they do not know how to derive those. They want to know it. That is why they read the book! In the end, I still wonder why the book is often written in that way. Is it so troublesome to add more details .. ?

No responses yet

Older posts »