[{"data":1,"prerenderedAt":101},["ShallowReactive",2],{"\u002Ftlt-2009.11.15-the-internets-make-programming-easy":3},{"id":4,"title":5,"body":6,"createdAt":88,"description":12,"draft":89,"extension":90,"image":91,"mastodonThread":91,"meta":92,"navigation":93,"path":94,"seo":95,"stem":96,"tags":97,"updatedAt":99,"__hash__":100},"content\u002FTLT - 2009.11.15 - The Internets Make Programming Easy.md","TLT_-_2009.11.15_-_The_Internets_Make_Programming_Easy",{"type":7,"value":8,"toc":85},"minimark",[9,13,16,27,38,41,73,76,82],[10,11,12],"p",{},"Tags: C++, Programming, UIUC, Data Mining, Homework",[10,14,15],{},"In the class I'm taking (Intro to Data Mining) we get to implement a classifier. Alas... we must use either C++ or Java. I haven't programmed in either for quite a few years, and even with further pursuit I'm not allowed to use OCaml.",[10,17,18,19,26],{},"That's OK! Best to stretch my mind out a bit. I'm afraid I'm getting rusty at being multi-lingual in my old age anyway, so this is good exercise. First thing first, I have to read in the training data. But best start with the basic Hello World even before that. Google... I figure I'll ",[20,21,25],"a",{"href":22,"rel":23},"http:\u002F\u002Fwww.cplusplus.com\u002Fdoc\u002Ftutorial\u002Fprogram_structure\u002F",[24],"nofollow","start with the basics",", and now I have:",[28,29,34],"pre",{"className":30,"code":32,"language":33},[31],"language-text","#include \u003Ciostream>\nusing namespace std;\n\nint main() {\n  cout \u003C\u003C \"Hello World!\" \u003C\u003C endl;\n  return 0;\n}\n","text",[35,36,32],"code",{"__ignoreMap":37},"",[10,39,40],{},"I don't even remember doing that std namespace thing last time I programmed in C++. Oh well. It runs! So from there I just keep searching and adding...",[42,43,44,52,59,66],"ul",{},[45,46,47],"li",{},[20,48,51],{"href":49,"rel":50},"http:\u002F\u002Fwww.cppreference.com\u002Fwiki\u002Fio\u002Fexamples",[24],"Read a file",[45,53,54],{},[20,55,58],{"href":56,"rel":57},"http:\u002F\u002Fstackoverflow.com\u002Fquestions\u002F236129\u002Fc-how-to-split-a-string",[24],"Split the lines (I use a boost library way)",[45,60,61],{},[20,62,65],{"href":63,"rel":64},"http:\u002F\u002Fwww.yolinux.com\u002FTUTORIALS\u002FLinuxTutorialC++STL.html",[24],"Put it all into a two-dimensional vector, and then dump it using iterators",[45,67,68],{},[20,69,72],{"href":70,"rel":71},"http:\u002F\u002Fkengine.sourceforge.net\u002Ftutorial\u002Fg\u002Fstdmap-eng.htm",[24],"Create a key-value map (and dump with iterators!)",[10,74,75],{},"... and just like magic I am now reading the file, parsing it, and counting the frequency of items. Ahh the hive mind! Here's the result... it's messy and unstructured but damn... it works!",[28,77,80],{"className":78,"code":79,"language":33},[31],"\u002F\u002F Compile: g++ -o demo main.cpp\n#include \u003Ciostream>\n#include \u003Cfstream>\n#include \u003Cvector>\n#include \u003Cboost\u002Falgorithm\u002Fstring.hpp>\n#include \u003Cmap>\n\nusing namespace std;\n\ntypedef map\u003Cstring, int> ItemSet;\n\nint main() {\n  cout \u003C\u003C \"Hello World!\" \u003C\u003C endl;\n  ifstream fin(\"data\u002Ftrain1.txt\");\n  \u002F\u002F ifstream fin(\"data\u002Fsmall_train.txt\");\n  string s;\n  vector\u003C vector\u003Cstring> > d;\n\n  ItemSet itemset;\n\n  while(getline(fin,s)) {\n    vector\u003Cstring> row;\n    \u002F\u002F cout \u003C\u003C \"Read from file: \" \u003C\u003C s \u003C\u003C endl;\n    boost::split(row, s, boost::is_space());\n    d.push_back(row);\n  }\n\n  vector\u003C vector\u003Cstring> >::iterator d_iter;\n  vector\u003Cstring>::iterator row_iter;\n\n  for(d_iter = d.begin(); d_iter != d.end(); d_iter++) {\n    cout \u003C\u003C \"[ \";\n    for(row_iter = d_iter->.begin(); row_iter != d_iter->end(); row_iter++) {\n      cout \u003C\u003C *row_iter \u003C\u003C \" \";\n      itemset[*row_iter]++;\n    }\n    cout \u003C\u003C \"]\" \u003C\u003C endl;\n  }\n\n  cout \u003C\u003C \"Itemset:\" \u003C\u003C endl;\n\n  ItemSet::iterator itemset_iter;\n  for(itemset_iter = itemset.begin(); itemset_iter != itemset.end(); itemset_iter++) {\n    cout \u003C\u003C itemset_iter->first \u003C\u003C \" : \" \u003C\u003C itemset_iter->second \u003C\u003C endl;\n  }\n\n  return 0;\n}\n",[35,81,79],{"__ignoreMap":37},[10,83,84],{},"I'll keep going like this for a bit, but then I'll start organizing into actual objects and such. There is a good chance that I'll switch data structures, or perhaps not even bother keeping all this in memory. Most likely I'm also violating some other C++ socio-political norms. Fun!",{"title":37,"searchDepth":86,"depth":86,"links":87},2,[],"2009-11-15T23:18-05:00",false,"md",null,{},true,"\u002Ftlt-2009.11.15-the-internets-make-programming-easy",{"title":5,"description":12},"TLT - 2009.11.15 - The Internets Make Programming Easy",[98],"blog","2010-07-07T11:36-04:00","sszlNOaKmnf7tRXejfVxbl0l4WAa7iLwwYB97UylIPo",1778988314298]