leetcode-300 leetcode 300 连续增长子序列的个数,典型的动态规划 #include <iostream> #include <cstdio> #include <algorithm> #include <string> int lengthOfLIS(std::vector<int>& nums) { int len = nums.size(); int res = len; std::vector<int> seq
leetcode-213 直接上代码了。 最典型的动态规划,写出动态规划的方程就好。 这里分两种情况, 0号位选取时,0号位不选取时,len<=3时特殊处理。 f[i] = f[i-2] > f[i-3] ? f[i-2]+a[i] : f[i-3]+a[i]; #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <vector> int
bazel编译与类的继承 在类的继承里面,会涉及到虚函数的问题,我现在先贴一下正确的代码如下。 #ifndef _TEST_CLASS_H #define _TEST_CLASS_H class Base { public: virtual ~Base(); virtual void Print(); }; class Derive : public Base { public: virtual ~Derive(); virtual void Print(); }; #endif //TEST_CLASS
c++ memory pool 内存池 这里就直接贴上代码了,基本高效实现。 template<class T> class MemoryPool { public: T* Malloc() { if (free_element_ == last_element_) { return nullptr; } T* result = reinterpret_cast<T *>(free_element_); free_element_ = free_element_->n
获取时间 这里就直接贴上代码了,获取某一段程序运行的时间。 #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <sys/time.h> #include <unistd.h> #define USDIFF(new, old) (1000000 * (int64_t)((new
最大子数组的和 这里就直接上代码了,非常简单的一个代码了,动态规划 #include <iostream> #include <cstdio> // using namespace std; int main() { int arr[] = {-1, 5, -4, 7, 3, -2, -1, 4, -6}; int len = sizeof(arr)/sizeof(int); int sum_val = 0; int start_index = 0; int end_index
单例模式 这里直接上代码了 #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <memory> #include <mutex> class Singleton{ public: typedef std::shared_ptr<Singleton> Ptr; ~Singleton(){
python的string类型与dictionary 将字符串转为dictionary data_str = ''' {'start_time': '0', 'end_time': '70', 'text': '明天天气'} ''' 对于上面的字符串,可以直接用 info_map = eval(data_str) print('start:%s, end:%s' % (info_map['start_time'], info_map['end_ti...
python多线程互斥锁问题 之前一直觉得python的多线程有点问题,今天搞了一下多线程的事情;直接上代码了。 #-*- coding:utf8 -*- #!/usr/bin/env python import os import sys import subprocess import json import string import re import time from threading import Threa...
高斯混合模型 高斯混合模型,首先说的那就是高斯分布, f(x)=12πσexp(−(x−μ)22σ2)=N(x,σ,μ2) f(x)=\frac{1}{\sqrt{{2\pi}}\sigma}\exp(-\frac{(x-\mu)^2}{2\sigma^2})=N(x,\sigma,\mu^2) f(x)=2πσ1exp(−2σ2(x−μ)2)=N(x,σ,μ2) 对应的均值方差是μ\muμ,σ2\si...
最大似然估计 现在简单写写最大似然估计。 最大似然估计是一个概率估计问题,譬如已知一个数据空间XXX,数据XXX中的每一个样本都有n为特征。有样本整体x=[x1,x2,x3,x4,.....,xn]x=[x_1,x_2,x_3,x_4,.....,x_n]x=[x1,x2,x3,x4,.....,xn]。同时了有这样的先验知识,知道数据空间XXX里面所有的样本,都符合一个的概率密度函数(prob de...
python中文单字问题 一直都有这个问题的说,或许其实并没有自己想象的那么难处理的说; 对应的python2 python3都有相应的解决办法。 已知有文件 明天天气 现在需要进行单字切分,得到文件 明 天 天 气 python2 与 python3 都有相应的解决办法,现在直接贴代码了 python2 #!/usr/bin/env python #coding:utf-8 import os import sy...
fst-graph 这里就直接贴上代码了。 digraph G { node [shape = circle] 0 -> 1 [ label = sil ] 0 -> 2 [ label = w ] 1 -> 1 [ label = sil ] 1 -> 2 [ label = w ] 2 -> 2 [ label = w ] 2 -> 3 [ labe...
构图逻辑 现在写写一般的构图逻辑,这里会介绍ci-phone的,同时也会介绍cd-phone的构图逻辑。 一般介绍 ci-phone构图 cd-phone构图 下面先介绍下技术背景,主要应用在解码过程中,也就是语音识别;譬如唤醒、命令词都可以应用。对于一个词的发音序列 word : phn1 phn2 phn3 word: A B C D E ... Z 其中A就是词头,Z就是词尾。 先介绍ci-p...
c++一次性读取文件 c++中一次读取整个文件的内容的方法: 读取至char*的情况 std::ifstream t; int length; t.open("file.txt"); // open input file t.seekg(0, std::ios::end); // go to the end length = t.tellg(); // report ...
语音识别--gmm-hmm思考 简单回顾一下今天所看的内容: gmm-hmm pdf: 概率密度函数,在这里可以由gmm来估计,同样也可以用dnn来估计。 gmm: 高斯混合模型,单高斯函数,多高斯函数。 能拟合任何函数,这里会涉及到均值方差等变量 语音有短时平稳的特性,可以用高斯混合模型来估计;从而就会有概率密度函数。 hmm:隐马尔科夫模型,双马尔科夫链的过程。关键在于理解状态。 首先需要的说的马尔科夫链。当与时间无关时,...
语音识别-先验概率后验概率似然函数 这里贴一个网页: https://www.cnblogs.com/wjgaas/p/4523779.html 简单的说: Posterior probability ∝ Likelihood × Prior probability 从语音识别的角度来看这个问题,那么就是,解码的过程就是求取后验概率的过程。 ref_W = argmax_w(p(O|W) * P(W)/P(O)) 已知观察...
语音识别Topo笔记 这里记录一下语音识别中的拓扑的问题。 三因子状态的topo Chain-model的topo Ctc的topo 三因子状态的topo <Topology> <TopologyEntry> <ForPhones> 1 2 3 4 5 6 7 8 </ForPhones> <State> 0 <PdfClass> 0 <...
dot图-有限状态机 dot图的规则跟语法,先来看一个最简单的例子。 digraph g { label=test 深圳 -> 南山 [ label = "process"] 南山 -> 科技园 南山 -> 金融公司 { rank=same 科技园 金融公司 } } 转成png的linux命令行是 dot -Tpng ./test.dot -o test.png 参考文献,见如下网页,非...