- 博客(56)
- 资源 (1)
- 收藏
- 关注
原创 leetcode 31. Next Permutation
void nextPermutation(vector<int>& nums) { if(nums.size()==1)return; vector<int> back; int i=nums.size()-1; do{ back.push_back(nums[i]); i--; }while(i>=0 && nums[i]>=
2016-06-29 19:52:23 293
原创 机器学习实战 第五章 logistic回归
机器学习实战 第五章 logistic回归二值型输出分类器。5.1 基于logistic回归和sigmoid函数的分类一个很有意思的阶跃函数叫做海维赛德阶跃函数,英文是heaviside step function,我原本以为这会是个人名——海维赛德,结果一看英文heaviside,这个意思难道不是一边重?因为一边重,所以一边就被压成了0,另一边就是1.sigmoid:def sigmoid(inX
2016-06-29 18:02:53 1564 1
原创 GibbsLDA model.cpp分析
GibbsLDA model.cpp分析刚刚是英格兰和冰岛的比赛,我也是醉了,本来以为大英格兰会血虐冰岛,但是目前为止看上去似乎冰岛在血虐英格兰的样子。目前冰岛2:1英格兰。冰岛第一个传中,前锋抢点铲射。第二个随便抡一脚,哈特就成了背景帝。我越来越觉得哈特具有国际奉献精神了,给各国球员送上值得纪念的经典入球。头文件这个cpp是包含了所有的头文件,可以看出是个大boss。函数函数1:model::~m
2016-06-28 04:17:18 598
原创 GibbsLDA model.h分析
GibbsLDA model.h分析头文件其他的头文件都分析完了,也没什么可以看的了,就是两个头文件,分别是constants.h 和 dataset.h.constants.h就是对于常数的设置,而dataset.h就是数据集合的一个设置。变量// fixed optionsstring wordmapfile; // file that contains word map [strin
2016-06-28 02:06:17 521
原创 GibbsLDA utils.cpp分析
GibbsLDA utils.cpp分析头文件都看到了这儿,头文件有啥已经不重要了,都在心中。函数函数1:int utils::parse_args(int argc, char ** argv, model * pmodel);变量:model_status就是当前model的状态,现在因为还不确定,所以是KNOWN。dir就是存有model的文件夹的路径?model_name是model的名称
2016-06-27 23:18:22 355
原创 GibbsLDA utils.h分析
GibbsLDA utils.h分析头文件头文件很少,只有string函数函数有五个:// parse command line argumentsstatic int parse_args(int argc, char ** argv, model * pmodel);// read and parse model parameters from <model_name>.othersstat
2016-06-27 22:45:31 479
原创 GibbsLDA dataset.cpp分析
GibbsLDA dataset.cpp分析头文件#include <stdio.h>#include <stdlib.h>#include "constants.h"#include "strtokenizer.h"#include "dataset.h"头文件有两个标准库和三个自己的头文件。constant设置了两类常量,buf的大小和MODEL的类型。strtokenizer的作用就
2016-06-27 21:40:08 446
原创 GibbsLDA strtokenizer.cpp分析
GibbsLDA strtokenizer.cpp分析头文件仅有\#include <string>\#include <vector>\#include "strtokenizer.h"功能简单。函数构造函数,直接调用parse函数。parse过程,soga!原来是这么分割的啊,我之前分割字符串都是傻傻的,先找到一个,然后把前面的都erase,然后再find_first_of,发现两个参数的
2016-06-27 20:47:11 547
原创 GibbsLDA strtokenizer.h分析
GibbsLDA strtokenizer.h分析 在这个文件中,实在是非常短。构造函数相当简单,一个字符串,和一个分隔符seperator。不过int idx是做什么的呢?以及五个函数。void parse(string str, string seperators);int count_tokens();string next_token(); void start_scan();
2016-06-27 20:38:51 329
原创 GibbsLDA dataset.h分析
GibbsLDA dataset.h分析 直觉上来说,可能和wordmap.txt有着很大关系,因为原文件中包含两个map,分别是mapid2word和mapword2id,来研读一下。// map of words/terms [string => int]typedef map<string, int> mapword2id;// map of words/terms [int =>
2016-06-27 20:25:49 508
原创 GibbsLDA constants.h分析
GibbsLDA constants.h分析就是几个常数的定义分别是buff_size_long = 1000000(1M)buff_size_short = 512有不同的buff_size大小然后就是MODEL_STATUS的定义,分别是:0:UNKNOWN 1:EST 2.ESTC 3.INF
2016-06-27 19:52:34 450
原创 GibbsLDA lda.cpp分析
GibbsLDA lda.cpp分析主函数非常简单,甚至头文件都非常简单:就是标准库的stdio和同文件夹下的model.h。其中只有两个函数,分别是main和show_help,在show_help中主要功能就是对于输入错误的指令进行输出提示。main函数中,建立了一个model,然后对于argc和argv进行分析,以及初始化操作。如果是est或者是estc,那么就需要对于模型的参数进行训练,如果
2016-06-27 19:43:21 535
原创 GibbsLDA++使用手册
GibbsLDA++使用手册1.DescriptionGNU license2.Compile GibbsLDA++默认编译器是CC= g++OBJS= strtokenizer.o dataset.o utils.o model.oMAIN= ldaall: $(OBJS) $(MAIN).cpp $(CC) -o $(MAIN) $(MAIN).c
2016-06-27 19:25:37 3447 1
原创 LDA图模型
LDA图模型:W为可观测变量,非阴影圆圈表示潜在变量,箭头表示依赖性,方框表示重复抽样,次数在右下角。M代表语料中的文章数。k代表主题数。θ\theta是M*K矩阵,表示文章的主题分布。ϕ\phi是K*V的矩阵,表示主题的词分布。α\alpha是文章的主题分布的先验狄利克雷分布的参数β\beta是主题的词分布的先验狄利克雷分布的参数。所以α\alpha和θ\theta是一对。β\beta和ϕ\phi
2016-06-26 19:45:02 1967
转载 link to python 3
http://old.sebug.net/paper/books/dive-into-python3/table-of-contents.html#serializing
2016-06-26 19:26:45 522
原创 chardet demo
0.Brief introduction:It’s hard to detect the type of the string , for example we open a file and want to detect the type of it.1.Install:pip install chardet2.Use chardet: Input: import urllib
2016-06-26 18:58:26 368
转载 link to 字符编码
http://www.crifan.com/files/doc/docbook/char_encoding/release/html/char_encoding.html#utf8_bom_efbbbf
2016-06-26 15:39:45 384
原创 link to install mysql on MAC
http://www.myexception.cn/mysql/2043991.html
2016-06-25 16:41:43 357
原创 《LDA漫游指南》数学基础阅读笔记
《LDA漫游指南》数学基础阅读笔记第二章 烧脑的数学公式。。。廉颇老矣,扶我起来,朕还能算。。。gamma函数这个函数主要目的是计算阶乘可以通过这个函数来进行转化。举个栗子:这么一看,其实挺简单的哈,无非就是一个积分运算,无非是表现形式有些复杂而已。再来重复一遍:第一个烧脑结果: Γ(12)\Gamma({1\over2}): 运算过程:首先将121\over2带入gamma函数,对于计算结果进行
2016-06-21 19:45:02 6216 2
原创 根据《LDA漫游指南》来对gibbsLDA++结果进行分析
根据LDA漫游指南来对gibbsLDA++结果进行分析在使用gibbsLDA++之前,对于文档进行预处理,第一行为文档的数目,第2 - n+1行为每一篇文章分词后的结果。 最终会产生许多文件,gibbsLDA++软件是通过迭代的方式来进行运算的,最后会生成:model-final.othersmodel-final.phimodel-final.tassignmodel-final.thet
2016-06-21 18:57:44 1973
原创 leetcode 30. Substring with Concatenation of All Words
一个简单的通过next_permutation来进行字符串查找的函数,很遗憾,超时vector<int> findSubstring(string s, vector<string>& words) {vector<int> order;vector<int> ret;for(int i=0;i<words.size();i++)order.push_back(i);string _s = s
2016-06-21 18:22:25 360
原创 leetcode 29. Divide Two Integers
int divide(int dividend, int divisor) {if(dividend == INT32_MIN){ if(divisor == 1)return INT32_MIN; if(divisor == -1) return INT32_MAX;}if(divisor == 0){ if(dividend > 0)return INT32_MAX;
2016-06-21 16:49:56 293
原创 leetcode 28. Implement strStr()
int strStr(string haystack, string needle) { return haystack.find(needle);}
2016-06-21 16:18:20 228
原创 leetcode 27. Remove Element
还是不知道这道题有什么可写的。。。int removeElement(vector<int>& nums, int val) {vector<int>::iterator iter;while( (iter = find(nums.begin(),nums.end(),val))!=nums.end()){ nums.erase(iter);}return nums.size();
2016-06-21 16:15:56 218
原创 leetcode 26. Remove Duplicates from Sorted Array
实在不明白有什么可写的。。。class Solution {public:int removeDuplicates(vector<int>& nums) { vector<int>::iterator iter = unique(nums.begin(),nums.end()); nums.erase(iter,nums.end()); return nums.size(
2016-06-21 16:08:49 232
原创 leetcode 23. Merge k Sorted Lists
class Solution {public:static bool comp(ListNode * a , ListNode * b){ return a->val > b->val;}ListNode* mergeKLists(vector<ListNode*>& lists) { ListNode head(0); ListNode *curNode = &he
2016-06-21 15:39:32 278
原创 leetcode 24. Swap Nodes in Pairs
class Solution {public:ListNode* swapPairs(ListNode* head) { ListNode * cur = head; while(cur!=NULL && cur->next!=NULL){ int tmp = cur->val; cur->val = cur->next->val;
2016-06-21 15:38:42 202
原创 leetcode 25. Reverse Nodes in k-Group
ListNode* reverseKGroup(ListNode* head, int k) {if( !head || k==1 )return head;int num = 0;ListNode * cur = head;while(cur!=NULL){++num;cur = cur->next;}ListNode * ghost = new ListNode;ghost->val
2016-06-21 15:37:08 233
原创 leetcode 22. Generate Parentheses
void generateParent(vector<string>& parenthesis , string cur ,int left,int n){ if(cur.length() == 2*n){ parenthesis.push_back(cur); return; } if(left> (cur.length()-left) ){
2016-06-20 16:23:16 239
原创 leetcode 21. Merge Two Sorted Lists
没有加新的链表,而是在原有的链表基础上进行next的修改。ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode * ret = NULL , *p = NULL; if(l1 == NULL)return ret = l2; if(l2 == NULL)return ret = l1; if(l2
2016-06-20 15:58:51 222
原创 leetcode 20. Valid Parentheses
bool isValid(string s) {stack<char> valid;int i;for(i=0;i<s.length();i++){ if(s[i] == '(' || s[i] == '[' || s[i] == '{'){ valid.push(s[i]); }else{ if(s[i]==')'){
2016-06-20 13:01:44 268
原创 leetcode 19. Remove Nth Node From End of List
其实三个指针可以简化称为两个,要删除的元素不需要指针,只需要记录其后面元素的指针,最后到达应该删除的位置之后: back -> next = back->next->next;ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode * front = head, * rem = head, * back = head;
2016-06-20 12:53:52 202
原创 leetcode 18. 4Sum
写过3Sum之后写4Sum感觉毫无难度 O(n^3)的时间复杂度vector<vector<int>> fourSum(vector<int>& nums, int target) {vector<vector<int> > res;if(nums.size()<=3)return res;int i,j,left,right;int a,b,c,d;sort(nums.begin(),
2016-06-20 12:44:38 234
原创 leetcode 15. 3Sum
这道题最后各种调整优化,但是就是超时,我也是跪了,所以我觉得根本还是算法的问题,我现在的复杂度是O(n^2logn)所以,感觉复杂度略高。vector<vector<int>> threeSum(vector<int>& nums){vector<vector<int>> ret;if(nums.size()<3)return ret;sort(nums.begin(),nums.end())
2016-06-19 21:48:37 203
原创 leetcode 11. Container With Most Water
int maxArea(vectorint>& height){ int left =0 , right = height.size()-1 , maxA=0; while(left int tmp = (right - left)*(height[right]left]?height[right--]:height[left++]);
2016-06-19 19:52:40 214
原创 leetcode 8. String to Integer (atoi)
int myAtoi(string str) { long res =0; int sign =1; int len = str.length(); int i = str.find_first_not_of(" "); if(str[i] =='+' || str[i] =='-'){ sign = (str[i
2016-06-18 19:04:11 222
原创 leetcode 7.Reverse Integer
//一个test case , 即翻转过来是-2147483648似乎并没有测试到,所以通过了。。。int reverse(int x){ int sign = x>0?1:-1; x = x*sign; char ret[16] = {'0','0','0','0','0','0','0','0','0','0'}; int
2016-06-18 18:31:39 204
NTUSD台湾大学情感词典
2016-07-12
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人