Ejemplo n.º 1
0
void PhoenixGlobals::setOfflineStoragePath( const QString &path ) {
    m_offline_storage_path = path;

    setBiosPath( path + "Bios/" );
    setArtworkPath( path + "Artwork/" );
    setSavePath( path + "Saves/" );
    setConfigPath( path + "Config/" );
}
Ejemplo n.º 2
0
void RobotWidget::setRobot(RobotConfig *rbt)
{
	setConfigPath(rbt->configFilePath.toStdString());
	setRobotName(rbt->robotName.toStdString());
	setSystem(rbt->system.toStdString());
	setDriveSystem(rbt->driveSystem.toStdString());
	setRobotPicture(rbt->image);
    setRobotNamespace(rbt->nameSpace.toStdString());
}
Ejemplo n.º 3
0
Settingsdialog::Settingsdialog(QWidget *parent, bool isCanvasVisible) :
    QDialog(parent),
    ui(new Ui::Settingsdialog)
{
    ui->setupUi(this);

    mSettingsFile = QApplication::applicationDirPath() + "editorSettings";
    mSettings = new QSettings(mSettingsFile, QSettings::NativeFormat);

    ui->resoursesPath->setText(mSettings->value("Editor/resourcesPath").toString());
    ui->configPath->setText(mSettings->value("Editor/configurationPath").toString());
    ui->pluginsPath->setText(mSettings->value("Editor/pluginsPath").toString());
    ui->ogreLogPath->setText(mSettings->value("Editor/ogreLogPath").toString());
    ui->morphLogPath->setText(mSettings->value("Editor/morphLogPath").toString());

    connect(ui->browseBtn, SIGNAL(clicked()), this, SLOT(browseDialog()));
    connect(ui->confBtn, SIGNAL(clicked()), this, SLOT(confDialog()));
    connect(ui->pluginsBtn, SIGNAL(clicked()), this, SLOT(pluginsDialog()));
    connect(ui->ogreBtn, SIGNAL(clicked()), this, SLOT(ogreLogDialog()));
    connect(ui->morphBtn, SIGNAL(clicked()), this, SLOT(morphLogDialog()));

    connect(ui->resoursesPath, SIGNAL(textChanged(QString)), this, SLOT(setResourcesPath(QString)));
    connect(ui->configPath, SIGNAL(textChanged(QString)), this, SLOT(setConfigPath(QString)));
    connect(ui->pluginsPath, SIGNAL(textChanged(QString)), this, SLOT(setPluginsPath(QString)));
    connect(ui->ogreLogPath, SIGNAL(textChanged(QString)), this, SLOT(setOgreLogPath(QString)));
    connect(ui->morphLogPath, SIGNAL(textChanged(QString)), this, SLOT(setMorphLogPath(QString)));
    connect(ui->buttonsBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(clicked()));

    if(isCanvasVisible)
    {
        ui->renderLayer->addItem("Back");
        ui->renderLayer->addItem("Front");

        mSize = mSettings->value("Grid/gridPrespectiveSize").toInt();
        ui->mPerspSize->setValue(mSize);

        mDivisions = mSettings->value("Grid/gridDivisions").toInt();
        ui->mGridSpacingMenu->setValue(mDivisions);

        mIndex = mSettings->value("Grid/gridRenderLayer").toInt();
        ui->renderLayer->setCurrentIndex(mIndex);

        mValue = mSettings->value("Grid/gridRenderScale").toBool();
        ui->renderScale->setChecked(mValue);

        mColor = mSettings->value("Grid/gridColor").toString();

        connect(ui->modify, SIGNAL(clicked()), this, SLOT(gridColorChanged()));
        connect(ui->mGridSpacingMenu, SIGNAL(valueChanged(int)), this, SLOT(gridDivisionsChanged(int)));
        connect(ui->mPerspSize, SIGNAL(valueChanged(int)), this, SLOT(gridPrespectiveSizeChanged(int)));
        connect(ui->renderLayer, SIGNAL(currentIndexChanged(int)), this, SLOT(gridRenderLayerChanged(int)));
        connect(ui->renderScale, SIGNAL(clicked(bool)), this, SLOT(gridRenderScaleChanged(bool)));
    }
    else
    {
LATENT_VAR infer_latent_variables(PATTERN x, LABEL y, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm) {
/*
  Complete the latent variable h for labeled examples, i.e.,
  computing argmax_{h} <w,psi(x,y,h)>. 
*/

  LATENT_VAR h;

  // 1. Write input to a file
  char *filename = "tmpfiles/inf_lat_var";
  // Online SVM: Note --- no longer using this code hence replace w by w_iters[0][0]
  write_to_file(x, y, sm->w_iters[0][0], sparm->max_feature_key, sparm->total_number_rels, filename);

  // 2. CALL the method InferLatentVarHelper FROM JAVA
  char *cmd = malloc(1000);
  	if(LD_LIBRARY_PATH == NULL)		setConfigPath();

  	strcpy(cmd, "export ");
  	strcat(cmd, LD_LIBRARY_PATH);
  	strcat(cmd, " && java -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelper tmpfiles/inf_lat_var");
  	system(cmd);
  //printf("export LD_LIBRARY_PATH=/usr/lib/lp_solve && java -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelper tmpfiles/inf_lat_var \n");
//  system("export LD_LIBRARY_PATH=/usr/lib/lp_solve && java -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelper tmpfiles/inf_lat_var");

  // 3. READ the LATENT VAR h from the file tmpfiles/inf_lat_var.latentvar
  FILE *fp = fopen("tmpfiles/inf_lat_var.latentvar","r");
  if (fp==NULL) {
	  printf("Cannot open output file %s!\n", "tmpfiles/inf_lat_var");
	  exit(1);
  }
  int num_mentions;
  fscanf(fp,"%d\n",&num_mentions);

  if(num_mentions != x.num_mentions){
	  printf("Something is wrong .. exiting ...");
	  exit(1);
  }

  h.num_mentions = num_mentions;
  h.mention_labels = (int*)malloc(sizeof(int)*num_mentions);
  int i;
  for(i = 0; i < num_mentions; i ++){
	  int label;
	  fscanf(fp, "%d\n", &label);
	  h.mention_labels[i] = label;
  }

  // CLEANUP
  fclose(fp);
  // Delete tmp files created.

  return(h); 
}
void infer_latent_variables_all(LATENT_VAR *imputed_h, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm,
		int numEgs, char* tmpdir, char *trainfile, int datasetStartIdx, int chunkSz, int eid, int chunkid){

	// 1. Write input to a file
	//char *filename = "tmpfiles/inf_lat_var_all";
	char *filename = (char*) malloc(100);
	strcpy(filename, tmpdir);
	strcat(filename,"inf_lat_var_all");

	printf("(onlinesvm) Before writing params to file "); fflush(stdout);
	write_to_file_params_t(sm->w_iters[eid][chunkid], sparm->max_feature_key, sparm->total_number_rels, filename);
	printf("(onlinesvm) After writing params to file "); fflush(stdout);

	// 2. Call the InferLatentVarHelperAll method from JAVA
	// TODO: Modifiy the cmds appropriately
//	char * cmd = " export LD_LIBRARY_PATH=/usr/lib/lp_solve && "
//			" java -Xmx8G -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelperAll "
//			" tmpfiles/inf_lat_var_all dataset/reidel_trainSVM.data ";
	char *cmd = malloc(1000);
	// LOCAL COPY
//	strcpy(cmd,"export LD_LIBRARY_PATH=/usr/lib/lp_solve && "
//			"java -Xmx8G -cp java/bin:java/lib/*  "
//			"-Djava.library.path='/home/ajay/Research/software/lp_solve/:/home/ajay/Research/software/mosek.5/5/tools/platform/linux64x86/bin/:/home/ajay/Research/software/x86-64_sles10_4.1/' "
//			"javaHelpers.InferLatentVarHelperAll ");

	// ON MONASH ....
//	strcpy(cmd,"export LD_LIBRARY_PATH=~/lsvm_code/libs/lp_solve/:~/lsvm_code/libs/mosek.5/5/tools/platform/linux64x86/bin/ "
//			"&& java -Xmx8G -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelperAll ");
//	strcpy(cmd,"export LD_LIBRARY_PATH=/usr/lib/lp_solve/:/home/sandip/mosek/5/tools/platform/linux64x86/bin/ "
//				"&& java -Xmx8G -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelperAll ");

	if(LD_LIBRARY_PATH == NULL)		setConfigPath();

	strcpy(cmd, "export ");
	strcat(cmd, LD_LIBRARY_PATH);
	strcat(cmd, " && java -Xmx8G -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelperAll ");
	strcat(cmd,filename);
	//strcat(command," dataset/reidel_trainSVM.data");
	strcat(cmd, " ");
	strcat(cmd, trainfile);
	strcat(cmd, " ");
	char datasetStartIdx_str[10]; sprintf(datasetStartIdx_str, "%ld", datasetStartIdx);
	strcat(cmd, datasetStartIdx_str);
	strcat(cmd, " ");
	char chunkSz_str[10]; sprintf(chunkSz_str, "%ld", chunkSz);
	strcat(cmd, chunkSz_str);
	strcat(cmd, " ");

		//printf("Running : %s\n", command);
	printf("Executing cmd (online SVM): %s\n", cmd);fflush(stdout);
	system(cmd);

	// 3. Read the values of ybar_all and hbar_all from the file tmpfiles/max_violator_all.result
//	char *filename_res = "tmpfiles/inf_lat_var_all.result";
	char *filename_res = (char*) malloc(100);
	strcpy(filename_res, tmpdir);
	strcat(filename_res, "inf_lat_var_all.result");

	FILE *fp = fopen(filename_res,"r");
	if (fp==NULL) {
		printf("Cannot open output file %s!\n", filename_res);
		exit(1);
	}
	int j;
	for(j = 0; j < numEgs; j ++){
		int num_mentions;
		fscanf(fp,"%d\n",&num_mentions);

		imputed_h[j].num_mentions = num_mentions;
		imputed_h[j].mention_labels = (int*)malloc(sizeof(int)*num_mentions);
		int i;
		for(i = 0; i < num_mentions; i ++){
			int label;
			fscanf(fp, "%d\n", &label);
			imputed_h[j].mention_labels[i] = label;
		}
	}

	free(cmd);
	free(filename);
	free(filename_res);
	fclose(fp);

}
void find_most_violated_constraint_marginrescaling(PATTERN x, LABEL y, LABEL *ybar, LATENT_VAR *hbar, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm) {
/*
  Finds the most violated constraint (loss-augmented inference), i.e.,
  computing argmax_{(ybar,hbar)} [<w,psi(x,ybar,hbar)> + loss(y,ybar,hbar)].
  The output (ybar,hbar) are stored at location pointed by 
  pointers *ybar and *hbar. 
*/

	// 1. Write input to a file
	char *filename = "tmpfiles/max_violator";
	// Online SVM: Note --- no longer using this code hence replace w by w_iters[0][0]
	write_to_file(x, y, sm->w_iters[0][0], sparm->max_feature_key, sparm->total_number_rels, filename);

	// 2. Call the FindMaxViolatorHelper method from JAVA
	char *cmd = malloc(1000);
	if(LD_LIBRARY_PATH == NULL)		setConfigPath();

	strcpy(cmd, "export ");
	strcat(cmd, LD_LIBRARY_PATH);
	strcat(cmd, " && java -Xmx1G -cp java/bin:java/lib/* javaHelpers.FindMaxViolatorHelper tmpfiles/max_violator");
	system(cmd);
//	system("export LD_LIBRARY_PATH=/usr/lib/lp_solve && java -Xmx1G -cp java/bin:java/lib/* javaHelpers.FindMaxViolatorHelper tmpfiles/max_violator");

	// 3. Read the values of ybar and hbar from the file tmpfiles/max_violator.result
	char *filename_res = "tmpfiles/max_violator.result";
	FILE *fp = fopen(filename_res,"r");
	if (fp==NULL) {
		printf("Cannot open output file %s!\n", filename);
		exit(1);
	}

	int num_ylabels;
	fscanf(fp,"%d\n",&num_ylabels);
	ybar->num_relations = num_ylabels;

	int i;
	ybar->relations = (int*)malloc(sizeof(int)*num_ylabels);
	for(i = 0; i < num_ylabels; i ++){
		int ylabel;
		fscanf(fp, "%d\n",&ylabel);
		ybar->relations[i] = ylabel;
	}

	int num_hlabels;
	fscanf(fp, "%d\n", &num_hlabels);
	hbar->num_mentions = num_hlabels;

	if(num_hlabels != x.num_mentions){
		printf("Something is wrong .. no. of h labels  %d not matching no. of mentions %d ... exiting \n",num_hlabels, x.num_mentions);
		exit(1);
	}

	hbar->mention_labels = (int*)malloc(sizeof(int)*num_hlabels);
	for(i = 0; i < num_hlabels; i ++){
		int hlabel;
		fscanf(fp, "%d\n", &hlabel);
		hbar->mention_labels[i] = hlabel;
	}

	fclose(fp);

}
void find_most_violated_constraint_marginrescaling_all(LABEL *ybar_all, LATENT_VAR *hbar_all, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm, int numEgs, char *tmpdir, char *trainfile, double frac_sim, char *dataset_stats_file, double rho_admm, long isExhaustive, long isLPrelaxation, double Fweight, int datasetStartIdx, int chunkSz){

	// 1. Write input to a file
	char *filename = (char*) malloc(100);
	strcpy(filename, tmpdir);
	strcat(filename, "max_violator_all");

	// Online SVM: Note --- no longer using this code hence replace w by w_iters[0][0]
	write_to_file_params_t(sm->w_iters[0][0], sparm->max_feature_key, sparm->total_number_rels, filename);

	// 2. Call the FindMaxViolatorHelperAll method from JAVA
//	char * cmd = "export LD_LIBRARY_PATH=/usr/lib/lp_solve && "
//			" java -Xmx8G -cp java/bin:java/lib/* "
//			" -Djava.library.path=/opt/ibm/ILOG/CPLEX_Studio124/cplex/bin/x86-64_sles10_4.1/:/usr/lib/lp_solve "
//			" javaHelpers.FindMaxViolatorHelperAll "
//			" tmpfiles/max_violator_all dataset/reidel_trainSVM.data 0.9 ";


	char *cmd = malloc(1000);

	if(LD_LIBRARY_PATH == NULL)		setConfigPath();

	strcpy(cmd, "export ");
	strcat(cmd, LD_LIBRARY_PATH);
	strcat(cmd, "  && java -Xmx1G -cp java/bin:java/lib/* ");
	strcat(cmd, JAVA_LIBRARY_PATH);
	strcat(cmd, " javaHelpers.FindMaxViolatorHelperAll ");

//	strcpy(cmd,"export LD_LIBRARY_PATH=/usr/lib/lp_solve && "
//			" java -Xmx1G -cp java/bin:java/lib/* "
////			" -Djava.library.path='/home/ajay/Research/software/lp_solve/:/home/ajay/Research/software/mosek.5/5/tools/platform/linux64x86/bin/:/home/ajay/Research/software/x86-64_sles10_4.1/' "
//			" -Djava.library.path=/home/sandip/DownloadDirector/cplex_installation/cplex/bin/x86-64_sles10_4.1/:/usr/lib/lp_solve:/home/sandip/mosek/5/tools/platform/linux64x86/bin/ "
//			" javaHelpers.FindMaxViolatorHelperAll ");
	strcat(cmd,filename);
	strcat(cmd, " ");
	strcat(cmd, trainfile);
	strcat(cmd, " ");
	char double_str[5]; sprintf(double_str,"%g", frac_sim);
	strcat(cmd, double_str);
	strcat(cmd, " ");
	strcat(cmd, dataset_stats_file);
	strcat(cmd, " ");
	char rho_str[5]; sprintf(rho_str,"%g", rho_admm);
	strcat(cmd, rho_str);
	strcat(cmd, " ");
	char isExhaustive_str[5]; sprintf(isExhaustive_str,"%ld", isExhaustive);
	strcat(cmd, isExhaustive_str);
	strcat(cmd, " ");
	char isLPrelaxation_str[5]; sprintf(isLPrelaxation_str,"%ld", isLPrelaxation);
	strcat(cmd, isLPrelaxation_str);
	strcat(cmd, " ");
	char Fweight_str[10]; sprintf(Fweight_str, "%g", Fweight);
	strcat(cmd, Fweight_str);
	strcat(cmd, " ");
	char datasetStartIdx_str[10]; sprintf(datasetStartIdx_str, "%ld", datasetStartIdx);
	strcat(cmd, datasetStartIdx_str);
	strcat(cmd, " ");
	char chunkSz_str[10]; sprintf(chunkSz_str, "%ld", chunkSz);
	strcat(cmd, chunkSz_str);
	strcat(cmd, " ");

	printf("Executing cmd : %s\n", cmd);fflush(stdout);
	system(cmd);


	// 3. Read the values of ybar_all and hbar_all from the file tmpfiles/max_violator_all.result
//	char *filename_res = "tmpfiles/max_violator_all.result";
	char *filename_res = (char*) malloc(100);
	strcpy(filename_res, tmpdir);
	strcat(filename_res, "max_violator_all.result");

	FILE *fp = fopen(filename_res,"r");
	if (fp==NULL) {
		printf("Cannot open output file %s!\n", filename_res);
		exit(1);
	}
	int j;
	for(j = 0; j < numEgs; j ++){

		int num_ylabels;
		fscanf(fp,"%d\n",&num_ylabels);
		ybar_all[j].num_relations = num_ylabels;

		int i;
		ybar_all[j].relations = (int*)malloc(sizeof(int)*num_ylabels);
		for(i = 0; i < num_ylabels; i ++){
			int ylabel;
			fscanf(fp, "%d\n",&ylabel);
			ybar_all[j].relations[i] = ylabel;
		}

		int num_hlabels;
		fscanf(fp, "%d\n", &num_hlabels);
		hbar_all[j].num_mentions = num_hlabels;

		hbar_all[j].mention_labels = (int*)malloc(sizeof(int)*num_hlabels);
		for(i = 0; i < num_hlabels; i ++){
			int hlabel;
			fscanf(fp, "%d\n", &hlabel);
			hbar_all[j].mention_labels[i] = hlabel;
		}
	}

	free(filename);
	free(filename_res);
	free(cmd);
	fclose(fp);
}
void classify_struct_example(PATTERN x, LABEL *y, LATENT_VAR *h, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm) {
/*
  Makes prediction with input pattern x with weight vector in sm->w,
  i.e., computing argmax_{(y,h)} <w,psi(x,y,h)>. 
  Output pair (y,h) are stored at location pointed to by 
  pointers *y and *h. 
*/

		// 1. Write input to a file
		char *filename = "tmpfiles/classify_ex";
		// Online SVM: Note --- no longer using this code hence replace w by w_iters[0][0]
		write_to_file(x, y, sm->w_iters[0][0], sparm->max_feature_key, sparm->total_number_rels, filename);

		// 2. Call the ClassifyStructEgHelper method from JAVA
		char *cmd = malloc(1000);
		if(LD_LIBRARY_PATH == NULL)		setConfigPath();

		strcpy(cmd, "export ");
		strcat(cmd, LD_LIBRARY_PATH);
		strcat(cmd, " && java -cp java/bin:java/lib/* javaHelpers.ClassifyStructEgHelper tmpfiles/classify_ex");
		system(cmd);
//		system("export LD_LIBRARY_PATH=/usr/lib/lp_solve && java -cp java/bin:java/lib/* javaHelpers.ClassifyStructEgHelper tmpfiles/classify_ex");

		// 3. Read the values of *y and *h from the file tmpfiles/max_violator.result
		char *filename_res = "tmpfiles/classify_ex.result";
		FILE *fp = fopen(filename_res,"r");
		if (fp==NULL) {
			printf("Cannot open output file %s!\n", filename);
			exit(1);
		}

		int num_ylabels;
		fscanf(fp,"%d\n",&num_ylabels);
		y->num_relations = num_ylabels;

		int i;
		y->relations = (int*)malloc(sizeof(int)*num_ylabels);
		for(i = 0; i < num_ylabels; i ++){
			int ylabel;
			fscanf(fp, "%d\n",&ylabel);
			y->relations[i] = ylabel;
		}

		int num_hlabels;
		fscanf(fp, "%d\n", &num_hlabels);
		h->num_mentions = num_hlabels;

		if(num_hlabels != x.num_mentions){
			printf("Something is wrong .. no. of h labels  %d not matching no. of mentions %d ... exiting \n",num_hlabels, x.num_mentions);
			exit(1);
		}

		h->mention_labels = (int*)malloc(sizeof(int)*num_hlabels);
		for(i = 0; i < num_hlabels; i ++){
			int hlabel;
			fscanf(fp, "%d\n", &hlabel);
			h->mention_labels[i] = hlabel;
		}

		// cleanup
		fclose(fp);
}