static void make_links(void) { int unit_ptr, mainUnit_Ptr; FlintType weight; weight = 1.0; for ((mainUnit_Ptr) = krui_getFirstUnit(); (mainUnit_Ptr) <= krui_getNoOfUnits(); (mainUnit_Ptr)++) /* main loop self connections too */ for ((unit_ptr) = krui_getFirstUnit(); (unit_ptr) <= krui_getNoOfUnits(); (unit_ptr)++) { /* inner loop */ /*if (NOT (unit_ptr == mainUnit_Ptr)) { not the same entry !! */ krui_setCurrentUnit(mainUnit_Ptr); if (NOT krui_isConnected(unit_ptr)) { krui_createLink(unit_ptr, weight); krui_setLinkWeight(weight); } } }
int snns_getNoOfUnits(stEval *args, stEval *result, void *instance) { int unitQuantity; unitQuantity = krui_getNoOfUnits(); STINT(result) = unitQuantity; return EC_OK; }
static void create_net_PROC(void) { int create=1; BN_ERROR = 0; if(krui_getNoOfUnits() != 0) { if(! ui_confirmYes("Create will erase current network. Create?")) { create = 0; } } if(create && (PLANE_length != 0)) { krui_deleteNet(); calculate_first_snns_unit_no_of_plane(); create_snns_unit(); make_links(); krui_setLearnFunc("BPTT"); krui_setUpdateFunc("Hopfield_Synchronous"); krui_setInitialisationFunc("ClippHebb"); ui_NumberOfLearnParamsChanged(); ui_NumberOfUpdateParamsChanged(); ui_NumberOfInitParamsChanged(); bn_basics_refresh(); }/* if */ }
static inline void delUnit(IPackage&p,IConnection*c) { uint32 subnet,unit,max; uint16 numunits; p>>subnet>>numunits; if(numunits<1)return; int uarr[numunits],num=0,i; max=krui_getNoOfUnits(); for(i=0;i<numunits;i++){ p>>unit; if(unit<=max&&unit!=0) uarr[num++]=unit; } if(num==0)return; int err=krui_deleteUnitList(num,uarr); //create deletion package IPackage op("set"); op<<QString("delete unit")<<subnet<<(uint16)num; for(i=0;i<num;i++)op<<(uint32)(uarr[i]); c->send(op); //send workaround packages for(i=0;i<num;i++)sendSNNS(c,"delete unit",uarr[i]-i); }
int ui_file_loadNet (Widget w, XtPointer button, caddr_t call_data) { char filename[4+MAX_NAME_LENGTH+MAX_NAME_LENGTH]; char string[MAX_NAME_LENGTH+MAX_NAME_LENGTH + 80]; /* filename plus some text */ Bool performLoad = TRUE; char *temp; int ret_val = 0; /* check now for errors and react ! */ if (strlen(ui_filenameNET) == 0) { ui_confirmOk("No file specified"); return (-1); } /* a filename is given */ if (ui_filenameNET[0] == '/') sprintf(filename, "%s%s", ui_filenameNET, ui_getExtension(UI_FILE_NET)); else sprintf(filename, "%s/%s%s", ui_pathname, ui_filenameNET, ui_getExtension(UI_FILE_NET)); if (NOT ui_fileExist(filename, 0)) { ui_confirmOk("No such network file exists!"); return(-1); } /* a file exists */ if (krui_getNoOfUnits() != 0) { if (NOT ui_confirmYes("Load will erase current network. Load?")) performLoad = FALSE; } if (INVERS_CREATED) { XtDestroyWidget(ui_InvRootWidget); INVERS_CREATED = 0; } if (performLoad) { sprintf(string,"Loading network: %s ...", filename); ui_printMessage(string); if(ui_controlIsCreated)ui_xSetLabel(ui_controlMessageWidget, ""); d3_clear_xyTranslationTable (); ui_checkError(krui_loadNet(filename, &temp)); if (ui_kernelError < 0){ ui_confirmOk("Error during loading the network!"); } else { ui_printMessage("Network loaded."); /* message to text window */ sprintf(string,"\n\n\nNetwork loaded from file:\n %s\n", filename); ui_tw_printMessage(string); /* try to load a configuration file with the same name */ if (ui_loadCorrespondingCfg) { ui_loadCorrespondingCfg = TRUE; sprintf(filename, "%s/%s%s", ui_pathname, ui_filenameNET, ui_getExtension(UI_FILE_CFG)); if (ui_fileExist(filename, 0) AND ui_confirmYes("Load corresponding configuration file")) { ui_file_doLoadConfiguration(filename); ret_val = 1; } } } /* initialization for graph */ if(o_open){ o_CurveNo += ((o_CurveLengths[o_CurveNo] != 0) && (o_CurveNo < MAX_CURVE_NO-2)) ? (2) : (0); o_InitCurve(); o_LearnStepCount = 0; } /* reset gui */ ui_sel_resetList(); /* reset selections */ ui_net_completeRefresh(ui_currentDisplay, UI_GLOBAL); /* show net */ ui_printMessage(""); ui_stat_displayStatus(ui_gridPosMouse); strcpy(ui_filenameSLNET, ui_filenameNET); ui_file_updateShellLabels(); ui_info_makeUnitInfoPanelConsistent(); ui_NumberOfLearnParamsChanged(); ui_NumberOfUpdateParamsChanged(); ui_NumberOfInitParamsChanged(); } return (ret_val); }
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; }
static inline void modifUnit(IPackage&p,IConnection*c) { uint32 subnet; uint16 numunits; int err; SUnit unit,ounit; IPackage op("set"); op<<QString("modify unit"); op<<subnet<<numunits; char buf[256]; for(int i=0;i<numunits;i++){ getUnit(unit,p); ounit=unit; //check for existance if(!(unit.mask&UNUM)){ int num=krui_createDefaultUnit(); if(num<0){ ounit.errcode="Unable to create unit."; setUnit(ounit,op); continue; } unit.id=ounit.id=num; } if(unit.id==0||unit.id>krui_getNoOfUnits()){ ounit.mask=UERR|UNUM; ounit.errcode="Unit doesn't exist."; setUnit(ounit,op); continue; } //prototype if(unit.mask&UPROTO){ err=krui_setUnitFType(unit.id,CHR(buf,unit.prototype)); if(err){ ounit.prototype=krui_getUnitFTypeName(unit.id); ounit.mask|=UERR; ounit.errcode=krui_error(err); } } //position if(unit.mask&UPOS){ PosType pos; pos.x=unit.xpos; pos.y=unit.ypos; pos.z=unit.zpos; krui_setUnitPosition(unit.id,&pos); krui_getUnitPosition(unit.id,&pos); ounit.xpos=pos.x; ounit.ypos=pos.y; ounit.zpos=pos.z; } //bias if(unit.mask&UBIAS){ krui_setUnitBias(unit.id,unit.bias); } //i_activation if(unit.mask&UIACT){ krui_setUnitInitialActivation(unit.id,unit.iact); } //activation if(unit.mask&UACT){ err=krui_setUnitActivation(unit.id,unit.act); if(err){ ounit.act=krui_getUnitActivation(unit.id); ounit.mask|=UERR; ounit.errcode=krui_error(err); } } //actfunc if(unit.mask&UACTF){ err=krui_setUnitActFunc(unit.id,CHR(buf,unit.actfunc)); if(err){ ounit.mask|=UERR; ounit.errcode=krui_error(err); ounit.actfunc=krui_getUnitActFuncName(unit.id); } } //outfunc if(unit.mask&UOUTF){ err=krui_setUnitOutFunc(unit.id,CHR(buf,unit.outfunc)); if(err){ ounit.mask|=UERR; ounit.errcode=krui_error(err); ounit.outfunc=krui_getUnitOutFuncName(unit.id); } } //name if(unit.mask&UNAME){ err=krui_setUnitName(unit.id,CHR(buf,unit.name)); if(err){ ounit.mask|=UERR; ounit.errcode=krui_error(err); ounit.name=krui_getUnitName(unit.id); } } //store setUnit(ounit,op); } c->send(op); }
/***************************************************************************** FUNCTION : ui_map_grid PURPOSE : draws a grid over the MAP squares and the axis NOTES : type == 1 for color display; == 0 for B/W RETURNS : UPDATE : 20.05.1994 ******************************************************************************/ static void ui_map_grid(int type) { char x_String[40], y_String[40]; int x_steps,y_steps; int n = 0; float x_no,y_no,x_foo=0,y_foo=0; int actual_sizeX,actual_sizeY; XPoint p1,p2,p3,p4; static char dash[]={6,6,6}; /* do nothing, if no network defined */ if(type == 0){ if( krui_getNoOfUnits() == 0 || (MAP_BW_squaresizeX == 0) || (MAP_BW_squaresizeY == 0) )return; }else{ if( krui_getNoOfUnits() == 0 || (MAP_squaresizeX == 0) || (MAP_squaresizeY == 0) )return; } /* set the square size */ if(type == 0){ actual_sizeX = MAP_BW_squaresizeX; actual_sizeY = MAP_BW_squaresizeY; }else{ actual_sizeX = MAP_squaresizeX; actual_sizeY = MAP_squaresizeY; } /* set output grid of units */ dash[0] = dash[1] = (int)(actual_sizeX*0.5 +0.5); XSetDashes(ui_display,MAP_GRAPH_gc[20*type], (int)(actual_sizeX*0.5 +0.5)+20*type,dash,2); XSetLineAttributes(ui_display,MAP_GRAPH_gc[20*type],0,LineOnOffDash, CapButt,JoinMiter); x_steps = (int)((MAP_xMax - MAP_xMin)/MAP_scaleX); y_steps = (int)((MAP_yMax - MAP_yMin)/MAP_scaleY); x_no = MAP_xMin; y_no = MAP_yMin; while(n <= 10){ sprintf(x_String,"%1.1f",x_no); sprintf(y_String,"%1.1f",y_no); p1.x = (int)(x_foo)+20; p1.y = 10; p2.x = (x_steps)*actual_sizeX+30; p2.y = (int)(y_foo)+20; p3.x = 0; p3.y = p2.y; p4.x = p1.x; p4.y = (y_steps)*actual_sizeY+20; XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type], p1.x,p1.y,x_String,(int)strlen(x_String)); XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type], p2.x,p2.y,y_String,(int)strlen(y_String)); XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type], p3.x,p3.y,y_String,(int)strlen(y_String)); XDrawString(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type], p4.x,p4.y+20,x_String,(int)strlen(x_String)); XDrawLine(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type], p1.x,p1.y,p4.x,p4.y); XDrawLine(ui_display,MAP_GRAPH_win,MAP_GRAPH_gc[20*type], p2.x,p2.y,p3.x+10,p3.y); n ++; x_foo = (type==0)?x_foo+(float)(x_steps*MAP_BW_squaresizeX)/10.0: x_foo+(float)(x_steps*MAP_squaresizeX)/10.0; y_foo = (type==0)?y_foo+(float)(y_steps*MAP_BW_squaresizeY)/10.0: y_foo+(float)(y_steps*MAP_squaresizeY)/10.0; x_no += (MAP_xMax-MAP_xMin)/10.0; y_no += (MAP_yMax-MAP_yMin)/10.0; } XSetLineAttributes(ui_display,MAP_GRAPH_gc[20*type],0, LineSolid,CapButt,JoinMiter); }
/***************************************************************************** FUNCTION : ui_map_geometry PURPOSE : compute the geometry of the displays and the size of the squares NOTES : RETURNS : UPDATE : 22.09.1994 ******************************************************************************/ static void ui_map_geometry(int zoom_fact) { int maxstepsX,maxstepsY; int n; XtWidgetGeometry geo_info, geo_data; XtWidgetGeometry disp_info, disp_data; XtWidgetGeometry view_info, view_data; XtGeometryResult geo_result; /* do nothing, if no network defined */ if( krui_getNoOfUnits() == 0) return; maxstepsX = (int) (MAP_xMax-MAP_xMin)/MAP_scaleX; maxstepsY = (int) (MAP_yMax-MAP_yMin)/MAP_scaleY; /* set the necessary xlib environment variables */ if(ui_col_monochromeMode){ /* this is a B&W terminal */ MAP_GRAPH_gc[0] = XCreateGC(ui_display,MAP_GRAPH_win,0,0); } else { /* this is a color terminal */ for(n=0;n<=20;n++) MAP_GRAPH_gc[n] = XCreateGC(ui_display,MAP_GRAPH_win,0,0); /* set the foreground and background colors */ for(n=0; n<10;n++){ XSetForeground(ui_display,MAP_GRAPH_gc[n], (uint) ui_col_rangePixels[(int)(n*1.7)]); XSetBackground(ui_display,MAP_GRAPH_gc[n], WhitePixel(ui_display,MAP_GRAPH_screen)); XSetForeground(ui_display,MAP_GRAPH_gc[10+n], (uint) ui_col_rangePixels[(int)(15+n*1.7)]); XSetBackground(ui_display,MAP_GRAPH_gc[10+n], WhitePixel(ui_display,MAP_GRAPH_screen)); } } /* get widget geometry */ geo_result = XtQueryGeometry(MAP_GRAPH_mainwidget,&geo_data,&geo_info); if(geo_result != XtGeometryYes){ geo_info.height = 400; geo_info.width = 400; } if(zoom_fact != 0){ XtResizeWidget(MAP_GRAPH_mainwidget,geo_info.width, geo_info.height,geo_info.border_width); } /* adjust squaresize */ if(ui_col_monochromeMode){ /* this is a B&W terminal */ MAP_BW_squaresizeX = MAP_BW_squaresizeX + zoom_fact; MAP_BW_squaresizeY = MAP_BW_squaresizeY + zoom_fact; if(MAP_BW_squaresizeX == 0)MAP_BW_squaresizeX = 1; if(MAP_BW_squaresizeY == 0)MAP_BW_squaresizeY = 1; MAP_windowsizeX = MAP_BW_squaresizeX*maxstepsX+40; MAP_windowsizeY = MAP_BW_squaresizeY*maxstepsY+40; }else{ /* this is a color terminal */ MAP_squaresizeX = MAP_squaresizeX + zoom_fact; MAP_squaresizeY = MAP_squaresizeY + zoom_fact; if(MAP_squaresizeX == 0)MAP_squaresizeX = 1; if(MAP_squaresizeY == 0)MAP_squaresizeY = 1; MAP_windowsizeX = MAP_squaresizeX*maxstepsX+62; MAP_windowsizeY = MAP_squaresizeY*maxstepsY+62; } /* Resize all involved windows so that they fit the data and the screen */ XtResizeWidget(MAP_GRAPH_displaywidget,MAP_windowsizeX+62, MAP_windowsizeY+62,0); MAP_viewsizeX = MAP_squaresizeX * maxstepsX; MAP_viewsizeY = MAP_squaresizeY * maxstepsY; geo_result = XtQueryGeometry(MAP_GRAPH_displaywidget, &disp_data,&disp_info); geo_result = XtQueryGeometry(view,&view_data,&view_info); if(view_info.width > disp_info.width) XtResizeWidget(view,disp_info.width, disp_info.height,view_info.border_width); else if(disp_info.width < geo_info.width) XtResizeWidget(view,disp_info.width, disp_info.height,view_info.border_width); else XtResizeWidget(view,geo_info.width, geo_info.height,view_info.border_width); }
/***************************************************************************** FUNCTION : ui_displMap PURPOSE : Main program to display the MAPs of the network NOTES : Initializes widgets and switches for color or b&w terminal RETURNS : UPDATE : 22.09.94 ******************************************************************************/ void ui_displMap(Widget w, caddr_t call_data) { Widget donebutton,setbutton,framewidget,zoomin,zoomout; int maxstepX,maxstepY; Arg args[25]; Cardinal n = 0; char buf[40]; /* do nothing, if no network is defined */ if( (krui_getNoOfUnits()) == 0){ ui_confirmOk("No network loaded !"); return; } /* If a MAP window already exists, just put it on top */ if(MAP_WINDOW_created == 1){ XRaiseWindow (XtDisplay (MAP_GRAPH_mainwidget), XtWindow (MAP_GRAPH_mainwidget)); return; } /* Create all necessary widgets */ n = 0; sprintf(buf," SNNS Unit Projection\n"); MAP_GRAPH_mainwidget = XtCreatePopupShell(buf,topLevelShellWidgetClass,ui_toplevel,args,n); n = 0; framewidget = XtCreateManagedWidget("form",formWidgetClass, MAP_GRAPH_mainwidget,args,n); donebutton = ui_xCreateButtonItem("done", framewidget, NULL, NULL); zoomin = ui_xCreateButtonItem("zoomin",framewidget,NULL,donebutton); setbutton = ui_xCreateButtonItem("setup",framewidget,zoomin,NULL); zoomout = ui_xCreateButtonItem("zoomout",framewidget,zoomin,donebutton); n = 0; XtSetArg(args[n], XtNx, 0);n++; XtSetArg(args[n], XtNy, 0);n++; XtSetArg(args[n], XtNwidth, 210); n++; XtSetArg(args[n], XtNheight, 25); n++; XtSetArg(args[n], XtNinternalHeight, 1); n++; XtSetArg(args[n], XtNinternalWidth , 1); n++; XtSetArg(args[n], XtNborderWidth, 0); n++; XtSetArg(args[n], XtNhorizDistance, 30); n++; XtSetArg(args[n], XtNfromHoriz, setbutton); n++; XtSetArg(args[n], XtNfromVert, NULL); n++; XtSetArg(args[n], XtNleft , XtChainLeft); n++; XtSetArg(args[n], XtNright , XtChainLeft); n++; XtSetArg(args[n], XtNtop , XtChainTop); n++; XtSetArg(args[n], XtNbottom, XtChainTop);n++; scale = XtCreateManagedWidget("Label",formWidgetClass,framewidget,args,n); n = 0; XtSetArg(args[n], XtNx, 0);n++; XtSetArg(args[n], XtNy, 0);n++; XtSetArg(args[n], XtNborderWidth, 1); n++; XtSetArg(args[n], XtNwidth, MAP_windowsizeX+62); n++; XtSetArg(args[n], XtNheight, MAP_windowsizeY+62); n++; XtSetArg(args[n], XtNallowHoriz, TRUE);n++; XtSetArg(args[n], XtNallowVert, TRUE);n++; XtSetArg(args[n], XtNforceBars, TRUE);n++; XtSetArg(args[n], XtNfromHoriz, NULL); n++; XtSetArg(args[n], XtNfromVert, zoomin); n++; XtSetArg(args[n], XtNvertDistance, 10); n++; XtSetArg(args[n], XtNleft , XtChainLeft); n++; XtSetArg(args[n], XtNright , XtChainRight); n++; XtSetArg(args[n], XtNtop , XtChainTop); n++; XtSetArg(args[n], XtNbottom, XtChainBottom);n++; view = XtCreateManagedWidget("view",viewportWidgetClass,framewidget,args,n); MAP_GRAPH_displaywidget = ui_createMyScreen("screen",view,MAP_windowsizeX,MAP_windowsizeY, NULL,scale); MAP_WINDOW_created = 1; /* define the routines to be called for widget events */ XtAddCallback(donebutton, XtNcallback, (XtCallbackProc)ui_map_close,MAP_GRAPH_mainwidget); XtAddCallback(setbutton, XtNcallback,(XtCallbackProc)ui_map_setup,NULL); XtAddCallback(zoomin, XtNcallback,(XtCallbackProc)ui_map_zoom_in,NULL); XtAddCallback(zoomout, XtNcallback,(XtCallbackProc)ui_map_zoom_out,NULL); XtAddEventHandler(MAP_GRAPH_displaywidget, StructureNotifyMask | ExposureMask, GraphicsExpose, (XtEventHandler) ui_map_event,ui_display); XtAddEventHandler(framewidget,KeyPressMask,FALSE, (XtEventHandler)ui_key_control,(Cardinal *) 0); /* set the maximum size of each square and the size of the whole window */ maxstepX = (int)((float)(MAP_xMax - MAP_xMin)/ MAP_scaleX); maxstepY = (int)((float)(MAP_yMax - MAP_yMin)/ MAP_scaleY); if(ui_col_monochromeMode){ /* B&W terminal => variable square size needed */ MAP_squaresizeX = (maxstepX > MAP_viewsizeX/MAP_BW_squaresizeX)? MAP_BW_squaresizeX: (int)((float)MAP_viewsizeX/(float)maxstepX); MAP_windowsizeX = MAP_squaresizeX*maxstepX+40; MAP_squaresizeY = (maxstepY > MAP_viewsizeY/MAP_BW_squaresizeY)? MAP_BW_squaresizeY: (int)((float)MAP_viewsizeY/(float)maxstepY); MAP_windowsizeX = MAP_squaresizeX*maxstepX+40; }else{ /* color terminal => fixed square size */ MAP_squaresizeX = ( maxstepX > MAP_viewsizeX/5)?5:(int)(MAP_viewsizeX/maxstepX); MAP_squaresizeY = ( maxstepY > MAP_viewsizeY/5)?5:(int)(MAP_viewsizeY/maxstepY); MAP_windowsizeX = MAP_squaresizeX*maxstepX+40; MAP_windowsizeY = MAP_squaresizeY*maxstepY+40; } /* Realize the window */ XtPopup(MAP_GRAPH_mainwidget, XtGrabNone); MAP_GRAPH_screen = DefaultScreen(ui_display); MAP_GRAPH_win = XtWindow(MAP_GRAPH_displaywidget); }