Пример #1
0
void processFile(Command command){
		
	InputCommand inputCommand = command.inputCommand;
	OutputCommand outputCommand = command.outputCommand;
		
	SNPArffParser parser;
	cout << inputCommand.filePath;
	
	//read data
	StructArff* arff=parser.ParseSNPArffFile(inputCommand.filePath);	
		
	//incrase data size by multiplying features or samples
	int multiplyFeatures = inputCommand.multiplyFeatures;
	int multiplySamples = inputCommand.multiplySamples;
	
	if(multiplyFeatures >= 1 || multiplySamples >= 1){
		int newFeatureCount = arff->FeatureCount * multiplyFeatures;
		int newSampleCount = arff->SampleCount * multiplySamples;
		int oldFeatureCount = arff->FeatureCount;
		int oldSampleCount = arff->SampleCount;
		
		char* newMatrix = new char[newFeatureCount * newSampleCount];
		char* newLabels = new char[newSampleCount];
		char** newSNPNames = new char*[newFeatureCount];
		
		for(int mf=0; mf<multiplyFeatures; mf++){
			for(int f=0; f<oldFeatureCount; f++){	
				int newf = mf*oldFeatureCount + f;
				for(int ms=0; ms<multiplySamples; ms++){
					for(int s=0; s<oldSampleCount; s++){
						int newi = (ms*oldSampleCount + s) * newFeatureCount + newf;
						int oldi = s*oldFeatureCount + f;
						newMatrix[newi] = arff->Matrix[oldi];
					}
				}
				
				newSNPNames[newf]=arff->SNPNames[f];
			}			
		}		
				
		for(int ms=0; ms<multiplySamples; ms++){
			for(int s=0; s<oldSampleCount; s++){
				newLabels[ms*oldSampleCount+s] = arff->Labels[s];
			}
		}
				
		arff->SampleCount = newSampleCount;
		arff->FeatureCount = newFeatureCount;
		arff->Matrix = newMatrix;
		arff->Labels = newLabels;
		arff->SNPNames = newSNPNames;		
	}
	
	/*
	for(int i=0;i<arff->FeatureCount;i++){
		cout<<i<<":";
		for(int j=800;j<arff->SampleCount;j++){
			cout<<0+arff->Matrix[i*arff->SampleCount+j];
		}
		cout<<endl;
	}

	for(int j=0;j<arff->SampleCount;j++){		
		if(arff->Labels[j]){
			cout<<1;
		}else{
			cout<<0;
		}
	}
	cout<<endl;
	*/
	
	//decrease data size by masking unwanted features
	int features = inputCommand.features;
	if(features==0){
		features = arff->FeatureCount;
	}
	cout<<"features="<<features<<endl;
	bool featureMask[arff->FeatureCount];
	for(int i=0;i<arff->FeatureCount;i++){
		if(i<features){
			featureMask[i]=true;
		}else{
			featureMask[i]=false;
		}
	}	
	
	int testNum = inputCommand.numOfTest;
	if(testNum >0){
		
		ofstream output;
		if (!outputCommand.stdout){
			output.open(outputCommand.outputFile.c_str());
			output<<"means_ms=[];\n";		
		}
		
		long processingTime[testNum];
		
		Processor* myProcessor = getProcessor(command.processorCommand);
		
		if(command.processorCommand.gpuAcceleration){
			//warm up GPU before performance test
			myProcessor->calculate(arff->SampleCount, arff->FeatureCount, arff->Matrix, featureMask, arff->Labels);
		}
			
		for(int i=0;i<testNum;i++){
			Result* r = myProcessor->calculate(arff->SampleCount, arff->FeatureCount, arff->Matrix, featureMask, arff->Labels);			
			processingTime[i] = r->endTime - r->startTime;
		}
		exportPerformance(processingTime, testNum, "test", output, outputCommand);
		
		if (!outputCommand.stdout){
			output.close();
		}
		
	} else {
		Processor* myProcessor = getProcessor(command.processorCommand);
		Result* result = myProcessor->calculate(arff->SampleCount, arff->FeatureCount, arff->Matrix, featureMask, arff->Labels);		
		//cout<<result->success<<endl;
		if (!result->success){
			cout<<result->errorMessage<<endl;
			return;
		}
		exportResult(arff, result, command);
	}
}
Пример #2
0
void folderloop(char* folderbase)
{
	char* filepath = new char[100];

	char folder[5];
	char tempfolder[5];
	memset(folder, 0, 5);
	strcat(folder, "/h01");
	folder[4] = 0;

	char file[21];
	char tempfile[21];
	memset(file, 0, 21);
	strcat(file, "/01_EDM-1_01txt.arff");
	file[20] = 0;

	FILE* writefile = fopen("D:\\snp.txt", "w+");

	for (int folderindex = 3; folderindex < 4; folderindex++)
	{
		strcpy(tempfolder, folder);
		tempfolder[3] += folderindex;

		for (int fileindex = 0; fileindex < 1; fileindex++)
		{
			strcpy(tempfile, file);
			tempfile[2] += folderindex;
			tempfile[8] += fileindex / 50;
			tempfile[10] += fileindex % 50 / 10;
			if (fileindex % 50 % 10<9)
			{
				tempfile[11] += fileindex % 50 % 10;
			}
			else
			{
				tempfile[10] += 1;
				tempfile[11] = '0';
			}
			
			memset(filepath, 0, 100);
			strcat(filepath, folderbase);
			strcat(filepath, tempfolder);
			strcat(filepath, tempfile);

			SNPArffParser s;
			StructArff* a=s.ParseSNPArffFile(filepath);
			//s.DisplayArffData(a);
			//s.DisplayArffLabels(a);
			//cout << a->SNPNames[1927] << endl;
			//cout << a->SNPNames[961] << endl;;
			//for (int i = 0; i < a->SampleCount; i++)
			//	cout << static_cast<int>(a->Labels[i]);
			////
			//
			// you can add your code here
			////
			int t = 0;
			cout << a->FeatureCount << " " << a->SampleCount;
			float* b = (float*)malloc(sizeof(float)*(a->FeatureCount));
			b=irelief(a->Matrix,a->Labels,t,a->SampleCount,a->FeatureCount);
			printfloat(b);
			cout << t << endl;
			vector<int> i;
			find_no_zero(b, i);
			cout << i.size();
			for (auto it = i.begin(); it != i.end(); it++)
			{
				cout << *it << " " << a->SNPNames[*it]<<endl;
				fprintf(writefile, "%f %s \n", b[*it], a->SNPNames[*it]);
			}
			//for (int i = 0; i < 1000; i++)
			//{
				//cout << b[i] << " ";
			//}
			//cout << rank_x(998, b)<<" " <<rank_x(999,b);
//			fprintf(writefile, "%d %d \n", rank_x(998, b), rank_x(999, b));
		}	
	}

	fclose(writefile);
}