bool StructuredLearnerRpc::ClassifyExample(const Json::Value& root, Json::Value& response) {
  if(learner) {
    int sess_ind = FindOrCreateSession(root, response);
    if(sess_ind < 0) 
      return false;
    
    if(root.isMember("partial_label")) {
      if(!sessions[sess_ind].partial_label)
        sessions[sess_ind].partial_label = learner->NewStructuredLabel(sessions[sess_ind].example->x);
      if(!sessions[sess_ind].partial_label->load(root["partial_label"], learner)) {
	JSON_ERROR("Invalid 'partial_label' parameter", sess_ind); 
      }
    }

    SparseVector *w = learner->GetCurrentWeights();
    double score = learner->Inference(sessions[sess_ind].example->x, sessions[sess_ind].example->y, w, 
                               sessions[sess_ind].partial_label);
    
    if(!isnan(score)) response["score"] = score;
    response["y"] = sessions[sess_ind].example->y->save(learner);
    if(root.isMember("visualization")) {
      char fname[1000]; strcpy(fname, root["visualization"].asString().c_str());
      learner->VisualizeExample(fname, sessions[sess_ind].example, NULL);
    }
    delete w;

    UnlockSession(sess_ind);

    return true;
  } else
    return false;
}
Beispiel #2
0
Datei: xsm.c Projekt: aosm/X11
void
EndSession(int status)
{
    if (verbose)
	printf ("\nSESSION MANAGER GOING AWAY!\n");

    FreeAuthenticationData (numTransports, authDataEntries);

    if (session_name)
    {
	UnlockSession (session_name);
	XtFree (session_name);
    }

    if (display_env)
	XtFree (display_env);
    if (session_env)
	XtFree (session_env);
    if (cmd_line_display)
	XtFree (cmd_line_display);
    if (non_local_display_env)
	XtFree (non_local_display_env);
    if (non_local_session_env)
	XtFree (non_local_session_env);
    if (audio_env)
	XtFree (audio_env);
    if (networkIds)
	free (networkIds);

    exit (status);
}
Beispiel #3
0
Datei: lock.c Projekt: aosm/X11
Bool
CheckSessionLocked(char *session_name, Bool get_id, char **id_ret)
{
    if (get_id)
	*id_ret = GetLockId (session_name);

    if (!LockSession (session_name, False))
	return (1);

    UnlockSession (session_name);
    return (0);
}
bool StructuredLearnerRpc::AddNewExample(const Json::Value& root, Json::Value& response) {
  if(learner) {
    char sess_id[1000];
    int sess_ind;
    if(strlen(root.get("session_id", "").asString().c_str()) < 1000)
      strcpy(sess_id, root.get("session_id", "").asString().c_str());
    else
      strcpy(sess_id, "");

    StructuredExample *ex = NULL;
    sess_ind = FindSession(sess_id, true);
    if(sess_ind >= 0) {
      ex = sessions[sess_ind].example;
      response["session_id"] = sessions[sess_ind].id;
    } else {
      ex = new StructuredExample;
      ex->x = learner->NewStructuredData();
      ex->y = learner->NewStructuredLabel(ex->x);
    }

    if(root.isMember("x")) {
      if(!ex->x->load(root["x"], learner)) { JSON_ERROR("Invalid 'x' parameter", sess_ind); }
    }
    if(root.isMember("y")) {
      if(!ex->y->load(root["y"], learner)) { JSON_ERROR("Invalid 'x' parameter", sess_ind); }
    } else if(sess_ind < 0) {
      delete ex;
      JSON_ERROR("No 'y' parameter specified", sess_ind); 
    }

    int ind = learner->AddExample(ex->x, ex->y);
    if(ind < 0) { JSON_ERROR("Error adding example\n", sess_ind) }
    response["index"] = ind;

    learner->SaveTrainingSet(ind);

    if(sess_ind >= 0)
      UnlockSession(sess_ind);
    else {
      delete ex;
    }

    return true;
  } else
    return false;
Beispiel #5
0
static void
ChooseSessionBreakLockXtProc(Widget w, XtPointer client_data, 
			     XtPointer callData)
{
    XawListReturnStruct *current;
    char *name;

    CheckDeleteCancel ();

    current = XawListShowCurrent (chooseSessionListWidget);

    if (!current || !(name = current->string) || *name == '\0')
    {
	if (current)
	    XtFree ((char *) current);
#ifdef XKB
	XkbStdBell(XtDisplay(topLevel),XtWindow(topLevel),0,XkbBI_BadValue);
#else
	XBell (XtDisplay (topLevel), 0);
#endif
	return;
    }

    break_lock_phase++;

    if (break_lock_phase == 1)
    {
	XtVaSetValues (chooseSessionMessageLabel,
	    XtNforeground, save_message_foreground,
            NULL);

#ifdef XKB
	XkbStdBell(XtDisplay(topLevel),XtWindow(topLevel),0,XkbBI_BadValue);
#else
	XBell (XtDisplay (topLevel), 0);
#endif
    }
    else
    {
	int longest;

	XtVaSetValues (chooseSessionMessageLabel,
	    XtNforeground, save_message_background,
            NULL);

	name = sessionNamesShort[current->list_index];

	(void) GetLockId (name);

	UnlockSession (name);

	sessionsLocked[current->list_index] = False;
	XtFree ((char *) sessionNamesLong[current->list_index]);
	sessionNamesLong[current->list_index] =
	    sessionNamesShort[current->list_index];

	XtVaGetValues (chooseSessionListWidget,
	    XtNlongest, &longest,
	    NULL);

	XawListChange (chooseSessionListWidget,
	    sessionNamesLong, sessionNameCount, longest, True);

	SessionSelected (current->list_index, True);

	break_lock_phase = 0;
    }

    XtFree ((char *) current);
}