/* * Write the record to the storage in case there are write and closes the * record and frees up the stuff. With the pickled buf for each udf_record * it create single pickled buf for the entire LDT to be sent to the remote * for replica. * * Parameter: * lrecord : LDT record to operate on * pickled_* (out) to be populated is null if there was delete * lrecord_op (out) is set properly for the entire ldt * set_id : Set id for record. Passed for delete operation. * * Returns: 0 on success * otherwise on failure */ static int rw_finish(ldt_record *lrecord, write_request *wr, udf_optype * lrecord_op, uint16_t set_id) { int subrec_count = 0; udf_optype h_urecord_op = UDF_OPTYPE_READ; *lrecord_op = UDF_OPTYPE_READ; udf_record *h_urecord = as_rec_source(lrecord->h_urec); bool is_ldt = false; int ret = 0; getop(h_urecord, &h_urecord_op); if (h_urecord_op == UDF_OPTYPE_DELETE) { post_processing(h_urecord, &h_urecord_op, set_id); wr->pickled_buf = NULL; wr->pickled_sz = 0; as_rec_props_clear(&wr->pickled_rec_props); *lrecord_op = UDF_OPTYPE_DELETE; } else { if (h_urecord_op == UDF_OPTYPE_WRITE) { *lrecord_op = UDF_OPTYPE_WRITE; } FOR_EACH_SUBRECORD(i, j, lrecord) { udf_optype c_urecord_op = UDF_OPTYPE_READ; udf_record *c_urecord = &lrecord->chunk[i].slots[j].c_urecord; getop(c_urecord, &c_urecord_op); if (UDF_OP_IS_WRITE(c_urecord_op)) { is_ldt = true; subrec_count++; } post_processing(c_urecord, &c_urecord_op, set_id); } // Process the parent record in the end .. this is to make sure // the lock is held till the end. post_processing(h_urecord, &h_urecord_op, set_id); if (is_ldt) { // Create the multiop pickled buf for thr_rw.c ret = as_ldt_record_pickle(lrecord, &wr->pickled_buf, &wr->pickled_sz); FOR_EACH_SUBRECORD(i, j, lrecord) { udf_record *c_urecord = &lrecord->chunk[i].slots[j].c_urecord; // Cleanup in case pickle code bailed out // 1. either because this single node run no replica // 2. failed to pack stuff up. udf_record_cleanup(c_urecord, true); } } else {
void ds_query_batch() { dc->cout() << "\n1 Start building label system..." << std::endl; build_label(n_tree); for (size_t i = 0; i < n_query; i += n_query_batch) { dc->cout() << "\n2 Perform DS..." << std::endl; dc->cout() << "\t2.0 Reading test cases..." << std::endl; results.resize(dc->numprocs()); inst_set.resize(dc->numprocs()); size_t n_query_to_perform = std::min(n_query_batch, n_query - i * n_query_batch); read_tcs(n_query_to_perform); dc->cout() << "\t2.1 Gather dest codes..." << std::endl; gather_dst(); dc->cout() << "\t2.2 Create gs inst..." << std::endl; create_instances(); dc->cout() << "\t2.3 Start dec search... " << std::endl; start_ds_search(); dc->cout() << "\t2.4 Gathering results..." << std::endl; ds_aggregate_results(); dc->cout() << "\t2.5 Clean containers..." << std::endl; post_processing(); } dc->cout() << "\n3 Writing results to file..." << std::endl; ds_write_results(); dc->cout() << "\nDone." << std::endl; }
void communicator::communicate() { while(true) { //send or recv send_or_recv(); //check_status int any_done=check_status(); //post processing if(any_done!=-1) post_processing(any_done); } }
PyObject * pyCitcom_ic_postProcessing(PyObject *self, PyObject *args) { PyObject *obj; struct All_variables* E; if (!PyArg_ParseTuple(args, "O:postProcessing", &obj)) return NULL; E = (struct All_variables*)(PyCObject_AsVoidPtr(obj)); post_processing(E); Py_INCREF(Py_None); return Py_None; }
int main(int argc, char **argv) { if (argc != 3) { printf("Usage:%s train_file test_file\n",argv[0]); exit(1); } pre_processing(argv[1], argv[2]); create_trees(50); calculate_label(); post_processing(); return(0); }
template <class PathType> inline void LongstaffSchwartzPathPricer<PathType>::calibrate() { const Size n = paths_.size(); Array prices(n), exercise(n); std::vector<StateType> p_state(n); std::vector<Real> p_price(n), p_exercise(n); for (Size i=0; i<n; ++i) { p_state[i] = pathPricer_->state(paths_[i],len_-1); prices[i] = p_price[i] = (*pathPricer_)(paths_[i], len_-1); p_exercise[i] = prices[i]; } post_processing(len_ - 1, p_state, p_price, p_exercise); std::vector<Real> y; std::vector<StateType> x; for (Size i=len_-2; i>0; --i) { y.clear(); x.clear(); //roll back step for (Size j=0; j<n; ++j) { exercise[j]=(*pathPricer_)(paths_[j], i); if (exercise[j]>0.0) { x.push_back(pathPricer_->state(paths_[j], i)); y.push_back(dF_[i]*prices[j]); } } if (v_.size() <= x.size()) { coeff_[i-1] = GeneralLinearLeastSquares(x, y, v_).coefficients(); } else { // if number of itm paths is smaller then the number of // calibration functions then early exercise if exerciseValue > 0 coeff_[i-1] = Array(v_.size(), 0.0); } for (Size j=0, k=0; j<n; ++j) { prices[j]*=dF_[i]; if (exercise[j]>0.0) { Real continuationValue = 0.0; for (Size l=0; l<v_.size(); ++l) { continuationValue += coeff_[i-1][l] * v_[l](x[k]); } if (continuationValue < exercise[j]) { prices[j] = exercise[j]; } ++k; } p_state[j] = pathPricer_->state(paths_[j],i); p_price[j] = prices[j]; p_exercise[j] = exercise[j]; } post_processing(i, p_state, p_price, p_exercise); } // remove calibration paths and release memory std::vector<PathType> empty; paths_.swap(empty); // entering the calculation phase calibrationPhase_ = false; }
/*-------------------------------------------------------------*/ int main(int argc, char *argv[]) { /* check for and handle version tag */ int nargs = handle_version_option (argc, argv, "$Id: mri_gcut.cpp,v 1.14 2011/03/02 00:04:16 nicks Exp $", "$Name: stable5 $"); if (nargs && argc - nargs == 1) { exit (0); } argc -= nargs; Progname = argv[0] ; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; parse_commandline(argc, argv); MRI *mri, *mri2, *mri3, *mri_mask=NULL; mri3 = MRIread(in_filename); if ( mri3 == NULL ) { printf("can't read file %s\nexit!\n", in_filename); exit(0); } mri = MRISeqchangeType(mri3, MRI_UCHAR, 0.0, 0.999, FALSE); mri2 = MRISeqchangeType(mri3, MRI_UCHAR, 0.0, 0.999, FALSE); //MRI* mri4 = MRIread("gcutted.mgz"); if (bNeedMasking == 1) { printf("reading mask...\n"); mri_mask = MRIread(mask_filename); if ( mri_mask == NULL ) { printf("can't read %s, omit -mult option!\n", mask_filename); print_help(); exit(1); } else { if ( mri_mask->width != mri->width || mri_mask->height != mri->height || mri_mask->depth != mri->depth ) { printf("Two masks are of different size, omit -mult option!\n"); print_help(); exit(1); } } } int w = mri->width; int h = mri->height; int d = mri->depth; // -- copy of mri matrix unsigned char ***label; label = new unsigned char**[d]; for (int i = 0; i < d; i++) { label[i] = new unsigned char*[h]; for (int j = 0; j < h; j++) { label[i][j] = new unsigned char[w]; for (int k = 0; k < w; k++) { label[i][j][k] = 0; } } } // -- gcut image int ***im_gcut; im_gcut = new int**[d]; for (int i = 0; i < d; i++) { im_gcut[i] = new int*[h]; for (int j = 0; j < h; j++) { im_gcut[i][j] = new int[w]; for (int k = 0; k < w; k++) { im_gcut[i][j][k] = 0; } } } // -- diluted int ***im_diluteerode; im_diluteerode = new int**[d]; for (int i = 0; i < d; i++) { im_diluteerode[i] = new int*[h]; for (int j = 0; j < h; j++) { im_diluteerode[i][j] = new int[w]; for (int k = 0; k < w; k++) { im_diluteerode[i][j][k] = 0; } } } //int w, h, d; //int x, y, z; double whitemean; if (bNeedPreprocessing == 0) { // pre-processed: 110 intensity voxels are the WM if (LCC_function(mri ->slices, label, mri->width, mri->height, mri->depth, whitemean) == 1) { if ( whitemean < 0 ) { printf("whitemean < 0 error!\n"); exit(0); } } else { whitemean = 110; printf("use voxels with intensity 110 as WM mask\n"); } } else { printf("estimating WM mask\n"); whitemean = pre_processing(mri ->slices, label, mri->width, mri->height, mri->depth); if ( whitemean < 0 ) { printf("whitemean < 0 error!\n"); exit(0); } } double threshold = whitemean * _t; printf("threshold set to: %f*%f=%f\n", whitemean, _t, threshold); for (int z = 0 ; z < mri->depth ; z++) { for (int y = 0 ; y < mri->height ; y++) { for (int x = 0 ; x < mri->width ; x++) { if ( mri->slices[z][y][x] < threshold + 1 ) { mri->slices[z][y][x] = 0; } } }//end of for } //new code int ***foregroundseedwt; int ***backgroundseedwt; matrix_alloc(&foregroundseedwt, d, h, w); matrix_alloc(&backgroundseedwt, d, h, w); double kval = 2.3; graphcut(mri->slices, label, im_gcut, foregroundseedwt, backgroundseedwt, w, h, d, kval, threshold, whitemean); printf("g-cut done!\npost-processing...\n"); //printf("_test: %f\n", _test); post_processing(mri2->slices, mri->slices, threshold, im_gcut, im_diluteerode, w, h, d); printf("post-processing done!\n"); if (bNeedMasking == 1)//masking { printf("masking...\n"); for (int z = 0 ; z < mri_mask->depth ; z++) { for (int y = 0 ; y < mri_mask->height ; y++) { for (int x = 0 ; x < mri_mask->width ; x++) { if ( mri_mask->slices[z][y][x] == 0 ) { im_diluteerode[z][y][x] = 0; } } } } } //if the output might have some problem int numGcut = 0, numMask = 0; double _ratio = 0; int error_Hurestic = 0; if (bNeedMasking == 1)//-110 and masking are both set { for (int z = 0 ; z < mri_mask->depth ; z++) { for (int y = 0 ; y < mri_mask->height ; y++) { for (int x = 0 ; x < mri_mask->width ; x++) { if ( im_diluteerode[z][y][x] != 0 ) { numGcut++; } if ( mri_mask->slices[z][y][x] != 0 ) { numMask++; } } } } _ratio = (double)numGcut / numMask; if (_ratio <= 0.85) { error_Hurestic = 1; } } if (error_Hurestic == 1) { printf("** Gcutted brain is much smaller than the mask!\n"); printf("** Using the mask as the output instead!\n"); //printf("** Gcutted output is written as: 'error_gcutted_sample'\n"); } for (int z = 0 ; z < mri->depth ; z++) { for (int y = 0 ; y < mri->height ; y++) { for (int x = 0 ; x < mri->width ; x++) { if (error_Hurestic == 0) { if ( im_diluteerode[z][y][x] == 0 ) { mri2 ->slices[z][y][x] = 0; } } else { if ( mri_mask->slices[z][y][x] == 0 ) { mri2 ->slices[z][y][x] = 0; } //if( im_diluteerode[z][y][x] == 0 ) //mri ->slices[z][y][x] = 0; } } }//end of for 2 }//end of for 1 MRIwrite(mri2, out_filename); // if user supplied a filename to which to write diffs, then write-out // volume file containing where cuts were made (for debug) if (diff_filename[0] && (error_Hurestic != 1)) { MRI *mri_diff = MRISeqchangeType(mri3, MRI_UCHAR, 0.0, 0.999, FALSE); for (int z = 0 ; z < mri3->depth ; z++) { for (int y = 0 ; y < mri3->height ; y++) { for (int x = 0 ; x < mri3->width ; x++) { if (mri_mask) { mri_diff->slices[z][y][x] = mri2->slices[z][y][x] - mri_mask->slices[z][y][x]; } else { mri_diff->slices[z][y][x] = mri2->slices[z][y][x] - mri3->slices[z][y][x]; } } }//end of for 2 }//end of for 1 MRIwrite(mri_diff, diff_filename); MRIfree(&mri_diff); } if (mri) { MRIfree(&mri); } if (mri2) { MRIfree(&mri2); } if (mri3) { MRIfree(&mri3); } if (mri_mask) { MRIfree(&mri_mask); } for (int i = 0; i < d; i++) { for (int j = 0; j < h; j++) { delete[] im_diluteerode[i][j]; delete[] im_gcut[i][j]; delete[] label[i][j]; } delete[] im_diluteerode[i]; delete[] im_gcut[i]; delete[] label[i]; } delete[] im_diluteerode; delete[] im_gcut; delete[] label; return 0; }
int main() { NETWORK *net; //MEMORY_SLPA *mem; PROCESSING_QUEUE *que; NEIGHBOR_VERTICES *nei; LABEL_PROBABILITIES *pro,*pro1; SEND_LIST *sendlist; RESULT_VERTEX *result1, *comp1; RESULT_COMMUNITY *result2, *comp2; COEFFICIENT1 *co1; COEFFICIENT2 *co2; DELETE_LIST *dellist; int i,j,iterator,c,k,*synlist; float nmi; //int MAX_T; FILE *fp,*fout; //if((fp=fopen("dolphins.gml","r"))==NULL) if((fp=fopen("network0.dat","r"))==NULL) { printf("can not open file\n"); system("pause"); exit(0); } if((fout=fopen("output.txt","w"))==NULL) { printf("can not open file\n"); system("pause"); exit(0); } net=(NETWORK *)malloc(sizeof(NETWORK)); //mem=(MEMORY_SLPA *)malloc(sizeof(MEMORY_SLPA)); que=(PROCESSING_QUEUE *)malloc(sizeof(PROCESSING_QUEUE)); nei=(NEIGHBOR_VERTICES *)malloc(sizeof(NEIGHBOR_VERTICES)); pro=(LABEL_PROBABILITIES *)malloc(sizeof(LABEL_PROBABILITIES)); pro1=(LABEL_PROBABILITIES *)malloc(sizeof(LABEL_PROBABILITIES)); //pro->index=NULL; //pro->probability=NULL; sendlist=(SEND_LIST *)malloc(sizeof(SEND_LIST)); result1=(RESULT_VERTEX *)malloc(sizeof(RESULT_VERTEX)); comp1=(RESULT_VERTEX *)malloc(sizeof(RESULT_VERTEX)); result2=(RESULT_COMMUNITY *)malloc(sizeof(RESULT_COMMUNITY)); comp2=(RESULT_COMMUNITY *)malloc(sizeof(RESULT_COMMUNITY)); co1=(COEFFICIENT1 *)malloc(sizeof(COEFFICIENT1)); co2=(COEFFICIENT2 *)malloc(sizeof(COEFFICIENT2)); dellist=(DELETE_LIST *)malloc(sizeof(DELETE_LIST)); MEMORY_VERTEX *mem1; mem1=(MEMORY_VERTEX *)malloc(sizeof(MEMORY_VERTEX)); printf("Reading network..."); read_network_bn(net,fp); //read_network(net,fp); //show_network(net,fout); printf("finish!\n"); fclose(fp); if((fp=fopen("community0.dat","r"))==NULL) { printf("can not open file\n"); system("pause"); exit(0); } printf("Reading communities of BN..."); read_communities(comp1,fp); community_statistics(comp1,comp2); //show_result_vertex(comp1,fout); //show_result_community(comp2,fout); printf("finish!\n"); //sort_network(net,1); printf("Calculating coefficients..."); calculate_coefficient(net,co1,co2); printf("finish!\n"); dellist->nvertices=net->nvertices; dellist->nlabels=(int *)calloc(dellist->nvertices,sizeof(int)); dellist->label=(int **)malloc(dellist->nvertices*sizeof(int *)); //for(i=0;i<co1->nvertices;i++){ // // fprintf(fout,"%d %f\n",i,co1->coefficients[i]); //} //fprintf(fout,"asdasdasdd\n"); //for(i=0;i<co2->nvertices;i++){ // for (j=0;j<co2->degrees[i];j++) // { // fprintf(fout,"%f ",co2->coefficients[i][j]); // } // fprintf(fout,"\n"); //} // //MAX_T=0; //while(MAX_T<100){ // MAX_T++; c=10; while(c--){ synlist=(int *)malloc(net->nvertices*sizeof(int)); printf("Initialing memory..."); //initial_memory(mem, net->nvertices); //show_memory(mem,fout); initial_memory1(mem1, net->nvertices); //show_memory1(mem1,fout); printf("finish!\n"); initial_queue(que, net->nvertices); iterator=MAX_T; printf("Calculating..."); while(iterator--){ //处理队列随机排序 random_sort(que); //show_queue(que); for(i=0;i<que->length;i++){ //查找邻节点 find_neighbor(net,nei,que->queue[i]); //printf("%d ",que->queue[i]); //show_neighbor(nei); sendlist->num=nei->degree; sendlist->list=(SL_ELEMENT *)malloc(nei->degree*sizeof(SL_ELEMENT)); for(j=0;j<nei->degree;j++){ //计算概率 //count_probabilities(pro,mem,nei->neighbor[j],MAX_T-iterator); count_probabilities1(pro1,mem1,nei->neighbor[j]); //printf("pro1: "); //for(k=0;k<pro->numlabel;k++){ // printf("%d %f ",pro->index[k],pro->probability[k]); //} //printf("\npro2: "); //for(k=0;k<pro1->numlabel;k++){ // printf("%d %f ",pro1->index[k],pro1->probability[k]); //} //printf("\n"); //if(!pro_compare(pro,pro1)){ // printf("%d %d %d %d",iterator,i,j,nei->neighbor[j]); // system("pause"); //} //根据概率发送标签至sendlist k=send_label(pro1,&sendlist->list[j].index); sendlist->list[j].weight=(1+co2->coefficients[que->queue[i]][j])*pro1->probability[k]; //sendlist->list[j].weight=1+co2->coefficients[que->queue[i]][j]; sendlist->list[j].weight2=co1->coefficients[nei->neighbor[j]]; //send_label(pro1,&sendlist->list[j].index); free(pro1->index); free(pro1->probability); } //show_sendlist(sendlist,fout); free(nei->neighbor); //记录dellist //count_delete_vertices(mem1,sendlist,dellist,que->queue[i]); //从sendlist中选择标签 //j=receive_label(sendlist); j=receive_label_old(sendlist); //异步写入memory //mem->memory[que->queue[i]][MAX_T-iterator]=j; //add_label(mem1,que->queue[i],j); //记录同步列表synlist synlist[que->queue[i]]=j; free(sendlist->list); } //同步接收标签 add_label_syn(mem1,synlist); //删除dellist中的标签 //delete_vertices(mem1,dellist); //重置dellist //reset_delete_list(dellist); } free(synlist); free(que->queue); show_memory1(mem1,fout); printf("finish!\n"); result1->nvertices=mem1->nvertices; result1->numbelong=(int *)malloc(result1->nvertices*sizeof(int)); result1->communities=(int **)malloc(result1->nvertices*sizeof(int*)); printf("Post processing..."); for(i=0;i<result1->nvertices;i++){ //count_probabilities(pro,mem,net->vertex[i].id,MAX_T+1); count_probabilities1(pro,mem1,net->vertex[i].id); post_processing(pro,result1,i,0.05); } printf("finish!\n"); free(pro->index); free(pro->probability); //for(i=0;i<mem->nvertices;i++){ // free(mem->memory[i]); //} //free(mem->memory); destroy_memory(mem1); //printf("Output results..."); //show_result_vertex(result1,fout); community_statistics(result1,result2); //show_result_community(result2,fout); nmi=1-(result_comparison(comp2,result2,net->nvertices)+result_comparison(result2,comp2,net->nvertices))/2; fprintf(fout,"%f\t",nmi); //删除被完全包含的社区 result_processing(result1,result2); //show_result_community(result2,fout); //printf("finish!\n"); printf("Calculating NMI..."); //log((float)exp((float)1)); nmi=1-(result_comparison(comp2,result2,net->nvertices)+result_comparison(result2,comp2,net->nvertices))/2; printf("finish!\n"); fprintf(fout,"%f\n",nmi); for(i=0;i<result1->nvertices;i++){ free(result1->communities[i]); } free(result1->communities); free(result1->numbelong); for(i=0;i<result2->ncommunities;i++){ free(result2->vertices[i]); } free(result2->vertices); free(result2->nvertices); } //} for(i=0;i<comp1->nvertices;i++){ free(comp1->communities[i]); } free(comp1->communities); free(comp1->numbelong); for(i=0;i<comp2->ncommunities;i++){ free(comp2->vertices[i]); } free(comp2->vertices); free(comp2->nvertices); free(dellist->label); free(dellist->nlabels); free(dellist); free(mem1); free(que); free(nei); free(sendlist); free_network(net); fclose(fout); fclose(fp); //printf("hello world!!"); system("pause"); return 0; }