int main() { std_setup(); int N = 300; grid2D<> u( N, 0, 1, N, 0, 1 ); plot2D plt( 0,1,0,1, N, N); plt = ml_white; ml_random rng; int count = 0; for (int k=0; k<100000; k++) { cout << k << endl; plt = ml_white; double x1 = rng.gen_double(); double x2 = rng.gen_double(); double x3 = rng.gen_double(); double x4 = rng.gen_double(); double y1 = rng.gen_double(); double y2 = rng.gen_double(); double y3 = rng.gen_double(); double y4 = rng.gen_double(); double x,y; int res = intersection( x,y, x1, y1, x2, y2, x3, y3, x4, y4 ); bool straddle = straddle_test( x1,x2,x3,x4,y1,y2,y3,y4 ); plt.ptDot( x,y, 5, ml_green ); if ( ( straddle and res == 1 ) or ( !straddle and res == 0 ) ) { plt.ptLine( x1,y1,x2,y2, ml_black ); plt.ptLine( x3,y3,x4,y4, ml_black ); // sprintf(fname, "/workspace/output/SDE/project1/test/%04d.png", k ); // plt.png(fname); count ++; } } cout << count << endl; std_exit(); }
int main() { std_setup(); grid2D<> G1; grid2D<> G2; /*sprintf(fname,"/workspace/output/anisotropic_propagate_2d/out_dat/C2.dat" ); readFile(G,fname); sprintf(fname,"/workspace/output/anisotropic_propagate_2d/out_png/C2.png" ); plotGrid2D_1(G,fname,cmap);*/ for( int n = 0; n<9000; n+=1) { sprintf(fname,"/workspace/output/elastic_propagate_2d/out_dat/u1_%05d.dat" ,n); cout << fname << endl; if ( readFile(G1,fname) ) break; sprintf(fname,"/workspace/output/elastic_propagate_2d/out_dat/u2_%05d.dat" ,n); cout << fname << endl; if ( readFile(G2,fname) ) break; sprintf(fname,"/workspace/output/elastic_propagate_2d/out_png/%05d.png" ,n); plot( fname, G1, G2, cmap ); } }
int main() { std_setup(); if (0) { plot2D plot(-4.0,4.0,-4.0,4.0, 600,600 ); plot = c3_creme; plot.axes_1(0,0, 1, c3_creme,c3_black,plot2D_stdFormat,c3_black, 10,10,1,10 ); // plot.plot( plot_schauder ,c3_blue); sprintf(fname,"%s/out/out.png",pwd); plot.png(fname); } double stop_time = 1.0; int j = 3; for (j=0; j<=7; j++) { int k_max = stop_time*(1 << j); int n_steps = 400; double W[n_steps]; double t[n_steps]; /* ml_random rng; for (int step = 0; step<n_steps; step++) { t[step] = (stop_time*step)/n_steps; double sum = 0; for (int k=0; k<=k_max; k++) sum += N_RV(rng.gen_double())*phi(t[step],k,j); W[step] = sum; } */ plot2D plot(-0.1,stop_time*1.1,-10,10, 900,600 ); plot = c3_creme; plot.axes_1(0,-7, 1, c3_creme,c3_black,plot2D_stdFormat,c3_black, 0.1,10,1,10 ); //plot.plot<double, double >(&(t[0]),&(W[0]),n_steps ,c3_black); sprintf(fname,"%s/out/.png",pwd,j); plot.png(fname); } }
int main() { std_setup(); int N = 12; double X0 = 10; int n1 = 256; int n2 = n1; rgrid2D grid( n1, -X0, X0, n2, -X0, X0 ); rgrid2D * AN = new rgrid2D [N+1]; for (int k=0; k<=N; k++ ) AN[k] = grid; rgrid2D * NU = new rgrid2D [N+1]; for (int k=0; k<=N; k++ ) NU[k] = grid; // laplacian_2d_fd Del2; // Del2.init( grid.n1, grid.n2, grid.b1-grid.a1, grid.b2-grid.a2, 24, 24 ); double gamma = 0.4; int m = 12; laplacian_2d_hdaf Del2; Del2.init( grid.n1, grid.n2, grid.b1-grid.a1, grid.b2-grid.a2, m, m, gamma, gamma ); for (int k=0; k<=N; k++ ) AN[k] = gauss(k); NU[0] = AN[0]; for (int k=1; k<=N; k++ ) Del2.execute( NU[k-1].array, NU[k].array ); double * x = ml_alloc<double> (N); double * y = ml_alloc<double> (N); for (int k=1; k<=N; k++ ) { y[k-1] = log10(l2_error( AN[k].array, NU[k].array, n1, n2 )); x[k-1] = k; if (k >1 ) cout << k << "\t" << y[k-1] << "\t" << y[k-1]-y[k-2] << endl; else cout << k << "\t" << y[k-1] << endl; sprintf(fname, "/workspace/output/temp/numeric_%02d.png", k ); plotGrid2D_1( NU[k], fname,cmap); sprintf(fname, "/workspace/output/temp/analytic_%02d.png", k ); plotGrid2D_1( AN[k], fname,cmap); } double slope, wefqewf; ml_slope( x, y, N, slope, wefqewf ); cout << slope << endl; }
int main( int argc, char **argv ) { #ifdef HAVE_PSAP_H PE pe; PS psin, psout, pserr; /* read the pe from standard in */ if ( (psin = ps_alloc( std_open )) == NULLPS ) { perror( "ps_alloc" ); exit( EXIT_FAILURE ); } if ( std_setup( psin, stdin ) == NOTOK ) { perror( "std_setup" ); exit( EXIT_FAILURE ); } /* write the pe to standard out */ if ( (psout = ps_alloc( std_open )) == NULLPS ) { perror( "ps_alloc" ); exit( EXIT_FAILURE ); } if ( std_setup( psout, stdout ) == NOTOK ) { perror( "std_setup" ); exit( EXIT_FAILURE ); } /* pretty print it to standard error */ if ( (pserr = ps_alloc( std_open )) == NULLPS ) { perror( "ps_alloc" ); exit( EXIT_FAILURE ); } if ( std_setup( pserr, stderr ) == NOTOK ) { perror( "std_setup" ); exit( EXIT_FAILURE ); } while ( (pe = ps2pe( psin )) != NULLPE ) { pe2pl( pserr, pe ); pe2ps( psout, pe ); } exit( EXIT_SUCCESS ); #else fprintf(stderr, "requires ISODE X.500 distribution.\n"); return( EXIT_FAILURE ); #endif }
int main() { std_setup(); int n = 256; double x0 = ml_pi; double tf = 1.0; double dt = 0.1; grid2D<double,double,double > grid( n,-x0,x0, n,-x0,x0 ),u,v,C2,damp; grid = 0.0; u = grid; v = grid; C2 = grid; C2 = 1.0; u = u_0_func(); sprintf(fname,"/workspace/output/acoustic_propagate_2d/out_dat/C2.dat", n); writeFile(C2,fname); linear_propagator P; P.init( grid, 1, C2 ); double t = 0.0; while (t <= tf) { output(t,u,v); double t1 = get_real_time(); P( dt, u,v,u,v ); double t2 = get_real_time(); cout << t << "\t" << t2-t1 << endl; t += dt; } output(t,u,v); }
int main() { std_setup(); grid2D<> G; sprintf(fname,"/workspace/output/acoustic_propagate_2d/out_dat/C2.dat" ); readFile(G,fname); sprintf(fname,"/workspace/output/acoustic_propagate_2d/out_dat/C2.png" ); plotGrid2D_1(G,fname,cmap); for( int n = 0; n<9000; n+=1) { sprintf(fname,"/workspace/output/acoustic_propagate_2d/out_dat/u_%05d.dat" ,n); cout << fname << endl; if ( readFile(G,fname) ) break; sprintf(fname,"/workspace/output/acoustic_propagate_2d/out_png/%05d.png" ,n); plotGrid2D_1(G,fname,cmap); } }
int main() { std_setup(); ml_random rng; { // output analytic solution grid2D<double, double > F1( 500, -10.0, 10.0, 500, -10.0, 10.0 ); grid2D<double, double > F2( F1 ); grid2D<double, double > G1( F1 ); grid2D<double, double > G2( F1 ); F1 = V_1; F2 = V_2; laplacian_2d_hdaf Del2; Del2.init( F1.n1, F1.n2, F1.b1-F1.a1, F1.b2-F1.a2, 24, 24, .5, .5 ); Del2.execute( F1.array, G1.array ); Del2.execute( F2.array, G2.array ); plotGrid2D_1( F1, "/workspace/output/scratch/F1.png", color_map_green ); plotGrid2D_1( F2, "/workspace/output/scratch/F2.png", color_map_green ); plotGrid2D_1( G1, "/workspace/output/scratch/G1.png", color_map_error ); plotGrid2D_1( G2, "/workspace/output/scratch/G2.png", color_map_error ); } std_exit(); }
int main() { std_setup(); double T0; int tres=0; tres = 1.0/get_time_resolution(); T0=get_real_time(); cout << tres << endl; pthread_t pth; char args[100]; *(double*)args =T0; *(int*)(args+8)=tres; pthread_create( &pth, NULL, threadFunc, (void*)args ); pthread_join(pth, NULL); for (int k=0; k<100; k++) { cout << "m\t" << (get_real_time()-T0)*tres << endl; } std_exit(); }
main() { struct passwd *pw_entry ; struct passwd *getpwuid() ; struct stat buf ; int i = 1 ; int uid ; int um ; char pass1[LINESIZE] ; char pass2[LINESIZE] ; char Read_in_Stuff[LINESIZE] ; char **vecptr ; char *tmpdraft ; char home_dir[LINESIZE] ; char *p, *part1, *part2 ; char quipurc_file[100] ; char tailor_file[100] ; char user_name[9] ; char *localptr = Local ; char print_format = EDBOUT ; EntryInfo *ptr ; static CommonArgs ca = default_common_args; vecptr = (char **) malloc(100) ; vecptr[0] = malloc (LINESIZE) ; (void) strcpy(vecptr[0], "showentry") ; (void) strcpy(pass1, "x") ; (void) strcpy(pass2, "y") ; tmpdraft = malloc (LINESIZE) ; (void) strcpy(tmpdraft, "/tmp/dish-") ; if ((opt = ps_alloc (std_open)) == NULLPS) fatal (-62, "ps_alloc failed"); if (std_setup (opt, stderr) == NOTOK) fatal (-63, "std_setup failed"); if ((rps = ps_alloc (std_open)) == NULLPS) fatal (-64, "ps_alloc 2 failed"); if (std_setup (rps, stdout) == NOTOK) fatal (-65, "std_setup 2 failed"); (void) strcpy(filterstring, "userid=") ; /* Sort out files, userids etc. */ uid=getuid() ; if ((pw_entry=getpwuid(uid)) == 0) { ps_printf(rps, "Who are you? (no name for your uid number)\n") ; exit(1) ; } (void) strcpy(user_name, pw_entry->pw_name) ; (void) strcat(tmpdraft, user_name) ; if (getenv("HOME") == 0) { ps_printf(rps, "No home directory?!!") ; (void) strcpy(home_dir, pw_entry->pw_dir) ; } else { (void) strcpy(home_dir, getenv("HOME")) ; } (void) strcpy(quipurc_file, home_dir) ; (void) strcat(quipurc_file, "/.quipurc") ; (void) strcpy(tailor_file, isodefile ("dishinit", 1)); Manager[0] = 0; Password[0] = 0; Local[0] = 0; (void) stat(tailor_file, &buf) ; (void) seteuid(buf.st_uid) ; /* set effective to enable */ /* us to read protected file */ if ((fp_tailor = fopen(tailor_file, "r")) == 0) { ps_print(rps, "Can't open Tailor File. Abort.\n") ; exit(1) ; } while (fgets (Read_in_Stuff, LINESIZE, fp_tailor) != 0) { if (!strcmp(Read_in_Stuff, "##Anything after this line is copied into the users ~/.quipurc file\n")) { break ; } p = SkipSpace (Read_in_Stuff); if (( *p == '#') || (*p == '\0')) continue; /* ignore comments and blanks */ part1 = p; if ((part2 = index (p,':')) == NULLCP) { ps_printf (opt,"Seperator missing '%s'. Ignoring..\n",p); } *part2++ = '\0'; part2 = TidyString (part2); if (lexequ(part1, "manager") == 0) { (void) strcpy(Manager, part2) ; } else if (lexequ(part1, "password") == 0) { (void) strcpy(Password, part2) ; } else if (lexequ(part1, "local") == 0) { (void) strcpy(Local, part2) ; } else { ps_printf(rps, "Error in tailor. What's a %s?\n", part1) ; } } (void) setuid(uid) ; /* Restore Userid to original user. */ /* create ~/.quipurc file. NB this does eradicate anything in there. * (Theoretically nothing.) */ if (Manager[0] == 0) { ps_print(rps, "Can't find out the managers name\n") ; exit(1) ; } if (Password[0] == 0) { ps_print(rps, "Can't find out the managers password\n") ; exit(1) ; } if (Local[0] == 0) { ps_print(rps, "Can't find out where to search\n") ; exit(1) ; } um = umask(0177) ; if ((fp_quipurc = fopen(quipurc_file, "w")) == 0) { ps_printf(rps, "Can't open ~/.quipurc. Aborting..\n") ; exit(1) ; } (void) umask(um) ; if ((fileps = ps_alloc(std_open)) == NULLPS) { fatal (-66, "ps_alloc 2 failed"); } if (std_setup (fileps, fp_quipurc) == NOTOK) { fatal (-67, "std_setup 2 failed"); } /* Sorting out the bind section */ quipu_syntaxes() ; /* set up the needed function pointers */ dsap_init(&i, &vecptr) ; (void) strcpy(bindarg.dba_passwd, Password) ; bindarg.dba_version = DBA_VERSION_V1988; bindarg.dba_passwd_len = strlen(bindarg.dba_passwd) ; if ((bindarg.dba_dn = str2dn (Manager)) == NULLDN) { ps_printf (opt,"Invalid Manager name %s (???!)\n",Manager) ; exit(1) ; } if (ds_bind (&bindarg, &binderr, &bindresult) != OK) { ps_printf(rps, "Can't bind as the manager.\n") ; exit(1); } /* Hopefully, should be successfully bound */ /* * We now call the search stuff with the right bits, to see if we can get a * match of uid='user_name'. Once there, we echo lots of information from * their entry out to the .quipurc file. * Hopefully there should only be one match. This assumes that ALL dir info * up to date, and that SG do not allow multiple users with the same login. */ /* set up the appropriate structures and defaults. */ search_arg.sra_common = ca; /* struct copy */ search_arg.sra_common.ca_servicecontrol.svc_sizelimit = 2 ; search_arg.sra_eis.eis_allattributes = FALSE ; search_arg.sra_searchaliases = FALSE; search_arg.sra_subset = SRA_ONELEVEL; search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES ; search_arg.sra_eis.eis_select = NULLATTR ; search_arg.sra_eis.eis_allattributes = TRUE ; search_arg.sra_filter = filter_alloc() ; /* Default filter. */ search_arg.sra_filter->flt_next = NULLFILTER; search_arg.sra_filter->flt_type = FILTER_ITEM; search_arg.sra_filter->FUFILT = NULLFILTER; if (*localptr == '@') { localptr++; } if ((search_arg.sra_baseobject = str2dn(localptr)) == NULLDN) { ps_printf (opt,"Invalid sequence in username %s.\n", localptr); exit(1) ; } (void) strcat(filterstring, user_name) ; search_arg.sra_filter->flt_un.flt_un_item.fi_type = FILTERITEM_EQUALITY ; if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type = AttrT_new ("userid")) == NULLAttrT) { ps_printf(rps, "Oops, userid is not a valid attr type. ABORT!!\n") ; exit(1) ; } if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_value = str2AttrV (user_name, search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type->oa_syntax)) == NULLAttrV) { ps_printf(rps, "%s is not a valid attribute value.\n", user_name) ; } /* call search */ /* We now ought to be in the right place, and with the search stuff set, * ready to call search, and receive one (or no) entry back, which then * gets processed accordingly. */ if (ds_search (&search_arg, &search_error, &search_result) != DS_OK) { ps_printf(rps, "Search failed...\n") ; exit (1) ; /* This is not the same as coming back with */ /* message "search failed to find anything. */ } /* If the user does not exist in the DIT, print out the limited .quipurc * and the warning message, and allow the user to play DISH. */ if (search_result.CSR_entries == NULLENTRYINFO) { ps_printf(opt, "Unfortunately, you seem to have no entry in\n") ; ps_printf(opt, "the directory. Contact '%s' who should be able to help.\n", Manager) ; ps_printf(opt, "In the mean time, you can read, but not write.\n") ; } else { ptr = search_result.CSR_entries ; dn = dn_cpy(ptr->ent_dn) ; /* Essence of move user_name. */ /* collect the info and put it into current_entry */ /* Set up the desired attribute type to be read*/ /* from read.c */ if ((at = AttrT_new ("userPassword")) != NULLAttrT) { as_flag = as_merge (as_flag, as_comp_new (AttrT_cpy (at), NULLAV, NULLACL_INFO)); } else { ps_printf(rps, "Oops, Serious error. unknown attribute type 'userPassword'.\n") ; exit(1) ; } if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY) { read_arg.rda_common = ca; /* struct copy */ read_arg.rda_object = dn; read_arg.rda_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES; read_arg.rda_eis.eis_allattributes = TRUE ; read_arg.rda_eis.eis_select = NULLATTR ; if (ds_read (&read_arg, &read_error, &read_result) != DS_OK) { ps_printf(rps, "We even seem to be having problems reading\n" ) ; ps_printf(rps, "an entry we searched and found!! HELP!!\n") ; exit(1) ; } if (read_result.rdr_entry.ent_attr == NULLATTR) { ps_printf(rps, "No attributes present. Even though\n") ; ps_printf(rps, "we found you by userid attribute!!! HELP!!\n") ; exit (1) ; } cache_entry (&(read_result.rdr_entry), read_arg.rda_eis.eis_allattributes, TRUE) ; } if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY) { ps_printf(rps, "We still have nothing.Even after reading? Abort.\n") ; exit(1) ; } ps_printf(fileps, "username: "******"\n") ; ps_printf(fileps, "me: ") ; dn_print(fileps, dn, EDBOUT) ; ps_printf(fileps, "\n") ; /* now showattribute -nokey to display it. */ ps_printf(fileps, "password: "******"You need a password...\n") ; (void) strcpy(pass1, getpassword("Enter Password: "******"Re-enter password: "******"\nMismatch - Try again.\n") ; } } ps_printf(fileps, "%s\n", pass1) ; um = umask(0177) ; if ((fp_draft = fopen(tmpdraft, "w")) == 0) { ps_print(rps, "Can't open draft file... Abort.\n") ; exit(1) ; } (void) umask(um) ; (void) fprintf(fp_draft, "UserPassword = %s\n", pass1) ; (void) fprintf(fp_draft, "acl = self # write # attributes # acl $ userPassword\n") ; (void) fprintf(fp_draft, "acl = others # compare # attributes # acl $ userPassword\n\n") ; (void) fclose(fp_draft) ; if ((fp_draft = fopen (tmpdraft, "r")) == NULL) { ps_printf (opt, "Can't open draft entry %s\n", tmpdraft); exit(1) ; } entry_ptr = get_default_entry (NULLENTRY); #ifdef TURBO_DISK entry_ptr->e_attributes = fget_attributes (fp_draft); #else entry_ptr->e_attributes = get_attributes (fp_draft); #endif (void) fclose (fp_draft); mod_arg.mea_common = ca; /* struct copy */ mod_arg.mea_object = dn; for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent) ; entry_ptr->e_name = rdn_cpy (moddn->dn_rdn); /* add rdn as attribute */ avst = avs_comp_new (AttrV_cpy (&entry_ptr->e_name->rdn_av)); temp = as_comp_new (AttrT_cpy (entry_ptr->e_name->rdn_at), avst, NULLACL_INFO); entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp); for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; trail = as->attr_link; as->attr_link = NULLATTR; temp = current_entry->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) { /* found it - does it need changing ? */ if (avs_cmp (as->attr_value, temp->attr_value) != 0) emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type); break; } if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_ADDATTRIBUTE; emnew->em_what = as_cpy(as); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) { mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); } as->attr_link = trail; } while (ds_modifyentry (&mod_arg, &mod_error) != DS_OK) { if (dish_error (opt, &mod_error) == 0) { ps_printf(rps,"We have a dish error. Bye.\n") ; entry_free (entry_ptr); exit(1) ; } mod_arg.mea_object = mod_error.ERR_REFERRAL.DSE_ref_candidates->cr_name; } ps_print (rps, "Modified "); dn_print (rps, dn, EDBOUT); ps_print (rps, "\n"); delete_cache (dn); /* re-cache when next read */ entry_free (entry_ptr); ems_part_free (mod_arg.mea_changes); } } while(fgets(Read_in_Stuff, LINESIZE, fp_tailor) != 0) { fputs(Read_in_Stuff, fp_quipurc) ; } (void) fclose(fp_quipurc) ; (void) fclose(fp_tailor) ; /* (void) fprintf(fp_quipurc, "dsap: local_dit \"%s\"\n", Local) ; (void) fprintf(fp_quipurc, "notype: acl\n") ; (void) fprintf(fp_quipurc, "notype: treestructure\n") ; (void) fprintf(fp_quipurc, "notype: masterdsa\n") ; (void) fprintf(fp_quipurc, "notype: slavedsa\n") ; (void) fprintf(fp_quipurc, "notype: objectclass\n") ; (void) fprintf(fp_quipurc, "cache_time: 30\n") ; (void) fprintf(fp_quipurc, "connect_time: 2\n") ; */ (void) ds_unbind() ; (void) unlink(tmpdraft) ; }
int main() { std_setup(); int n_runs = 1E5; int n_steps = 30; int **M=0; walk_test(M,n_steps,n_runs); for ( int k=1; k<n_steps; k++ ) cout << k << "\t" << M[k][0] << "\t" << M[k][n_runs-1] << endl; for ( int k=1; k<n_steps; k++ ) { int max_ = max(M[k], n_runs ); int min_ = min(M[k], n_runs ); int n = abs(max_) + abs(min_) + 1; if ( max_>1 && min_<-1 ) { int * c_ = ml_alloc<int > ( n ); int *c = &c_[ -min_ ]; for (int j=min_; j<=max_; j++) c[j] = 0; for (int j=0; j<n_runs; j++) c[ M[k][j] ] ++; float * p_ = ml_alloc<float > ( n ); float * p = &p_[ -min_ ]; for (int j=min_; j<=max_; j++) p[j] = ((float)c[j])/n_runs; float mu = 0; for (int j=min_; j<=max_; j++) mu += p[k]*j; float sig2 = 0; for (int j=min_; j<=max_; j++) sig2 += p[k]*j*j; sig2 -= mu*mu; float sig = sqrt(sig2); clean_print(k); cout << "\t"; clean_print(mu); cout << "\t"; clean_print(sig); cout << "\t"; clean_print(sig2); cout << endl; sprintf(fname, "/workspace/output/out_%d", k); output( p_ , n, fname ); p=0; ml_free(p_); ml_free(c_); } } std_exit(); }
int main() { std_setup(); // setup: int n_steps = 500; int n_runs = 10000; double X0 = 0.0; double stop_time = 2.0; double dt = stop_time/n_steps; double * time = ml_alloc<double > ( n_steps ); for (int k=0; k<n_steps; k++ ) time[k] = dt*k; double **W=0, *X_true=0; double **X = ml_alloc<double> ( n_runs, n_steps ); double * X_mean = ml_alloc<double> (n_steps); double **M = ml_alloc<double> ( n_runs, n_steps ); // generate the BMs: gen_BM( dt, n_steps, W, n_runs, BM_mode_2 ); // integrate the SDE for ( int run=0; run<n_runs; run++ ) { X[run][0] = X0; for ( int j=1; j<n_steps; j++ ) { X[run][j] = X[run][j-1] + ( drift(dt*j) + drift(dt*(j-1)) )*dt/2 + volatility(X[run][j-1], dt*(j-1))*(W[run][j]-W[run][j-1]); } } // compute the Girsanov change of measure at every t for ( int run=0; run<n_runs; run++ ) for ( int k=0; k<n_steps-1; k++ ) { double sum1 = 0; for (int j=0; j<=k; j++) sum1 += drift(dt*j)*drift(dt*j)*dt; double sum2 = 0; for (int j=0; j<=k; j++) sum2 += drift(dt*j)*(W[run][j+1]-W[run][j]); M[run][k] = exp(-sum2 -0.5*sum1); } // compute expectation of X, output results so far. for ( int step=0; step<n_steps; step++ ) X_mean[step] = 0; for ( int run=0; run<n_runs; run++ ) for ( int step=0; step<n_steps; step++ ) X_mean[step] += X[run][step]/n_runs; output( X, max(n_runs,min(100,n_runs)), n_steps, "/workspace/output/SDE/test/X" ); output( X_mean, n_steps, "/workspace/output/SDE/test/X_mean" ); output( time, n_steps, "/workspace/output/SDE/test/time" ); output( M, max(n_runs,min(100,n_runs)), n_steps, "/workspace/output/SDE/test/M" ); // compute expectation of X, with respect to new measure, output results. for ( int run=0; run<n_runs; run++ ) for ( int step=0; step<n_steps; step++ ) X[run][step] *= M[run][step]; for ( int step=0; step<n_steps; step++ ) X_mean[step] = 0; for ( int run=0; run<n_runs; run++ ) for ( int step=0; step<n_steps; step++ ) X_mean[step] += X[run][step]/n_runs; output( X, max(n_runs,min(100,n_runs)), n_steps, "/workspace/output/SDE/test/XM" ); output( X_mean, n_steps, "/workspace/output/SDE/test/QX" ); ml_free( X, n_runs ); ml_free( X_mean ); ml_free( W, n_runs ); ml_free( time ); ml_free( X_mean ); std_exit(); }
int main() { std_setup(); int n=6; double a=1.0; transform_args args( a,n,0 ); { double xi_f = 10.0; int N = 500; double h = xi_f/N; double *rp = ml_alloc<double> (2*N+1); double *ip = ml_alloc<double> (2*N+1); double *xi = ml_alloc<double> (2*N+1); for ( int j=-N; j<=N; j++ ) { args.xi = h*j; xi[j+N] = args.xi; rp[j+N] = integrate_R ( real_part, (void *)(&args) ); ip[j+N] = integrate_R ( imag_part, (void *)(&args) ); } output( xi, rp, ip, 2*N+1, "/workspace/output/temp/FTF" ); } //--------------------- { double xf = 10.0; int N = 500; double h = xf/N; double *F = ml_alloc<double> (2*N+1); double *X = ml_alloc<double> (2*N+1); for ( int j=-N; j<=N; j++ ) { double x = h*j; X[j+N] = x; F[j+N] = exp(-a*x*x)*pow(x,n); } output( X, F, 2*N+1, "/workspace/output/temp/F" ); } //----------------------- { double xi_f = 10.0; int N = 500; double h = xi_f/N; double *FTR = ml_alloc<double> (2*N+1); double *FTI = ml_alloc<double> (2*N+1); double *Xi = ml_alloc<double> (2*N+1); ml_poly<double > P0(n); P0 = 0.0; ml_poly<double > P1(n); P1 = 0.0; ml_poly<double > P2(n); P2 = 0.0; ml_poly<double > P3(n); P3 = 0.0; for ( int k=0; k<=n; k++ ) { if (k%4 == 0) P0[k] = binom(n,k)*dfact2n_n[n-k]*sqrtpi*pow(a,-n)*pow(2.0,k-2*n); if (k%4 == 1) P1[k] = binom(n,k)*dfact2n_n[n-k]*sqrtpi*pow(a,-n)*pow(2.0,k-2*n); if (k%4 == 2) P2[k] = binom(n,k)*dfact2n_n[n-k]*sqrtpi*pow(a,-n)*pow(2.0,k-2*n); if (k%4 == 3) P3[k] = binom(n,k)*dfact2n_n[n-k]*sqrtpi*pow(a,-n)*pow(2.0,k-2*n); } ml_poly<double > PR(n); P0 = 0.0; ml_poly<double > PI(n); P1 = 0.0; PR = P0; PR -= P2; PI = P1; PI-= P3; for ( int j=-N; j<=N; j++ ) { double xi = h*j; Xi[j+N] = xi; FTR[j+N] = exp(-xi*xi/(a*4))*PR(xi); FTI[j+N] = exp(-xi*xi/(a*4))*PI(xi); } output( Xi, FTR, FTI, 2*N+1, "/workspace/output/temp/test" ); } std_exit(); }
int main() { std_setup(); int n = 256; double x0 = 10; double tf = 10.0; double dt = 0.05; int expansion_order = 7; int hdaf_order = 8; grid2D<double,double,double > grid( n,-10,10.0, n,-10,10.0 ),u,v,C2,damping; grid = 0.0; u = grid; v = grid; C2 = grid; damping = grid; u = u_0_func(); C2 = C2_func(); damping = damping_func(); sprintf(fname,"/workspace/output/acoustic_propagate_2d/out_dat/C2.dat" ); writeFile(C2,fname); void * pdata = 0; method1_init( &pdata, grid.n1, grid.n2, grid.dx1(), grid.dx2(), C2.array, damping.array, 7, hdaf_order, hdaf_order, 0.8, 0.8 ); //acoustic_propagator P; //P.init( grid, 7, C2, damping ); double t = 0.0; cout << "step: " << t << "\t" << L2norm(u) << endl; n=0; double * b_times = new double [ int(tf/dt+5) ]; while (t <= tf) { output(t,u,v); double t1 = get_real_time(); method1_execute( pdata, dt, u.array,v.array,u.array,v.array ); //P( dt, u,v,u,v ); double t2 = get_real_time(); b_times[n] = t2-t1; double mean = 0; for (int j=0; j<n; j++) mean += b_times[j]/n; cout << mean << endl; n++; double mag = L2norm(u); cout << "step: " << t << "\t" << t2-t1 << "\t" << mag << endl; t += dt; if ( mag > 1E10 ) break; } output(t,u,v); }
int main() { std_setup(); mp::mp_init(100); int n = pow(2,12); double a = 0.0; double b = ml_2pi; int m = 4; double gamma = 0.75; vector<double > frequency; vector<double > error; vector<double > measured_response; vector<double > response; vector<double > expected_error; for (int k=1; k<=n/2; k += max(n/100,1) ) { double K = (ml_2pi/(b-a))*k; double * signal = ml_alloc<double > (n); for (int i=0; i<n; i++) { double x = ((b-a)*i)/n+a; signal[i] = cos( x*K ); } complex<double > * fft_ker=0; hdaf_filter_kernel ( fft_ker, b-a, n, m, (ml_2pi/(b-a))*(gamma*n/2) ); double * signal_filtered=0; complex<double > * workspace=0; fft( signal, workspace, n ); for (int i=0; i<n/2+1; i++) workspace[i] *= fft_ker[i]; ifft( workspace, signal_filtered, n ); //--------------- cout << K << "\t" << l2_error( signal, signal_filtered, n ) << endl; hdaf_delta_hat delta( m, sqrt(2*m+1)/( (ml_2pi/(b-a))*(gamma*n/2) ) ); frequency.push_back( K ); measured_response.push_back( rms(signal_filtered,n)/rms(signal,n ) ); response.push_back ( delta(K) ); expected_error.push_back ( log10( fabs(delta(K)-1.0)+1E-18 ) ); error.push_back( log10(fabs(l2_error( signal, signal_filtered, n )) +1E-18) ); ml_free(fft_ker); ml_free(signal); } sprintf( fname, "/workspace/output/temp/frequency" ); output ( frequency, fname ); sprintf( fname, "/workspace/output/temp/measured_response" ); output ( measured_response, fname ); sprintf( fname, "/workspace/output/temp/error" ); output ( error, fname ); sprintf( fname, "/workspace/output/temp/expected_error" ); output ( expected_error, fname ); sprintf( fname, "/workspace/output/temp/response" ); output ( response, fname ); std_exit(); }
int main() { std_setup(); int n_steps = 500; int n_runs = 1000; double X0 = 0.0; double stop_time = 2.0; double dt = stop_time/n_steps; double * time = ml_alloc<double > ( n_steps ); for (int k=0; k<n_steps; k++ ) time[k] = dt*k; double **W=0, *X_true=0; double **X = ml_alloc<double> ( n_runs, n_steps ); double * X_mean = ml_alloc<double> (n_steps); double **M = ml_alloc<double> ( n_runs, n_steps ); gen_BM( dt, n_steps, W, n_runs, BM_mode_2 ); for ( int run=0; run<n_runs; run++ ) for ( int k=0; k<n_steps-1; k++ ) { double sum1 = 0; for (int j=0; j<=k; j++) sum1 += drift(dt*j)*drift(dt*j)*dt; double sum2 = 0; for (int j=0; j<=k; j++) sum2 += drift(dt*j)*(W[run][j+1]-W[run][j]); M[run][k] = exp(-sum2 -0.5*sum1); } for ( int run=0; run<n_runs; run++ ) { X[run][0] = X0; for ( int j=1; j<n_steps; j++ ) { X[run][j] = X[run][j-1] + ( drift(dt*j) + drift(dt*(j-1)) )*dt/2 + volatility(X[run][j-1], dt*(j-1))*(W[run][j]-W[run][j-1]); } } for ( int step=0; step<n_steps; step++ ) X_mean[step] = 0; for ( int run=0; run<n_runs; run++ ) for ( int step=0; step<n_steps; step++ ) X_mean[step] += X[run][step]/n_runs; output( X, max(n_runs,min(100,n_runs)), n_steps, "/workspace/output/SDE/test/X" ); output( X_mean, n_steps, "/workspace/output/SDE/test/X_mean" ); output( time, n_steps, "/workspace/output/SDE/test/time" ); output( M, max(n_runs,min(100,n_runs)), n_steps, "/workspace/output/SDE/test/M" ); for ( int run=0; run<n_runs; run++ ) for ( int step=0; step<n_steps; step++ ) X[run][step] *= M[run][step]; for ( int step=0; step<n_steps; step++ ) X_mean[step] = 0; for ( int run=0; run<n_runs; run++ ) for ( int step=0; step<n_steps; step++ ) X_mean[step] += X[run][step]/n_runs; output( X, max(n_runs,min(100,n_runs)), n_steps, "/workspace/output/SDE/test/XM" ); output( X_mean, n_steps, "/workspace/output/SDE/test/QX" ); ml_free( X, n_runs ); ml_free( X_mean ); ml_free( W, n_runs ); ml_free( time ); ml_free( X_mean ); std_exit(); }
int main( int argc, char *argv[] ) { //for (int k=1; k<argc; k++ ) // cout << argv[k] << endl; std_setup(); // setup: int n_steps = 100; int n_runs = 100; double X0 = 0.0; double stop_time = 2.0; double * drift=0; char dir[] = "/workspace/output/SDE/test"; { // n_runs if(argc>=2) try { n_runs = boost::lexical_cast< int >( argv[1] ); } catch (const boost::bad_lexical_cast &) { } // n_steps if(argc>=3) try { n_steps = boost::lexical_cast< int >( argv[2] ); } catch (const boost::bad_lexical_cast &) { } // X0 if(argc>=4) try { X0 = boost::lexical_cast< double >( argv[3] ); } catch (const boost::bad_lexical_cast &) { } // stop_time if(argc>=4) try { stop_time = boost::lexical_cast< double >( argv[4] ); } catch (const boost::bad_lexical_cast &) { } // drift if(argc>=6) { ifstream in; sprintf(fname,"%s/%s", dir, argv[5]); in.open(fname, ios::in); if ( in.good() && in.is_open() ); { drift = ml_alloc<double> (n_steps); for (int k=0; k<n_steps; k++) drift[k] = 0.0; char str[200]; int k=0; while ( in>>str and k<n_steps ) { try { drift[k] = boost::lexical_cast< double >( str ); } catch (const boost::bad_lexical_cast &) { } k++; } in.close(); } } }