int ocos_update(NSLNSLnet *net,va_list args) { int nn; nio_ds *np=nsl_drv(nio_ds); static char buff[20]; sprintf(buff,"%ld:%d",net->time,np->xx++); w_title(np->scr_t,NIO_TR,NIO_DRAW,FALSE,buff); w_track(np->scr_d,NIO_FLOAT,np->trk_probe, dsf(np->d0,data_ds,output), (float)1.0-dsf(np->d0+1,data_ds,output)); for(nn=0;nn<np->fld_siz;++nn) {w_track(np->scr_l,NIO_FLOAT,np->my_tracks[nn], ((float)nn/(np->fld_siz-1)), (float)1.0-dsf(np->bs_hd+nn,ocos_ds,output)); } w_update(np->scr_l); w_update(np->scr_d); return(0); }
static int phantom_console_window_puts(const char *s) { if(phantom_console_window == 0) return 0; w_font_tty_string( phantom_console_window, &CON_FONT, s, console_fg, console_bg, &ttx, &tty ); w_update( phantom_console_window ); return 0; }
int hop_update(NSLNSLnet *net,va_list args) { int nn; static char buff[20]; hop_io_ds *hp=nsl_drv(hop_io_ds); nio_ds *np=(&hp->nio); sprintf(buff,"%ld:%d",net->time,np->xx++); w_title(np->scr_t,NIO_TR,NIO_DRAW,FALSE,buff); for(nn=0;nn<np->fld_siz;++nn) {updnode(np->scr_p,nn,dsf(np->d0,hop_ctrl_ds,output[nn])); updnode(np->scr_d,nn,dsf(np->bs_hd+nn,hop_ds,output)); w_track(np->scr_l,NIO_FLOAT,np->my_tracks[nn], ((float)nn/(np->fld_siz-1)), (float)1.0-dsf(np->bs_hd+nn,hop_ds,output)); } w_update(np->scr_l); return(0); }
void infomax(gsl_matrix *x_white, gsl_matrix *weights, gsl_matrix *S, int verbose){ /*Computes ICA infomax in whitened data Decomposes x_white as x_white=AS *Input x_white: whitened data (Use PCAwhiten) *Output A : mixing matrix S : source matrix */ // int verbose = 1; //true size_t NCOMP = x_white->size1; size_t NVOX = x_white->size2; //getting permutation vector const gsl_rng_type * T; gsl_rng * r; gsl_permutation * p = gsl_permutation_alloc (NVOX); // gsl_rng_env_setup(); T = gsl_rng_default; r = gsl_rng_alloc (T); gsl_permutation_init (p); gsl_matrix *old_weights = gsl_matrix_alloc(NCOMP,NCOMP); gsl_matrix *bias = gsl_matrix_calloc(NCOMP, 1); gsl_matrix *d_weights = gsl_matrix_calloc(NCOMP,NCOMP); gsl_matrix *temp_change = gsl_matrix_alloc(NCOMP,NCOMP); gsl_matrix *old_d_weights = gsl_matrix_calloc(NCOMP,NCOMP); gsl_matrix *shuffled_x_white = gsl_matrix_calloc(NCOMP,x_white->size2); gsl_matrix_memcpy(shuffled_x_white, x_white); gsl_matrix_set_identity(weights); gsl_matrix_set_identity(old_weights); double lrate = 0.005/log((double)NCOMP); double change=1; double angle_delta =0; size_t step = 1; int error = 0; while( (step < MAX_STEP) && (change > W_STOP)){ error = w_update(weights, x_white, bias, shuffled_x_white, p, r, lrate); if (error==1 || error==2){ // It blowed up! RESTART! step = 1; // change = 1; error = 0; lrate *= ANNEAL; gsl_matrix_set_identity(weights); gsl_matrix_set_identity(old_weights); gsl_matrix_set_zero(d_weights); gsl_matrix_set_zero(old_d_weights); gsl_matrix_set_zero(bias); if (lrate > MIN_LRATE){ printf("\nLowering learning rate to %g and starting again.\n",lrate); } else{ printf("\nMatrix may not be invertible"); } } else if (error==0){ gsl_matrix_memcpy(d_weights, weights); gsl_matrix_sub(d_weights, old_weights); change = matrix_norm(d_weights); if (step > 2){ // Compute angle delta gsl_matrix_memcpy(temp_change, d_weights); gsl_matrix_mul_elements(temp_change, old_d_weights); angle_delta = acos(matrix_sum(temp_change) / sqrt(matrix_norm(d_weights)*(matrix_norm(old_d_weights)))); angle_delta *= (180.0 / M_PI); } gsl_matrix_memcpy(old_weights, weights); if (angle_delta > 60){ lrate *= ANNEAL; gsl_matrix_memcpy(old_d_weights, d_weights); } else if (step==1) { gsl_matrix_memcpy(old_d_weights, d_weights); } if ((verbose && (step % 10)== 0) || change < W_STOP){ printf("\nStep %zu: Lrate %.1e, Wchange %.1e, Angle %.2f", step, lrate, change, angle_delta); } step ++; } } matrix_mmul(weights, x_white, S); gsl_matrix_free(old_d_weights); gsl_matrix_free(old_weights); gsl_matrix_free(bias); gsl_matrix_free(d_weights); gsl_matrix_free(shuffled_x_white); gsl_rng_free (r); gsl_permutation_free (p); }
static void phantom_debug_window_loop() { static char buf[DEBBS+1]; int step = 0; int show = 's'; t_current_set_name("Debug Win"); // Which thread will receive typein for this window phantom_debug_window->owner = get_current_tid(); int wx = 600; #if CONF_NEW_CTTY if( t_new_ctty( get_current_tid() ) ) panic("console t_new_ctty"); #else // Need separate ctty t_set_ctty( get_current_tid(), wtty_init( WTTY_SMALL_BUF ) ); #endif // TODO HACK! Need ioctl to check num of bytes? wtty_t *tty; t_get_ctty( get_current_tid(), &tty ); while(1) { if(tty && !wtty_is_empty(tty)) { char c = wtty_getc( tty ); switch(c) { case '?': case'h': printf( "Commands:\n" "---------\n" "w\t- show windows list\n" "t\t- show threads list\n" "s\t- show stats\n" "p\t- show profiler\n" "d\t- dump threads to JSON\n" ); break; case 'p': // profiler case 't': //w_set_title( phantom_debug_window, "Threads" ); //show = c; //break; case 'w': //w_set_title( phantom_debug_window, "Windows" ); //show = c; //break; case 's': //w_set_title( phantom_debug_window, "Stats" ); show = c; break; case 'd': { json_output jo = { 0 }; json_start( &jo ); json_dump_threads( &jo ); json_stop( &jo ); } break; } } { static char old_show = 0; if( old_show != show ) { old_show = show; switch(show) { case 't': w_set_title( phantom_debug_window, "Threads" ); break; case 'w': w_set_title( phantom_debug_window, "Windows" ); break; case 's': w_set_title( phantom_debug_window, "Stats" ); break; case 'p': w_set_title( phantom_debug_window, "Profiler" ); break; } } } //hal_sleep_msec(1000); hal_sleep_msec(100); #if 1 #if 1 w_clear( phantom_debug_window ); ttyd = DEBWIN_YS-20; ttxd = 0; #endif //put_progress(); void *bp = buf; int len = DEBBS; int rc; time_t sec = uptime(); int min = sec/60; sec %= 60; int hr = min/60; min %= 60; int days = hr/24; hr %= 24; struct tm mt = *current_time; rc = snprintf(bp, len, " View: \x1b[32mt\x1b[37mhreads \x1b[32ms\x1b[37mtats \x1b[32mw\x1b[37mindows \x1b[32mp\x1b[37mrofile \x1b[32m?\x1b[37m - help\n \x1b[32mStep %d, uptime %dd, %02d:%02d:%02d\x1b[37m, %d events\n Time %04d/%02d/%02d %02d:%02d:%02d GMT, CPU 0 %2d%% idle\n", step++, days, hr, min, (int)sec, ev_get_n_events_in_q(), mt.tm_year + 1900, mt.tm_mon, mt.tm_mday, mt.tm_hour, mt.tm_min, mt.tm_sec, 100-percpu_cpu_load[0] ); bp += rc; len -= rc; switch(show) { case 't': default: phantom_dump_threads_buf(bp,len); break; case 'w': phantom_dump_windows_buf(bp,len); break; case 's': phantom_dump_stats_buf(bp,len); break; case 'p': phantom_dump_profiler_buf(bp,len); break; } phantom_debug_window_puts(buf); if(wx == 600) wx = 620; else wx = 600; //w_move( phantom_debug_window, wx, 50 ); #endif put_progress(); w_update( phantom_debug_window ); } }
void phantom_init_console_window() { hal_mutex_init( &buf_mutex, "console" ); console_fg = COLOR_LIGHTGRAY; console_bg = COLOR_BLACK; int xsize = 620, ysize = 300; int cw_x = 50, cw_y = 450; if( scr_get_ysize() < 600 ) { cw_x = cw_y = 0; } drv_video_window_t *w = drv_video_window_create( xsize, ysize, cw_x, cw_y, console_bg, "Console", WFLAG_WIN_DECORATED|WFLAG_WIN_DOUBLEBUF ); phantom_console_window = w; w->owner = get_current_tid(); phantom_set_console_ops( &win_ops ); phantom_console_window_puts("Phantom console window\n"); phantom_debug_window = drv_video_window_create( DEBWIN_XS, DEBWIN_YS, DEBWIN_X, DEBWIN_Y, console_bg, "Threads", WFLAG_WIN_DECORATED|WFLAG_WIN_DOUBLEBUF|WFLAG_WIN_FULLPAINT ); //phantom_debug_window->flags |= WFLAG_WIN_DOUBLEBUF|WFLAG_WIN_FULLPAINT; //w_update( phantom_debug_window ); // For dbl buf flags to start working ok phantom_debug_window_puts("Phantom debug window\n\nt - threads\nw - windows\ns - stats\np - profiler\n"); w_update( phantom_debug_window ); //hal_sleep_msec(4000); hal_start_kernel_thread(phantom_debug_window_loop); // ------------------------------------------------------------------- // Launcher window // ------------------------------------------------------------------- color_t la_bg = { 0x19, 0x19, 0x19, 0xFF }; color_t la_b1 = { 68, 66, 62, 0xFF }; color_t la_b2 = { 88, 84, 79, 0xFF }; color_t la_txt = { 0x11, 0xd5, 0xff, 0xFF }; //#define BTEXT_COLOR COLOR_YELLOW #define BTEXT_COLOR la_txt phantom_launcher_window = drv_video_window_create( scr_get_xsize(), 32, 0, 0, console_bg, "Launcher", WFLAG_WIN_ONTOP ); phantom_launcher_window->inKernelEventProcess = phantom_launcher_event_process; w_fill( phantom_launcher_window, la_bg ); int lb_x = scr_get_xsize(); lb_x -= power_button_sm_bmp.xsize + 5; w_add_button( phantom_launcher_window, -1, lb_x, 2, &power_button_sm_bmp, &power_button_pressed_sm_bmp, BUTTON_FLAG_NOBORDER ); pool_handle_t bh; lb_x = 5; int nwin = 0; for( nwin = 0; nwin < MAX_LAUNCH_BUTTONS; nwin++ ) { char * wname = "win1"; // crashes in some configurations?? //wname[3] = '0' + nwin; bh = w_add_button( phantom_launcher_window, nwin, lb_x, 5, &task_button_bmp, &task_button_bmp, BUTTON_FLAG_NOBORDER ); w_button_set_text( phantom_launcher_window, bh, wname, BTEXT_COLOR ); lb_x += 5+task_button_bmp.xsize; taskbuttons[nwin] = bh; } w_draw_line( phantom_launcher_window, 0, 31, scr_get_xsize(), 31, la_b1 ); w_draw_line( phantom_launcher_window, 0, 30, scr_get_xsize(), 30, la_b2 ); w_update( phantom_launcher_window ); //hal_start_kernel_thread(phantom_launcher_window_loop); }
void draw_change(WORD w_handle, GRECT *pt) { GRECT c, pprev; register GRECT *pw; register WORD start; WORD stop, moved; WORD oldtop, clrold, diffbord, wasclr; wasclr = !(D.w_win[w_handle].w_flags & VF_BROKEN); /* save old size */ w_getsize(WS_CURR, w_handle, &c); w_setsize(WS_PREV, w_handle, &c); /* set new size's */ w_setsize(WS_CURR, w_handle, pt); pw = (GRECT *) w_getxptr(WS_WORK, w_handle); wm_calc(WC_WORK, D.w_win[w_handle].w_kind, pt->g_x, pt->g_y, pt->g_w, pt->g_h, &pw->g_x, &pw->g_y, &pw->g_w, &pw->g_h); /* update rect. lists */ everyobj(gl_wtree, ROOT, NIL, (void(*)())newrect, 0, 0, MAX_DEPTH); /* remember oldtop */ oldtop = gl_wtop; gl_wtop = W_TREE[ROOT].ob_tail; /* if new top then */ /* change men */ if (gl_wtop != oldtop) w_menufix(); /* set ctrl rect and */ /* mouse owner */ w_setactive(); /* init. starting window*/ start = w_handle; /* stop at the top */ stop = DESKWH; /* set flag to say we */ /* haven't moved */ /* the top window */ moved = FALSE; /* if same upper left */ /* corner and not */ /* zero size window */ /* then its a size or */ /* top request, else */ /* its a move, grow, */ /* open or close. */ if ( (!rc_equal(&gl_rzero, pt)) && (pt->g_x == c.g_x) && (pt->g_y == c.g_y) ) { /* size or top request */ if ( (pt->g_w == c.g_w) && (pt->g_h == c.g_h) ) { /* sizes of prev and */ /* current are the same*/ /* so its a top request*/ /* return if this isn't */ /* a top request */ if ( (w_handle != W_TREE[ROOT].ob_tail) || (w_handle == oldtop) ) return; /* say when borders will*/ /* change */ diffbord = !( (D.w_win[oldtop].w_flags & VF_SUBWIN) && (D.w_win[gl_wtop].w_flags & VF_SUBWIN) ); /* draw oldtop covered */ /* with deactivated */ /* borders */ if (oldtop != NIL) { if (diffbord) w_clipdraw(oldtop, 0, MAX_DEPTH, 2); clrold = !(D.w_win[oldtop].w_flags & VF_BROKEN); } else clrold = TRUE; /* if oldtop isn't */ /* overlapped and new */ /* top was clear then */ /* just draw activated*/ /* borders */ if ( (clrold) && (wasclr) ) { w_clipdraw(gl_wtop, 0, MAX_DEPTH, 1); return; } } else /* size change */ { /* stop before current */ /* window if shrink */ /* was a pure subset */ if ( (pt->g_w <= c.g_w) && (pt->g_h <= c.g_h) ) { stop = w_handle; w_clipdraw(gl_wtop, 0, MAX_DEPTH, 2); moved = TRUE; } /* start at bottom if */ /* a shrink occurred */ if ( (pt->g_w < c.g_w) || (pt->g_h < c.g_h) ) start = DESKWH; /* update rect. is the */ /* union of two sizes */ /* + the drop shadow */ c.g_w = max(pt->g_w, c.g_w) + 2; c.g_h = max(pt->g_h, c.g_h) + 2; } } else { /* move or grow or open */ /* or close */ if ( !(c.g_w && c.g_h) || ( (pt->g_x <= c.g_x) && (pt->g_y <= c.g_y) && (pt->g_x+pt->g_w >= c.g_x+c.g_w) && (pt->g_y+pt->g_h >= c.g_y+c.g_h))) { /* a grow that is a */ /* superset or an open */ rc_copy(pt, &c); } else { /* move, close or shrink*/ /* do a move of top guy */ if ( (pt->g_w == c.g_w) && (pt->g_h == c.g_h) && (gl_wtop == w_handle) ) { moved = w_move(w_handle, &stop, &c); start = DESKWH; } /* check for a close */ if ( !(pt->g_w && pt->g_h) ) start = DESKWH; /* handle other moves */ /* and shrinks */ if ( start != DESKWH ) { rc_union(pt, &c); if ( !rc_equal(pt, &c) ) start = DESKWH; } } } /* update gl_wtop */ /* after close, */ /* or open */ if ( oldtop != W_TREE[ROOT].ob_tail ) { if (gl_wtop != NIL) { /* open or close with */ /* other windows open */ w_getsize(WS_CURR, gl_wtop, pt); rc_union(pt, &c); /* if it was an open */ /* then draw the */ /* old top guy */ /* covered */ if ( (oldtop != NIL ) && (oldtop != w_handle) ) { /* BUGFIX 2/20/86 LKW */ /* only an open if prev */ /* size was zero. */ w_getsize(WS_PREV, gl_wtop, &pprev); if (rc_equal(&pprev, &gl_rzero)) w_clipdraw(oldtop, 0, MAX_DEPTH, 2); /* */ } } } c.g_w += 2; /* account for drop shadow*/ c.g_h += 2; /* BUGFIX in 2.1 */ /* update the desktop */ /* background */ if (start == DESKWH) w_drawdesk(&c); /* start the redrawing */ w_update(start, &c, stop, moved, TRUE); }