/*!
 * When the program is closed this will save all 
 * the changes made in the parameters in the configurations.ini file
 */
Cparameter::~Cparameter(void)
{
	/* WORK SEQUENCE
	 * opens the ini file 
	 * Gets the current values if changed in the process by some other functions
	 * simply overwrites all the values when the destructor is called
	 */
	QSettings get(QDir::currentPath()+ "/" + "configurations.ini", QSettings::IniFormat);
	get.beginGroup("Parameters");
	QString name = getLogFileName();
	//qDebug() << name ;
	get.setValue("LogFileName", name);

	QString path = getLogFileDirectory();
	get.setValue("LogFileDirectory", path);

	QString ip = getIpAddress();
	get.setValue("IpAddress", ip);

	int port = getPort();
	get.setValue("Port", port);

	QString resolution = getResolution();
	get.setValue("Resolution", resolution);

	int frames = getFrames();
	get.setValue("Frames", frames);

	float HorizontalFcl = settings->value("HorizontalFocalLength").toFloat();

}
void logMsePerIteration(collaborativeFiltering &collabFilteringModel) {

	/* Get the feature length. */
	unsigned int latentSpace = collabFilteringModel.latentSpace;

	/* Get the maximum iterations. */
	unsigned int maxIterations = collabFilteringModel.maxIterations;

	/* Get the array for storing MSE per iteration. */
	double *msePerIteration = collabFilteringModel.msePerIteration;

	/* File object for logging data. */
	ofstream fout;

	/* Log file name. */
	string logFileName;

	/* Get the log file name. */
	logFileName = getLogFileName(LOG_MEAN_SQUARE_ERROR, latentSpace,
			maxIterations);

	/* Open the log file. */
	fout.open(logFileName.c_str());

	/* Write the data. */
	for (unsigned int i = 0; i < maxIterations; i++) {
		fout << setw(3) << (i + 1) << ", " << setw(10) << setprecision(5)
				<< msePerIteration[i] << ", " << endl;
	}

	/* Close log file. */
	fout.close();
}
Beispiel #3
0
void checkLogFile()
{
    static long prevLogTime = 0;
    long nowTime = 0;
    struct tm *tm;

    time(&nowTime);
    if (0 < prevLogTime)
    {
        if ((nowTime-prevLogTime) < changeLogDiffTime)
        {
            //时间未到
            return;
        }

        tm = localtime(&nowTime);
        if (tm->tm_hour == changeLogTime)//一天一个日志
        {
            string newLogFileName = getLogFileName();
            gOsLog<<"before close!"<<endl;
            gOsLog<<"new log file is "<<newLogFileName<<endl;

            prevLogTime = nowTime;
            gOsLog.close();
            gOsLog<<"after close!"<<endl;
            gOsLog.open(newLogFileName.c_str());
            gOsLog<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%after open!%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
            if (false == gOsLog.is_open()) 
            {
                cout<<"Unable to open "<<newLogFileName<<"for log!"<<endl;
            }
        }
    }//end of if ()
    else
    {
        string newLogFileName = getLogFileName();
        prevLogTime = nowTime;
        gOsLog.open(newLogFileName.c_str());
        if (false == gOsLog.is_open()) 
        {
            gOsLog<<"Unable to open "<<newLogFileName<<"for log!"<<endl;
        }
    }
    
    return;
}
Beispiel #4
0
void Logger::writeLog(const char *functionName, const char *fileName, int lineNumber, std::string message, ...) {
  va_list args;
  
  if (access(getLogFileName().c_str(), W_OK) == -1) {
    return;
  }
  
	FILE *log;
  log = fopen(getLogFileName().c_str(), "a");
  
  string logLinePrefix = logLine(functionName, fileName, lineNumber);
  fprintf(log, "%s ", logLinePrefix.c_str());
	va_start(args, message);
	vfprintf(log, message.c_str(), args);
	va_end(args);
	fprintf(log, "\n");
	fclose(log);
  
}
HINSTANCE initConfig(){
	HINSTANCE l_rc = 0;
	DWORD dw_rc;
	DWORD dwSize;

	HINSTANCE hSetupAPI = LoadLibrary(_T("SETUPAPI.DLL"));
	if (hSetupAPI == 0){
		return 0;//abort
	}
	lpfnLPSETUPDIOPENDEVREGKEY = reinterpret_cast<SETUPDIOPENDEVREGKEY*>(GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey"));
	lpfnSETUPDIGETCLASSDEVS = reinterpret_cast<SETUPDIGETCLASSDEVS*>(GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA"));
	lpfnSETUPDIDESTROYDEVICEINFOLIST = reinterpret_cast<SETUPDIDESTROYDEVICEINFOLIST*>(GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList"));
	lpfnSETUPDIENUMDEVICEINFO = reinterpret_cast<SETUPDIENUMDEVICEINFO*>(GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo"));
	lpfnSETUPDICLASSGUIDSFROMNAME = reinterpret_cast<SETUPDICLASSGUIDSFROMNAME*>(GetProcAddress(hSetupAPI, "SetupDiClassGuidsFromNameA"));
	lpfnSETUPDIGETDEVICEREGISTRYPROPERTY = reinterpret_cast<SETUPDIGETDEVICEREGISTRYPROPERTY*>(GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA"));
	if (lpfnLPSETUPDIOPENDEVREGKEY ==0 || 
		lpfnSETUPDIGETCLASSDEVS==0 ||
		lpfnSETUPDIDESTROYDEVICEINFOLIST==0||
		lpfnSETUPDIENUMDEVICEINFO==0||
		lpfnSETUPDICLASSGUIDSFROMNAME==0||
		lpfnSETUPDIGETDEVICEREGISTRYPROPERTY==0){
			hSetupAPI = 0;
	}
	libApiDLL = hSetupAPI;
	l_rc = (HINSTANCE)1;


	if (hSetupAPI){//last step was ok
		//get the directory of this executable
		dwSize = sizeof(modulePath)/sizeof(TCHAR);
		dw_rc = GetModuleFileNameW(0,modulePath,dwSize);
		if (dw_rc == (dwSize-1)){//buffer could be to small
			l_rc =0;//error
		}
		if (GetLastError()==ERROR_INSUFFICIENT_BUFFER){//buffer to small, log it
			l_rc =0;//error  
		}
		if (dw_rc ==0){//error log it
			l_rc =0;//error
		}
		if (l_rc ==0){//application dialog error
			MessageBox(NULL,_T("The application could not determine the location of the working directory of this executable"),_T("FATAL ERROR!"),MB_ICONHAND|MB_APPLMODAL);

		}
		getLogFileName();
		getConfigFileName();
		reOpenFiles();
		cacheConfigFile();
	}
	return l_rc;
}
Beispiel #6
0
bool Test::checkLogFileIfTestWasSuccessfulAfterExecution()
{
    QFile file(getLogFileName());
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    QString document;
    while (!file.atEnd())
    {
        QByteArray line = file.readLine();
        document+=QString(file.readLine());
    }
    if(document.contains("FAIL") || document.contains("failure"))
        return false;
    return true;
}
Beispiel #7
0
bool Test::execute()
{
    QString syscall=QString("%1 > %2").arg(getTestFileName())
                                      .arg(getLogFileName());

    qDebug(QString("Executing test with command: %1").arg(syscall).toStdString().c_str());
    qDebug(QString("TestType is set to %1. Starting test...").arg(testType2String(getTestType())).toStdString().c_str());

    setState(TRS_RUNNING);
    system( syscall.toStdString().c_str() );

    qDebug("...finished test execution.\n");

    bool success=checkLogFileIfTestWasSuccessfulAfterExecution();
    success ? setState(TRS_SUCCESS) : setState(TRS_FAILURE);

    return success;
}
Beispiel #8
0
	virtual void run() {
		ofstream logFile;
		logFile.open(getLogFileName());

		vector<Data*>::iterator it;

		bool isBreak = false;
		for (it = memory.begin(); it != memory.end(); it++) {
			Data* data = *it;
			if (!isBreak) {
				Instruction* instP = InstructionBuilder::build(
						data->getAddress(), data->getBitString());
				logFile << instP->toString() << endl;
				isBreak = instP->getOpCode() == BREAK;
			} else {
				logFile << (*it)->toString() << endl;
			}
		}

		logFile.close();
	}
Beispiel #9
0
#include <dlfcn.h>
#include <glob.h>
#include <unistd.h>
#include <thread>
#include <iostream>
#include <fstream>
#include <syscall.h>
#include <string>

#include "files.h"
#include "deltatimeexecutor.h"
#include "destructionexecutor.h"
#include "getlogfilename.h"

static const std::string logFileName = getLogFileName();

/**
 * @return The global ID of the current thread
 */
static pid_t getCurrentThreadId() { return syscall(SYS_gettid); }

/**
 * @brief Get the statistics and print them if necessary
 */
static Files &files() {
  static std::ofstream log(logFileName);
  static Files sinceLast;
  static Files total;
  // print the final statistics on exit
  static DestructionExecutor finalExecutor([&]() {
void runPmfBatchGradientDescentOMP(vector<users> &allUsers,
		vector<business> &allBusiness) {

	/* Switch off the dynamic thread setting. */
	omp_set_dynamic(0);

	/* Set the number of threads. */
	omp_set_num_threads(NO_OF_TRIALS);

	/* Output file object. */
	ofstream fout;

	/* Input file object. */
	ifstream fin;

#if !FORCE_INPUT
	editInputBatchTextForGradientDescent();
#endif

	/* Open input batch file mentioning different models. */
	fin.open(BATCH_INPUT_TEXT);

	/* Read number of models. */
	unsigned int n;
	fin >> n;

	/* Read the model parameters. */
	unsigned int *latentSpace = new unsigned int[n];
	unsigned int *maxIterations = new unsigned int[n];
	double *lambdaU = new double[n];
	double *lambdaV = new double[n];

	for (unsigned int i = 0; i < n; i++) {
		fin >> latentSpace[i];
		fin >> maxIterations[i];
		fin >> lambdaU[i];
		fin >> lambdaV[i];
	}

	fin.close();

	/* Log file name. */
	string logFileName;

	/* Get the log file name. */
	logFileName = getLogFileName(LOG_BATCH_RESULTS, 0, 0);

	/* Open the log file. */
	fout.open(logFileName.c_str());

	/* Now run each of these models and test them against the validation and
	 * test data sets. */
	for (unsigned int i = 0; i < n; i++) {

		/* Declare the model. */
		collaborativeFiltering collabFilteringModel[NO_OF_TRIALS];

		/* Initialize the root mean square errors to 0.*/
		double rmseTraining[NO_OF_TRIALS] = { 0.0 };
		double rmseValidation[NO_OF_TRIALS] = { 0.0 };
		double rmseTest[NO_OF_TRIALS] = { 0.0 };
		double rmsTrainError = 0.0;
		double rmsValidationError = 0.0;
		double rmsTestError = 0.0;

		/* Train the model for some fixed number of times and accumulate the
		 * error results and log its average values. */

		/* Launch as per given thread ID. */
		cout << "Running PMF Algorithm with K = " << latentSpace[i] << " for "
				<< maxIterations[i] << " iterations, lambda U = " << lambdaU[i]
				<< ", lambda V = " << lambdaV[i] << endl << endl;

		collaborativeFiltering collabFilteringTest;
		/* Initialize the model. */
		initCollabFilteringModel(collabFilteringTest, allUsers, allBusiness,
				latentSpace[0], maxIterations[0], lambdaU[0], lambdaV[0], true);

		vector<review> testReviews = collabFilteringTest.testReviews;
		vector<users> trainUsers = collabFilteringTest.trainUsers;
		vector<business> trainBusiness = collabFilteringTest.trainBusiness;

		deinitCollabFilteringModel(collabFilteringTest);

#pragma omp parallel
		{

			/* Get the thread ID. */
			unsigned int j = omp_get_thread_num();

			/* Initialize the model. */
			collabFilteringModel[j].testReviews = testReviews;
			initCollabFilteringModel(collabFilteringModel[j], trainUsers,
					trainBusiness, latentSpace[i], maxIterations[i], lambdaU[i],
					lambdaV[i], false);

			/* Train the model. */
			probablisticMatrixFactorizationGradientDescent(
					collabFilteringModel[j]);

#if LOG_FEATURES
			cout << "Logging the computed features." << endl;

			/* Save the estimated user and business data. */
			logUserBusinessFeatures(collabFilteringModel[j]);

			cout << "Validating the computed features." << endl;

			/* Validate the computed features with existing reviews on training
			 * data. */
			validateAndLogReviews(collabFilteringModel[j], TRAINING_DATA);

			/* Validate the computed features with existing reviews on
			 * validation data. */
			validateAndLogReviews(collabFilteringModel[j], VALIDATION_DATA);

			/* Validate the computed features with existing reviews on testing
			 * data. */
			validateAndLogReviews(collabFilteringModel[j], TESTING_DATA);
#endif

#if LOG_MSE
			cout << "Logging the mean square error after every iteration."
			<< endl;

			/* Log the mean square error. */
			logMsePerIteration(collabFilteringModel[j]);
#endif

			/* Compute the error on training data set. */
			rmseTraining[j] = computeMSE(collabFilteringModel[j],
					TRAINING_DATA);

			/* Compute the error on validation data set. */
			rmseValidation[j] = computeMSE(collabFilteringModel[j],
					VALIDATION_DATA);

			/* Compute the error on testing data set. */
			rmseTest[j] = computeMSE(collabFilteringModel[j], TESTING_DATA);

			/* De-initialize the model. */
			deinitCollabFilteringModel(collabFilteringModel[j]);
		}

		for (unsigned int j = 0; j < NO_OF_TRIALS; j++) {
			rmsTestError += rmseTest[j];
			rmsValidationError += rmseValidation[j];
			rmsTrainError += rmseTraining[j];
		}

		/* Log the findings along with the model specifications. */
		fout << "Model " << setw(7) << i + 1 << ", ";
		fout << setw(13) << setprecision(5) << latentSpace[i] << ", ";
		fout << setw(13) << setprecision(5) << maxIterations[i] << ", ";
		fout << setw(13) << setprecision(5) << lambdaU[i] << ", ";
		fout << setw(13) << setprecision(5) << lambdaV[i] << ", ";
		fout << setw(13) << setprecision(5) << rmsTrainError / NO_OF_TRIALS
				<< ", ";
		fout << setw(13) << setprecision(5) << rmsValidationError / NO_OF_TRIALS
				<< ", ";
		fout << setw(13) << setprecision(5) << rmsTestError / NO_OF_TRIALS
				<< ", ";
		fout << endl;
	}

	/* Close the log file.*/
	fout.close();

	/* Switch on the dynamic thread setting. */
	omp_set_dynamic(1);

	delete latentSpace;
	delete maxIterations;
	delete lambdaU;
	delete lambdaV;
}
void validateAndLogReviews(collaborativeFiltering &collabFilteringModel,
		testDataType testingDataType) {

	/* Use a local pointer to access the all users. */
	vector<users> *allUsers = collabFilteringModel.allUsers;

	/* Use a local pointer to access the all businesses. */
	vector<business> *allBusiness = collabFilteringModel.allBusiness;

	/* Get a local pointer to the review vector. */
	vector<review> *reviewVec;

	/* Get the log type from testing data type. */
	logTypes logType;

	/* Check for which data set log request has been made. */
	if (testingDataType == TRAINING_DATA) {
		reviewVec = &(collabFilteringModel.trainingReviews);
		logType = LOG_TRAINING_DATA;
	} else if (testingDataType == VALIDATION_DATA) {
		reviewVec = &(collabFilteringModel.validationReviews);
		logType = LOG_VALIDATION_DATA;
	} else if (testingDataType == TESTING_DATA) {
		reviewVec = &(collabFilteringModel.testReviews);
		logType = LOG_TEST_DATA;
	} else {

		/* Else return if invalid request. */
		return;
	}

	/* Get the user feature space. */
	double **u = collabFilteringModel.u;

	/* Get the business feature space. */
	double **v = collabFilteringModel.v;

	/* Get the feature length. */
	unsigned int latentSpace = collabFilteringModel.latentSpace;

	/* Get the maximum iterations. */
	unsigned int maxIterations = collabFilteringModel.maxIterations;

	/* Get the total number of reviews. */
	unsigned int totalReviews = (*reviewVec).size();

	/* File object for logging data. */
	ofstream fout;

	/* Log file name. */
	string logFileName;

	/* Get the log file name. */
	logFileName = getLogFileName(logType, latentSpace, maxIterations);

	/* Open the log file. */
	fout.open(logFileName.c_str());

	/* Iterate over all the reviews. */
	for (unsigned int i = 0; i < totalReviews; i++) {

		/* Get the business ID. */
		unsigned int businessID = (*reviewVec)[i].bussinessId;

		/* Get the user ID. */
		unsigned int userID = (*reviewVec)[i].userId;

		/* Initialize the computed rating to 0.0. */
		double computedRating = 0.0;

		/* Get the actual rating. */
		double actualRating = (*reviewVec)[i].stars;

		/* Now accumulate the rating. */
		for (unsigned int k = 0; k < latentSpace; k++) {
			computedRating += u[userID][k] * v[businessID][k];
		}

		if (computedRating > 5) {
			computedRating = 5.0;
		} else if (computedRating < 1) {
			computedRating = 1.0;
		}

		/* Now write all the pertinent data into file. */
		fout << setw(6) << userID << ", ";
		fout << (*allUsers)[userID].genericID << ", ";
		fout << setw(6) << businessID << ", ";
		fout << (*allBusiness)[businessID].genericID << ", ";
		fout << setw(5) << setprecision(5) << actualRating << ", ";
		fout << setw(10) << setprecision(5) << computedRating << ", ";
		fout << setw(13) << setprecision(5) << (actualRating - computedRating)
				<< ", " << endl;
	}

	/* Close the file. */
	fout.close();
}
void logUserBusinessFeatures(collaborativeFiltering &collabFilteringModel) {

	/* Get the user feature space. */
	double **u = collabFilteringModel.u;

	/* Get the business feature space. */
	double **v = collabFilteringModel.v;

	/* Get the feature length. */
	unsigned int latentSpace = collabFilteringModel.latentSpace;

	/* Get the maximum iterations. */
	unsigned int maxIterations = collabFilteringModel.maxIterations;

	/* Get the total number of businesses. */
	unsigned int totalBusiness = collabFilteringModel.trainBusiness.size();

	/* Get the total number of users. */
	unsigned int totalUsers = collabFilteringModel.trainUsers.size();

	/* File object for logging data. */
	ofstream fout;

	/* Log file name. */
	string logFileName;

	/* Get the log file name. */
	logFileName = getLogFileName(LOG_USER_FEATURES, latentSpace, maxIterations);

	/* Open the log file. */
	fout.open(logFileName.c_str());

	/* Log the user feature space data. */
	for (unsigned int i = 0; i < totalUsers; i++) {
		fout << "u " << setw(6) << i << ", ";
		for (unsigned int j = 0; j < latentSpace; j++) {
			fout << setw(13) << setprecision(5) << u[i][j] << ", ";
		}

		fout << endl;
	}

	/* Close the log file. */
	fout.close();

	/* Get the log file name. */
	logFileName = getLogFileName(LOG_BUSINESS_FEATURES, latentSpace,
			maxIterations);

	/* Open the log file. */
	fout.open(logFileName.c_str());

	/* Log the business feature space data. */
	for (unsigned int i = 0; i < totalBusiness; i++) {
		fout << "v " << setw(6) << i << ", ";
		for (unsigned int j = 0; j < latentSpace; j++) {
			fout << setw(13) << setprecision(5) << v[i][j] << ", ";
		}

		fout << endl;
	}

	/* Close the log file. */
	fout.close();
}