예제 #1
0
/*
 * Writing models to resource directory
 */
void LinemodInterface::writeModels(const std::string &resourcePath)
{
  const std::vector<std::string> ids = detector->classIds();
  const std::string
  basePath = resourcePath[resourcePath.size() - 1] == '/' ? resourcePath : resourcePath + '/',
  file = "/linemod.yml",
  fileGZ = file + ".gz";

  std::map<std::string, std::vector<std::string> > baseIds;
  for(int i = 0; i < (int)ids.size(); ++i)
  {
    const std::string
    &classId = ids[i],
     baseId = classId.substr(0, classId.rfind("_r"));
    baseIds[baseId].push_back(classId);
  }

  std::map<std::string, std::vector<std::string> >::const_iterator
  it = baseIds.begin(),
  end = baseIds.end();
  for(; it != end; ++it)
  {
    writeModel(basePath + it->first + file, it->second);
    writeModel(basePath + it->first + fileGZ, it->second);
  }
}
예제 #2
0
void eeCheck(bool immediately)
{
  if (immediately) {
    eepromWriteWait();
  }

  assert(eepromWriteState == EEPROM_IDLE);

  if (s_eeDirtyMsk & EE_GENERAL) {
    TRACE("eeprom write general");
    s_eeDirtyMsk -= EE_GENERAL;
    writeGeneralSettings();
    if (immediately)
      eepromWriteWait();
    else
      return;
  }

  if (s_eeDirtyMsk & EE_MODEL) {
    TRACE("eeprom write model");
    s_eeDirtyMsk -= EE_MODEL;
    writeModel(g_eeGeneral.currModel);
    if (immediately)
      eepromWriteWait();
  }
}
예제 #3
0
void 
GeometryExportFile::exportData( ofstream &out )
{
    vector<Selectable *>* list;
    list = ObjectDB::getInstance()->getSelected();

    //list = getMeshes();

    // kts for now just edit the last one selected
    Entity* entity = NULL;

    for(int i=0; i<(int)list->size(); i++)
    {
        if((*list)[i]->isA(Object::TYPE))
        {
            entity = (Entity *) (*list)[i];
        }
    }

    if(entity)  
        writeModel( ( Object * ) ( entity ), out );
    else
    {
       int n = 1;
       QString strMessage = "You must select at least ";
       QString num;
       num.setNum( n );
       strMessage += num;
       strMessage += " items first";
    
       QMessageBox::information( 0, "World Foundry Geometry Exporter", strMessage );
    }
   //writeSprite( ( Object * ) ( entity ), out );
}
예제 #4
0
int main(int argc, char* argv[])
{
	boostStruct		bst;
	char			input_file_name[1024], model_file_name[1024];

	boost_config(&bst);

	parse_command_line(argc, argv, &input_file_name[0], &model_file_name[0], &bst);

	read_problem(input_file_name, &bst);

	adaBoost(&bst);

	writeModel(&bst, model_file_name);

	boost_destroy(&bst);

}
예제 #5
0
void save_solution(const solution_t *solution_curr, 
    const input_parameters_t *in_para, const int *model){
    const protein_t* p_curr;
    FILE * pdbfile; 
    char *file_name;
    file_name = Malloc(char, MAX_FILE_NAME);
    strcpy(file_name, "monte_carlo_solutions.pdb");
    char *fname = path_join_file(in_para->path_local_execute,
        file_name);    
    p_curr = (protein_t*) solution_curr->representation;
    if (*model == 1){
        pdbfile = open_file(fname, fWRITE);
        writeHeader(pdbfile, 0.00, &p_curr->p_topol->numatom);
    }else{
        pdbfile = open_file(fname, fAPPEND);
    }
    writeModel(pdbfile, model);
    writeATOM(pdbfile, p_curr->p_atoms, &p_curr->p_topol->numatom);
    writeEndModel(pdbfile);
    fclose(pdbfile);

    free(fname);
    free(file_name);    
}
예제 #6
0
파일: main.c 프로젝트: venkatesh20/SVM
int main( int argc, char  **argv ) {

     char *progname = argv[0];
     FILE *in ,  *out;
     char opt;
     int i;
     double startTime;

     C = 0;
     kernelType =  -1;
     degree = 0;
     sigmaSqr = 0;
     binaryFeature = 0;

     /* Check command line options */
     optarg = NULL;
     while (((opt = getopt(argc, argv, OPTSTRING)) != -1)) {
            switch(opt)  {
            case 't':
            if ( strcmp(optarg, "0") == 0 ) kernelType = 0;
            else if ( strcmp(optarg, "1")  == 0 ) kernelType = 1;
            else if ( strcmp(optarg, "2")  == 0 ) kernelType = 2;
            else {
                   fprintf( stderr, "kernel type is either 0,1 or 2\n");
                   exit(1);
            }
            break;
            case 'c':
            if( sscanf(optarg, "%f", &C) == 0 ) {
                fprintf(stderr,"Expect  a positive number for C.\n");
                exit(1);
            } else
                C = atof(optarg);
              if( C  <= 0 ) {
                 fprintf( stderr, "C has to be > 0\n");
                 exit(1);
              }
              break;
              case 'd':
                if( sscanf(optarg, "%d", &degree) == 0 ) {
                   fprintf( stderr, "Expect degree to be a positive integer.\n");
                   exit(1);
                } else degree = atoi(optarg);
                if ( degree <= 0 ) {
                  fprintf( stderr, "degree has to be a positive integer.\n");
                  exit(1);
                }
                break;
                case 'v':
                if( sscanf(optarg, "%f", &sigmaSqr) == 0 ) {
                    fprintf(stderr,"Expect  a positive number for variance.\n");
                    exit(1);
                } else sigmaSqr = atof(optarg);
                  if( sigmaSqr  <= 0 ) {
                     fprintf( stderr, "variance has to be > 0\n");
                     exit(1);
                  }

                  rbfConstant = 1/(2*sigmaSqr);
                  break;
                  case 'b':
                  if( sscanf(optarg, "%d", &binaryFeature) == 0 ) {
                     fprintf( stderr, "binaryFeature option is either 0 or 1.\n");
                     exit(1);
                  } else binaryFeature = atoi(optarg);
                if ( binaryFeature != 0 && binaryFeature != 1 ) {
                    fprintf( stderr, "binaryFeature option is either 0 or 1.\n");
                    exit(1);
                }
                break;
                case 'h':
                useMsg( progname );
                exit(1);
                break;
                default:
                  useMsg( progname );
                  exit(1);
                  break;
               }
          }

          /* Check all necessary parameters are in */

          if( kernelType ==  -1 ) {
               fprintf( stderr, "Kernel type has not been specified.\n");
               exit(2);
          } else if( kernelType == 1 && degree == 0 ) {
              fprintf( stderr, "Degree has not been specified.\n");
              exit(2);
          } else if( kernelType == 2 && sigmaSqr == 0 ){
                fprintf( stderr, "Variance has not been specified.\n");
                exit(2);
          } else if( C == 0 ) C = DEFAULT;

        /* Check training file and model file */
         printf("INPUT FILE %s\n", argv[argc-2]);
          if (( in = fopen( argv[argc-2], "r") ) == NULL ) {
               fprintf( stderr, "Can't open %s\n",  argv[argc-2] );
               exit(2);
          }

          if (( out = fopen( argv[argc-1], "w") ) == NULL ) {
              fprintf( stderr, "Can't open %s\n",  argv[argc-1] );
              exit(2);
          }

         printf("smo_learn is preparing to learn. . .\n");
         if( ! readFile( in ) ) {
             fprintf( stderr, "Error in initializing. Program exits.\n" );
             exit (1);
         } else fclose( in );

         if( !initializeTraining()) {
             fprintf( stderr, "Error in initializing data structure. Program exits.\n");
             exit(1);
         }

         printf("Start training . . .\n");
         startTime = clock()/CLOCKS_PER_SEC;
         startLearn();
         printf("Training is completed\n");

         /* Print training statistics */
         printf("CPU time is %f secs\n", clock()/CLOCKS_PER_SEC-startTime);
         printf("Writing training results . . .\n");
         writeModel( out );
         fclose( out );
         printf("Finish writing training results.\n");
         printf("no of iteration is %f\n",  iteration);
         printf("threshold b is %f\n", getb());
         if ( kernelType == 0 )
                printf("norm of weight vector is %f\n",  calculateNorm());
         printf("no. of unBound multipliers is %d\n",  unBoundSv );
         printf("no. of bounded multipliers is %d\n",  boundSv );

         /* Free memory */
         free( target );
         free( lambda );
         free( nonZeroFeature );
         free( error );
         free( nonBound );
         free( weight );
         free( unBoundIndex );
         free( nonZeroLambda );
         for( i = 0; i <= numExample; i++ ) {
            free( example[i] );
         }
         free( example );
         free( errorCache );

         return 0;
}
예제 #7
0
int main(int argc, char *argv[]) {

	DIR *dir;
	ofstream fout;
	char slash = Unix ? '/' : '\\'; // It is '/' or '\' depending on OS
	char POS_PATH_BASE[MAX_PATH_LENGTH];
	char NEG_PATH_BASE[MAX_PATH_LENGTH];
	clock_t tic, toc;

	if (argc != 4) {
		error("Usage: train [POS_DIR] [NEG_DIR] [OUTPUT_FILE].");
	}

	if (!(dir = opendir(argv[1]))) {
		error("train: [POS_DIR] open failed.");
	}
	/* Set POS_PATH_BASE to [POS_DIR] and append '/' or '\' */
	strcpy(POS_PATH_BASE, argv[1]);
	sprintf(POS_PATH_BASE, "%s%c", POS_PATH_BASE, slash);
	closedir(dir);

	if (!(dir = opendir(argv[2]))) {
		error("train: [NEG_DIR] open failed.");
	}
	/* Set NEG_PATH_BASE to [NEG_DIR] and append '/' or '\' */
	strcpy(NEG_PATH_BASE, argv[2]);
	sprintf(NEG_PATH_BASE, "%s%c", NEG_PATH_BASE, slash);
	closedir(dir);

	fout.open(argv[3]);
	if (!(fout)) {
		error("train: [OUTPUT_FILE] open failed.");
	}

	/** Command is correct **/
	echoOS();
	cout << "This program provides cascaded-AdaBoost training.\n" <<
		"Please make sure that [POS_DIR] and [NEG_DIR] contain only training image data,\n" <<
		"  whose size is " << WINDOW_WIDTH << " x " << WINDOW_HEIGHT << ".\n" <<
		"Press [Enter] to continue, or ctrl+C/D/Z to exit ...";
	getchar();

	tic = clock();
	/* Use only one large matrix for storing all POS / NEG feature data */
	CvMat *POS = NULL, *NEG = NULL;
	int N1, N2; /* number of positive / negative images */
	int blockCount = 0; /* number of blocks in an image */

	/* [1] Feature extraction */
	/* First, check for validity of extraction parameters */
	assert(!(360 % (BIN_NUM * 2))); // (360 / BIN_NUM / 2) should be an integer */
	assert(360 / BIN_NUM == BIN_SIZE);
	assert(BIN_SIZE >> 1 == HALF_BIN_SIZE);

	cout << "\nStart of feature extraction ...\n";
	/* Should pass (CvMat *&) to really create the matrices */
	extractAll(POS_PATH_BASE, POS, N1, blockCount);
	cout << "Extraction of POS data completed.\n";

#if CHECKNaN
	cout << "Check POS matrix for NaN values:" << endl;
	if (checkNaN(POS, "POS")) {
	    error("POS matrix contains NaN values!");
    }
    else {
        cout << "OK!" << endl;
    }
#endif
	
	extractAll(NEG_PATH_BASE, NEG, N2, blockCount);
	cout << "Extraction of NEG data completed.\n";

#if CHECKNaN
	cout << "Check NEG matrix for NaN values:" << endl;
	if (checkNaN(NEG, "NEG")) {
	    error("NEG matrix contains NaN values!");
    }
    else {
        cout << "OK!" << endl;
    }
#endif
	assert(blockCount > 0);
	cout << endl << "# of blocks per image: " << blockCount << ".\n";
#if GETCHAR
	getchar();
#endif

	
	/* [2] Cascaded-AdaBoost training */
	cout << "Start of cascaded-AdaBoost training ...\n";
	srand(time(NULL));
	float F_current = 1.0;  // current overall false positive rate
	int i = 1;  // AdaBoost stage counter
	int rejectCount = 0;  // # of negative images rejected so far

	/* Allocate rejection table */
	/** Note: All the xxxTable[]'s are of boolean flags **/
	bool *rejectTable = new bool[ N2 ];
	memset(rejectTable, 0, N2);

	bool stop = false;  // Stopping flag
	vector<AdaStrong> H;  // A cascade of AdaBoost strong classifiers

	/*** The training algorithm ***/
	while (F_current > F_target && !stop) {
		/* upper bound for j */
		int jEnd = (i == 1) ? (ni + 1) : ni;

		for (int j = 1; j <= jEnd; j++) {
			/* Learn an A[i,j] stage */
			cout << "\nLearning stage A[" << i << "," << j << "]...\n";
			if ((stop = learnA(N1, N2, blockCount, rejectCount, rejectTable, POS, NEG, H, F_current))) {
				break;
			}
			cout << "Stage A[" << i << "," << j << "] completed.\n";
#if GETCHAR
			getchar();
#endif
		}
#if META
		if (stop) break;
		/* Learn a M[i] stage */
		cout << "\nLearning stage M[" << i << "]...\n";
		learnM();
		cout << "Stage M[" << i << "," << j << "] completed.\n";
  #if GETCHAR
		getchar();
  #endif
#endif
		i++;

	} // End of loop while (F_current > F_target && !stop)

	cout << "The entire training process completed.\nWriting model parameters to " << argv[3] << " ... ";
	/* Write model parameters to [OUTPUT_FILE]. See docs/train_format.txt for explanation. */
	writeModel(H, fout);
	cout << "done!\n";

	/* Show running time */
	toc = clock();
	runningTime(tic, toc);

	/* Don't forget to close the file stream */
	fout.close();
	return 0;
}
예제 #8
0
int SbmlWriter::write( string filepath,string target )
{
	cout << "Sbml Writer: " << filepath << " ---- " << target << endl;
	//cout << "use_SBML:" << USE_SBML << endl;
	
	#ifdef USE_SBML
	string::size_type loc;
	while ( ( loc = filepath.find( "\\" ) ) != string::npos ) 
	  {
	    filepath.replace( loc, 1, "/" );
	  }
	if ( filepath[0]== '~' )
	  {
	    cerr << "Error : Replace ~ with absolute path " << endl;
	  }
	string filename = filepath;
	string::size_type last_slashpos = filename.find_last_of("/");
	filename.erase( 0,last_slashpos + 1 );  
	
	vector< string > fileextensions;
	fileextensions.push_back( ".xml" );
	fileextensions.push_back( ".zip" );
	fileextensions.push_back( ".bz2" );
	fileextensions.push_back( ".gz" );
	vector< string >::iterator i;
	for( i = fileextensions.begin(); i != fileextensions.end(); i++ ) 
	  {
	    string::size_type loc = filename.find( *i );
	    if ( loc != string::npos ) 
	      {
		int strlen = filename.length(); 
		filename.erase( loc,strlen-loc );
		break;
	      }
	  }
	if ( i == fileextensions.end() && filename.find( "." ) != string::npos )
	  {
	    string::size_type loc;
	    while ( ( loc = filename.find( "." ) ) != string::npos ) 
	      {
		filename.replace( loc, 1, "_" );
	      }
	  }

	if ( i == fileextensions.end() )
	  filepath += ".xml";

	cout << " filepath " << filepath << filename << endl;
	bool SBMLok = false;
	SBMLDocument sbmlDoc(2,4);
	createModel(filename,sbmlDoc);
	if (SBMLok)
	  writeModel(&sbmlDoc,filepath);
	if( !SBMLok) cerr << "Errors encountered " << endl;
	
	/**
	string::size_type loc;
	// if blackslash is found then its replaced to '/'
	while ((loc = filepath.find("\\")) !=string::npos) 
	  {  filepath.replace(loc,1,"/"); }
	if(filepath[0] == '~')
	  {cerr << "Error : Replace '~' with absolute path" << endl; }
	string filename = filepath;
	string ::size_type last_slashpos = filename.find_last_of("/");
	filename.erase(0,last_slashpos+1);

	int strlen = filepath.length();
	filepath.erase(last_slashpos+1,strlen);

	cout << "\t \t here file path  "  << filepath  << " name " << filename << endl;
	//cout << "filepath" << filepath << "filename " << filename;
	vector <string> fileextensions;
	fileextensions.push_back(".xml");
	fileextensions.push_back(".zip");
	fileextensions.push_back(".bz2");
	fileextensions.push_back(".gz");
	vector <string>::iterator i;
	// here I need to check for exact file extensions, this peice of code works for any extensions+anything like this xmll
	for (i = fileextensions.begin(); i != fileextensions.end(); i++)
	  { 
	    string::size_type loc = filename.find(*i);
	    cout << "fileextensions -- " << *i << "loc  " << loc << endl;
	    if(loc != string::npos)
	      { int strlen = filename.length();
		filename.erase(loc,strlen-loc);
		cout << "file   " << filename << endl;
		break;
	      }
	  }
	if(i == fileextensions.end())
	  { 
	    string :: size_type loc = filename.find(".");
	    if(loc != string::npos)
	     { filename.replace(loc,1,"_");
	       cout <<" %%" << filename << endl;
	       filename +='.xml';
	       cout <<" %%%" << filename << endl;
	     }
	    else
	      { filename+='.xml'; }
	  }
	cout << "$$$" << filepath << "  " << filename << endl;
	filepath = filepath+filename;
	cout << "filepath ---  " << filepath << "--filename-- " << filename << endl;
	**/
	#endif     
	return 0;
}
예제 #9
0
int main(int argc, const char *argv[])
{
    int N,
		    M,
		    T,
		    maxIters,
		    seed,
		    i,
		    j,
		    iter,
        str_len;

    char **alphabet;

    double logProb,
           newLogProb;

  	double *pi,
           *piBar, 
           **A,
           **Abar,
           **B,
           **Bbar;

    struct stepStruct *step;

    FILE *in,
         *out;
    
    char s[80];

	int wantTraining = 1;
    
    if(argc != 10)
    {
        fprintf(stderr, "\nUsage: %s N M T maxIters filename alphabet modelfile seed\n\n", argv[0]);
        fprintf(stderr, "where N == number of states of the HMM\n");
        fprintf(stderr, "      M == number of observation symbols\n");
        fprintf(stderr, "      T == number of observations in the training set\n");
        fprintf(stderr, "      maxIters == max iterations of re-estimation algorithm\n");
        fprintf(stderr, "      filename == name of input file\n");
        fprintf(stderr, "      alphabet == name of file defining the alphabet\n");
        fprintf(stderr, "      modelfile == name of model output file\n");
        fprintf(stderr, "      seed == seed value for pseudo-random number generator (PRNG)\n\n");
		fprintf(stderr, "      wantTraining == to train enter 1, otherwise 0 \n\n");
        fprintf(stderr, "For example:\n\n      %s 2 10 10000 500 datafile alphabet modelfile 1241\n\n", argv[0]);
        fprintf(stderr, "will create a HMM with 2 states and 10 observation symbols,\n");
        fprintf(stderr, "will read in the first 10000 observations from `datafile',\n");
        fprintf(stderr, "will use the observation symbols defined in file `alphabet', and\n");
        fprintf(stderr, "will write the model (pi, A, B) to `modelfile', and\n");
        fprintf(stderr, "will seed the PRNG with 1241 and train the HMM with a maximum of 500 iterations.\n\n");
        exit(0);
    }

    N = atoi(argv[1]);
    M = atoi(argv[2]);
    T = atoi(argv[3]);
    maxIters = atoi(argv[4]);
    seed = atoi(argv[8]);
	wantTraining = atoi(argv[9]);

    pi = (double *)malloc(N * sizeof(double));
    piBar = (double *)malloc(N * sizeof(double));

    A = (double **)malloc(N * sizeof(double*));
    Abar =static_cast<double **>(malloc(N * sizeof(double*)));
    for (i=0; i<N; ++i)
    {
      A[i] = static_cast<double *>(malloc(N * sizeof(double)));
      Abar[i] = static_cast<double *>(malloc(N * sizeof(double)));
    }

    B = static_cast<double **>(malloc(N * sizeof(double*)));
    Bbar = static_cast<double **>(malloc(N * sizeof(double*)));
    for (i=0; i<N; ++i)
    {
      B[i] = static_cast<double *>(malloc(M * sizeof(double)));
      Bbar[i] = static_cast<double *>(malloc(M * sizeof(double)));
    }
    
   
    ////////////////////////
    // read the data file //
    ////////////////////////

    // allocate memory
    printf("allocating %d bytes of memory... ", (T + 1) * sizeof(struct stepStruct));
    fflush(stdout);
    if((step = static_cast<stepStruct *>(calloc(T + 1, sizeof(struct stepStruct)))) == NULL)
    {
        fprintf(stderr, "\nUnable to allocate alpha\n\n");
        exit(0);
    }
    for (i=0; i<T+1; ++i)
    {
      step[i].alpha = static_cast<double *>(malloc(N * sizeof(double)));
      step[i].beta = static_cast<double *>(malloc(N * sizeof(double)));
      step[i].gamma = static_cast<double *>(malloc(N * sizeof(double)));
      step[i].diGamma = static_cast<double **>(malloc(N * sizeof(double*)));
      for (j=0; j<N; ++j)
      {
        step[i].diGamma[j] = static_cast<double *>(malloc(N * sizeof(double)));
      }
    }
    printf("done\n");

    // read in the observations from file
    printf("GetObservations... ");
    fflush(stdout);
    in = fopen(argv[5], "r"); // argv[5] = filename
    if(in == NULL)
    {
        fprintf(stderr, "\nError opening file %s\n\n", argv[5]);
        exit(0);
    }
    i = 0;
    fgets(s,80,in); // get rid of the first line
    while (i < T)
    {
      fgets(s,80,in);
      step[i].obs = atoi(s);
      ++i;
    }
    fclose(in);
    printf("done\n");

    // read in the alphabet from file
    printf("GetAlphabet... ");
    fflush(stdout);
    alphabet = static_cast<char **>(malloc(M * sizeof (char*)));
    in = fopen(argv[6], "r"); // argv[6] = alphabet
    if(in == NULL)
    {
        fprintf(stderr, "\nError opening file %s\n\n", argv[6]);
        exit(0);
    }
    i = 0;
    fgets(s,80,in); // get rid of the first line
    while (i < M)
    {
      fgets(s,80,in);
	    str_len = strlen(s);
      alphabet[i] = static_cast<char *>(malloc(str_len * sizeof(char)));
      strncpy(alphabet[i], s, str_len-1);
      alphabet[i][str_len-1] = '\0';
      ++i;
    }
    fclose(in);
    printf("done\n");


    /////////////////////////
    // hidden markov model //
    /////////////////////////

    srand(seed);

    // initialize pi[], A[][] and B[][]
    initMatrices(pi, A, B, N, M, seed);

    // print pi[], A[][] and B[][] transpose
    printf("\nN = %d, M = %d, T = %d\n", N, M, T);
    printf("initial pi =\n");
    printPi(pi, N);
    printf("initial A =\n");
    printA(A, N);
    printf("initial B^T =\n");
    printBT(B, N, M, alphabet);

    // initialization
    iter = 0;
    logProb = -1.0;
    newLogProb = 0.0;

	if (wantTraining) {

		// main loop
		while((iter < maxIters) && (newLogProb > logProb))
		{
			printf("\nbegin iteration = %d\n", iter);

			logProb = newLogProb;

			// alpha (or forward) pass
			printf("alpha pass... ");
			fflush(stdout);
			alphaPass(step, pi, A, B, N, T);
			printf("done\n");

			// beta (or backwards) pass
			printf("beta pass... ");
			fflush(stdout);
			betaPass(step, pi, A, B, N, T);
			printf("done\n");

			// compute gamma's and diGamma's
			printf("compute gamma's and diGamma's... ");
			fflush(stdout);
			computeGammas(step, pi, A, B, N, T);
			printf("done\n");

			// find piBar, reestimate of pi
			printf("reestimate pi... ");
			fflush(stdout);
			reestimatePi(step, piBar, N);
			printf("done\n");

			// find Abar, reestimate of A
			printf("reestimate A... ");
			fflush(stdout);
			reestimateA(step, Abar, N, T);
			printf("done\n");

			// find Bbar, reestimate of B
			printf("reestimate B... ");
			fflush(stdout);
			reestimateB(step, Bbar, N, M, T);
			printf("done\n");

	#ifdef PRINT_REESTIMATES
			printf("piBar =\n");
			printPi(piBar, N);
			printf("Abar =\n");
			printA(Abar, N);
			printf("Bbar^T = \n");
			printBT(Bbar, N, M, alphabet);
	#endif // PRINT_REESTIMATES

			// assign pi, A and B corresponding "bar" values
			for(i = 0; i < N; ++i)
			{
				pi[i] = piBar[i];

				for(j = 0; j < N; ++j)
				{
					A[i][j] = Abar[i][j];
				}

				for(j = 0; j < M; ++j)
				{
					B[i][j] = Bbar[i][j];
				}

			}// next i

			// compute log [P(observations | lambda)], where lambda = (A,B,pi)
			newLogProb = 0.0;
			for(i = 0; i < T; ++i)
			{
				newLogProb += log(step[i].c);
			}
			newLogProb = -newLogProb;

			// a little trick so that no initial logProb is required
			if(iter == 0)
			{
				logProb = newLogProb - 1.0;
			}

			printf("completed iteration = %d, log [P(observation | lambda)] = %f\n",
					iter, newLogProb);

			++iter;

		}// end while
    
		out = fopen(argv[7], "w"); // argv[7] = modelfile
		writeModel(pi, A, B, N, M, T, alphabet, out);
		fclose(out);
    
		printf("\nT = %d, N = %d, M = %d, iterations = %d\n\n", T, N, M, iter);
		printf("final pi =\n");
		printPi(pi, N);
		printf("\nfinal A =\n");
		printA(A, N);
		printf("\nfinal B^T =\n");
		printBT(B, N, M, alphabet);
		printf("\nlog [P(observations | lambda)] = %f\n\n", newLogProb);

	} // end of training
	else { //want to do testing


		out = fopen(argv[7], "r"); // argv[7] = modelfile
		readModelFile(pi, A, B, N, M, T, alphabet, out);
		
		// alpha (or forward) pass
		printf("alpha pass... ");
		fflush(stdout);
		alphaPass(step, pi, A, B, N, T);
		printf("done\n");
		printf("logProb %f\n", computeLogProb(step, T)/T);
		
	//	FILE * newFile = fopen("testing.txt", "a");
		//writeModel(pi, A, B, N, M, T, alphabet, newFile);

		//fclose(newFile);

		fclose(out);
	} // end of testing
}// end hmm