Mixture

身未动,心已远

导航

04 2014 档案

Gibbs Sampling for the Uninitiated 资料
摘要:第一个链接的读书笔记接近翻译,比较简练,贴在这里吧:http://www.crescentmoon.info/?p=504 andhttp://www.crescentmoon.info/?p=525还有一个也挺赞:http://www.xperseverance.net/blogs/2013/03... 阅读全文

posted @ 2014-04-28 18:10 parapax 阅读(310) 评论(0) 推荐(0)

【转】LDA
摘要:论文看了前三个section, 然后搜资料发现了些不错的。-------------------------------------------------------------------------------------------------------------------------... 阅读全文

posted @ 2014-04-24 23:11 parapax 阅读(1291) 评论(0) 推荐(0)

【转】Dirichlet分布
摘要:转自:http://blog.csdn.net/jiang1st2010/article/details/8841644这一系列(机器学习的数学基础)主要包括目前学习过程中回过头复习的基础数学知识的总结。基础知识:conjugate priors共轭先验 共轭先验是指这样一种概率密度:它使得后验概... 阅读全文

posted @ 2014-04-24 15:55 parapax 阅读(303) 评论(0) 推荐(0)

【转】概率主题模型简介 Introduction to Probabilistic Topic Models
摘要:看了David M. Blei写的《Introduction to Probabilistic Topic Models》,有的地方不是很清楚,然后搜到了这篇译文,感觉很棒,转来备份一下~转载自:http://www.cnblogs.com/siegfang/archive/2013/01/30/2... 阅读全文

posted @ 2014-04-24 14:25 parapax 阅读(272) 评论(0) 推荐(0)

codility: Fibonacci numbers (FibFrog, Ladder)
摘要:FibFrog:The Fibonacci sequence is defined using the following recursive formula: F(0) = 0 F(1) = 1 F(M) = F(M - 1) + F(M - 2) if M >= 2A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other b... 阅读全文

posted @ 2014-04-08 10:17 parapax 阅读(2108) 评论(0) 推荐(0)

codility: Euclidean algorithm ( ChocolatesByNumbers, CommonPrimeDivisors)
摘要:Chocolates By NumbersTwo positive integers N and M are given. Integer N represents the number of chocolates arranged in a circle, numbered from 0 to N... 阅读全文

posted @ 2014-04-07 10:10 parapax 阅读(1542) 评论(0) 推荐(0)

effective c++ 11: Handle assignment to self in operator =
摘要:比如有这样一个class:class A {};class B { ...private: A* a;};在写class B的赋值函数的时候,假如写成下面这样:B& B::operator=(const B& rhs) { delete a; a = new A(*rhs.a); return *this;}假如是自我赋值,那上面这个代码显然就不对了,*this和rhs是一个对象,所以如果都delete a 了下面还怎么new A(*rhs.a)呢。可以通过identity test检查是否是自我赋值:if(this==&rhs) return *this在上面那... 阅读全文

posted @ 2014-04-07 00:08 parapax 阅读(272) 评论(0) 推荐(0)

effective c++ 10: Have assignment operators return a reference to *this
摘要:为了实现连锁赋值,赋值操作符需要返回一个reference指向操作符的左侧实参。就像这样:class Widget {public: ... Widget& operator=(const Widget& rhs) { ... return *this; } ...};除了标准赋值,任何赋值相关的运算都应当返回一个reference to *this。 阅读全文

posted @ 2014-04-06 23:39 parapax 阅读(147) 评论(0) 推荐(0)

effective c++ 9: Never call virtual functions during construction or destruction
摘要:因为base class的构造函数的执行早于derived class,所以如果在构造函数里调用virtual函数,很可能derived class部分的成员变量还没初始化。并且在derived class对象的base class构造期间,对象是被看做一个base class对象的,所以显然调用virtual函数不会达到想象的效果。比较好的方式是把原本在构造函数中调用的virtual函数改为non-virtual,并通过derived lass构造函数传递信息给baseclass构造函数。比如:class Transaction {public: explicit Transactio... 阅读全文

posted @ 2014-04-06 23:33 parapax 阅读(225) 评论(0) 推荐(0)

effective c++ 8: Prevent exceptions from leaving destrctors
摘要:析构函数的异常会导致不确定行为。比如说我要有若干个自定义类的对象存在vector里,但是在析构函数里销毁这个vector第一个元素的时候发生了异常,那后面的元素可能无法正确销毁从而导致内存泄露。解决析构函数抛异常的方法有这样两种:1. 一旦抛异常就结束程序(catch里abort()),这样避免了异常继续传播。2. 吞下异常(catch里记录异常原因等等)。但是更好的方式是把可能导致异常的操作写在析构函数外面的普通函数里,这样就有机会去处理这个可能的异常。 阅读全文

posted @ 2014-04-06 23:18 parapax 阅读(160) 评论(0) 推荐(0)

effective c++ 7: Declare destructors virtual in polymorphic base classes
摘要:比如我们有个factory函数,这个函数返回一个base class的指针,指向derived class对象。在使用完毕后要正确的删除这个factory返回的每个对象。但是假如derived class对象通过一个base的指针删除,但是这个base class的析构函数是non-virtual的话,这个对象的derived部分一般是无法被销毁的。对于上面这种带有多态性质的base class应该声明一个virtual析构函数。任何class只要带有virtual函数都应该有个virtual析构函数。但是如果一个class不含virtual函数的话就不要随便乱写virtual析构函数了,那样 阅读全文

posted @ 2014-04-06 23:08 parapax 阅读(187) 评论(0) 推荐(0)

文件按行随机排列
摘要:今天碰到了个需求,就是我需要在一个文件里随机抽一些行出来做训练集,剩下的做测试集。因为原来的文件排列有一定的顺序可能影响结果,所以不能直接head或者tail。我以为肯定有个命令很方便的完成这件事情,结果搜了半天没搜到可以直接用的(可能还是有,只是我太蠢没有找到。。。),结果发现了一个博客是用c结合shell做的,感觉还挺不错。思路就是用c把文件每行的尾部加上一个随机数(各行后面的随机数不重复),之后再用shell按最后一列排序就好。原文在这里:http://blog.csdn.net/liyuxia713/article/details/7445592备份下代码在下面://random.c# 阅读全文

posted @ 2014-04-05 10:52 parapax 阅读(919) 评论(0) 推荐(0)

codility:Maximum slice problem (MaxDoubleSliceSum, MaxProfit, MaxSliceSum)
摘要:唯一一个全部一次100%的lesson。(实在因为太简单。。。)MaxSliceSum:A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P ≤ Q &A);that, given an array A consisting of N integers, returns the maximum sum of any slice of A.For example, given array A such that:A[0] 阅读全文

posted @ 2014-04-04 12:34 parapax 阅读(3309) 评论(0) 推荐(0)

Intel vt-d技术资料收集
摘要:Intel的vt-d specification:http://download.intel.com/technology/computing/vptech/Intel(r)_VT_for_Direct_IO.pdf下面这个关于IOMMU的讲解还挺好懂:from:http://bbs.chinaunix.net/thread-2072818-1-1.html在没有IOMMU的情况下,设备(指32bit或64bit设备,老的16bit的不提)的DMA操作可以访问整个物理地址空间,所以理论上设备可以向操作系统的代码段、数据段等内存区域做DMA,从而破坏整个系统。当然,通常来说不会有这样的设备。IO 阅读全文

posted @ 2014-04-04 11:37 parapax 阅读(1315) 评论(0) 推荐(0)

effective c++ 6: Explicitly disallow the use of compiler-generated functions you do not want
摘要:假如有个类,我不想让这个类的对象产生副本,即不想让它支持copy构造函数以及copy assignment操作符。那么比较好的办法是把这两个函数声明为private并且不定义。这样即使member或者friend函数想用着两个函数也会发生连接错误。把这个错误提到编译器的一个好办法是专门设计一个Uncopyable类,然后来继承这个Uncopyable类,这样无论任何形式对这两个函数的调用都会在编译期报错了。class Uncopyable {protected: Uncopyable() {} ~Uncopyable() {}private: Uncopyable(const... 阅读全文

posted @ 2014-04-03 18:29 parapax 阅读(158) 评论(0) 推荐(0)

effective c++ 5: Know what functions C++ silently writes and calls
摘要:编译器会自动为一个类声明一个copy构造函数,一个copy assignment操作符和一个析构函数(如果没有自己声明这些函数的话)。如果没有声明任何构造函数,c++也会声明一个default构造函数。当这些函数需要被调用的时候,才会被创建。default构造函数和析构函数中一般是调用base classes和non-static成员变量的构造函数。编译器自动产生的析构函数为non-virtual,除非这个class的base class自身声明有virtual析构函数。copy构造函数和copy assignment操作符只是将来源对象的每个non-static成员变量拷到目标对象里。但是假 阅读全文

posted @ 2014-04-03 18:20 parapax 阅读(159) 评论(0) 推荐(0)

effective C++ 4 Make sure objects are initialized before they are used
摘要:由于读取未初始化的值可能导致的结果不确定,为了避免出错,在用它们之前一定要初始化。1.对于内置类型以外的对象,要在构造函数里完成对象每一个成员的初始化。使用成员初值列,而不是在构造函数内赋值需要搞清楚的是赋值和初始化的区别,举个书上的例子:class PhoneNumber {...};class ABEntry {public: ABEntry(const std::string &name, const std::string& address, const std::list &phones);private: std::string theName; std:: 阅读全文

posted @ 2014-04-02 18:07 parapax 阅读(162) 评论(0) 推荐(0)

effective C++ 3 use const whenever possible
摘要:const一直是个我记不太清楚的东西,这一节内容还挺多,希望自己可以记住。首先是const指针的问题,到底指针是const,还是指针指向的东西是const。这里提供了一条很简单的法则,那就是看const出现在星号*的左边还是右边:const在*左边,那就是指向的东西是const,如果在*右边,那就是指针本身是个const。比如char test[] = "test";const char *p = test; //non-const pointer, const datachar* const p = test; //const pointer, non-const dat 阅读全文

posted @ 2014-04-01 10:05 parapax 阅读(221) 评论(0) 推荐(0)

STL: string:erase
摘要:leetcode: permutation sequence用了https://github.com/soulmachine/leetcode上面康托编码的思路:class Solution {public: string getPermutation(int n, int k) { string s(n,'0'); for(int i=1;i<=n;i++) { s[i-1]+=i; } string res = ""; k = k-1; int base = getFatorial(n... 阅读全文

posted @ 2014-04-01 06:49 parapax 阅读(292) 评论(0) 推荐(0)

STL: 从reverse到iterator
摘要:leetcode:Next Permutationclass Solution {public: void nextPermutation(vector &num) { auto rfirst = num.rbegin(); auto rlast = num.rend(); auto pivot = next(rfirst); while(pivot!=rlast&&*pivot>=*prev(pivot)) { ++pivot; } if(pivot==rlast) { ... 阅读全文

posted @ 2014-04-01 06:03 parapax 阅读(222) 评论(0) 推荐(0)

STL: remove
摘要:leetcode:Remove Elementcode from:https://github.com/soulmachine/leetcodeclass Solution {public: int removeElement(int A[], int n, int elem) { return distance(A,remove(A,A+n,elem)); }};又是STL一句话搞定。distance之前已经学过了,正好复习一下:distance(InputIterator first, InputIterator last), 返回的是两个迭代器的距离。remov... 阅读全文

posted @ 2014-04-01 05:45 parapax 阅读(200) 评论(0) 推荐(0)

STL: vector range constructor, set::insert
摘要:思路来自https://github.com/soulmachine/leetcode,是4Sum这道题class Solution {public: vector > fourSum(vector &num, int target) { vector > res; if(num.size() > > twoSumBuf; sort(num.begin(),num.end()); for(int i=0;i(i,j)); } } set > setRes; for(si... 阅读全文

posted @ 2014-04-01 05:17 parapax 阅读(339) 评论(0) 推荐(0)