예제 #1
0
파일: breveSNNS.c 프로젝트: B-Rich/breve
int snns_process(stEval *args, stEval *result, void *instance) {
  stEvalListHead *head = STLIST(&args[0]);
  float *params = (float*)STLIST(&args[1]);
  int numParams = STINT(&args[2]);
  FlintTypeParam *array_ptr;
  double *returnarray_ptr;
  double *iterator;
  int quant;
  int i;
  int n;
  int *n_ptr;
  krui_err errCode;
  char *errMsg;
  stEvalListHead *result_head = STLIST(result); 
  array_ptr = list_toArray(head);
  iterator = array_ptr;
  quant = krui_getNoOfUnits();
  
  i = 1;
  n = 0;
  
  for(i=1;i <= quant; i++){
	if(krui_getUnitTType(i)==INPUT){
		krui_setUnitActivation(i, *iterator);
		iterator++;
		n++;
	}
  }
  
  krui_updateNet(params, numParams);
  
 free(array_ptr);   //at the moment no space is allocated in list_toArray so commenting out this will result in a delay of the seg fault.
  
  i=0;
  n=0;
  
 
  for(i=1;i <= quant; i++){
	if(krui_getUnitTType(i)==OUTPUT){
		n++;
	}
  }

  returnarray_ptr = slMalloc(sizeof(double)*n);
  iterator = returnarray_ptr;
  i=1;
  
  
  for(i=1;i <= quant; i++){
	  if(krui_getUnitTType(i)==OUTPUT){
		  *iterator = krui_getUnitOutput(i);
		  //		  printf("Got output of %d\n", (*iterator));
		  *(iterator++);
	  }
  }
  
  
  result->values.listValue = array_toList(returnarray_ptr, n);
  result->type = AT_LIST;
  
  free(returnarray_ptr); 

  return EC_OK;

}	    
예제 #2
0
/*****************************************************************************
  FUNCTION : o_createOszi

  PURPOSE  : creates the  window GRAPH
  RETURNS  : void
  NOTES    :

  UPDATE   : 08.03.95
******************************************************************************/
void o_createOszi (void)
{
    Widget       menu,mItem,form,w1,w2,printlab;
    Widget       Done_oszi, clear_oszi, print_oszi;
    Arg          arg[5];
    Cardinal     n;
    char         buf[40];
    Colormap     o_graph_col;
    unsigned long foreground,background;
    int          curr_unit,test_unit,
    count_unit = 0;


    o_graph_error_scale = GRAPH_SSE;

    /* test whether there are output units defined. Since no error can be 
       computed in the opposit case, the graph tool can not be used */
    curr_unit  = krui_getCurrentUnit();
    test_unit  = krui_getFirstUnit();
    do{
	n=krui_getUnitTType(test_unit);
	if( (n == 2) || (n == 7) ) count_unit = 1;
    }while((test_unit  = krui_getNextUnit()) && (count_unit == 0));
    curr_unit  = krui_setCurrentUnit(curr_unit);
 
    if(count_unit == 0){
	ui_confirmOk("No Output units defined!\nAn error can neither be\ncomputed nor displayed!");
	return;
    }


    if(o_open) {
	XRaiseWindow (XtDisplay (o_displayMainWidget), 
		      XtWindow (o_displayMainWidget));
	return;
    }
	
    o_open = 1; 
    o_init();
    
    sprintf (buf, "SNNS graph");
    n = 0;  

    XtSetArg(arg[n],XtNminWidth,460); n++;  
    XtSetArg(arg[n],XtNminHeight,200); n++;
    XtSetArg(arg[n],XtNheight,o_WindowHeight+58); n++;
    XtSetArg(arg[n],XtNwidth,o_WindowWidth+10); n++;
    XtSetArg(arg[n],XtNborderWidth,1); n++;
    
    o_displayMainWidget = XtCreatePopupShell(buf, topLevelShellWidgetClass,
					     ui_toplevel, arg, n); 
    n = 0;  
    form = XtCreateManagedWidget ("form", formWidgetClass, 
				  o_displayMainWidget, arg, n);

    grid_oszi = ui_xCreateToggleItem ("grid",form,NULL,NULL,NULL);
    ui_xSetToggleState (grid_oszi, FALSE) ; 
    XtAddCallback (grid_oszi, XtNcallback, (XtCallbackProc) o_gridProc, NULL);

    print_oszi = ui_xCreateButtonItem ("print",form,grid_oszi,NULL);
    XtAddCallback(print_oszi, XtNcallback, (XtCallbackProc) o_printProc, NULL);

    if(strlen(o_printfile) == 0)sprintf(o_printfile,"./graph.ps");
    printlab = ui_xCreateLabelItem("Print to file:",form,14*8,print_oszi,NULL); 
    o_printW = ui_xCreateDialogItem ("o_printW",form,o_printfile,0,
				     printlab,NULL);

    Done_oszi = ui_xCreateButtonItem ("done",form,NULL,grid_oszi);
    XtAddCallback(Done_oszi,XtNcallback,(XtCallbackProc) o_DoneProc,NULL);

    clear_oszi = ui_xCreateButtonItem ("clear",form,Done_oszi,grid_oszi);
    XtAddCallback(clear_oszi,XtNcallback,(XtCallbackProc) o_clearProc,NULL);

    w1 = ui_xCreateLabelItem ("Scale X:",form,7*8,print_oszi,grid_oszi); 
    w2 = ui_xCreateButtonItem ("prev",form,w1,grid_oszi);
    XtAddCallback(w2,XtNcallback,(XtCallbackProc) o_XForwardProc,NULL);
    w1 = ui_xCreateButtonItem ("next",form,w2,grid_oszi);
    XtAddCallback(w1,XtNcallback,(XtCallbackProc) o_XBackProc,NULL);

    w2 = ui_xCreateLabelItem ("  Scale Y:",form,9*8,w1,grid_oszi); 
    w1 = ui_xCreateButtonItem ("prev",form,w2,grid_oszi); 
    XtAddCallback(w1,XtNcallback,(XtCallbackProc) o_YBackProc,NULL);
    w2 = ui_xCreateButtonItem ("next",form,w1,grid_oszi);
    XtAddCallback(w2,XtNcallback,(XtCallbackProc) o_YForwardProc,NULL);

    w1 = ui_xCreateLabelItem ("  Display:",form,9*8,w2,grid_oszi); 
    o_scaleWidget = ui_xCreateMenuButtonItem("   SSE  ",form,w1,grid_oszi);
    menu  = XtCreatePopupShell("menu",simpleMenuWidgetClass,o_scaleWidget,
			       NULL,ZERO);
    mItem = XtCreateManagedWidget("  SSE",smeBSBObjectClass,menu,NULL,ZERO);
    XtAddCallback(mItem,XtNcallback,(XtCallbackProc)o_set_err_scale,(caddr_t)1);
    mItem = XtCreateManagedWidget("  MSE",smeBSBObjectClass,menu,NULL,ZERO);
    XtAddCallback(mItem,XtNcallback,(XtCallbackProc)o_set_err_scale,(caddr_t)2);
    mItem = XtCreateManagedWidget("SSE/#out", smeBSBObjectClass,menu,NULL,ZERO);
    XtAddCallback(mItem,XtNcallback,(XtCallbackProc)o_set_err_scale,(caddr_t)3);

    o_DisplayWidget = o_xCreateScreenItem("screen",form,o_WindowWidth,
					  o_WindowHeight,NULL,clear_oszi);
    XtAddEventHandler(o_DisplayWidget,StructureNotifyMask | ExposureMask, 
		      FALSE,(XtEventHandler) o_eventProc,o_display);

    XtAddEventHandler(form,KeyPressMask,FALSE,
		      (XtEventHandler)ui_key_control,(Cardinal *) 0);

    ui_checkWindowPosition(o_displayMainWidget);
    XtPopup (o_displayMainWidget, XtGrabNone);

    o_display = XtDisplay (o_DisplayWidget); 
    o_window = XtWindow (o_DisplayWidget);
    o_fontStruct = XLoadQueryFont(o_display, "6x12");

    o_gc[label_gc] = XCreateGC (o_display, o_window, ZERO, NULL);
    o_gc[train_gc] = XCreateGC (o_display, o_window, ZERO, NULL);
    o_gc[test_gc] = XCreateGC (o_display, o_window, ZERO, NULL);
    XSetFont(o_display,o_gc[label_gc],(*o_fontStruct).fid);
    o_screen = DefaultScreen (o_display);
    o_depth = DisplayPlanes(o_display,o_screen);
    o_graph_col = DefaultColormap(o_display, o_screen);

    if(ui_col_monochromeMode == FALSE){
	/* settings for black learning curve */
	fg.red = 0; fg.green = 0; fg.blue = 0; 
	fg2.red = 65535; fg2.green = 0; fg2.blue = 0;

    }else{
	XSetLineAttributes(o_display, o_gc[test_gc],1,LineDoubleDash,
			   CapButt,JoinMiter);
	fg.red = 0; fg.green = 0; fg.blue = 0;
	fg2.red = 0; fg2.green = 0; fg2.blue = 0;
    }
    background = WhitePixel (o_display, o_screen);
    XSetBackground (o_display, o_gc[train_gc], background);
    XSetBackground (o_display, o_gc[test_gc],  background);
    XSetBackground (o_display, o_gc[label_gc], background);
    XAllocColor(o_display,o_graph_col,&fg);
    XAllocColor(o_display,o_graph_col,&fg2);
    foreground = BlackPixel (o_display, o_screen); 
    XSetForeground (o_display, o_gc[train_gc], fg.pixel); 
    XSetForeground (o_display, o_gc[test_gc],  fg2.pixel); 
    XSetForeground (o_display, o_gc[label_gc], foreground); 

    XSetGraphicsExposures(o_display,o_gc[label_gc],0);
    XSetGraphicsExposures(o_display,o_gc[train_gc],0);
    XSetGraphicsExposures(o_display,o_gc[test_gc],0);

    o_Pixmap = XCreatePixmap(o_display,o_window, (unsigned int) o_PixmapWidth, 
			     (unsigned int) o_PixmapHeight, 
			     (unsigned int) o_depth);
    o_ClearPixmap(o_display,o_Pixmap,o_gc[train_gc],fg.pixel,o_screen,0,0,
		  o_PixmapWidth,o_PixmapHeight); 
    o_ClearPixmap(o_display,o_Pixmap,o_gc[test_gc],fg2.pixel,o_screen,0,0,
		  o_PixmapWidth,o_PixmapHeight); 
    XClearArea(o_display,o_window,o_OsziXPos,o_OsziYPos, 
	       (unsigned int) o_OsziWidth-1, (unsigned int) o_OsziHeight,1);
    o_PressPossible = 1;
}