Exemple #1
0
FactorAnalysisStat::FactorAnalysisStat(String & featFilename,FeatureServer & fs,Config & config):_ms(config),_ss(config){ // constructor for a single file
	XList faNdx;	
	XLine featLine;
	featLine.addElement(featFilename);
        faNdx.addLine()=featLine;
        _init(faNdx,fs,config);
}
//-------------------------------------------------------------------------
// Get a tab with indexes of speakers with maximum likelihood (mdtm and etf only)
void getTarClientIdx(Config & config, XList & inputList, unsigned long nbLoc, unsigned long * tarTab)
{
	XLine *linep;
	unsigned long cpt=0;
	unsigned long cpttab=0;
	double minLLK=config.getParam("minLLK").toDouble();
	double maxScore=minLLK;
	unsigned long idxTar=0;
    bool verbose=config.existsParam("verbose");
    
	while((linep=inputList.getLine())!=NULL)
	{
		double score=linep->getElement(6).toDouble();
		if (score>=maxScore)
		{
			maxScore=score;		// this is the maximum score
			idxTar=cpt;			// index is just the line
			if (verbose) {cout << "giving highest score to " << linep->getElement(1) << " "<<maxScore << endl;} 
		}                         
		if (cpt%nbLoc==(nbLoc-1))	// when changing segment
		{
			tarTab[cpttab]=idxTar;   // idx of the target goes in the tab
			if (verbose) {cout << linep->getElement(1) << " max score: "<<maxScore <<"idx: "<<idxTar<<"cpt: "<<cpt<< endl;}
			cpttab++;	
			maxScore=minLLK; 	//reset maxScore
		}
		cpt++;
	}
}
Exemple #3
0
void *list_update(void *arguments){
	XList<T>* list = (XList<T>*) arguments;
        XListIterator<T> iterator;
        while (true) {
                iterator = list->begin();
	        for (int i = 0; i < rand()%(static_cast<int>(list->size()) + 1)
				; i++) {
	        	iterator.operator++();
		}
		*iterator = rand();
		cout << "Update Sleep" << endl;
                this_thread::sleep_for (chrono::seconds(4));
		cout << "Update Wakeup" << endl;
        }
	pthread_exit(NULL);
}
//-------------------------------------------------------------------------
// 
unsigned long getIndexOfMaxScore(XList & inputList,unsigned long scoreField, unsigned long segField, unsigned long & i, unsigned long nbListLines)
{
	String seg=inputList.getLine(i).getElement(segField);	//this is a new segment
	long max_score=-200;
	long score;
	unsigned long maxIndex=0; 

	while (inputList.getLine(i).getElement(segField)==seg)	// while same segment test
	{
		score= inputList.getLine(i).getElement(scoreField).toLong();
		if (score >= max_score) {max_score=score; maxIndex=i;}	// store max score and its index
		i++;
		if (i >= nbListLines) break; // break the loop if end of file
	}
return maxIndex;
}
Exemple #5
0
// this function is what is required by task #3 here: https://sites.google.com/site/kostovoop/tasks
//    Составить и отладить программу:
//    - создать некий XList фигур, наполнить его случайным образом конкретными фигурами всех типов;
//    - вывести в std::cout общее кол-во фигур с помощью Shape::GetCount();
//    - напечатать в std::cout сведения обо всех фигурах, находящихся в списке;
//    - очистить память;
//    - вывести в std::cout общее кол-во фигур с помощью Shape::GetCount() – удостовериться, что там 0;
//    - завершить работу программы.
void task3()
{
    XList<Shape> shapesList;
    // pt, circle, rect, square, polyline
    Point * pt = new Point("a point", 10, 100); // 1
    Circle * circle = new Circle("a circle", 30, Point("circle center", 10, 20)); // 2
    Rect * rect = new Rect("a rect", 10, -30, 10, -100); // 2
    Square * square = new Square("a square", 40, 20, 10); // 2
    Polyline * line = new Polyline("line"); // 1
    
    Point * pt1 = new Point("", 10, 20);
    Point * pt2 = new Point("", 20, 20);
    Point * pt3 = new Point("", 20, 40);
    Point * pt4 = new Point("", 10, 40);

    line->AddPoint(*pt1);
    line->AddPoint(*pt2);
    line->AddPoint(*pt3);
    line->AddPoint(*pt4);

    shapesList.pushBack(pt);
    shapesList.pushBack(circle);
    shapesList.pushBack(rect);
    shapesList.pushBack(square);
    shapesList.pushBack(line);
    
    std::cout << "Total number of shapes is: " << Shape::getCount() << std::endl;
    assert(Shape::getCount() == 16); // 5 figures in list and their copies, 4 points in the polyline, rect's origin, square's origin, circle's center
    
    XList<Shape>::Iterator it = shapesList.begin();
    int l = shapesList.numberOfElements() + 1;
    while(--l > 0){
        Shape * shape = it.currentItem();
        std::cout << *shape << std::endl;
        it.next();
    }
    
    shapesList.clearList();
    // freeing memory
    delete pt;
    delete circle;
    delete square;
    delete rect;
    delete line;
    delete pt1;
    delete pt2;
    delete pt3;
    delete pt4;
    
    std::cout << "Total number of shapes is now: " << Shape::getCount() << std::endl;
    assert(Shape::getCount() == 0);
}
Exemple #6
0
int AVIopen(char *filename,int flags,int channel,void **avi)
{
	AVIFile *newavi = new AVIFile;

	if(!newavi -> open(filename,flags,channel))
		return 0;

	*avi = newavi;
	aviXList.AddElement((XListElement*)newavi);

	xtRegisterSysFinitFnc(FinitAVI,XAVI_SYSOBJ_ID);
	return 1;
}
Exemple #7
0
void *list_read(void *arguments) {
	bool flag;
	XList<T>* list = (XList<T>*) arguments;
	XListIterator<T> iterator = list->begin();
	flag = true;
	while (true) {
		if (flag) {
			++iterator;
			this_thread::sleep_for(chrono::seconds(1));
			if(iterator == list->end()){
				flag = false;
				cout << "Read Forward: Finished" << endl;
			}
		} else {
			--iterator;
			this_thread::sleep_for(chrono::seconds(2));
			if(iterator == list->begin()){
				flag = true;
				cout << "Read Reverse: Finished" << endl;
			}
		}
	}
	pthread_exit(NULL);
}
Exemple #8
0
void main()
{
  XList<Shape *> shapes;  
  for (int i = 0; i < 5; i++)
  {

    shapes.AddLast(ShapeFactory::CreateShape(circle));
    shapes.AddLast(ShapeFactory::CreateShape(point));
    shapes.AddLast(ShapeFactory::CreateShape(rect));
    shapes.AddLast(ShapeFactory::CreateShape(polyline));
    shapes.AddLast(ShapeFactory::CreateShape(polygone));

  }


  std::cout << "shapes:" << Shape::GetCount() << std::endl;
  std::cout << "points:" << Point::GetCount() << std::endl;
  std::cout << "circles:" << Circle::GetCount() << std::endl;
  std::cout << "rect:" << Rect::GetCount() << std::endl;
  std::cout << "polyline:" << Polyline::GetCount() << std::endl;
  std::cout << "polygone:" << Polygone::GetCount() << std::endl << std::endl;

  for (int i = 0; i < shapes.GetSize(); i++)
    std::cout << *dynamic_cast<Printable *>(shapes.GetByIndex(i)) << std::endl;


  for (size_t i = 0; i < (size_t)shapes.GetSize(); i++)
    delete shapes.GetByIndex(i);
      

  std::cout << std::endl;
  std::cout << "shapes:" << Shape::GetCount() << std::endl;
  std::cout << "points:" << Point::GetCount() << std::endl;
  std::cout << "circles:" << Circle::GetCount() << std::endl;
  std::cout << "rect:" << Rect::GetCount() << std::endl;
  std::cout << "polyline:" << Polyline::GetCount() << std::endl;
  std::cout << "polygone:" << Polygone::GetCount() << std::endl << std::endl;

  _getch();
}
//-------------------------------------------------------------------------
// Produce a tab with mean and cov by segment without the maximum score(mdtm and etf only)
void getSegmentalMeanCovWithoutMax(Config & config, XList & inputList, unsigned long nbLoc, unsigned long * tarTab, double* meanTab, double * covTab)
{
	XLine *linep;
	unsigned long cpt=0;
	unsigned long cpttab=0;
	double minLLK=config.getParam("minLLK").toDouble();
	double maxScore=minLLK;
	double meanAcc=0.0;
	double covAcc=0.0;
	unsigned long idxTar=0;
	bool verbose=config.existsParam("verbose");

	while((linep=inputList.getLine())!=NULL)
	{
		double score=linep->getElement(6).toDouble();
		if (score>=maxScore)
		{
			maxScore=score;		// this is the maximum score
			idxTar=cpt;			// index is just the line
			if (verbose) {cout << "giving highest score to " << linep->getElement(1) << " "<<maxScore << endl;} 
		}
		meanAcc+=score;			// Accumulate mean and cov
		covAcc+=(score*score);
          
		if (cpt%nbLoc==(nbLoc-1))	// when changing segment
		{	
			tarTab[cpttab]=idxTar;
			meanAcc-=maxScore;	//remove max from Stats
			covAcc-=(maxScore*maxScore);
			meanTab[cpttab]=meanAcc;
			covTab[cpttab]=covAcc;
			if (verbose) {cout << linep->getElement(1) << " max score: "<<maxScore <<"idx: "<<idxTar<<"cpt: "<<cpt<< " meanA: "<<meanAcc<<" covA: "<<covAcc<<endl;}
			cpttab++;	
			maxScore=minLLK;
			meanAcc=0.0;
			covAcc=0.0;
		}
		cpt++;
	}
}  
//-------------------------------------------------------------------------
// Produce a tab with mean and cov by segment (mdtm and etf only)
void getSegmentalMeanCov(XList & inputList, unsigned long nbLoc, double* meanTab, double * covTab)
{
	XLine *linep;
	unsigned long cpt=0;
	unsigned long cpttab=0;
	double meanAcc=0.0;
	double covAcc=0.0;
     
	while((linep=inputList.getLine())!=NULL)
	{
		double score=linep->getElement(6).toDouble();
		meanAcc+=score;			// Accumulate mean and cov
		covAcc+=(score*score);
		if (cpt%nbLoc==(nbLoc-1))	// when changing segment
		{
			meanTab[cpttab]=meanAcc;
			covTab[cpttab]=covAcc;
			cpttab++;	
			meanAcc=0.0;
			covAcc=0.0;
		}
		cpt++;
	}
}
Exemple #11
0
void AVIclose(void *avi)
{
	AVIFile* p = (AVIFile*)avi;
	aviXList.RemoveElement((XListElement*)p);
	delete p;
}
Exemple #12
0
int main()
{
	XList<int> list;
	XList<int>::iterator it;
	XList<int>::reverse_iterator rit;
	
	list.push_back(11);
	list.push_front(8);
	list.push_back(12);
	list.push_back(13);
	list.push_back(14);

	list.print();
	std::cout<<list.size()<<std::endl;

	it = list.begin();
	std::cout<<*(++it)<<std::endl;

	for (it = list.begin(); it != list.end(); ++it)
		std::cout<<*it<<" ";
	std::cout<<std::endl;

	for (rit = list.rbegin(); rit != list.rend(); ++rit)
		std::cout<<*rit<<" ";
	std::cout<<std::endl;

	it = list.end();

	return 0;
}
void launchTurnDetectionProcess(Config & config){

	String outputFilesPath=config.getParam("outputFilesPath");

	String inputListFileName = config.getParam("listFileToSegment");	//file including the list of files to segment
	XLine classToAnalyse;	//Array of labels to analyze
	classToAnalyse.reset();

	if(verbose){
		cout << "*********** Current Configuration ***************" << endl;
		for(unsigned long i=0; i<config.getParamCount(); i++){
			cout << config.getParamName(i) << " => " <<  config.getParamContent(i) << endl;
		}
		cout << "*************************************************" << endl;
	}

	try{
		XList listLabel;
		XList listFileName;
		try{
			listFileName.load(inputListFileName,config);
		}
		catch(FileNotFoundException& e){
			cout<<"There is no files to segment !"<<endl;
		      	exit(-1);
		}
		listFileName.rewind();
		XLine *filep;
		while ((filep=listFileName.getLine()) != NULL){							// For each stream of audio data (in several files in the same line)
			const XLine & listFile=filep->getElements();						// One or several files, as several part of the same stream
		      	MixtureServer ms(config);
	      		StatServer ss(config, ms);
		      	SegServer Resultat;
	      		FeatureServer fs(config,listFile);							// Reading the features (one or more files) 
		      	SegServer segmentsServer;								// Create the segment server for managing the segments/clusters
	      		LabelServer labelServer;								// Create the lable server, for indexing the segments/clusters
		      	initializeClusters(listFile,segmentsServer,labelServer,config);				// Reading the segmentation files for each feature input file
	      		verifyClusterFile(segmentsServer,fs,config);						// Verify if the segments ending before the end of the feature files
			String fileInit=listFile.getElement(0);
			config.setParam("fileSize", String::valueOf(fs.getFeatureCountOfASource(fileInit)));	

			if(config.existsParam("fileRefPath")){
				// assumption: all the segments in the segment server come from the same source file !!!
				displayAllSegmentsFromRef(config, fileInit, fs.getFeatureCountOfASource(fileInit));
			}

			for(unsigned long icluster=0;icluster<segmentsServer.getClusterCount();icluster++){	// for each cluster
				SegCluster& cluster=segmentsServer.getCluster(icluster);
  				SegServer segOutputServer;
  				TurnDetection(config,cluster,segOutputServer,ss,fs,ms,labelServer);
				displayAllSegments(config,segOutputServer); 
  				for(unsigned long i=0;i<segOutputServer.getSegCount();i++){
    					Seg& segment=segOutputServer.getSeg(i);
	    				Resultat.createSeg(segment.begin(),segment.length(),segment.labelCode(),segment.string(),segment.sourceName());
	  			}
			}//for icluster
			saveSegmentation(config,Resultat,fs,outputFilesPath,1);
		}// while
	} // end try
	catch (Exception& e){ 
		cout << e.toString().c_str() << endl;
	}
}//launchTurnDetectionProcess
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
int IvExtractorEigenDecomposition(Config& config)
{
	String inputWorldFilename = config.getParam("inputWorldFilename");

	// label for selected frames - Only the frames associated with this label, in the label files, will be used
	bool fixedLabelSelectedFrame=true;
	String labelSelectedFrames;
	if (config.existsParam("useIdForSelectedFrame"))    // the ID of each speaker is used as labelSelectedFrame ?
		fixedLabelSelectedFrame=(config.getParam("useIdForSelectedFrame").toBool()==false);  
	if (fixedLabelSelectedFrame)                        // the label is decided by the command line and is unique for the run
		labelSelectedFrames=config.getParam("labelSelectedFrames");
 
try{
	MixtureServer ms(config);
	if (verbose) cout << "(IvExtractor) Approximate i-vector by using Eigen Decomposition"<<endl;
	if (verbose) cout << "(IvExtractor) TotalVariability - Load world model [" << inputWorldFilename<<"]"<<endl;
	MixtureGD& world = ms.loadMixtureGD(inputWorldFilename);      

	//Read the NDX file
	String ndxFilename = config.getParam("targetIdList");

	//Remove the first element of each line which is the model name
	XList tmpFileList(ndxFilename);
	XList fileList;
	for(unsigned long ll=0;ll<tmpFileList.getLineCount();ll++){
		fileList.addLine();
		for(unsigned long i=1;i<tmpFileList.getLine()->getElementCount();i++){
			fileList.getLine(fileList.getLineCount()-1).addElement(tmpFileList.getLine(ll).getElement(i));
		}
	}
	
	//Create and initialise the accumulator
	TVAcc tvAcc(fileList, config);
	Matrix<double> Q(tvAcc.getRankT(),tvAcc.getRankT());
	Matrix<double> D(tvAcc.getNDistrib(),tvAcc.getRankT());

	if(config.existsParam("loadEigenDecompositionParam") && config.getParam("loadEigenDecompositionParam").toBool()){	// Load normalized T matrix and weighted Covariance matrix if pre-computed

		//Load TotalVariability matrix
		String normTFilename = config.getParam("totalVariabilityMatrix") + "_norm";
		tvAcc.loadT(normTFilename, config);

		//Load D and Q matrices
		String dFilename = config.getParam("matrixFilesPath") + config.getParam("totalVariabilityMatrix") + "_EigDec_D" + config.getParam("loadMatrixFilesExtension");
		D.load(dFilename,config);

		String qFilename = config.getParam("matrixFilesPath") + config.getParam("totalVariabilityMatrix") + "_EigDec_Q" + config.getParam("loadMatrixFilesExtension");
		Q.load(qFilename,config);

	}
	else{
		//Load TotalVariability matrix
		tvAcc.loadT(config.getParam("totalVariabilityMatrix"), config);

		// Normalize matrix T
		tvAcc.normTMatrix();

		// Compute weighted co-variance matrix by using UBM weight coefficients
		DoubleSquareMatrix W(tvAcc.getRankT());
		W.setAllValues(0.0);
		tvAcc.getWeightedCov(W,world.getTabWeight(),config);

		// Eigen Decomposition of W to get Q
		Matrix<double> tmpW(W);
		Q.setAllValues(0.0);
		tvAcc.computeEigenProblem(tmpW,Q,tvAcc.getRankT(),config);

		// Compute D matrices (approximation of Tc'Tc matrices)
		D.setAllValues(0.0);
		tvAcc.approximateTcTc(D,Q,config);
	}

	//Load the statistics from files or compute statistics for all segments at once
	if((config.existsParam("loadAccs")) && config.getParam("loadAccs").toBool()){	//load pre-computed statistics
		cout<<"	(IvExtractor) Load Accumulators"<<endl;
		tvAcc.loadN(config);
		tvAcc.loadF_X(config);
	}
	else{															//Compute statistics if they don't exists
		tvAcc.computeAndAccumulateTVStat(config);
		tvAcc.saveAccs(config);
	}

	// Then load the meanEstimate computed by minDiv if required
	DoubleVector meanEstimate = tvAcc.getUbmMeans();
	if(config.existsParam("minDivergence")&& config.getParam("minDivergence").toBool()){
		String minDivName = config.getParam("matrixFilesPath") + config.getParam("meanEstimate") + config.getParam("loadMatrixFilesExtension");
		Matrix<double> tmpMean(minDivName,config);
		for(unsigned long i=0;i<meanEstimate.size();i++){
			meanEstimate[i] = tmpMean(0,i);
		}
	}
	//Update the mean Estimate
	cout<<"	(IvExtractor) Load Mean Estimate"<<endl;
	tvAcc.loadMeanEstimate(meanEstimate);

	//Substract mean from the statistics and normalize co-variance
	tvAcc.normStatistics(config);

	// Estimate I-Vectors
	tvAcc.estimateWEigenDecomposition(D,Q,config);

	cout<<"--------- save IV by File --------"<<endl;
	tvAcc.saveWbyFile(config);
	cout<<"--------- end of process --------"<<endl;


} // fin try
catch (Exception& e) {cout << e.toString().c_str() << endl;}
return 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
int IvExtractor(Config& config)
{
	String inputWorldFilename = config.getParam("inputWorldFilename");

	// label for selected frames - Only the frames associated with this label, in the label files, will be used
	bool fixedLabelSelectedFrame=true;
	String labelSelectedFrames;
	if (config.existsParam("useIdForSelectedFrame"))    // the ID of each speaker is used as labelSelectedFrame ?
		fixedLabelSelectedFrame=(config.getParam("useIdForSelectedFrame").toBool()==false);  
	if (fixedLabelSelectedFrame)                        // the label is decided by the command line and is unique for the run
		labelSelectedFrames=config.getParam("labelSelectedFrames");
 
try{
	MixtureServer ms(config);
	if (verbose) cout << "(IvExtractor) TotalVariability - Load world model [" << inputWorldFilename<<"]"<<endl;
	MixtureGD& world = ms.loadMixtureGD(inputWorldFilename);      
	
	//Load the statistics from files or compute statistics for all segments at once
	//Read the NDX file
	String ndxFilename = config.getParam("targetIdList");

	//Remove the first element of each line which is the model name
	XList tmpFileList(ndxFilename);
	XList fileList;
	for(unsigned long ll=0;ll<tmpFileList.getLineCount();ll++){
		fileList.addLine();
		for(unsigned long i=1;i<tmpFileList.getLine()->getElementCount();i++){
			fileList.getLine(fileList.getLineCount()-1).addElement(tmpFileList.getLine(ll).getElement(i));
		}
	}

	//Create and initialise the accumulator
	TVAcc tvAcc(fileList, config);

	//Load TotalVariability matrix
	tvAcc.loadT(config.getParam("totalVariabilityMatrix"), config);

	//Statistics
	if((config.existsParam("loadAccs")) && config.getParam("loadAccs").toBool()){	//load pre-computed statistics
		cout<<"	(IvExtractor) Load Accumulators"<<endl;
		tvAcc.loadN(config);
		tvAcc.loadF_X(config);
	}
	else{															//Compute statistics if they don't exists
		tvAcc.computeAndAccumulateTVStat(config);
		tvAcc.saveAccs(config);
	}

	// Then load the meanEstimate computed by minDiv if required
	DoubleVector meanEstimate = tvAcc.getUbmMeans();
	if(config.existsParam("minDivergence")&& config.getParam("minDivergence").toBool()){
		String minDivName = config.getParam("matrixFilesPath") + config.getParam("meanEstimate") + config.getParam("loadMatrixFilesExtension");
		Matrix<double> tmpMean(minDivName,config);
		for(unsigned long i=0;i<meanEstimate.size();i++){
			meanEstimate[i] = tmpMean(0,i);
		}
	}
	//Update the mean Estimate
	cout<<"	(IvExtractor) Load Mean Estimate"<<endl;
	tvAcc.loadMeanEstimate(meanEstimate);

	//Substract mean from the statistics
	tvAcc.substractM(config);

	//Compute vEvT for each session
	tvAcc.estimateTETt(config);

	// Estimate I-Vectors
	tvAcc.estimateW(config);

	cout<<"--------- save IV by File --------"<<endl;
	tvAcc.saveWbyFile(config);
	cout<<"--------- end of process --------"<<endl;

} // fin try
catch (Exception& e) {cout << e.toString().c_str() << endl;}
return 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
int TrainTargetLFA(Config& config)
{
	String inputClientListFileName = config.getParam("targetIdList");
	String inputWorldFilename = config.getParam("inputWorldFilename");
	String outputSERVERFilename = "";
	if (config.existsParam("mixtureServer")) outputSERVERFilename =config.getParam("mixtureServer");
	bool initByClient=false;                                              // In this case, the init model is read from the file
	if (config.existsParam("initByClient")) initByClient=config.getParam("initByClient").toBool();
	bool saveEmptyModel=false;
	if (config.existsParam("saveEmptyModel")) saveEmptyModel=config.getParam("saveEmptyModel").toBool();
	// label for selected frames - Only the frames associated with this label, in the label files, will be used
	bool fixedLabelSelectedFrame=true;
	String labelSelectedFrames;
	if (config.existsParam("useIdForSelectedFrame"))    // the ID of each speaker is used as labelSelectedFrame ?
		fixedLabelSelectedFrame=(config.getParam("useIdForSelectedFrame").toBool()==false);  
	if (fixedLabelSelectedFrame)                        // the label is decided by the command line and is unique for the run
		labelSelectedFrames=config.getParam("labelSelectedFrames");
	bool modelData=false;
	if (config.existsParam("useModelData")) modelData=config.getParam("useModelData").toBool();
	String initModelS=inputWorldFilename;
	if (modelData) if (config.existsParam("initModel")) initModelS=config.getParam("initModel"); // Use a specific model for Em init
	bool outputAdaptParam=false;
	if (config.existsParam("superVectors")) outputAdaptParam=true;
 
try{
	XList inputClientList(inputClientListFileName,config);          // read the Id + filenames for each client
	XLine * linep;
	inputClientList.getLine(0);
	MixtureServer ms(config);
	StatServer ss(config, ms);
	if (verbose) cout << "(TrainTarget) Latent Factor Analysis - Load world model [" << inputWorldFilename<<"]"<<endl;
	MixtureGD& world = ms.loadMixtureGD(inputWorldFilename);      
	if (verbose) cout <<"(TrainTarget) Use["<<initModelS<<"] for initializing EM"<<endl;
	
	//LOAD JFA MAtrices
	unsigned long svsize=world.getDistribCount()*world.getVectSize();
	Matrix<double> U, V; 
	DoubleVector D(svsize,svsize);
	
	//Initialise EC matrix
	if(config.existsParam("eigenChannelMatrix")){
		String uName = config.getParam("matrixFilesPath") + config.getParam("eigenChannelMatrix") + config.getParam("loadMatrixFilesExtension");
 		U.load (uName, config);
		if (verboseLevel >=1) cout << "(TrainTargetLFA) Init EC matrix from "<< config.getParam("eigenChannelMatrix") <<"  from EigenChannel Matrix: "<<", rank: ["<<U.rows() << "] sv size: [" << U.cols() <<"]"<<endl;
	}
	else{
		U.setDimensions(1,svsize);
		U.setAllValues(0.0);
		if (verboseLevel >1) cout << "(TrainTargetLFA) Init EC matrix to 0"<<endl;
	}
	
	V.setDimensions(1,svsize);
	V.setAllValues(0.0);
	if (verboseLevel >=1) cout << "(TrainTargetLFA) Init EV matrix to 0"<<endl;

	//Initialise the D matrix for MAP adaptation
	for(unsigned long i=0; i<world.getDistribCount(); i++){
		for(unsigned long j = 0; j<world.getVectSize(); j++){
			D[i*world.getVectSize()+j] = sqrt(1.0/(world.getDistrib(i).getCovInv(j)*config.getParam("regulationFactor").toDouble()));
		}
	}

	// *********** Target loop ***************** 
	while ((linep=inputClientList.getLine()) != NULL){             	// linep gives the XLine with the Id of a given client and the list of files

		String *id=linep->getElement();                              		// Get the Client ID (id)
		XLine featureFileListp=linep->getElements();	           	// Get the list of feature file for the client (end of the line)
		if (verbose) cout << "(TrainTargetLFA) Train model ["<<*id<<"]"<<endl;
	
		XList ndx; ndx.addLine() = featureFileListp;
		JFAAcc jfaAcc(ndx,config,"TrainTarget");
		
		//Charger les matrices V, U et D a partir des objets matrice existant.
		jfaAcc.loadEV(V, config); jfaAcc.loadEC(U, config); jfaAcc.loadD(D);  

		//Initialise VU matrix
		jfaAcc.initVU();

		FeatureServer fs(config,featureFileListp);											// Reading the features (from several files)
		SegServer segmentsServer;															// Create the segment server for managing the segments/clusters
		LabelServer labelServer;															// Create the lable server, for indexing the segments/clusters
		initializeClusters(featureFileListp,segmentsServer,labelServer,config);				// Reading the segmentation files for each feature input file
		verifyClusterFile(segmentsServer,fs,config);                                     	// Verify if the segments ending before the end of the feature files...

		MixtureGD & adaptedMixture = ms.duplicateMixture(world,DUPL_DISTRIB);               // Creating final as a copy of the world model
		MixtureGD & clientMixture= ms.duplicateMixture(world,DUPL_DISTRIB);
		long codeSelectedFrame=labelServer.getLabelIndexByString(labelSelectedFrames);   	// Get the index of the cluster with in interest audio segments
		if (codeSelectedFrame==-1){                                                         	// No data for this model !!!!!!!!!!!!!!
			cout << " WARNING - NO DATA FOR TRAINING ["<<*id<<"]";
			if (saveEmptyModel){
				cout <<" World model is returned"<<endl;                                    // In this case, the client model is the world model
				if (verbose) cout << "Save client model ["<<*id<<"]" << endl;
				adaptedMixture.save(*id, config);                                           // Save the client model
			}
		}			

		else{
			SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame); // Gives the cluster of the selected/used segments                                   

			//Compute the JFA statistics
			jfaAcc.computeAndAccumulateJFAStat(selectedSegments,fs,config);

			//Estimate X and Y in one time for each speaker
			jfaAcc.storeAccs();
			jfaAcc.estimateVUEVUT(config);
			jfaAcc.estimateAndInverseL_VU(config);
			jfaAcc.substractMplusDZ(config);
			jfaAcc.estimateYX();
			//Reinitialise the accumulators
			jfaAcc.resetTmpAcc();
			jfaAcc.restoreAccs();
			
			//Split X and Y estimates
			jfaAcc.splitYX();

			//Substract speaker and channel statistics M + VUYX
			jfaAcc.substractMplusVUYX();		
			//Estimate Z for each speaker
			double tau = config.getParam("regulationFactor").toLong();
			jfaAcc.estimateZMAP(tau);
			//Reinitialise the accumulators
			jfaAcc.resetTmpAcc();
			jfaAcc.restoreAccs();

			bool varAdapt = false;
			if((config.existsParam("varAdapt")) && ( config.getParam("varAdapt").toBool() )){
				varAdapt = true;
			}

			DoubleVector clientModel(jfaAcc.getSvSize(), jfaAcc.getSvSize());
			clientModel.setSize(jfaAcc.getSvSize());

			jfaAcc.getMplusVYplusDZ(clientModel, 0);
			
			//Create the ClientMixture
			svToModel(clientModel, clientMixture);
			clientMixture.save(*id, config);

			long tid=ms.getMixtureIndex(*id);
			ms.deleteMixtures(tid,tid);
			ms.deleteUnusedDistribs();
		}
	}
} // fin try
catch (Exception& e) {cout << e.toString().c_str() << endl;}
return 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
int TrainTargetJFA(Config& config)
{
	String inputClientListFileName = config.getParam("targetIdList");
	String inputWorldFilename = config.getParam("inputWorldFilename");
	String outputSERVERFilename = "";
	if (config.existsParam("mixtureServer")) outputSERVERFilename =config.getParam("mixtureServer");
	bool initByClient=false;                                              // In this case, the init model is read from the file
	if (config.existsParam("initByClient")) initByClient=config.getParam("initByClient").toBool();
	bool saveEmptyModel=false;
	if (config.existsParam("saveEmptyModel")) saveEmptyModel=config.getParam("saveEmptyModel").toBool();
	// label for selected frames - Only the frames associated with this label, in the label files, will be used
	bool fixedLabelSelectedFrame=true;
	String labelSelectedFrames;
	if (config.existsParam("useIdForSelectedFrame"))    // the ID of each speaker is used as labelSelectedFrame ?
		fixedLabelSelectedFrame=(config.getParam("useIdForSelectedFrame").toBool()==false);  
	if (fixedLabelSelectedFrame)                        // the label is decided by the command line and is unique for the run
		labelSelectedFrames=config.getParam("labelSelectedFrames");
	bool modelData=false;
	if (config.existsParam("useModelData")) modelData=config.getParam("useModelData").toBool();
	String initModelS=inputWorldFilename;
	if (modelData) if (config.existsParam("initModel")) initModelS=config.getParam("initModel"); // Use a specific model for Em init
	bool outputAdaptParam=false;
	if (config.existsParam("superVectors")) outputAdaptParam=true;
 
try{
	XList inputClientList(inputClientListFileName,config);          // read the Id + filenames for each client
	XLine * linep;
	inputClientList.getLine(0);
	MixtureServer ms(config);
	StatServer ss(config, ms);
	if (verbose) cout << "(TrainTarget) Joint Factor Analysis - Load world model [" << inputWorldFilename<<"]"<<endl;
	MixtureGD& world = ms.loadMixtureGD(inputWorldFilename);      
	if (verbose) cout <<"(TrainTarget) Use["<<initModelS<<"] for initializing EM"<<endl;
	
	//LOAD JFA MAtrices
	Matrix<double> U, V; 
	DoubleVector D;
	
	//Initialise EC matrix
	if(config.existsParam("eigenChannelMatrix")){
		String uName = config.getParam("matrixFilesPath") + config.getParam("eigenChannelMatrix") + config.getParam("loadMatrixFilesExtension");
 		U.load (uName, config);
		if (verboseLevel >=1) cout << "(TrainTargetJFA) Init EC matrix from "<< config.getParam("eigenChannelMatrix") <<"  from EigenChannel Matrix: "<<", rank: ["<<U.rows() << "] sv size: [" << U.cols() <<"]"<<endl;
	}
	else{
		unsigned long sS = world.getVectSize() * world.getDistribCount();
		U.setDimensions(1,sS);
		U.setAllValues(0.0);
		if (verboseLevel >=1) cout << "(TrainTargetJFA) Init EC matrix to 0"<<endl;
	}
	
	//Initialise EV matrix
	if(config.existsParam("eigenVoiceMatrix")){
		String vName = config.getParam("matrixFilesPath") + config.getParam("eigenVoiceMatrix") + config.getParam("loadMatrixFilesExtension");
		V.load (vName, config);
		if (verboseLevel >=1) cout << "(TrainTargetJFA) Init EV matrix from "<< config.getParam("eigenVoiceMatrix") <<"  from EigenVoice Matrix: "<<", rank: ["<<V.rows() << "] sv size: [" << V.cols() <<"]"<<endl;
	}
	else{
		unsigned long sS = world.getVectSize() * world.getDistribCount();
		V.setDimensions(1,sS);
		V.setAllValues(0.0);
		if (verboseLevel >=1) cout << "(TrainTargetJFA) Init EV matrix to 0"<<endl;
	}
	
	//Initialise D matrix
	if(config.existsParam("DMatrix")){
		String dName = config.getParam("matrixFilesPath") + config.getParam("DMatrix") + config.getParam("loadMatrixFilesExtension");
		Matrix<double> tmpD(dName, config);
		
		if( (tmpD.rows() != 1) || ( tmpD.cols() != world.getVectSize()*world.getDistribCount() ) ){
			throw Exception("Incorrect dimension of D Matrix",__FILE__,__LINE__);
		}
		else{
			D.setSize(world.getVectSize()*world.getDistribCount());
			D.setAllValues(0.0);
			for(unsigned long i=0; i<world.getVectSize()*world.getDistribCount(); i++){
				D[i] = tmpD(0,i);
			}
			if (verboseLevel >=1) cout << "(TrainTargetJFA) Init D matrix from "<<config.getParam("DMatrix")<<endl;
		}
	}
	else{
		unsigned long sS = world.getVectSize() * world.getDistribCount();
		D.setSize(sS);
		D.setAllValues(0.0);
		if (verboseLevel >1) cout << "(TrainTargetJFA) Init D matrix to 0"<<endl;
	}
	
	// *********** Target loop ***************** 
	while ((linep=inputClientList.getLine()) != NULL){             	// linep gives the XLine with the Id of a given client and the list of files

		String *id=linep->getElement();                              		// Get the Client ID (id)
		XLine featureFileListp=linep->getElements();	           	// Get the list of feature file for the client (end of the line)
		if (verbose) cout << "(TrainTarget) Train model ["<<*id<<"]"<<endl;
	
		XList ndx; ndx.addLine() = featureFileListp;
		JFAAcc jfaAcc(ndx,config,"TrainTarget");

		//Load V, U and D from existing matrices.
		jfaAcc.loadEV(V, config); jfaAcc.loadEC(U, config); jfaAcc.loadD(D);  

		//Initialize VU matrix
		jfaAcc.initVU();

		FeatureServer fs(config,featureFileListp);                                            			// Reading the features (from several files)
		SegServer segmentsServer;                                                             				// Create the segment server for managing the segments/clusters
		LabelServer labelServer;                                                              				// Create the lable server, for indexing the segments/clusters
		initializeClusters(featureFileListp,segmentsServer,labelServer,config);         		// Reading the segmentation files for each feature input file
		verifyClusterFile(segmentsServer,fs,config);                                     				// Verify if the segments ending before the end of the feature files...

		MixtureGD & adaptedMixture = ms.duplicateMixture(world,DUPL_DISTRIB);                 	// Creating final as a copy of the world model
		MixtureGD & clientMixture= ms.duplicateMixture(world,DUPL_DISTRIB);
		long codeSelectedFrame=labelServer.getLabelIndexByString(labelSelectedFrames);   	// Get the index of the cluster with in interest audio segments
		if (codeSelectedFrame==-1){                                                           					// No data for this model !!!!!!!!!!!!!!
			cout << " WARNING - NO DATA FOR TRAINING ["<<*id<<"]";
			if (saveEmptyModel){
				cout <<" World model is returned"<<endl;                                    				// In this case, the client model is the world model
				if (verbose) cout << "Save client model ["<<*id<<"]" << endl;
				adaptedMixture.save(*id, config);                                           					// Save the client model
			}
		}			

		else{
			SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame); // Gives the cluster of the selected/used segments                                   

			//Compute the JFA statistics
			jfaAcc.computeAndAccumulateJFAStat(selectedSegments,fs,config);

			//Estimate X and Y in one time for each speaker
			jfaAcc.storeAccs();
			jfaAcc.estimateVUEVUT(config);

			jfaAcc.estimateAndInverseL_VU(config);

			jfaAcc.substractMplusDZ(config);

			jfaAcc.estimateYX();
			//Reinitialise the accumulators
			jfaAcc.resetTmpAcc();
			jfaAcc.restoreAccs();
			
			//Split X and Y estimates
			jfaAcc.splitYX();

			//Substract speaker and channel statistics M + VUYX
			jfaAcc.substractMplusVUYX();		
			//Estimate Z for each speaker
			jfaAcc.estimateZ();
			//Reinitialise the accumulators
			jfaAcc.resetTmpAcc();
			jfaAcc.restoreAccs();

			bool varAdapt = false;
			if((config.existsParam("varAdapt")) && ( config.getParam("varAdapt").toBool() )){
				varAdapt = true;
			}

			DoubleVector clientSV(jfaAcc.getSvSize(), jfaAcc.getSvSize());
			clientSV.setSize(jfaAcc.getSvSize());
			DoubleVector clientModel(jfaAcc.getSvSize(), jfaAcc.getSvSize());
			clientModel.setSize(jfaAcc.getSvSize());

			bool saveMixture = true;
			if((config.existsParam("saveMixture")) && !( config.getParam("saveMixture").toBool() ))	saveMixture = false;
			bool saveSuperVector = true;
			if((config.existsParam("saveSuperVector")) && !( config.getParam("saveSuperVector").toBool() ))	saveSuperVector = false;
			bool saveX = false;
			bool saveY = false;
			bool saveZ = false;


			if(config.existsParam("saveX"))			saveX = config.getParam("saveX").toBool();
			if(config.existsParam("saveY"))			saveY = config.getParam("saveY").toBool();
			if(config.existsParam("saveZ"))			saveZ = config.getParam("saveZ").toBool();
			String xExtension = ".x"; String yExtension = ".y"; String zExtension = ".z";
			if(config.existsParam("xExtension"))	xExtension = config.getParam("xExtension");
			if(config.existsParam("yExtension"))	yExtension = config.getParam("yExtension");
			if(config.existsParam("zExtension"))	zExtension = config.getParam("zExtension");

			jfaAcc.getVYplusDZ(clientSV, 0);
			jfaAcc.getMplusVYplusDZ(clientModel, 0);
			
			//WARNING !!!!! only the SuperVector model is divided by the UBM Co-Variance.
			for(unsigned long i=0; i<jfaAcc.getSvSize(); i++){
				clientSV[i] *= jfaAcc.getUbmInvVar()[i];
			}
			
			//Create the ClientMixture to save if required
			if(saveMixture){
				svToModel(clientModel, clientMixture);
				clientMixture.save(*id, config);
			}

			if(saveSuperVector){
				String svPath=config.getParam("saveVectorFilesPath");
				String svExt=config.getParam("vectorFilesExtension"); 
				String svFile=svPath+*id+svExt; 
				((Matrix<double>)clientSV).save(svFile,config);   
			}

			String svPath=config.getParam("saveVectorFilesPath");

			if(saveX){
				String xFile=svPath+*id+xExtension;
				jfaAcc.saveX(xFile,config);
			}
			if(saveY){
				String yFile=svPath+*id+yExtension;
				jfaAcc.saveY(yFile,config);
			}
			if(saveZ){
				String zFile=svPath+*id+zExtension;
				jfaAcc.saveZ(zFile,config);
			}

			long tid=ms.getMixtureIndex(*id);
			ms.deleteMixtures(tid,tid);
			ms.deleteUnusedDistribs();
		}
	}
} // fin try
catch (Exception& e) {cout << e.toString().c_str() << endl;}
return 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
int TrainTargetFA(Config& config)
{
  String inputClientListFileName = config.getParam("targetIdList");
  String inputWorldFilename = config.getParam("inputWorldFilename");
  String outputSERVERFilename = "";
  if (config.existsParam("mixtureServer")) outputSERVERFilename =config.getParam("mixtureServer");
  bool initByClient=false;                                              // In this case, the init model is read from the file
  if (config.existsParam("initByClient")) initByClient=config.getParam("initByClient").toBool();
  bool saveEmptyModel=false;
  if (config.existsParam("saveEmptyModel")) saveEmptyModel=config.getParam("saveEmptyModel").toBool();
  // label for selected frames - Only the frames associated with this label, in the label files, will be used
  bool fixedLabelSelectedFrame=true;
  String labelSelectedFrames;
  if (config.existsParam("useIdForSelectedFrame"))    // the ID of each speaker is used as labelSelectedFrame ?
    fixedLabelSelectedFrame=(config.getParam("useIdForSelectedFrame").toBool()==false);  
  if (fixedLabelSelectedFrame)                        // the label is decided by the command line and is unique for the run
    labelSelectedFrames=config.getParam("labelSelectedFrames");
  bool modelData=false;
  if (config.existsParam("useModelData")) modelData=config.getParam("useModelData").toBool();
  String initModelS=inputWorldFilename;
  if (modelData) if (config.existsParam("initModel")) initModelS=config.getParam("initModel"); // Use a specific model for Em init
  bool outputAdaptParam=false;
  if (config.existsParam("superVectors")) outputAdaptParam=true;
  Matrix <double> ChannelMatrix;
  if (verbose) cout<< "EigenMAP and Eigenchannel with [" << config.getParam("initChannelMatrix") << "] of size: ["; 
  ChannelMatrix.load(config.getParam("initChannelMatrix"),config); //get Channel Matrix from args and load in a Matrix object
  if (verbose) cout << ChannelMatrix.rows() << "," <<ChannelMatrix.cols() << "]" << endl;
  bool varAdapt=false;
  if (config.existsParam("FAVarAdapt")) varAdapt=true;
  bool saveCompleteServer=false;
 
  try{
    XList inputClientList(inputClientListFileName,config);          // read the Id + filenames for each client
    XLine * linep;
    inputClientList.getLine(0);
    MixtureServer ms(config);
    StatServer ss(config, ms);
    if (verbose) cout << "(TrainTarget) Factor Analysis - Load world model [" << inputWorldFilename<<"]"<<endl;
    MixtureGD& world = ms.loadMixtureGD(inputWorldFilename);      
    if (verbose) cout <<"(TrainTarget) Use["<<initModelS<<"] for initializing EM"<<endl;
    
    // *********** Target loop ***************** 
    while ((linep=inputClientList.getLine()) != NULL){             // linep gives the XLine with the Id of a given client and the list of files

      String *id=linep->getElement();                              // Get the Client ID (id)
      XLine featureFileListp=linep->getElements();	           // Get the list of feature file for the client (end of the line)
      if (verbose) cout << "(TrainTarget) Train model ["<<*id<<"]"<<endl;   
      FeatureServer fs(config,featureFileListp);                                            // Reading the features (from several files)
      SegServer segmentsServer;                                                             // Create the segment server for managing the segments/clusters
      LabelServer labelServer;                                                              // Create the lable server, for indexing the segments/clusters
      initializeClusters(featureFileListp,segmentsServer,labelServer,config);               // Reading the segmentation files for each feature input file
      verifyClusterFile(segmentsServer,fs,config);                                          // Verify if the segments ending before the end of the feature files...
      MixtureGD & adaptedMixture = ms.duplicateMixture(world,DUPL_DISTRIB);                 // Creating final as a copy of the world model
      MixtureGD & clientMixture= ms.duplicateMixture(world,DUPL_DISTRIB);
      long codeSelectedFrame=labelServer.getLabelIndexByString(labelSelectedFrames);        // Get the index of the cluster with in interest audio segments
      if (codeSelectedFrame==-1){                                                           // No data for this model !!!!!!!!!!!!!!
	cout << " WARNING - NO DATA FOR TRAINING ["<<*id<<"]";
	if (saveEmptyModel){
	  cout <<" World model is returned"<<endl;                                    // In this case, the client model is the world model
	  if (verbose) cout << "Save client model ["<<*id<<"]" << endl;
	  adaptedMixture.save(*id, config);                                           // Save the client model
	}
      }
      else{
	SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame); // Gives the cluster of the selected/used segments                                   
        /// **** Factor Analysis Stuff
        XList faNdx;
        faNdx.addLine()=featureFileListp; 
        FactorAnalysisStat FA(faNdx,fs,config); // give all features to FA stats
        
        //FA.computeAndAccumulateGeneralFAStats(selectedSegments,fs,config);    
        for(int i=0;i<config.getParam("nbTrainIt").toLong();i++){
          if (verbose) cout << "------ Iteration ["<<i<<"] ------"<<endl;
          FA.computeAndAccumulateGeneralFAStats(selectedSegments,fs,config);                
          /*if (!varAdapt) FA.getTrueSpeakerModel(clientMixture,linep->getElement(1));
          else FA.getFactorAnalysisModel(clientMixture,linep->getElement(1));
          if (verbose) cout << "LLK for model["<<*id<<"] at it["<<i-1<<"]="<<FA.getLLK(selectedSegments,clientMixture,fs,config) << endl; */
          FA.estimateAndInverseL(config);
          FA.substractSpeakerStats();
          FA.getXEstimate();
          FA.substractChannelStats(); 
          FA.getYEstimate();    
      }      
      MixtureGD & sessionMixture= ms.duplicateMixture(world,DUPL_DISTRIB);
      bool saveSessionModel=false;
      if (config.existsParam("saveSessionModel")) saveSessionModel=true;
      if (saveSessionModel) FA.getSessionModel(sessionMixture,linep->getElement(1));
      if (!varAdapt) FA.getTrueSpeakerModel(clientMixture,linep->getElement(1)); // basically compute M_s_h=M+Dy_s and get a model
      else FA.getFactorAnalysisModel(clientMixture,linep->getElement(1)); // get FA variance adapted model
      if (verbose) cout << "Final LLK for model["<<*id<<"]="<<FA.getLLK(selectedSegments,clientMixture,fs,config) << endl;    

      /// **** End of FA
        if (!outputAdaptParam) {
            if (verbose) cout << "Save client model ["<<*id<<"]" << endl;
            clientMixture.save(*id, config);                                           // Save the client model
            if (saveSessionModel) {
              String sessionfile=*id+".session";
              if (verbose) cout << "Save session model ["<<sessionfile<<"]" << endl;              
              sessionMixture.save(sessionfile,config);   
            }              
        }
	if (!saveCompleteServer){
	  long tid=ms.getMixtureIndex(*id);      // TO BE SUPPRESSED BY
	  ms.deleteMixtures(tid,tid);            // ADDING a delete on a mixture pointor
	  ms.deleteUnusedDistribs();
	  }
      }
    }    
  } // fin try
catch (Exception& e) {cout << e.toString().c_str() << endl;}
  return 0;
}
Exemple #19
0
int main(){
    XList<Shape*> shapes;
    Point * point1 = new Point(0., 2., "point_1");
    shapes.push_back(point1);
    Point * point2 = new Point(2., 2., "point_2");
    shapes.push_back(point2);
    Point * point3 = new Point(2., 0., "point_3");
    shapes.push_back(point3);
    Point * point4 = new Point(0., 0., "point_4");
    shapes.push_back(point4);

    Circle * circle = new Circle(point4, 10., "circle_1");
    shapes.push_back(circle);

    Rect * rect = new Rect(point1, point2, point3, point4, "rectangle");
    shapes.push_back(rect);

    try {
        Square * square = new Square(point1, point2, point3, point4, "square");
        shapes.push_back(square);
    } catch (const char* error){
        // std::cout << "EXCEPTION RAISED: " << error << std::endl;
    }


    Polyline * polyline = new Polyline("polyline");
    polyline->AddPoint(point1);
    polyline->AddPoint(point2);
    polyline->AddPoint(point3);
    polyline->AddPoint(point4);
    shapes.push_back(polyline);

    for (XList<Shape*>::iterator it = shapes.begin(); it != NULL; ++it) {
        std::cout << *it;
    }
    printf("Number of shapes = %d\n", Shape::GetCount());
    for (XList<Shape*>::iterator it = shapes.begin(); it != NULL; ++it) {
        delete *it;
    }
    printf("Number of shapes = %d\n", Shape::GetCount());
    return 0;
}
Exemple #20
0
int main()
{
	std::cout<<Shape::GetCount()<<std::endl; //0

	XList<Shape*>* shlist = new XList<Shape*>;
	Point* point0 = new Point("simple_point");
	Point* point1 = new Point(1,1);
	Point* point2 = new Point(-2.2, 2);
	Circle* circle = new Circle("bublic", *point0,5);
	Rect* rect1 = new Rect(*point1, *point2);
	Square* square = new Square(*point0, *point1);
	Rect* rect2 = new Rect(*square);
	Polyline* pl = new Polyline;
	pl->AddPoint(*point0);
	pl->AddPoint(*point1);
	pl->AddPoint(*point2);
	Square* sq = NULL;
	try
	{
		sq = new Square("ABBA", *point1, *point2);
		shlist->push_front(sq);
	}
	catch (std::exception& e)
	{
		std::cout << e.what() << std::endl;
	}
	try
	{
		sq = new Square("ABBA2", *point1, *point0);
		shlist->push_front(sq);
	}
	catch (std::exception& e)
	{
		std::cout << e.what() << std::endl;
	}

	circle->Print();

	std::cout<<Shape::GetCount()<<std::endl; //21

	shlist->push_back(point0);
	shlist->push_back(rect2);
	shlist->push_back(circle);
	shlist->push_front(rect1);
	shlist->push_back(square);
	shlist->push_back(pl);
	shlist->push_back(point2);
	shlist->push_front(point1);
	

	std::cout<<Shape::GetCount()<<std::endl; //21

	for (XList<Shape*>::iterator it = shlist->begin(); it != shlist->end(); ++it)
	{
		std::cout<<**it<<std::endl;
	}
	std::cout<<Shape::GetCount()<<std::endl; //21
	
	for (XList<Shape*>::iterator it = shlist->begin(); it != shlist->end(); ++it)
	{
		delete *it;
	}
	std::cout<<Shape::GetCount()<<std::endl; //0

	delete shlist;

	std::cout<<Shape::GetCount()<<std::endl; //0
	Named *myshape = new Point(0, 0);
	delete myshape;
	std::cout<<Shape::GetCount()<<std::endl; //0
	return 0;
}
//-------------------------------------------------------------------------
// Retrieve info in a nist file providing the good fields
void retrieveNISTSegmentInfo(XList & inputList, String & gender, String & clientName, String & seg, unsigned long genderField, unsigned long nameField, unsigned long segField, unsigned long & i) {
	if (inputList.getLine(i).getElement(genderField)=="F") {gender="f";} else {gender="m";}
	clientName=inputList.getLine(i).getElement(nameField);
	seg=inputList.getLine(i).getElement(segField);
}
Exemple #22
0
int main(int argc, char ** argv) {

	vector<pthread_t> reader, writer, updater ,remover;
	if (argc == 5) {
		cout << "number of reader thread(s):" << argv[1] << 
			" writer thread(s):" << argv[2] << 
			" updater thread(s):" << argv[3] << 
			" remover thread(s):" << argv[4] << endl;
		reader.resize(atoi(argv[1]));
		writer.resize(atoi(argv[2]));
		updater.resize(atoi(argv[3]));
		remover.resize(atoi(argv[4]));
	} else {
		cout << "number of reader thread(s):" << READER_THREADS 
			<< " writer thread(s):"	<< WRITER_THREADS 
			<< " updater thread(s):" << UPDATER_THREADS
		       	<< " remover thread(s):" << REMOVER_THREADS << endl; 
		reader.resize(READER_THREADS);
		writer.resize(WRITER_THREADS);
		updater.resize(UPDATER_THREADS);
		remover.resize(REMOVER_THREADS);
	}

	//define mutex
	mutex mtx;
	//define Xlist
	XList<int> xlist;
	for (int j = 0; j < 10; j++) {
		xlist.push_back(j);
	}

	list_struct<int> list;
	list.list = &xlist;
	list.mtx = &mtx;

	signal_struct<int> sig;
	sig.list = &xlist;
	int s;
	sigset_t set;
	
	pthread_t thread;
	sigemptyset(&set);
        sigaddset(&set, SIGQUIT);
	sigaddset(&set, SIGUSR1);
	sigaddset(&set, SIGALRM);
        s = pthread_sigmask(SIG_BLOCK, &set, NULL);
        if (s != 0)
        	handle_error_en(s, "pthread_sigmask");
	sig.set = &set;
        s = pthread_create(&thread, NULL, sig_handler<int>, (void *) &sig);
        if (s != 0)
                handle_error_en(s, "pthread_create");

	//create reader threads
	int rc = 0;
	for (vector<pthread_t>::iterator it = reader.begin(); 
			it != reader.end(); ++it) {
		cout << "list_read(): creating thread, " << endl;
                rc = pthread_create(&*it, NULL, list_read<int>, 
				(void *) &xlist);
                if (rc) {
                	cout<< "Error:unable to create read thread, " << endl;
			exit(-1);
		}
	}

	for (vector<pthread_t>::iterator it = writer.begin(); 
			it != writer.end(); ++it) {
        	cout << "list_write(): creating thread, " << endl;
		rc = pthread_create(&*it, NULL, list_write<int>,
			       	(void *) &list);
                if (rc) {
                	cout<< "Error:unable to create write thread, " << endl;
			exit(-1);
		}
	}

	for (vector<pthread_t>::iterator it = updater.begin();
		       	it != updater.end(); ++it) {
        	cout << "list_update(): creating thread, " << endl;
                rc = pthread_create(&*it, NULL, list_update<int>,
			       	(void *) &xlist);
		if(rc){
			cout<< "Error:unable to create read thread, " << endl;
			exit(-1);
		}
	}

	for (vector<pthread_t>::iterator it = remover.begin();
		       	it != remover.end(); ++it) {
        	cout << "list_remove(): creating thread, " << endl;
		rc = pthread_create(&*it, NULL, list_remove<int>, 
				(void *) &list);
                if (rc) {
                	cout<< "Error:unable to create read thread, " << endl;
			exit(-1);
		}
	}

	void *status;
	for (vector<pthread_t>::iterator it = reader.begin();
		       	it != reader.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join reader," << rc << endl;
			exit(-1);
		}
   	}

	for (vector<pthread_t>::iterator it = writer.begin();
			it != writer.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join writer," << rc << endl;
			exit(-1);
		}
   	}

	for (vector<pthread_t>::iterator it = updater.begin();
		       	it != updater.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join updater," << rc << endl;
			exit(-1);
		}
   	}

	for (vector<pthread_t>::iterator it = remover.begin();
		       	it != remover.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join remover," << rc << endl;
			exit(-1);
		}
   	}

   	cout << "Main: program exiting." << endl;
	pthread_exit(NULL);
	return 0;
}
Exemple #23
0
int main() {	
	srand((unsigned) time(NULL));

	try {
		XList<Shape*> list;
		// filling list of figures with random figures of all types.
		int numberOfElements = rand() % 100;
		for(int i = 0; i < numberOfElements; i++) {
			switch (i % 5) {
			case 0:
				list.pushElementToBack(new Point("TestPoint", rand() % 100, rand() % 100));
				break;
			case 1:
				list.pushElementToBack(new Circle("TestCircle", rand() % 100, rand() % 100, rand() % 100));
				break;
			case 2:
				list.pushElementToBack(new Rect("TestRect", rand() % 100, rand() % 100, rand() % 100, rand() % 100));
				break;
			case 3:
				list.pushElementToBack(new Square("TestSquare", rand() % 100, rand() % 100, rand() % 100));
				break;
			case 4:
				Polyline* pol = new Polyline("TestPol");				
				Point p1("pol_point_1", rand() % 100, rand() % 100);
				Point p2("pol_point_2", rand() % 100, rand() % 100);
				Point p3("pol_point_3", rand() % 100, rand() % 100);
				pol->addPoint(p1);
				pol->addPoint(p2);
				pol->addPoint(p3);
				list.pushElementToBack(pol);
				break;
			}
		}

		std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
		XList<Shape*>::Iterator it = list.begin();
		for(it = list.begin(); it != list.end(); ++it) {
			std::cout << "\n" << **it << "\n";
		}

		std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
		for(it = list.begin(); it != list.end(); ++it) {
			delete *it;
		}

		// should be zero
		std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";

		return 0;
	} catch (std::exception ex) {
		std::cerr << ex.what();
		return 1;
	}
}