main(int argc, char *argv[]) {

  FILE *freqfileinptr;
  FILE *resultproboutptr;
  FILE *filecountptr;

  char resultprob[30];

  char shingle[300];

  char *basedirectory="/u/gelila/computation/dictionary/dateshingfreqdir/"; 
  
  char *freqfile="freq";
  char currentfilename[200], currentfilenamenew[200], currentdirfilename[200];
  char countstring[10];
  char currentstring[100];
  
  int t, i, countfile;
  int mindatedata=1089;
  int maxdatedata=1466;
  int mindate=1089;
  int maxdate=1466;
  
  float prob;
  float Colarray[378];

  strcpy(resultprob, argv[1]);  /* datetrainshing1totalprob */
  

  for(t=0;  t<=maxdatedata-mindatedata ; t++){ /* initializing Colarray to 0 */
    Colarray[t]=0;
  }
 
    
  for(i=1; i<=42978; i++){
    strcpy(currentfilenamenew, basedirectory); 
    strcat(currentfilenamenew, freqfile); 
    inttostring(i, currentstring);
    strcat(currentfilenamenew, currentstring);
    strcpy(currentdirfilename, currentfilenamenew); 
    freqfileinptr=fopen(currentdirfilename, "r");
    for(t=0;  t<=maxdatedata-mindatedata ; t++){
      fscanf(freqfileinptr, "%f", &prob);
      Colarray[t]=Colarray[t] + log(1-prob); /* no chance of prob being equal to 1, so we're ok */
      /* printf("%s %d %.12f %.12f \n", shingle, t, log(1-prob), Colarray[t] ); */
    }
    fclose(freqfileinptr);
  }
  
  resultproboutptr=fopen(resultprob, "w");
  for(t=0;  t<=maxdatedata-mindatedata ; t++){
    fprintf(resultproboutptr, "%.12f\t", Colarray[t]);
  }
  fclose(resultproboutptr);
}
Esempio n. 2
0
int main()
{
    char str1[10] = "1101";
    char str2[10] = "1100";
    char *str3;
    int len1, len2, len3, i, d1, d2;
    len1 = strlen(str1);
    len2 = strlen(str2);
    len3 = ((len1 >= len2) ? len1:len2); 
    str3 = (char *)malloc((len3+1)*sizeof(char));
    d1 = stringtoint(str1);
    d2 = stringtoint(str2);
    printf("\n%d\t%d\n", d1, d2);
    inttostring((d1+d2), str3);
    reverse(str3, strlen(str3));
    printf("\n\t%s\n", str3);
}
string serialize(TreeNode* root)
{
    queue<TreeNode*> q;
    stringstream ss;
    q.push(root);
    string s;

    if (root==NULL)
        return s;

    while (!q.empty())
    {
        TreeNode* tmpnode = q.front();
        string tmpstring;
        if (tmpnode != NULL)
        {
            tmpstring = inttostring(tmpnode->val);
            s = s + tmpstring + " ";
        }
        else
        {
            s = s + "# ";
        }
        q.pop();
        if (tmpnode!=NULL)
        {
            q.push(tmpnode->left);
            q.push(tmpnode->right);
        }
    }
    s.erase(s.end()-1);
    while (s[s.size()-1]=='#')
    {
        s.erase(s.end()-1);
        s.erase(s.end()-1);
    }
    return s;
}
Esempio n. 4
0
void Server::c_handshake(string msg) {
	string argument = get_argument(msg, 1);
	string line, data;
	ifstream motd("motd");
	if (motd.fail()) {
		throw new ServerException("[Server::c_handshake] couldnt read the motd", true);
	}
	clean(argument);
	if (cmap.find(argument) != cmap.end()) {
		srand(time(NULL));
		argument = "guest" + inttostring(rand());
		say("NOTICE user with such nickname is already connect so yours was changed to " + argument);
	}
	this->nick = argument;
	cmap.insert(make_pair(argument, this->fd));
	say("NOTICE Hi, this is talkr server!");
	if (motd.is_open()) {
		while (! motd.eof() ) {
			getline (motd,line);
			say("NOTICE " + line);
		}
		motd.close();
	}
}
Esempio n. 5
0
main(int argc, char *argv[]) {

  FILE *totalwordcountinptr;
  FILE *dateinptr;
  FILE *currentshinglefileinptr;
  FILE *shinglefileinptr;
  FILE *wordcountfileinptr;
  FILE *dateestfileoutptr;
  FILE *testoutputptr;
  FILE *randomnumfileinptr;


  char shinglefile[30];
  char totalwordcount[30];
  char randomnumfile[30];
  char aawmaster[30];
  char dateest[30];

  char *basedirectory="/u/gelila/computation/dictionary/dateshingprobdir/";
  char *wordcountfile="count";
  char *shingled=".shingled";
  char *basename="aaw";
  char *at="@";
  char currentfilename[200];
  char *currentstring;
  char tempcurrentstring[100];

  /*char currentstring[10];*/
  char dummystring1[20];
  char dummystring2[20];
  char dummystring3[20];
  char dummystring4[20];

  char shingle[300];
  char *shinglearray[500000];

  int i, j, l,k, t, count,wordcount, ti,freq, date, remainder, lengthshingarray,location, optdate,randomnum ;

  int randomnumvec[1500000];
  int traindate[3000];
  int bootvector[3000];
  int Occvector[3000];
  int Occvectortotal[3000];
  int ns[3000];
  int Nt[3000];
  int indicator[3000];

  int sizeoftrain=2608;
  int /* mindatedata=1050;*/ mindatedata=1089;
  int /* maxdatedata=1500; */ maxdatedata=1466;
  int mindate=1089;
  int maxdate=1466;
  int RESIDUEval=8;
  int RESIDUEtest=9;
  int bootstrapsample=500;

  float h, sum, Num[400], Den[400], probs[400], probdoc[400], kernelvalue[378];
  float bottomline;
 
  strcpy(shinglefile, argv[1]); /* mergershing4onlysortuniq */
  strcpy(randomnumfile, argv[2]); /* randomnumberfile */
  strcpy(totalwordcount, argv[3]); /*  totaldocboot */
  strcpy(aawmaster, argv[4]); /* aawmaster */
  h=atoi(argv[5]); /* bandwidth value h */
  strcpy(dateest, argv[6]); /* dateestboot */ 
 

  currentstring = malloc(11*sizeof(char));

  totalwordcountinptr=fopen(totalwordcount, "r");
  for(i=0; i<sizeoftrain; i++){
    fscanf(totalwordcountinptr, "%d",  &wordcount);
    Occvectortotal[i]=wordcount;
  }
  fclose(totalwordcountinptr);
  
  for(i=0; i<=500000; i++){
    shinglearray[i]=malloc(200*sizeof(char));
  }
  
  i=0; 
  shinglefileinptr=fopen(shinglefile, "r");
  fscanf(shinglefileinptr, "%s", shingle);
  while(!feof(shinglefileinptr)){
    /*printf("%s \n", shingle);*/
    strcpy(shinglearray[i],shingle);
    fscanf(shinglefileinptr, "%s", shingle);
    i++;
  }
  fclose(shinglefileinptr);
  lengthshingarray=i;
  printf("%d %s \n", i, shinglearray[i]);

  randomnumfileinptr=fopen(randomnumfile, "r");
  j=0;
  while(!feof(randomnumfileinptr)){
    fscanf(randomnumfileinptr, "%d", &randomnum);
    randomnumvec[j]=randomnum;
    j++;
  }
  printf("%d \n", j);

 
  dateinptr=fopen(aawmaster, "r");
  j=0;
  for(i=1; i<=3353; i++){
    fscanf(dateinptr, "%s %d %s", dummystring1, &date, dummystring2); 
    if( (i%RESIDUEval)!=0 && (i%RESIDUEtest)!=0 ){
      traindate[j]=date;
      j++;
    }
  }
  fclose(dateinptr);

  /* PUT THE KERNEL VALUES HERE */
  for(i=0; i<=maxdate-mindate;i++){
    kernelvalue[i]= dt((float)(i/h),10.5);
    /*printf("%.12f \n",  kernelvalue[i]);*/
  }
  bottomline=/*exp(-pow(378/5,2))/(450*378);*/ log(pow(5,-30));
  dateestfileoutptr=fopen(dateest, "w");
  /* this comand just wipes out the previous contents of the file.   later it will
     be re-opened in append mode */
  fclose(dateestfileoutptr);


  for(k=0; k<bootstrapsample; k++){ /* AN OUTER LOOP HERE FOR REPEATING BOOTSTRAP SAMPLING */
    for(i=0; i<sizeoftrain; i++){
      bootvector[i]=0;
    }
    for(i=0; i<sizeoftrain; i++){  /* THE END OF THE LOOP DOESN'T HAVE TO BE sizeoftrain....SHOULD
				      PERHAPSE BE MUCH LARGER */
       bootvector[i]=randomnumvec[i + sizeoftrain * k];
      /* printf("%d ",  bootvector[i]); */
    }
   
    if(k>=0){  /* for debugging purposes ....since it crashes after k>=72 */
    
      for(i=1; i<=1026/*3353*/; i++){
	if( (i%RESIDUEtest)==0 && (i%RESIDUEval)!=0 ){
	  inttostring(i, currentstring);  /* TAKING A DOC FROM THE TEST SET */
	  currentstring = currentstring + 2*sizeof(char);
	  strcpy(currentfilename, basename);
	  strcat(currentfilename, currentstring);
	  strcat(currentfilename, shingled);
	  currentstring = currentstring - 2*sizeof(char);  /* reset the pointer for currentstring */
	  currentshinglefileinptr=fopen(currentfilename, "r"); /* SUCH AS AAW0009.SHINGLED */ 
	  for(t=0; t<=maxdate-mindate; t++){
	    probdoc[t]=0;
	  }
	  while(!feof(currentshinglefileinptr)){
	    fscanf(currentshinglefileinptr, "%s %s %s %s", dummystring1, dummystring2, dummystring3, 
		   dummystring4);
	    strcpy(shingle, dummystring1);
	    strcat(shingle, at);
	    strcat(shingle, dummystring2);
	    strcat(shingle, at);
	    strcat(shingle, dummystring3);
	    strcat(shingle, at);
	    strcat(shingle, dummystring4);
	    
	    location=binarystringsearch(shinglearray, shingle, lengthshingarray); 
	    /* printf("%s %d \n", shingle, location); */
	    if(location!=0){
	      inttostring(location, currentstring);
	      strcpy(tempcurrentstring, basedirectory);
	      strcat(tempcurrentstring, wordcountfile);
	      strcat(tempcurrentstring, currentstring);
	      /*printf("%s %d %s \n", shingle, location, tempcurrentstring);*/
	      wordcountfileinptr=fopen(tempcurrentstring, "r");
	      count=0;
	      fscanf(wordcountfileinptr, "%d", &freq); 
	      while(!feof(wordcountfileinptr)){
		Occvector[count]=freq;
		fscanf(wordcountfileinptr, "%d", &freq);
		count++;
	      }
	      fclose(wordcountfileinptr);
	      /*printf("count=%d \n", count);*/
	      /* NEED TO SET UP dateshingresultfileboot FROM THE PREVIOUS PROGRAM INTO FILE
		 AND THEN USE mergershing2onlysortuniq AS AN INPUT IN ORDER TO USE THE BINARY SEARCH
		 ALGORITHM */
	      /* ASSUMING THE LOCATION OF THE SHINGLE HAS BEEN FOUND, (NEED TO PUT STATEMENT IF NOT FOUND) */
	      
	      /* YOU THEN PUT ALL THE 2608 COLUMNS INTO AN ARRAY CALLED Occvector */
	      
	      for(l=0; l<sizeoftrain; l++){
		ns[l]=Occvector[l]*bootvector[l];
	      }
	      
	      for(t=0; t<=maxdate-mindate; t++){
		sum=0;
		for(j=0; j<sizeoftrain; j++){
		  sum=sum+((float) ns[j])*kernelvalue[abs( (traindate[j]-mindate)-t )]; 
		  /*printf("kernelvalue[traindate[j]-t]=%.20f \n", 
		    kernelvalue[abs( (traindate[j]-mindate)-t )]);*/
		}
		Num[t]=sum;
	      }
	      
	      
	      for(l=0; l<sizeoftrain; l++){
		Nt[l]=Occvectortotal[l]*bootvector[l];
		/*printf("occvectortotal[%d] = %d \t bootvector[%d] = %d \n", l, Occvectortotal[l], l, 
		  bootvector[l] );*/
	      }
	      
	      for(t=0; t<=maxdate-mindate; t++){
		sum=0;
		for(j=0; j<sizeoftrain; j++){
		  sum=sum+((float) Nt[j])*kernelvalue[abs( (traindate[j]-mindate)-t )]; 
		}
		Den[t]=sum;
	      }
	      for(t=0; t<=maxdate-mindate; t++){
		/*printf("%.20f %.20f \n", Num[t], Den[t]);*/
	      }
	      
	      for(t=0; t<=maxdate-mindate; t++){
		if(log((float)(Num[t]/Den[t])) <bottomline){
		  probs[t]=bottomline;
		}
		else{
		  probs[t]=log((float)(Num[t]/Den[t]));
		}
	      }
	      /*printf("%f %f %f \n", Num[t], Den[t],probs[t]);*/
	      for(t=0; t<=maxdate-mindate; t++){
		probdoc[t]=probdoc[t]+probs[t];
	      }
	    } /* if(location!=0) */
	  } /*while(!feof(currentshinglefileinptr)) */
	  fclose(currentshinglefileinptr);
	  optdate=0;
	  for(t=0;  t<=maxdatedata-mindatedata ; t++){ 
	    /*printf("%.12f \n", probdoc[t]);*/
	    if(probdoc[t]>=probdoc[optdate]){
	      optdate=t; 
	    }
	  }
	  
	  dateestfileoutptr=fopen(dateest, "a");
	  fprintf(dateestfileoutptr, "%d\t%d\n", optdate+1089, i);
	  fclose(dateestfileoutptr);
	  
	  printf("%d %d\n",optdate+1089, i);
	}
      } /* for(i=1; i<=3353; i++) */
    }
    /*fclose(dateestfileoutptr);*/
  } /* for(k=1; k<=bootstrapsample; k++) */
}
Esempio n. 6
0
main(int argc, char *argv[]) {

  FILE *mergershinginptr;
  FILE *resultoutptr;
  FILE *wordcountfileoutptr;
 
  char mergershinguniq[30];
  char resultdateshing[30];
 
  char currentshingle[300];
  char shingle[400];
  char currentstring[10];
  char currentcountfile[200];

  char *basedirectory="/u/gelila/computation/dictionary/dateshingprobdir/";
  char *wordcountfile="count";

  int trainfilearray[2608]; /* the number of training date */
  int trainfilenum;

  int numberoffile=3353;
  int mindate=1089;
  int maxdate=1466;
  int RESIDUEval=9;
  int RESIDUEtest=8;
  int sizeoftrain=2608;

  int date, repetition;
  int i,k, j,a;

  strcpy(mergershinguniq, argv[1]); /* mergershing2sortuniqboot */
  
  for(i=0;i<sizeoftrain; i++){
    trainfilearray[i]=0;
  }
        
  mergershinginptr=fopen(mergershinguniq,"r");
  fscanf(mergershinginptr, "%d %s %d %d", &repetition, shingle, &date, &trainfilenum);
  strcpy(currentshingle, shingle);
  rewind(mergershinginptr);
  
  j=1;

  /* THIS PART IS TEMPORARY BECAUSE THE PROGRAM CRASHED AT COUNT380092 */
  /* ***************************************************************** */
  /* for(k=1; k<=380090; k++){
    fscanf(mergershinginptr, "%d %s %d %d", &repetition, shingle, &date, &trainfilenum);
    }
    printf("%d \n", k);
    strcpy(currentshingle, shingle);
    j=k; */
  /* ******************************************************************* */

  while(!feof(mergershinginptr)){
    while(!feof(mergershinginptr) && strcmp(shingle,currentshingle)==0){
      a=trainfilenum-floor((float)trainfilenum/RESIDUEval)-floor((float)trainfilenum/RESIDUEtest)+
	floor((float)trainfilenum/(RESIDUEtest*RESIDUEval));
      trainfilearray[a-1]=repetition;
      fscanf(mergershinginptr, "%d %s %d %d", &repetition, shingle, &date, &trainfilenum);
    }
        
    inttostring(j, currentstring);
    strcpy(currentcountfile, basedirectory);
    strcat(currentcountfile, wordcountfile);
    strcat(currentcountfile, currentstring);
    /*printf("%s \n", currentcountfile);*/
    
    wordcountfileoutptr=fopen(currentcountfile,"w");
    for(i=0;i<sizeoftrain; i++){
      fprintf(wordcountfileoutptr, "%d\t", trainfilearray[i]);
    }
    fclose(wordcountfileoutptr);
    j++;
    
    strcpy(currentshingle, shingle);

    /* reset datearray to zero again for the new shingle */
    for(i=0;i<sizeoftrain; i++){
     trainfilearray[i]=0;
    }
  }
  fclose(mergershinginptr);
  printf("shingle= %s \n", shingle);
}
Esempio n. 7
0
main(int argc, char *argv[]) {

  FILE *dateshingtotalprobinptr;
  FILE *dateshingresultprobinptr;
  FILE *shinglefileinptr;
  FILE *resultvalproboutptr;
  FILE *currentfileptr;
  FILE *currentdirfileptr;
  FILE *dateinfileptr;
  

  char dateshingtotalprob[30];
  char dateshingprob[30];
  char shinglefile[30];
  char resultvalprob[30];
  char dateinfile[20];

  char *basefilename="/u/gelila/computation/dictionary/";
  char *basedirectory="/u/gelila/computation/dictionary/dateshingfreqdir/";
  char *suffix=".shingled";
  char *at="@";
  char *freqfile="freq";
  char currentstring[10];
  char currentshingle[200];
  char currentfilename[100];
  char currentname[100];
  char currentfilenamenew[200];
  char currentnamenew[100];
  char currentdirfilename[100];

  char shingle[1000];
  char shinglefirst[300];
  char shinglesecond[300];
  char shinglethird[300];
  char shinglefourth[300];
  char shingletemp[300];

  char *filenamearray[3353];
  char filename[25];
  char *shinglearray[500000];

  int datemasterarray[3353];
  int t, i, j, dummy, date, dateest, location, lengthshingarray;
  int numberoffile=3353;
  int mindatedata=1089;
  int maxdatedata=1466;
  int RESIDUEval=8;
  int RESIDUEtest=9;
  float bottomline, logoneminusprob, prob;
  float Colarray[378];
  float Totallogoneminusprob[378];
    
  strcpy(dateshingtotalprob, argv[1]); /* datetrainshing4totalprob */ 
  strcpy(shinglefile, argv[2]); /* mergershing4onlysortuniq */
  strcpy(dateinfile, argv[3]); /* aawmaster */
  strcpy(resultvalprob, argv[4]);  /* dateshingtestprob */

 
  /* bottomline=exp(-pow(378/5,2))/(450*378);*/
  bottomline=exp(-50);
  
  for(i=0; i<numberoffile; i++){
    filenamearray[i]= malloc(25*sizeof(char));
  }	
  
  for(i=0; i<=500000; i++){
    shinglearray[i]=malloc(300*sizeof(char));
  }

  dateinfileptr=fopen(dateinfile,"r");
  i=0;
  while(i<numberoffile){        /* read in dates into filenamearray and store them into aawmaster */
    fscanf(dateinfileptr, "%d %d %s", &dummy, &date ,filename);
    datemasterarray[i]=date;
    strcpy(filenamearray[i],filename);
    /* printf("%d %s \n", i,filenamearray[i]); */
    i++;
  }
  fclose(dateinfileptr);
    
  dateshingtotalprobinptr=fopen(dateshingtotalprob, "r");
  for(t=0;  t<=maxdatedata-mindatedata ; t++){
    fscanf(dateshingtotalprobinptr, "%f", &logoneminusprob);
    Totallogoneminusprob[t]=logoneminusprob;
    /* printf("%d  %.12f \n", t,Totallogoneminusprob[t]);  */
  }
  fclose(dateshingtotalprobinptr);
  printf("i'm here \n");

  i=0;
  shinglefileinptr=fopen(shinglefile, "r");
  fscanf(shinglefileinptr, "%s", shingle);
  while(!feof(shinglefileinptr)){
    strcpy(shinglearray[i],shingle);
    i++;
    fscanf(shinglefileinptr, "%s", shingle);
  }
  fclose(shinglefileinptr);
  lengthshingarray=i;
  printf("i=%d, shinglearray[2]=%s\n", i, shinglearray[2]);

  /* ******Compute the probability vectors (from 1089 to 1466) for each document in the validation***** */ 
  
  resultvalproboutptr=fopen(resultvalprob, "w");
  for(i=1; i<=numberoffile; i++){ 
    /* unlike other times i starts from one b/c we're initialyzing validation docs from aawmaster */
    if( (i%RESIDUEval!=0)&&(i%RESIDUEtest==0)){
      strcpy(currentfilenamenew, basefilename);
      strcat(currentfilenamenew, filenamearray[i-1]);
      strcpy(currentfilename, currentfilenamenew);
      strcat(currentfilename, suffix);  /* reads in files such as aaw0008.shingled */
      /*printf("\n\n");
      printf("%s \n", currentfilename);
      printf("\n\n");*/
      for(t=0;  t<=maxdatedata-mindatedata ; t++){ /* initializing Colarray to zero */
	Colarray[t]=0;
      }
      currentfileptr=fopen(currentfilename, "r"); /* opening aaw0008.shingled */
      /* printf("currentfilename=%s\n", currentfilename);*/
      while(!feof(currentfileptr)){ 
	fscanf(currentfileptr, "%s %s %s %s", shinglefirst, shinglesecond, shinglethird, shinglefourth);
	strcpy(shingle, shinglefirst);
	strcat(shingle, at);
	strcpy(shingletemp, shinglesecond);
	strcat(shingle, shingletemp); 
	strcpy(shingletemp, shinglethird);
	strcat(shingle, at);
	strcat(shingle, shingletemp);
	strcpy(shingletemp,at);
	strcat(shingle, shingletemp);
	strcpy(shingletemp,shinglefourth);
	strcat(shingle,shingletemp);
	if(!feof(currentfileptr)){
	  /*printf("shingle=%s  currentfilename=%s \n", shingle, currentfilename);*/
	  location=binarystringsearch(shinglearray, shingle, lengthshingarray); 
	  /* returns the position of the location of the shingle, strating from
	     1.....lengthshingarray. If it returns 0, it means  the shingle was not found */
	  
	  /* if(strcmp(currentfilename,"/u/gelila/computation/dictionary/aaw2992.shingled")==0){
	    printf("shingle=%s, location=%d currentfilename=%s \n", shingle, location, currentfilename);
	    printf("location=%d\n",location);
	    }*/
	  if(location!=0){
	    inttostring(location, currentstring);
	    strcpy(currentfilenamenew, basedirectory);
	    strcat(currentfilenamenew, freqfile);
	    strcat(currentfilenamenew, currentstring);
	    strcpy(currentdirfilename, currentfilenamenew);  
	    /* printf("currentdirfilename=%s\n", currentdirfilename);*/
	    /*  reads in files e.g "/u/gelila/computation/dictionary /dateshingfreqdir/freq00001" */
	    currentdirfileptr=fopen(currentdirfilename, "r");
	    for(t=0;  t<=maxdatedata-mindatedata ; t++){
	      fscanf(currentdirfileptr, "%f", &prob);
	      if(prob==0){
		Colarray[t]=Colarray[t]  + Totallogoneminusprob[t]-log(1-prob) +log(bottomline);
	      }
	      else{
		Colarray[t]=Colarray[t] + Totallogoneminusprob[t]-log(1-prob) +log(prob);
	      }
	    }
	    fclose(currentdirfileptr);
	  }
	}
      }
      fclose(currentfileptr); 
      /* print the probability of a val document 378 vectors long */
      dateest=0;
      for(t=0;  t<=maxdatedata-mindatedata ; t++){ 
	if(Colarray[t]>=Colarray[dateest]){
	  dateest=t; 
	}
      }
      fprintf(resultvalproboutptr, "%d\n", dateest+1089);
    }
  }
  fclose(resultvalproboutptr);
}
Esempio n. 8
0
main( int argc, char *argv[] )

{

  
  char *basefilenewname;
  char *systemcommandbase;
  char *currentstring;

  char currentfilename[60];
  char systemcommand[40];
  char movefilename[50];
  char id[8]; 
  char filename[8];

  int i, firstfilenumber, lastfilenumber;
  int currentfilenumber, datediff;
 
  
  FILE *movefileinptr;

  /* now we take the variables controlling the run of the program from the input of the user. */

  basefilenewname = argv[1]; /* aaaw */
  firstfilenumber = atoi(argv[2]); /*1 */
  lastfilenumber = atoi(argv[3]); /*10837 */
  strcpy(movefilename, argv[4]); /* aawmasterTravisIDdfiledsortdatefinal */
  /* initialize variables */

  currentstring = malloc(12 * sizeof(char));
  systemcommandbase = "cp  ";
   
  /* the outer for loop just goes through the shingling procedure once for each of the files in the list. 
     we are, of course, assuming that if N is entered as the number of files then the files
     basename0001, ..., basenameNshingler.c actually exist.  if not, the file error message gets printed. */


  movefileinptr= fopen(movefilename, "r");

  for (currentfilenumber = firstfilenumber; currentfilenumber <= lastfilenumber; currentfilenumber++) {
         /* we begin by putting together the name of the current file, created from the file name base
	 given by the user by appending the string corresponding to the number of the currentfile. */
      
    fscanf(movefileinptr, "%s %s %d", id, filename, &datediff);
    inttostring(currentfilenumber, currentstring);
    
    strcpy(currentfilename ,systemcommandbase);
    strcat(currentfilename, filename);
    strcat(currentfilename, " ");
    strcat(currentfilename, basefilenewname);
    strcat(currentfilename, currentstring);
   
    printf("currentfilename is %s \n", currentfilename); 
      
    /* now we actually open the file. */
    
    system(currentfilename); 
    
  } 
	
  fclose(movefileinptr);
	
}
Esempio n. 9
0
main(int argc, char *argv[]) {

  FILE *dateshingresultinptr;
  FILE *datetotalinptr;
  FILE *currentfileoutptr;

  char dateshingresult[30];
  char datetotal[30];

  char shingle[300];

  char *basedirectory="/home/gelila/computation/dictionary/dateshingfreqdir/";
  char *freqfile="freq";
  char currentfilename[200];
  char currentstring[10];

  int i, t, ti, date;
  int Nti[500], nsti[500];
  int mindate=1053;
  int maxdate=1491;
  float h, df, sumnum, sumden;
 

  strcpy(dateshingresult, argv[1]); /* dateshingresultfile */
  strcpy(datetotal, argv[2]); /*  datetotal */
  /* strcpy(resultout, argv[3]);  dateshingresultprob (nolonger we need this as results will be written 
   in .....dictionary/dateshingfreqdir  directory with each file corresponding to the N-W estimator
   of a shingle for each date ranging fron 1089 to 1466 */
  h=atoi(argv[3]); /* bandwidth value h */
  df=atoi(argv[4]); /* degree of freedom */

  datetotalinptr=fopen(datetotal, "r");
  for(ti=0; ti<=maxdate-mindate; ti++){
    fscanf(datetotalinptr, "%d %d", &date, &Nti[ti]);
  }
  fclose(datetotalinptr);

  dateshingresultinptr=fopen(dateshingresult, "r");
  printf("i'm here 1\n");
  
  
  i=1;
  while(!feof(dateshingresultinptr)){
    fscanf(dateshingresultinptr, "%s", shingle);
    /*printf("%d %s \n", i, shingle);*/
    if(!feof(dateshingresultinptr)) {
      for(ti=0; ti<=maxdate-mindate ; ti++){
	fscanf(dateshingresultinptr, "%d", &nsti[ti]);
      }
      
      inttostring(i, currentstring);
      /*printf("%s\n", currentstring);*/
      strcpy(currentfilename, basedirectory);
      strcat(currentfilename, freqfile);
      strcat(currentfilename, currentstring);
      currentfileoutptr=fopen(currentfilename, "w");

      for(t=0;  t<=maxdate-mindate ; t++){
	/*printf("starting t = %d\n", t);*/
	sumnum=0; sumden=0;
	for(ti=0; ti<=maxdate-mindate; ti++){
	  sumnum=sumnum+nsti[ti]*dt((float)(ti-t)/h, df);    /* *exp(-pow((float)((ti-t)/h),2)/2) ;*/
	  sumden=sumden+Nti[ti]*dt((float)(ti-t)/h, df);  /*exp(-pow((float)((ti-t)/h),2)/2)  ;*/
	}

	/* to print in the directory .../dictionary/dateshingfreqdir */
	/*printf("%d\t%d\t%s\t%.12f \n", i, t,currentfilename, sumnum/sumden);*/
	fprintf(currentfileoutptr, "%.12f\t", sumnum/sumden);
      }
      fprintf(currentfileoutptr,"\n");
      fclose(currentfileoutptr);
      i++;
    }
  }
  fclose(dateshingresultinptr);
}
Esempio n. 10
0
/**
 * \fn void addVideos(std::string bddName, std::string activity, int nbVideos, std::string* videoPaths, int dim, int maxPts)
 * \brief Adds a new video in the choosen activity of the specified BDD.
 * \param[in] bddName The name of the BDD.
 * \param[in] activity The name of the activity.
 * \param[in] nbVideos The number of videos we want to add.
 * \param[in] videoPaths The different paths to the videos.
 */
void addVideos(std::string bddName, std::string activity, int nbVideos, std::string* videoPaths){
  std::string path2bdd("bdd/" + bddName);
  
  //int desc = getDescID(path2bdd);
  //int dim = getDim(desc);
  
  // Loading the bdd
  IMbdd bdd(bddName,path2bdd);
  bdd.load_bdd_configuration(path2bdd.c_str(),"imconfig.xml");
  
  // Saving its parameters
  int maxPts = bdd.getMaxPts();
  int scale_num = bdd.getScaleNum();
  std::string descriptor = bdd.getDescriptor();
  int dim = bdd.getDim();
    
  // Loading the mapping file to get the video label
  activitiesMap *am;
  int nbActivities = mapActivities(path2bdd,&am);
  int i = 0;
  while(am[i].activity.compare(activity) != 0 && i < nbActivities) i++;
  if(am[i].activity.compare(activity) != 0){
    std::cerr << "Activity not found!\n" << std::endl;
    exit(EXIT_FAILURE);
  }
  int label = am[i].label;
  delete []am;
  
  // Import videos in the selected database
  string strlabel = inttostring(label);
  
  std::string copypath(path2bdd + "/" + strlabel + "/avi");
  int nbFiles = nbOfFiles(copypath);
  int j = nbFiles + 1;
  for(int i=0 ; i<nbVideos ; i++){
    string idFile = inttostring(j);
    string cmd("cp " + videoPaths[i] + " " + copypath + "/" + strlabel + idFile + ".avi");
    system(cmd.c_str());
    j++;
  }
  
  // Extract STIPs from the videos and save them in the repertory /path/to/bdd/label/
  string fpointspath(path2bdd + "/" + strlabel + "/fp");
  j = nbFiles + 1;
  
  for(int i=0 ; i<nbVideos ; i++){
    KMdata dataPts(dim,maxPts);
    string idFile = inttostring(j);
    string videoInput(copypath + "/" + strlabel + idFile + ".avi");
    string fpOutput(fpointspath + "/" + strlabel + "-" + idFile + ".fp");
    int nPts;
    
    nPts = extract_feature_points(videoInput,
				  scale_num, descriptor, dim,
				  maxPts, dataPts);		
    if(nPts != 0){
      dataPts.setNPts(nPts);
      exportSTIPs(fpOutput, dim,dataPts);
    }
    j++;
  }
}
Esempio n. 11
0
/**
 * \fn void im_refresh_folder(std::string folder, std::vector<std::string> activities, int scale_num, int dim, int maxPts)
 * \brief Deletes all files excepted videos and extracts STIPs again.
 *
 * \param[in] folder the path to the folder containing videos.
 * \param[in] activities the vector containing all the activities.
 * \param[in] scale_num the number of scales used for the feature points extraction.
 * \param[in] dim the dimension of the feature points.
 * \param[in] maxPts the maximum number of feature points we can extract.
 */
void im_refresh_folder(const IMbdd& bdd, std::string folder){
  std::vector<std::string> activities = bdd.getActivities();
  int scale_num = bdd.getScaleNum();
  std::string descriptor(bdd.getDescriptor());
  int dim = bdd.getDim();
  int maxPts = bdd.getMaxPts();

  
  // Deleting all features points
  for(std::vector<std::string>::iterator activity = activities.begin() ;
      activity != activities.end() ;
      ++activity){
    string rep(folder + "/" + *activity + "/fp");
    DIR * repertoire = opendir(rep.c_str());
    std::cout << rep << std::endl;
    if (repertoire == NULL){
      std::cerr << "Impossible to open the fp folder for deletion!" << std::endl;
      exit(EXIT_FAILURE);
    }
    struct dirent *ent;
    while ( (ent = readdir(repertoire)) != NULL){
      if(strcmp(ent->d_name,".") != 0 && strcmp(ent->d_name,"..") != 0)
	remove(ent->d_name);
    }
    closedir(repertoire);
  } 
  
  // Extracting feature points for each videos
  for(std::vector<std::string>::iterator activity = activities.begin() ;
      activity != activities.end() ;
      ++activity){
    std::string avipath(folder + "/" + *activity + "/avi");
    std::string FPpath(folder + "/" +  *activity + "/fp");
    DIR * repertoire = opendir(avipath.c_str());
    if (repertoire == NULL){
      std::cerr << "Impossible to open the avi folder for extraction!" << std::endl;
      exit(EXIT_FAILURE);
    }
    struct dirent * ent;
    int j = 1;
    while ( (ent = readdir(repertoire)) != NULL){
      std::string file = ent->d_name;
      if(file.compare(".") != 0 && file.compare("..") != 0){
	string idFile = inttostring(j);
        // Extract feature points from the videos and save them in the repertory /path/to/folder/activity/fp
        KMdata dataPts(dim,maxPts);
        string videoInput(avipath + "/" + file);
        string stipOutput(FPpath + "/" + *activity + "-" + idFile + ".fp");
	int nPts;
	nPts = extract_feature_points(videoInput,
				      scale_num, descriptor, dim,
				      maxPts, dataPts);		
	if(nPts != 0){
	  dataPts.setNPts(nPts);
	  exportSTIPs(stipOutput, dim, dataPts);
	}
	j++;	
      }
    }
    closedir(repertoire);
    // The extraction of the videos feature points of the activity is terminated.
  }
  
  im_concatenate_bdd_feature_points(bdd.getFolder(),
				    bdd.getPeople(),
				    bdd.getActivities());
}