// selecting codec by predict #include "../headers/common.h" #include "../headers/codecfactory.h" #include "../headers/caltime.h" #include "../headers/lr.h" #include "../headers/create_feature.h" #include "../headers/microunit.h" #include "../headers/easylogging++.h" #include "../headers/MLP.h" #include "../headers/regress_tree.h" #include "../headers/file_manage.h" #include "../headers/model_selection.h" using namespace Eigen; INITIALIZE_EASYLOGGINGPP const int input_size = 7; std::vector weights = {"../reg_model/reg_model_piecewise.txt","../reg_model/reg_model_FOR.txt","../reg_model/reg_model_rle.txt"}; int main() { using namespace Codecset; // We pick a CODEC std::vector data; std::ifstream srcFile("../data/standard/lognormal_200M_uint32.txt",std::ios::in); //std::ofstream outfile("out.txt", std::ios::app); if(!srcFile) { std::cout << "error opening source file." << std::endl; return 0; } while(1){ uint32_t next ; srcFile >> next; if(srcFile.eof()){break;} data.push_back(next); } srcFile.close(); int N = data.size(); if (data.size() == 0) { std::cout << "Empty vector" << std::endl; return 0; } std::cout << "vector size = " << data.size() << std::endl; std::cout << "vector size = " << data.size() * sizeof(uint32_t) / 1024.0 << "KB" << std::endl; // prepare classifier std::vector models; for (int i=0;i<(int)weights.size();i++){ std::ifstream infile(weights[i], std::ios::in); RegressionTree model; model.rebuild(infile,0); models.push_back(model); infile.close(); } int block_size =20000; int blocks = data.size() / block_size; if (blocks * block_size < N) { blocks++; } //handle with the last block, maybe < block_size int delta =0; std::vector codec_fac; std::vector codec_name={"piecewise_fix","FOR","rle"}; //std::vector codec_name={"piecewise_fix"}; for(int i=0;i<(int)codec_name.size();i++){ IntegerCODEC &codec = *CODECFactory::getFromName(codec_name[i]); codec.init(blocks,block_size,delta); codec_fac.push_back(&codec); } std::vector method_vec; int totalsize = 0; //outfile<< "len" <<" "<<"avg"<<" "<<"min"<<" "<<"max"<<" "<<"num_distinct"<<" "<<"rl"<<" label"<encodeArray8(data.data()+(i*block_size),block_length ,descriptor,i); int tmp_size = (res-descriptor); free(descriptor); //seg.write_feature(outfile,method); method_vec.push_back(pick_method); totalsize +=tmp_size; } //outfile.close(); double end = getNow(); double compressrate = (totalsize)*100.0 / (4*N*1.0); std::cout << "total compression rate:" << std::setprecision(4)<< compressrate << std::endl; //******************* EXHAUSTIVE ************************************** std::vector method_vec_truth; int totalsize_best = 0; for(int i=0;iencodeArray8(data.data()+(i*block_size),block_length ,descriptor,i); int tmp_size = (res-descriptor); if(tmp_size