bool load_fddb(std::vector< std::unique_ptr<NeuralNet::Image> >& images,
        size_t num_image, bool uses_first)
{
    const size_t patch_size = 32;
    size_t loaded_image = 0;

    std::ifstream ellipse_list;
    if (uses_first)
    {
        ellipse_list.open("data-fddb/ellipse-1to5.txt");
    }
    else
    {
        ellipse_list.open("data-fddb/ellipse-6to10.txt");
    }

    while (loaded_image < num_image)
    {
        std::string file_line;
        if (!std::getline(ellipse_list, file_line))
        {
            std::cout << "end-of-file of ellipse file" << std::endl;
            return false;
        }
        file_line.insert(file_line.size(), ".ppm");
        file_line.insert(0, "data-fddb/");

        auto img_ptr = NeuralNet::loadPPMImage(file_line.c_str());
        if (!img_ptr)
        {
            std::cout << "missing file " << file_line << std::endl;
            return false;
        }

        std::string line_str;
        if (!std::getline(ellipse_list, line_str))
        {
            std::cout << "end-of-file of ellipse file" << std::endl;
            return false;
        }
        
        std::istringstream iss(line_str);
        size_t face_count;
        iss >> face_count;

        size_t actual_count = 0;
        for (size_t i = 0; i < face_count && actual_count+loaded_image < num_image; i++)
        {
            if (!std::getline(ellipse_list, line_str))
            {
                std::cout << "end-of-file of ellipse file" << std::endl;
                return false;
            }
            
            std::istringstream iss2(line_str);
            float majsize, minsize, tilt, centx, centy;
            iss2 >> majsize >> minsize >> tilt >> centx >> centy;

            if (majsize < patch_size)
                continue;

            auto crop_ptr = NeuralNet::cropImage(img_ptr,
                        centx - majsize/2,
                        centy - minsize/2,
                        majsize,
                        majsize);
            auto fit_ptr = NeuralNet::fitImageTo(crop_ptr, patch_size, patch_size);
            images.push_back(preprocessImage(fit_ptr));
            actual_count++;
        }
        loaded_image += actual_count;
    }

    return true;
}
Exemple #2
0
//NOTE: The file index starts at 1, but we'll subtract one
//      to match vector index.
void readInFromFile( vector<Node> &g, string fileName )
{
    //clear g
    g = {};
    
    Node emptyNode;
    
    ifstream inFile( fileName, ios::in );
    if ( !inFile )
    {
        cerr << endl << "File could not be opened." << endl << endl;
        exit(1);
    }
    
    string line;
    
    while( getline(inFile, line) )
    {
        istringstream iss1(line);
        string tab;
        
        string sindex;
        long index;
        getline(iss1, sindex, '\t');
        istringstream issIndex(sindex);
        issIndex >> index;
        //Make index match array index
        --index;
        //cout << "Index: " << index << endl;
        
        //Add a node
        g.push_back(emptyNode);

        
        
        while( getline(iss1, tab, '\t') )
        {
            //extra crap (like space or newline) in last iteration
            if( tab.length() >= 3 )
            {
                istringstream iss2(tab);
                
                string comma;
                
                int counter = 0;
                long iVert = -1000;
                long edgeDist = -1000;
                while( getline(iss2, comma, ',') )
                {
                    istringstream iss3(comma);
                    
                    if( counter == 0 )
                    {
                        iss3 >> iVert;
                        //Make vertex match array index
                        --iVert;
                        counter++;
                    }
                    else if( counter == 1 )
                    {
                        iss3 >> edgeDist;
                        counter++;
                    }
                    else
Exemple #3
0
// Test program
int main(int argc, char *argv[])
{
    clock_t s,e;
    s = clock();
    /**** get inputs ****/
//    argv[1] = "T10I4D100K.dat";
//    argv[2] = "1";
//    argv[3] = "outss.txt";
    string input_filename = argv[1];
    string output_filename = argv[3];
    int min_st = atoi(argv[2]);


    /*** check if the input file exist***/
    ifstream input(input_filename);
    if ( !input.is_open() ) {
        // handle error.
        cout << "input file not found!"<< endl;	
    }

    /***** read input file and count one-item frequecies *****/
    item_freq_map one_item_candidate;
    Itemset is;
    is.freq(input, one_item_candidate);

    /****** find one-item sets ******/
    for (auto it = one_item_candidate.begin(); it != one_item_candidate.end(); ){
        if (it->second < min_st){
                one_item_candidate.erase(it++);
        }
        else{
            ++it;
        }
    }

    ofstream output;
    output.open(output_filename);
    vector <int> one_item;
    /****** write one-item sets into the output file ****/
    for (item_freq_map::iterator it = one_item_candidate.begin(); it != one_item_candidate.end(); ++it) {
        output << it->first << " ("<< it->second << ")\n";
        one_item.push_back(stoi(it->first));
    }

    sort(one_item.begin(), one_item.end());

    Trie trie;
    map <string ,int> two_item_candidate;
    for(int i = 0; i < one_item.size(); i++){
        for(int j = i + 1; j < one_item.size(); j++){

            string candidate = to_string(one_item[i])+" "+to_string(one_item[j]);
            trie.addWord(candidate);
            two_item_candidate[candidate] = 0;
        }
    }
    ifstream in(input_filename);
    if (!in.is_open() ) {
    // handle error.
        cout << "input file not found!"<< endl;	
    }
    Utils utils;
    string trans;
    int tid = 0;
    while (std::getline(in, trans))
	{
    	istringstream iss(trans);
    	string s;
    	vector<int> st;    
        //cout << "tid = " << tid<< endl;
    	while ( getline( iss,s, ' ' ) ) 
    	{
            st.push_back(atoi(s.c_str()));
            }
            sort(st.begin(), st.end());
            vector<string> sorted_trans;
            int k;
            for( k = 0; k < st.size(); k++){
            string temp = to_string(st[k]);
            sorted_trans.push_back(temp);
            }
            vector<strset> cursubsets = utils.subsets(2, sorted_trans, tid);
            tid++;
            //utils.printVecOfStrset(cursubsets);
            for(int sub = 0; sub < cursubsets.size(); sub ++)
            {
                string subsetStr = "";
                for (int submem = 0; submem < cursubsets.at(sub).size(); submem++)
                {
                    subsetStr = subsetStr + cursubsets.at(sub).at(submem).c_str() + " ";
                }
                subsetStr = subsetStr.substr(0, subsetStr.length() - 1);
                int support = trie.searchWord(subsetStr);
                two_item_candidate[subsetStr] = support;             
                //cout << "support = " << support << endl;
            }
	}		
    in.close();
    //count_frequency(two_item_candidate)
    
    /*** check which two-item-candidate are frequent ****/
    for (auto it = two_item_candidate.begin(); it != two_item_candidate.end(); ){
        if (it->second < min_st){
            two_item_candidate.erase(it++);
        }
        else{
            ++it;
        }
    }

    /*** get item names ***/
    vector <string> two_item;

    /****** write two-item sets into the output file ****/
    for (item_freq_map::iterator it = two_item_candidate.begin(); it != two_item_candidate.end(); ++it) {
            //cout << it->first << " ("<< it->second << ")\n";
            output << it->first << " ("<< it->second << ")\n";
            two_item.push_back(it->first);
    }

    vector <string> many_item = two_item;
    //cout<<"two_item: "<<two_item.size()<<endl;
    //cout<<"many:"<<many_item.size()<<endl;
    

    int count = 0;
    int k_item = 3;
    
    while(k_item<=5){
       // vector <string> prev_item = many_item;
        map <string ,int> many_item_candidate;
        //cout<<"AREA 2: "<< many_item.size() <<endl;
        for(int i = 0; i < many_item.size(); ++i){
            for(int j = i + 1; j < many_item.size(); ++j){
                vector<int> st;
                int item_size = 0;

                /****** split string by space *****/
                string s1;
                istringstream iss(many_item[i]);
                while ( getline( iss, s1, ' ' ) ) {
                    st.push_back(atoi(s1.c_str()));
                    item_size ++;
                }

                istringstream iss2(many_item[j]);
                string s2;
                while ( getline( iss2, s2, ' ' ) ) {
                        st.push_back(atoi(s2.c_str()));
                        }
                sort(st.begin(), st.end());
                st.erase( unique( st.begin(), st.end() ), st.end() );
                if(st.size()> item_size+1) continue;
                string candidate;
                /*** concatinate string *****/
                int k = 0;
                for(k = 0; k != st.size()-1; ++k){
                    string temp = to_string(st[k]) + " " ;
                    candidate = candidate + temp;
                }

                candidate = candidate + to_string(st[k]);  
                
                many_item_candidate[candidate]++;

            }
            //cout << "i: "<< i<< endl;
        }
        Trie trie2;
        for(auto it = many_item_candidate.begin(); it != many_item_candidate.end();){
				int val = it->second;
				if(val<k_item){
					many_item_candidate.erase(it++);
				}
				else{
                                    trie2.addWord(it->first);
                                    //cout<<"candidate: "<<it->first<<"e"<<endl;
					++it;
				}

			}
        

            //count_frequency(many_item_candidate)
        ifstream in(input_filename);
        if (!in.is_open() ) {
        // handle error.
        cout << "input file not found!"<< endl;	
        }
    //Utils utils;
    string trans;
    int tid = 0;
    while (std::getline(in, trans))
	{
    	istringstream iss(trans);
    	string s;
    	vector<int> st;    
        //cout << "tid = " << tid<< endl;
        
    	while ( getline( iss,s, ' ' ) ) 
    	{
            st.push_back(atoi(s.c_str()));
            }
            sort(st.begin(), st.end());
            vector<string> sorted_trans;
            int k;
            for( k = 0; k < st.size(); k++){
            string temp = to_string(st[k]);
            sorted_trans.push_back(temp);
            }
            //cout << "vec: ";
            //for(int m = 0; m < sorted_trans.size(); m ++)
        	//cout << sorted_trans.at(m) << " ";
            //cout << endl;
            vector<strset> cursubsets = utils.subsets(k_item, sorted_trans, tid);
            tid++;
            //utils.printVecOfStrset(cursubsets);
            for(int sub = 0; sub < cursubsets.size(); sub ++)
            {
                string subsetStr = "";
                for (int submem = 0; submem < cursubsets.at(sub).size(); submem++)
                {
                    subsetStr = subsetStr + cursubsets.at(sub).at(submem).c_str() + " ";
                }
                subsetStr = subsetStr.substr(0, subsetStr.length() - 1);
                //cout << "afterSubStr = " << subsetStr << "e" << endl;
                int support = trie2.searchWord(subsetStr);
                many_item_candidate[subsetStr] = support;             
                //cout << "support = " << support << endl;
                //cout<< "support: " << many_item_candidate[subsetStr] << endl;
//                cout<< "CANDIDATE: " << many_item_candidate["39 120 205"] << endl;
            }
	}		
    in.close();
        
            /*** check which many-item-candidate are frequent ****/
        for (auto it = many_item_candidate.begin(); it != many_item_candidate.end(); ){
            if (it->second < min_st){
                many_item_candidate.erase(it++);
            }
            else{
                ++it;
            }
        }

        //vector <string> many_item;
        many_item.clear();
        /****** write many-item sets into the output file ****/
        for (item_freq_map::iterator it = many_item_candidate.begin(); it != many_item_candidate.end(); ++it) {
            //cout << "$%^" <<it->first << " ("<< it->second << ")\n";
            output << it->first << " ("<< it->second << ")\n";
            many_item.push_back(it->first);
        }
        //cout<<"size_many_2: "<<many_item.size()<<endl;

        count ++;
        k_item ++;
    }




    output.close();
    cout << "Done!\n";



    //set <int> items;
    //vector <vector<int> > transactions;
    //string line;
    /***** another way to read input file and save it as 2D vector ****/
    //while(getline(input, line)){
    //stringstream ss(line);
    //istream_iterator<int> begin(ss), end;
    //transactions.push_back(vector<int>(begin, end));
    //items.insert(transactions.end())
    //}

    //cout << two_item[0]<<endl;

    /**** stop timer *****/
    e = clock();
    float diff ((float)e-(float)s);
    cout << diff << endl;
    return 0;
}
/**
 *  Parse the basis set file and generate a set of reference shells
 *  from which local and external basis set objects are constructed
 */
void BasisSet::parseGlobal(){

  std::string readString;
  std::string nameOfAtom;
  std::string shSymb;
  int         contDepth;
  int atomicNumber;
  int indx;
  std::vector<libint2::Shell> tmpShell;

  bool readRec = false;
  bool newRec  = false;
  bool firstRec = true;
  int nEmpty = 0;
  int nComm  = 0;
  int nRec   = 0;

  while(!this->basisFile_->eof()){
    std::getline(*this->basisFile_,readString);
    if(readString.size() == 0)    nEmpty++;
    else if(readString[0] == '!') nComm++;
    else if(!readString.compare("****")){
      std::getline(*this->basisFile_,readString);
      if(readString.size() == 0) { nEmpty++; readRec = false; continue;}
      nRec++;
      readRec = true;
      newRec  = true;
    }

    if(readRec){
      std::istringstream iss(readString);
      std::vector<std::string> tokens(std::istream_iterator<std::string>{iss},
        std::istream_iterator<std::string>{});
      if(newRec){
        if(!firstRec) {
          this->refShells_.push_back(ReferenceShell{atomicNumber,indx,tmpShell});
        }
        indx = HashAtom(tokens[0],0);
        atomicNumber = elements[indx].atomicNumber;
        newRec = false;
        firstRec = false;
        tmpShell.clear();
      } else {
        contDepth = std::stoi(tokens[1]);
        shSymb    = tokens[0];
        std::vector<double> exp;
        std::vector<double> contPrimary;
        std::vector<double> contSecondary;

        for(auto i = 0; i < contDepth; i++) {
          std::getline(*this->basisFile_,readString);
          std::istringstream iss2(readString);
          std::vector<std::string> tokens2(std::istream_iterator<std::string>{iss2},
            std::istream_iterator<std::string>{});

          exp.push_back(std::stod(tokens2[0]));
          contPrimary.push_back(std::stod(tokens2[1]));
          if(!shSymb.compare("SP"))
            contSecondary.push_back(std::stod(tokens2[2]));
        }

        if(!shSymb.compare("SP")) {
          tmpShell.push_back(
            libint2::Shell{ exp, {{0,this->doSph_,contPrimary}}, {{0,0,0}} }
          );
          tmpShell.push_back(
            libint2::Shell{ exp, {{1,this->doSph_,contSecondary}}, {{0,0,0}} }
          );
        } else {
          tmpShell.push_back(
            libint2::Shell{ exp, {{HashL(shSymb),this->doSph_,contPrimary}}, {{0,0,0}} }
          );
        }
      }
    }
  }
  // Append the last Rec
  this->refShells_.push_back(ReferenceShell{atomicNumber,indx,tmpShell}); 
 
}; // BasisSet::parseGlobal
Exemple #5
0
void Correlation::getParameters(string filename, int start, int stop)
{
  chainName=filename;
  double tmp;
  string strtmp;
  try {

    if (start == -1)	{
	burnin = stop / 5;
    }
    else	{
	    burnin=start;
    }
    nbsample = stop-burnin;
    if(nbsample<=0)
      {
	cerr << "ERROR: in Correlation::getParameters, asking sampling from point " << start << " to point "<< stop <<", exiting\n";
	cerr.flush();
	throw(0);
      }
    cerr << filename << '\t' << " burnin : " << burnin << '\t' << "sample size : " << nbsample << '\n';
    ifstream *is=new ifstream;
    is->open(filename.c_str(), ifstream::in);

    char line[100000];
    string strline;
    is->getline(line,100000);
    strline=line;
    istringstream iss1(strline);

    nbparameter=0;

	/*ALL*/
    iss1 >> strtmp;
    iss1 >> strtmp;
    iss1 >> strtmp;
	/*ALL*/

    strtmp="null";

    while(iss1.good())
      {
	iss1 >> strtmp;
	nbparameter++;
      }
    init();
    istringstream iss2(strline);

	/*ALL*/
    iss2 >> strtmp;
    iss2 >> strtmp;
    iss2 >> strtmp;
	/*ALL*/

    for(int j=0;j<nbparameter;j++)
      iss2 >> parameterName[j];

    createParameterBuffer();
    createWeight();

    for(int i=0;i<stop;i++)
      {

	/*ALL*/
	*is >> tmp;
	*is >> tmp;
	*is >> tmp;
	/*ALL*/

	for(int j=0;j<nbparameter;j++)
	  {
	    *is >> tmp;

	    if(i>=burnin)
	      {
		parameters[j][i-burnin]=tmp;
	      }
	  }
      }
    delete is;
  } catch(...) {
    cerr << "ERROR while reading " << filename << "\n";
    cerr.flush();
    exit(0);
  }
}
Exemple #6
0
void define_data(IloEnv env) {
  string line("           ");
  ifstream myfile ("/home/DavidRC/data.txt");
  int i=0;
  int j=0;
  int x=0;
  int y=0;

  if (myfile.is_open())
  {
    i=0;
	  j=0;
    
	  getline(myfile,line);
	  n=atoi(line.c_str());
	  IloNumArray l(env,n);
	  NumMatrix w(env,n);
    
    for(i=0; i<n; i++)
    {
      w[i]=IloNumArray(env,n);
    }
	  
	  getline (myfile,line);
    
	  istringstream iss1(line);  
	  	while (iss1 && j<n) 
		{ 
			string subs; 
			iss1 >> subs; 
			string temp=subs;
			if(temp.compare("")==0)
			{
				continue;
			}
			else
			{

            l[j]=atoi(subs.c_str());
			}
			j++;
	    }
     exit(1);

     i=0;
	 j=0;
	 while ( getline (myfile,line) && i<n)
     {
	    istringstream iss2(line);
          j=0;

		while (iss2 && j<n) 
		{ 
			string subs; 
			iss2 >> subs; 
			string temp=subs;

			if(temp.compare("")==0)
			{
				continue;
                        j++;
			}
			else
			{

            w[i][j]=atoi(subs.c_str());
            			j++;
			}
	    }
		i++;
    }

	  m=atoi( line.c_str() );

    IloNumArray c(env,m);
	  NumMatrix d(env,m);
    
    for(i=0; i<m; i++)
    {
      d[i]=IloNumArray(env,m);
    } 
		  
  i=0;
  j=0;    
	getline (myfile,line);
	istringstream iss3(line);
	while (iss3 && j<m) 
	{ 
		string subs; 
		iss3 >> subs; 
		string temp=subs;
		if(temp.compare("")==0)
		{
			continue;
		}
		else
		{
           c[j]=atoi(subs.c_str());
		}
		j++;
	}
		
	i=0;
	j=0;
	while ( getline (myfile,line) && i<m)
    {
	    istringstream iss4(line);
          j=0;
		while (iss4 && j<m) 
		{ 
			string subs; 
			iss4 >> subs; 
			string temp=subs;
			if(temp.compare("")==0)
			{
				continue;
			}
			else
			{
            d[i][j]=atoi(subs.c_str());
			}
			j++;
	    }
		i++;
    }
    myfile.close();
  }