Viterbi Algorithm

矩阵法numpy

注:转移矩阵和发射矩阵以列维度上形式表示概率分布的,即列维度axis=1上元素和为1。注意:把隐状态概率分布表示为向量后,向量乘以状态转移矩阵的结果为新的隐状态。 同理,对发射矩阵做向量矩阵乘法会得到新的观测状态。


A* Heuristic Algorithm

content
    #include <algorithm>  // for sort
    #include <fstream>
    #include <iostream>
    #include <sstream>
    #include <string>
    #include <vector>
    using std::cout;
    using std::ifstream;
    using std::istringstream;
    using std::sort;
    using std::string;
    using std::vector;
    using std::abs;
    
    // TODO: Add kStart and KFinish enumerators to the State enum.
    enum class State {kStart …
    more ...

    Sort

    Quick Sort

    引例:荷兰国旗问题

    Merge Sort

    class Solution {
    public:
        ListNode* sortList(ListNode* head) {
            if (head == nullptr || head->next == nullptr) { return head; }
            ListNode* fast = head;
            ListNode* slow = head;
            while (fast->next && fast->next->next) {
                slow = slow->next;
                fast = fast->next->next;
            }
            fast = slow->next;
            slow …
    more ...

    LinkedList

    GitHub LinkedList

    链表结点定义

    class ListNode{
        public:
            int val;
            ListNode* next;
    
            ListNode() : val(0), next(nullptr) {}
            ListNode(int x) : val(x), next(nullptr) {}
            ListNode(int x, ListNode* next) : val(x), next(next) {}
    };
    

    链表基本操作

    链表的基本操作与 …

    more ...

    Algorithms

    Linked List

    206. Reverse Linked List

    class ListNode:
        def __init__(self, val):
            self.val = val
            self.next = None
    
    class Solution:
        def reverseLinkedList(self, head: ListNode) -> ListNode:
            if not head or not head.next:
                return head
            pre, cur, post = None, head, head.next
            while cur:
                post = cur.next
                cur.next = pre …
    more ...


    Topological Sorting

    Topological Sorting

    # Definition for a Directed graph node
    class DirectedGraphNode:
        def __init__(self, x):
            self.label = x
            self.neighbors = []
    
    
    class Solution:
        """
        @param graph: A list of Directed graph node
        @return: A list of integer
        """
        def topSort(self, graph):
            # 1. 统计结点入度
            indegree = self.get_indegree(graph …
    more ...