financialiq 的部落格

[re-class] Huffman coding

"In computer science and information theory, Huffman coding is an entropy encoding algorithm used for lossless data compression. The term refers to the use of a variable-length code table for encoding a source symbol (such as a character in a file) where the variable-length code table has been derived in a particular way based on the estimated probability of occurrence for each possible value of the source symbol. It was developed by David A. Huffman while he was a Ph.D. student at MIT, and published in the 1952 paper ""A Method for the Construction of Minimum-Redundancy Codes."" Huffman became a member of the MIT faculty upon graduation and was later the founding member of the Computer Science Department at the University of California, Santa Cruz, now a part of the Baskin School of Engineering. Huffman coding uses a specific method for choosing the representation for each symbol, resulting in a prefix-free code (sometimes called ""prefix codes"") (that is, the bit string representing some particular symbol is never a prefix of the bit string representing any other symbol) that expresses the most common characters using shorter strings of bits than are used for less common source symbols. Huffman was able to design the most efficient compression method of this type: no other mapping of individual source symbols to unique strings of bits will produce a smaller average output size when the actual symbol frequencies agree with those used to create the code. A method was later found to do this in linear time if input probabilities (also known as weights) are sorted. For a set of symbols with a uniform probability distribution and a number of members which is a power of two, Huffman coding is equivalent to simple binary block encoding, e.g., ASCII coding. Huffman coding is such a widespread method for creating prefix-free codes that the term ""Huffman code"" is widely used as a synonym for ""prefix-free code"" even when such a code is not produced by Huffman's algorithm. Although Huffman coding is optimal for a symbol-by-symbol coding with a known input probability distribution, its optimality can sometimes accidentally be over-stated. For example, arithmetic coding and LZW coding often have better compression capability. Both these methods can combine an arbitrary number of symbols for more efficient coding, and generally adapt to the actual input statistics, the latter of which is useful when input probabilities are not precisely known[@more@]"

[About] 機器人

"人工智慧真空吸塵器 今天收到一封廣告信,是 iRobot 公司出的 Roomba 智慧吸塵機器的廣告。先前讀到一些這方面的產品,就趁這個機會介紹一下好了,希望對於懶得打掃家裡地板的人有幫助 :p Roomba 和一般的智慧吸塵機器一樣,都是做成圓餅的形狀,主要還是為了在探索地型時撞到牆仍能順利轉彎。這類產品最基本的技術還是在於如何建立環境地圖,以及避開危險的地形;更進階的是要辨認什麼是需要清潔的,而什麼又是不能清理的(試想家中的博美狗被吸塵器抓住的樣子…) Roomba 用的概念很單純;它會先利用螺旋狀的路徑擴大自己的虛擬視野,試著找出房間的邊界在哪裡,同時記住自己走過的距離。當撞到東西時,它會先向後退一點點,轉一點點彎,再向前進。找到邊界之後,它會開始利用直線前進,並清掃記憶中還沒有打掃的區域。 在 Roomba 中比較有趣的是它還提供一個""虛擬牆""(Virtual Wall)的裝置;由於 Roomba 會儘量找出牆的範圍,所以如果門開著它搞不好就會跑出去了,若是我們希望門可以不要關,又不要它跑出房間,就可以把 Virtual Wall 放在門口,這樣它就不會跑出去了。Virtual Wall 其實是一個會發出不可見光的裝置,Roomba 感應到它的光線,就會當作那是禁區而轉彎了。 Roomba 這台能夠感測到樓梯之類的危險區域,而不會摔下去;當它在進行清掃的時候,會放音樂來降低它的噪音(還真貼心啊…-_-),它的聲音大約是 80dB左右。 同樣的智慧型吸塵器是瑞典的 Electrolux 公司所做的 trilobite;這台紅色的小圓餅功能和 Roomba 類似,不過它不會避樓梯,而需要用鋪在地上磁毯來畫出禁區。不過它有個有趣的功能,就是會自己跑回去固定的""家""充電,真是很可愛的功能 :p 看完這個,有沒有想去買一個來玩看看丫xd[@more@]"

[About] 心得

恩…這次的演算法是我第二次重修了… 第一次會沒過的原因很簡單…因為程式我不會寫… 程式…對於資工系的學生來說。應該是很簡單的事情。 但事實上,對我而言,卻是超級困難。 當然大部份的原因是因為我自已的不努力… 現在知道這個原因卻往往都沒去努力… 空想是我最大的失敗的地方吧…什麼事情都空想著 演算法…也是考碩士的其中一科… 該如何讀,老實說我沒有什麼頭緒… 總之…會讀不好的原因沒有其他…就是我自已不努力吧。 ps:想想…最近老師們也會為了教學評見煩腦吧。 也許是有「小白」關系吧

[About] 基因算演法

"這算是它的應用吧~~ 教電腦怎麼走路 現今充斥於電影或是電玩中的人物或角色,大多都無法避免要走得""像人"";當傳統的方法繁瑣而缺乏彈性,基因演算法再一次為動畫製片指出一條簡單易用的路…。 傳統上,要做出動畫中的人物走路的畫面,通常都需要仔細描述每個畫面怎麼走、或是把真人的動作拍攝下來再輸入進去。然而這種做法太繁瑣也缺乏彈性,所以 Torsten Reil 決定運用基因演算法,來教導他的人物走路。 首先必須建立環境;把重力和人物的肌肉結構都做好關連之後,每一個角色有七百組參數可以調整。他透過類神經網路來控制肌肉的運動,但是由於系統實在太複雜而不可能透過人來調整,所以這時就可以導入基因演算法來訓練。 由於系統中有重力等條件,所以系統評分的方法就採用人物走的步數來評分;走越多步的就越好,直到它跌倒為止。剛開始系統中的人物大都走不了一步,但至少有些會比其他晚一些倒下,這些表現比較好的個體會被複製二十份,再做一些細微的突變放到下一代。同時系統也會再產生八十個新的個體加入賽局。 但是由於評分標準是採用走的步數,所以有些角色就會發展出奇怪的走法,例如仆伏前進或是翻筋斗之類的,所以他再進一步把遊戲規則加入一條,就是重心不能低於某個高度。 經過二十回合,系統已經能夠產生走得非常順暢的角色了;我們不需要知道它內部的類神經網路怎麼排列,但可以確定的是演化的力量再一次的快速替我們找到一個解答。[@more@]"

[About] 我的專題

"我從我朋友那邊得到個想法~~ ETHERAL這個我們網概課用過了~!! 他是個不錯用的程式,不過美中不足~ 我想要做一個類似又不類似的東西~ WPE這個是我的想法來源~ ETHERAL是把封包分析 查看來源 而WPE是封包擷取修改封包~ 那現在如果把兩個結合 做出一個程式 可以監看執行中哪些程式在使用網路 那些程式又是透過何種路徑(DNS)來到我們這邊 還有其來源(IP)加上封包擷取功能和封包修改功能 這樣的程式或許對特定使用使會有相當的幫助 而且如此的監控法是否可以取代防火牆? 因為偷取電腦上資料的惡意軟體最終 還是要透過網路傳輸所竊取的資料 那此想法所做出的程式不是就可以防範此狀況嗎?!"

[re-class]Dynamic programming

"From Wikipedia, the free encyclopedia Jump to: navigation, search In computer science, dynamic programming is a method of solving problems exhibiting the properties of overlapping subproblems and optimal substructure (described below) that takes much less time than naive methods. The term was originally used in the 1940s by Richard Bellman to describe the process of solving problems where one needs to find the best decisions one after another. By 1953, he had refined this to the modern meaning. The field was founded as a systems analysis and engineering topic which is recognized by the IEEE. Bellman's contribution is remembered in the name of the Bellman equation, a key result. The word ""programming"" in ""dynamic programming"" has no particular connection to computer programming at all. A program is, instead, the plan for action that is produced. For instance, a finalized schedule of events at an exhibition is sometimes called a program. Programming, in this sense, is finding an acceptable plan of action. 危機百科可以找到很多東西~~"

[About] Divide and conquer algorithm

"In computer science, divide and conquer (D&C) is an important algorithm design paradigm. It works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem. A divide and conquer algorithm is closely tied to a type of recurrence relation between functions of the data in question; data is ""divided"" into smaller portions and the result calculated thence. This technique is the basis of efficient algorithms for all kinds of problems, such as sorting (quicksort, merge sort) and the discrete Fourier transform (FFTs). 它可以成為一個章結,必有其它的目的、跟用處。[edit] Implementation Divide-and-conquer algorithms are naturally implemented as recursive procedures. In that case, the partial sub-problems leading to the one currently being solved are implicitly stored in the procedure call stack. However, D&C solutions can also be implemented by a non-recursive algorithm that stores the partial sub-problems in some explicit data structure, such as a stack, queue, or priority queue. This approach allows more freedom in the choice of the sub-problem that is to be solved next, a feature that is important in some applications — e.g. in breadth-first recursion and the branch and bound method for function optimization."

[about] greedy 演算法

"零錢換整問題 問題: 要把 n 個 1 元硬幣兌換成 50 元, 10 元, 5 元, 1 元硬幣, 如何兌換可以讓最終的硬幣數最少? 愚公移山的想法 (exhaustive search): 把各種硬幣的各種組合都試過一次, 逐一檢查其和是否為 n, 並記錄符合條件的組合各用了多少個硬幣, 再找出最佳答案。 動態規劃的想法: 用愚公移山法解的過程中, 不同的子問題是否用到共同的孫問題答案? 短視/近利/偷懶/貪婪 (greedy) 的想法: x0 = n % 50; n = floor(n / 50); x1 = n % 10; n = floor(n / 10); x2 = n % 5; x3 = floor(n / 5); 則 ""x0 個 50 元, x1 個 10 元, x2 個 5 元, x3 個 1 元"" 即為答案。 恩,取這個greedy名字,真是名副其實丫"

[about]五子棋

來研究五子棋好了 雖然目前的程式程度超差 但還是希望可以來研究一樣東西 結果不管如何 加油吧恩,我找到一個人所放的資料 上面有完整的程式碼 大概看了一下 老實說不會 但我會努力的 僅僅一天,做不了什麼事,但希望能有些收獲

[re-class] 利用基因演算法來最佳化資料庫

"今天在看 PostgreSQL 的文件時,發現有個章節在講運用基因演算法(Genetic Algorithms) 來最佳化資料庫的查詢方法(Query Plan),就來介紹一下 PostgreSQL 是如何應用的。 所謂的 Query Plan(查詢方法),是指資料庫管理程式如何由現存的 Table 中,做出使用者想要的資料。Query Plan中最難以處理的是 Join 這個動作。Join 這個動作,簡而言之就是把兩個相關的 Table 合成一張大的 Table;例如我們有一個 Table 記錄 ""人名-居住城市"",另一個""人名-喜好"",今天如果我們要找出""住台北、又喜歡寫 Blog""的人,就可以利用 Join 這個指令,以人名當作索引值,合成一張同時具有我們所需要資料的 Table。 Join 有很多種方法可以做到,最差的狀況就是把所有的可能性都列出來,再刪掉不正確的。舉例來說,住址 Table 有一千筆,喜好資料也有一千筆,那麼就先產生一百萬筆的表格,再一一刪去;相對的,如果我們知道人名都沒有重覆、居住城市表格中,同一個人也只會有一筆資料、每個人也只有一個喜好,那麼甚至可能幾千筆就做出來了。 但並不是每一個 Query Plan 都是如此的顯而易見,當需要比對的 Table 越來越多,到底是先 Join 哪一個 Table、先 Join 哪兩個 Join 完的結果,會變成一個需要把全部的可能性都列出來,才知道哪個最好的問題,我們稱這種解法叫做""窮盡搜""(Exhaustiive Search),意思就是得把所有的組合都找出來才行。 更慘的是 Query Plan 的數量又隨著 Table 的增加而大幅增加,當需要 Join 的 Table 由兩個變三個、四個甚至到十幾個時, Query Plan 的總量就像 1*2*3*4 這樣呈指數成長,到最後要找出所有的可能解答本身所花的時間,搞不好都比資料庫查詢時間來得長了。 在德國的 University of Mining and Technology 自動控制學院設計了一個電力控制系統,用 PostgreSQL 來當作決策系統的資料庫,但是因為決策系統需要運用大量的 Join 來進行推理的運算,為了兼顧效率,他們把基因演算法引入資料庫的設計之中,用來快速產生有效率的 Query Plan。 關於基因演算法的基本概念在此略過,請參考本站相關文章。 Query Plan 最佳化的作法和著名的 Traveling Salesman Problem(TSP) 問題很類似,先將可能的解法變成數字的字串,例如 4-1-3-2 就表示先讓 Table 4 和 Table 1 做 Join,再和 Table 3、2 做 Join。 演化時採用穩態演化,也就是每次只把表現最差的一個 Plan 淘汰掉;而子代的產生則是運用 ""edge recombination crossover[註二]"",而突變的機制在這裡並不使用。 運用基因演算法,資料庫可以在合理的時間中找出有效的 Query Plan來進行 Join 的動作,然而除了找出最好的 Query Plan 之外,電腦的的Computation Time也是一個很重要的因素,不同的參數對於系統也會有不同的影響。 從這個例子可以看到基因演算法所運用的場合,還是脫離不開""在合理的時間""、""複雜度高的狀況下""、""找到合理可接受的解法""的特色。 註一:PostgreSQL 是一個 GPL 的資料庫,最早是由 Berkeley 所發展的,如今和 MySQL 同為網路上最受歡迎的 GPL 資料庫軟體,官方網站在 http://www.postgresql.org。 註二:關於 edge recombination crossover 的說明,請參考這裡。 參考資料: Genetic Query Optimization 相關閱讀: 上帝的靈藥─基因演算法(一) 上帝的靈藥─基因演算法(二) June 26th 2003 Posted to 基因演算法[@more@]"

訂閱文章