double TAGMFast::LikelihoodForRow(const int UID, const TIntFltH& FU) { double L = 0.0; TFltV HOSumFV; //adjust for Fv of v hold out if (HOVIDSV[UID].Len() > 0) { HOSumFV.Gen(SumFV.Len()); for (int e = 0; e < HOVIDSV[UID].Len(); e++) { for (int c = 0; c < SumFV.Len(); c++) { HOSumFV[c] += GetCom(HOVIDSV[UID][e], c); } } } TUNGraph::TNodeI NI = G->GetNI(UID); if (DoParallel && NI.GetDeg() > 10) { #pragma omp parallel for schedule(static, 1) for (int e = 0; e < NI.GetDeg(); e++) { int v = NI.GetNbrNId(e); if (v == UID) { continue; } if (HOVIDSV[UID].IsKey(v)) { continue; } double LU = log (1.0 - Prediction(FU, F[v])) + NegWgt * DotProduct(FU, F[v]); #pragma omp atomic L += LU; } for (TIntFltH::TIter HI = FU.BegI(); HI < FU.EndI(); HI++) { double HOSum = HOVIDSV[UID].Len() > 0? HOSumFV[HI.GetKey()].Val: 0.0;//subtract Hold out pairs only if hold out pairs exist double LU = NegWgt * (SumFV[HI.GetKey()] - HOSum - GetCom(UID, HI.GetKey())) * HI.GetDat(); L -= LU; } } else { for (int e = 0; e < NI.GetDeg(); e++) { int v = NI.GetNbrNId(e); if (v == UID) { continue; } if (HOVIDSV[UID].IsKey(v)) { continue; } L += log (1.0 - Prediction(FU, F[v])) + NegWgt * DotProduct(FU, F[v]); } for (TIntFltH::TIter HI = FU.BegI(); HI < FU.EndI(); HI++) { double HOSum = HOVIDSV[UID].Len() > 0? HOSumFV[HI.GetKey()].Val: 0.0;//subtract Hold out pairs only if hold out pairs exist L -= NegWgt * (SumFV[HI.GetKey()] - HOSum - GetCom(UID, HI.GetKey())) * HI.GetDat(); } } //add regularization if (RegCoef > 0.0) { //L1 L -= RegCoef * Sum(FU); } if (RegCoef < 0.0) { //L2 L += RegCoef * Norm2(FU); } return L; }
//############################################################################# double* TrTrackA::Prediction(TrRecHitR* phit){ if (!phit) return NULL; TrHitA* myhit = add_hit(phit); double* result = Prediction(myhit); del_hit(myhit); return result; }
void LL(node_ptr &head,LinkQueue hword)// { cout<<"LL(1)文法判断:"<<endl; kong *k=NULL; list *first=NULL; list *follow=NULL; selist *select=NULL; built(head,first,follow,1);//建立first builtKong(first,k);//根据first 建立非终结符是否能推出空的表格 built(head,first,follow,0);//建follow builtSelect(head,first,follow,select,k);//建立select kong *p=k; while(p) { cout<<p->ch<<" "<<p->b<<endl; p=p->next; } system("pause"); cout<<"FIRST:"<<endl; Display(first); system("pause"); cout<<"FOLLOW:"<<endl; Display(follow); system("pause"); cout<<"SELECT:"<<endl; selist *pf=select; while(pf) { cout<<setiosflags(ios_base::left)<<setw(10)<<pf->Vn<<": "; cout<<pf->Vt<<endl; pf=pf->next; } system("pause"); judge(select);//通过select判断是否为LL(1)文法 selist *analy=NULL; Prediction(select,analy);//通过select建立预测分析表 Analysis(analy,hword);//通过分析表开始分析 }
int CUKF::Doit() { // VehicleModel(); //StopWatch("start"); AddControlNoise(); //StopWatch("AddControlNoise"); Prediction(); //StopWatch("Prediction"); // PrintCvMat(XX, "after prediction : XX"); // PrintCvMat(PX, "after prediction : PX"); static double dtsum=0; dtsum += DT_CONTROLS; if(dtsum >= DT_OBSERVE) { // TRACE("xtrue : %.4f %.4f %.4f\n", xtrue->data.db[0], xtrue->data.db[1], xtrue->data.db[2]); dtsum = 0; GetVisibleLandmark(); //StopWatch("GetVisibleLandmark"); AddObservationNoise(); //StopWatch("AddObservationNoise"); KnownDataAssociation(); //StopWatch("KnownDataAssociation"); // PrintCvMat(XX, "before update : XX"); // PrintCvMat(PX, "before update : PX"); Update(); //StopWatch("Update"); // PrintCvMat(XX, "after update : XX"); // PrintCvMat(PX, "after update : PX"); Augment(); //StopWatch("Augment"); //PrintCvMat(XX, "after augment : XX"); //PrintCvMat(PX, "after augment : PX"); //TRACE("XX dim : %d %d\n", XX->rows, XX->cols); //TRACE("PX dim : %d %d\n", PX->rows, PX->cols); // TRACE("==== datable ====\n"); // for(int i=0; i<lm.size(); i++) // TRACE("%d\t", daTable[i]); // TRACE("=================\n"); } EllipseFitting(); //StopWatch("EllipseFitting"); return 0; }
double TAGMFast::LikelihoodHoldOut(const bool DoParallel) { double L = 0.0; for (int u = 0; u < HOVIDSV.Len(); u++) { for (int e = 0; e < HOVIDSV[u].Len(); e++) { int VID = HOVIDSV[u][e]; if (VID == u) { continue; } double Pred = Prediction(u, VID); if (G->IsEdge(u, VID)) { L += log(1.0 - Pred); } else { L += NegWgt * log(Pred); } } } return L; }
int main(int argc, char *argv[]){ //check validity of input arguments if(argc!=4){ PRINTDEBUGMODE0("[ERROR] Please check number of arguments!\n"); PRINTDEBUGMODE0("Application <gridsizes(m)> <searchRadius(m)> <PathtoTheInputFile.txt>\n"); PRINTDEBUGMODE0("argv[1]:%s\n",argv[1]); PRINTDEBUGMODE0("argv[2]:%s\n",argv[2]); PRINTDEBUGMODE0("argv[3]:%s\n",argv[3]); exit(0); } long temp_gridsize = atol(argv[1]); double GRID_SIZE = (double) temp_gridsize ; if(GRID_SIZE<1) GRID_SIZE = 0.5; //hard code for parsing args < 1 PRINTDEBUGMODE1("tempgrid:%lu\n",temp_gridsize); PRINTDEBUGMODE1("GRIDSIZE:%2.2f\n",GRID_SIZE); int searchRadius = strtol(argv[2],NULL,10);//for radius char *filename = argv[3]; char path_p[50]="/nfs/code/mata/output/PredictionPerGrid"; int rankId, numProcess; int bufflen = 512; char hostname[bufflen]; int i, j, k, p, q; int flag=0; int dsize=0; int nrbins = 50; double *x=NULL, *y=NULL, *z=NULL, **ptopDist; //double maxD; int minX_inputData, minY_inputData, maxX_inputData, maxY_inputData, gridXrange, gridYrange; int numberofGrids_X, numberofGrids_Y; double maxDistance; double startTime, endTime; double totalTime=0.0; //For variogram double sum_SqurZ[nrbins+2], distDelta[nrbins+2]; char fileType[] = ".txt"; FILE *fpdata=NULL; FILE *fPrediction=NULL; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rankId); MPI_Comm_size(MPI_COMM_WORLD, &numProcess); if(numProcess > NUM_MAX_PROCESS){ printf("[ERROR] numProcess > NUM_MAX_PROCESS\n"); exit(0); } startTime=MPI_Wtime(); /*===================== Read Data =============================*/ FILE *file = fopen ( filename, "r" ); int inputsize=0; if ( file != NULL ) { char line [ 128 ]; /* or other suitable maximum line size */ while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */ { //fputs ( line, stdout ); /* write the line */ inputsize++; } fclose ( file ); } else { printf("[ERROR] Invalid input Path\n"); perror ( filename ); /* why didn't the file open? */ } dsize = inputsize; i=0; fpdata = fopen(filename,"r"); x = (double*)malloc(sizeof(double)*dsize); y = (double*)malloc(sizeof(double)*dsize); z = (double*)malloc(sizeof(double)*dsize); if(x==NULL | y==NULL | z==NULL){ printf("[error malloc] X Y Z\n"); exit(0); } fseek(fpdata,0,SEEK_SET); gethostname(hostname, bufflen); PRINTDEBUGMODE1( "Start process %d at %s\n", rankId, hostname ); //Preprocessing steps is here while(!feof(fpdata)){ fscanf(fpdata, "%lf %lf %lf", &x[i], &y[i], &z[i]); findMinMax(x[i], y[i]); //fprintf(ferr,"data: %lf %lf %lf\n", x[i], y[i], z[i]); i++; } minX_inputData = (int)floor(minX); maxX_inputData = (int)ceil(maxX); minY_inputData = (int)floor(minY); maxY_inputData = (int)ceil(maxY); gridXrange = maxX_inputData-minX_inputData; gridYrange = maxY_inputData-minY_inputData; numberofGrids_X = gridXrange / GRID_SIZE; numberofGrids_Y = gridYrange / GRID_SIZE; int totalGrids = numberofGrids_X * numberofGrids_Y; int numGridPerNode = ceil(totalGrids/numProcess); if(rankId==0) {//choose the faster processor PRINTDEBUGMODE0("-----------------------------------------------\n"); PRINTDEBUGMODE0(" Total processors (workers) : %d\n", numProcess); PRINTDEBUGMODE0(" Number of Input LiDAR data : %d\n",dsize); PRINTDEBUGMODE0(" min (%d,%d)\n max (%d,%d)\n", minX_inputData, minY_inputData,maxX_inputData, maxY_inputData); PRINTDEBUGMODE0(" GRID_SIZE : %2.2f meter(s)\n",(double)GRID_SIZE); PRINTDEBUGMODE0(" SearchRadius : %d meter(s)\n",searchRadius); PRINTDEBUGMODE0(" GRIDrange (X,Y) : (%d,%d)\n", gridXrange, gridYrange); PRINTDEBUGMODE0(" numberofGrids (X,Y) : (%d,%d)\n", numberofGrids_X, numberofGrids_Y); PRINTDEBUGMODE0(" Total available Grids : %d\n",totalGrids); PRINTDEBUGMODE0(" NumGridsPerNode : %d\n",numGridPerNode); PRINTDEBUGMODE0("-----------------------------------------------\n"); } PRINTDEBUGMODE1("grid_index[%d]:%d\n",rankId,grid_index[rankId]); PRINTDEBUGMODE1("startGrid[%d]:(%2.2f,%2.2f)\n",rankId,startGrid_X[rankId],startGrid_Y[rankId]); // Prepare buffer to store nodes in a grid within searchRange buffNodes_inOneGrid = (PointerOfGrid**)malloc(sizeof(PointerOfGrid*)*(numberofGrids_X+1)); // assume that boundary X axis in also grid point if(buffNodes_inOneGrid== NULL){ printf("[malloc error] cannot allocate %d buffNodes_inOneGrid_X\n", numberofGrids_X+1); exit(0); } PRINTDEBUGMODE1("malloc buffNodes_inOneGrid %d ...\n", rankId); for(i=0;i<=numberofGrids_X;i++){ buffNodes_inOneGrid[i] = (PointerOfGrid*)malloc(sizeof(PointerOfGrid)*(numberofGrids_Y+1)); // assume that boundary Y axis in also grid point if(buffNodes_inOneGrid[i] == NULL){ printf("[malloc error] cannot allocate %d buffNodes_inOneGrid_Y \n", numberofGrids_Y+1); exit(0); } for(j=0;j<=numberofGrids_Y;j++){ buffNodes_inOneGrid[i][j].next=NULL; } //FOR_DEBUG_PRINT("row_num:%d\n",i);FOR_DEBUG_PRINT("Load grid on memory\n"); } //optimation per process int tempsize = dsize; while((tempsize%numProcess)!=0){ tempsize--; } PRINTDEBUGMODE1("numProcess: %d\n",numProcess); PRINTDEBUGMODE1("tempsize: %d\n",tempsize); /* lets process data input one by one : * hint : One input point will be places to only one closest grid point * */ int numInputdataPerProcessor = tempsize/numProcess; //equally divide jobs from each worker PRINTDEBUGMODE1("numInputdataPerProcessor: %d\n",numInputdataPerProcessor); for(i=0;i<dsize;i++){ //148355 //divide input data based on rankId on each processor(worker) int idx_datainput = i;//+rankId*numInputdataPerProcessor; if(idx_datainput<dsize){ //find a closest grid point from an input data int lower_gridX = (int)floor(x[idx_datainput]); int upper_gridX = (int)ceil(x[idx_datainput]); int lower_gridY = (int)floor(y[idx_datainput]); int upper_gridY = (int)ceil(y[idx_datainput]); double closest_gridpointX; double closest_gridpointY; if(GRID_SIZE >= 1){ int gridsize_var= GRID_SIZE; while((int)(lower_gridX%gridsize_var)!=0){ lower_gridX--; } while((int)(upper_gridX%gridsize_var)!=0){ upper_gridX++; } while((int)(lower_gridY%gridsize_var)!=0){ lower_gridY--; } while((int)(upper_gridY%gridsize_var)!=0){ upper_gridY++; } } if((sqrt(pow(x[idx_datainput]-lower_gridX,2)+pow(y[idx_datainput]-lower_gridY,2)))< (sqrt(pow(x[idx_datainput]-upper_gridX,2)+pow(y[idx_datainput]-upper_gridY,2))) ){ closest_gridpointX = lower_gridX; closest_gridpointY = lower_gridY; }else{ closest_gridpointX = upper_gridX; closest_gridpointY = upper_gridY; } //TODO iterate this closest grid point within a searchRange PRINTDEBUGMODE1("closest_gridpointX:%lf\n",closest_gridpointX); PRINTDEBUGMODE1("closest_gridpointY:%lf\n",closest_gridpointY); //ensure that still inside boundary area if((closest_gridpointX>=minX_inputData)&&(closest_gridpointY>=minY_inputData)&&(closest_gridpointX<=maxX_inputData)&&(closest_gridpointY<=maxY_inputData)){ if(((closest_gridpointX-minX_inputData)/GRID_SIZE)>= numberofGrids_X){ PRINTDEBUGMODE1("HOREWWWW X\n"); } if(((closest_gridpointY-minY_inputData)/GRID_SIZE)>= numberofGrids_Y){ PRINTDEBUGMODE1("HOREWWWW Y\n"); } if((abs(closest_gridpointX-x[idx_datainput])<searchRadius) && (abs(closest_gridpointY-y[idx_datainput])<searchRadius)){ int idx_x = (int)(closest_gridpointX-minX_inputData)/GRID_SIZE; int idx_y = (int)(closest_gridpointY-minY_inputData)/GRID_SIZE; PRINTDEBUGMODE1("numberofGrids_X:%d; numberofGrids_Y:%d\n", numberofGrids_X, numberofGrids_Y); if(buffNodes_inOneGrid[idx_x]!=NULL){ cur = buffNodes_inOneGrid[idx_x][idx_y].next; if(cur==NULL){ PRINTDEBUGMODE1("cur next NULL\n"); new_list = (Info_Grid*)malloc(sizeof(Info_Grid)); new_list->x = x[idx_datainput]; new_list->y = y[idx_datainput]; new_list->z = z[idx_datainput]; new_list->next=NULL; buffNodes_inOneGrid[idx_x][idx_y].next = new_list; } else { PRINTDEBUGMODE1("cur next NOT NULL\n"); while(cur->next!=NULL) { cur = cur->next; } new_list = (Info_Grid*)malloc(sizeof(Info_Grid)); new_list->x = x[idx_datainput]; new_list->y = y[idx_datainput]; new_list->z = z[idx_datainput]; new_list->next=NULL; cur->next = new_list; } }else{ //there must be some bug if this happened --> ussually malloc failed PRINTDEBUGMODE0("[ERROR] ANOTHER BUG\n"); PRINTDEBUGMODE0("X:%d; Y:%d\n",idx_x,idx_y); PRINTDEBUGMODE0("numberofGrids_X:%d; numberofGrids_Y:%d\n", numberofGrids_X, numberofGrids_Y); } } } } else{ PRINTDEBUGMODE0("idx_datainput:%d\n",idx_datainput); } } free(x); free(y); free(z); /** * Gridding, Semi-Variogram, Prediction Process is here */ strcat(path_p,itoa(rankId,10)); strcat(path_p,fileType); fPrediction = fopen(path_p,"w"); PRINTDEBUGMODE1("Start Gridding Process ... \n"); // Divide number of grids with the available process/workers for(p=0;p< numGridPerNode;p++){ int idx_grid =p+rankId*numGridPerNode; if(idx_grid<totalGrids){ int idx_x = idx_grid%numberofGrids_X; int idx_y = (int) floor(idx_grid/numberofGrids_X); int temp_idx_x = idx_x; int temp_idx_y = idx_y; //iterate based on search range & collect in a linked list int points_counter = 0; minX=0.0, minY=0.0, maxX=0.0, maxY=0.0; if(GRID_SIZE<searchRadius){ //TODO FIX this bug int max_loop = (int)ceil(searchRadius/GRID_SIZE); idx_x = idx_x-max_loop; idx_y = idx_y-max_loop; for(i=0;i<2*max_loop;i++){ for(j=0;j<2*max_loop;j++){ if((idx_x+i)>=0 && ((idx_x+i) < numberofGrids_X) && (idx_y+j)>=0 && (idx_y+j) < numberofGrids_Y) { //while still inside boundary of grids CalDistPointfromGrid(idx_x+i,idx_y+j, &points_counter); } } } }else{ CalDistPointfromGrid(idx_x,idx_y, &points_counter); } PRINTDEBUGMODE1("point_counter :%d\n",points_counter); //calculate variogram maxDistance = sqrt(pow(maxX-minX,2)+pow(maxY-minY,2)); maxDistance = maxDistance/2; points_counter = points_counter+1; ptopDist = (double**)malloc(sizeof(double*)*points_counter); for(k=0;k<points_counter;k++) { ptopDist[k] = (double*)malloc(sizeof(double)*points_counter); } //initialize with 0 value for(k=0;k<points_counter;k++) { for(q=0;q<points_counter;q++) { ptopDist[k][q] = 0.0; } } //calculate semivariogram FindSemivar(Head_distfromGrid, nrbins, sum_SqurZ, maxDistance, distDelta, ptopDist); double range, sill; //Fitting process with model FitSemivariogram(sum_SqurZ, distDelta, nrbins, &range, &sill); //Prediction double coord_gridX = minX_inputData + temp_idx_x*GRID_SIZE; double coord_gridY = minY_inputData + temp_idx_y*GRID_SIZE; Prediction(Head_distfromGrid, points_counter, range, sill, rankId, ptopDist, coord_gridX, coord_gridY, fPrediction); //free memory for(k=0;k<points_counter;k++) { free(ptopDist[k]); } free(ptopDist); Cur_DistfromGrid = Head_distfromGrid; while(Cur_DistfromGrid!=NULL) { ForFree_DistfromGrid = Cur_DistfromGrid; Cur_DistfromGrid = Cur_DistfromGrid -> next; free(ForFree_DistfromGrid); } Head_distfromGrid=NULL; Tail_DistfromGrid=NULL; } } endTime = MPI_Wtime(); totalTime = endTime-startTime; MPI_Finalize(); PRINTDEBUGMODE0( "Finished process %d at %s in %lf seconds\n", rankId, hostname, totalTime ); int temp_numProc=0; for(i=0;i<numProcess;i++){ temp_numProc = temp_numProc+i; } flag = flag + rankId; if(flag == temp_numProc){ char path_output[]="cat ../../mata/output/* > "; strcat(path_output,"result.txt"); system(path_output); } return 0; }
void TAGMFast::GradientForRow(const int UID, TIntFltH& GradU, const TIntSet& CIDSet) { GradU.Gen(CIDSet.Len()); TFltV HOSumFV; //adjust for Fv of v hold out if (HOVIDSV[UID].Len() > 0) { HOSumFV.Gen(SumFV.Len()); for (int e = 0; e < HOVIDSV[UID].Len(); e++) { for (int c = 0; c < SumFV.Len(); c++) { HOSumFV[c] += GetCom(HOVIDSV[UID][e], c); } } } TUNGraph::TNodeI NI = G->GetNI(UID); int Deg = NI.GetDeg(); TFltV PredV(Deg), GradV(CIDSet.Len()); TIntV CIDV(CIDSet.Len()); if (DoParallel && Deg + CIDSet.Len() > 10) { #pragma omp parallel for schedule(static, 1) for (int e = 0; e < Deg; e++) { if (NI.GetNbrNId(e) == UID) { continue; } if (HOVIDSV[UID].IsKey(NI.GetNbrNId(e))) { continue; } PredV[e] = Prediction(UID, NI.GetNbrNId(e)); } #pragma omp parallel for schedule(static, 1) for (int c = 0; c < CIDSet.Len(); c++) { int CID = CIDSet.GetKey(c); double Val = 0.0; for (int e = 0; e < Deg; e++) { int VID = NI.GetNbrNId(e); if (VID == UID) { continue; } if (HOVIDSV[UID].IsKey(VID)) { continue; } Val += PredV[e] * GetCom(VID, CID) / (1.0 - PredV[e]) + NegWgt * GetCom(VID, CID); } double HOSum = HOVIDSV[UID].Len() > 0? HOSumFV[CID].Val: 0.0;//subtract Hold out pairs only if hold out pairs exist Val -= NegWgt * (SumFV[CID] - HOSum - GetCom(UID, CID)); CIDV[c] = CID; GradV[c] = Val; } } else { for (int e = 0; e < Deg; e++) { if (NI.GetNbrNId(e) == UID) { continue; } if (HOVIDSV[UID].IsKey(NI.GetNbrNId(e))) { continue; } PredV[e] = Prediction(UID, NI.GetNbrNId(e)); } for (int c = 0; c < CIDSet.Len(); c++) { int CID = CIDSet.GetKey(c); double Val = 0.0; for (int e = 0; e < Deg; e++) { int VID = NI.GetNbrNId(e); if (VID == UID) { continue; } if (HOVIDSV[UID].IsKey(VID)) { continue; } Val += PredV[e] * GetCom(VID, CID) / (1.0 - PredV[e]) + NegWgt * GetCom(VID, CID); } double HOSum = HOVIDSV[UID].Len() > 0? HOSumFV[CID].Val: 0.0;//subtract Hold out pairs only if hold out pairs exist Val -= NegWgt * (SumFV[CID] - HOSum - GetCom(UID, CID)); CIDV[c] = CID; GradV[c] = Val; } } //add regularization if (RegCoef > 0.0) { //L1 for (int c = 0; c < GradV.Len(); c++) { GradV[c] -= RegCoef; } } if (RegCoef < 0.0) { //L2 for (int c = 0; c < GradV.Len(); c++) { GradV[c] += 2 * RegCoef * GetCom(UID, CIDV[c]); } } for (int c = 0; c < GradV.Len(); c++) { if (GetCom(UID, CIDV[c]) == 0.0 && GradV[c] < 0.0) { continue; } if (fabs(GradV[c]) < 0.0001) { continue; } GradU.AddDat(CIDV[c], GradV[c]); } for (int c = 0; c < GradU.Len(); c++) { if (GradU[c] >= 10) { GradU[c] = 10; } if (GradU[c] <= -10) { GradU[c] = -10; } IAssert(GradU[c] >= -10); } }
std::vector<Chromosome> BrainUnit::derivePopulation(std::string output) { if (!constants::IS_PERSISTANCE_MODE) return std::vector<Chromosome>(); // TODO: What about inputs? Store inputs in brain unit! // TODO: Properly check over effectiveness & function of following process: /* Steps: 1. Compute tentative similarity between each memory and the respective output 2. Sort memories by this similarity and extract 15% to use as derivation resources 3. Sort these filtered memories by similarity AND memory foundation index, extracting 25% to use as derivation resources. */ GoalState goalState = GoalState(output); Interpreter *interpreter; switch (constants::PREFERRED_LANGUAGE_INTERPRETER) { case constants::IntrepreterLanguageTypeBrainfuck: interpreter = new BrainfuckInterpreter(); break; default: break; } FitnessBaselineScoringSystem *scoringSystem; switch (constants::PREFERRED_SCORING_SYSTEM) { case constants::FitnessBaselineScoringSystemTypeStringToStringSimilarityScoring: switch (constants::PREFERRED_STRING_SIMILARITY_SCORING_FUNCTION) { case constants::FitnessBaselineScoringSystemTypeStringToStringSimilarityScoringTypeSE: scoringSystem = new FitnessBaselineScoringSystemStringToStringSimilaritySE(); break; default: break; } break; default: break; } std::vector<Memory> tempPopulation = memories; std::vector<Prediction> predictions; for (int j = 0; j < tempPopulation.size(); j++) { Prediction prediction = Prediction(interpreter->outputFromProgram(tempPopulation[j].chromosome.genome, std::vector<char>()), goalState); predictions.push_back(prediction); } scoringSystem->setScoringData(predictions); std::vector<double> costs = scoringSystem->computeCosts(); for (int j = 0; j < costs.size(); j++) { Memory *memory = &tempPopulation[j]; (*memory).tentativeSimilarity = costs[j]; } if (tempPopulation.size() > 1) { std::sort(std::begin(tempPopulation), std::end(tempPopulation), compareMemoriesOnSimilarity); tempPopulation.erase(tempPopulation.begin() + (tempPopulation.size() - ceil(tempPopulation.size() * 0.85)), tempPopulation.end()); if (tempPopulation.size() > 4) { std::sort(std::begin(tempPopulation), std::end(tempPopulation), compareMemoriesOnSimilarityAndFoundationIndex); tempPopulation.erase(tempPopulation.end() + (tempPopulation.size() - ceil(tempPopulation.size() * 0.25)), tempPopulation.end()); } } std::vector<Chromosome> derivedPopulation; for (int i = 0; i < tempPopulation.size(); i++) { remember_(i); derivedPopulation.push_back(tempPopulation[i].chromosome); } return derivedPopulation; }
//############################################################################# double* TrTrackA::Prediction(double* coo, double* ecoo, double* bfield) { TrHitA* myhit = add_hit(coo, ecoo, bfield); double* result = Prediction(myhit); del_hit(myhit); return result; }
//############################################################################# double* TrTrackA::Prediction(TrHitA* phit){ for(int i=0;i<NHits();i++) { if (phit==&_Hit[i]) return Prediction(i); } return NULL; }
Prediction::Prediction(HashErrorModel *phasherrormodel){ this->phasherrormodel = phasherrormodel; Prediction(); }
/* * Initialize the GUI interface for the plugin - this is only called once when the plugin is * added to the plugin registry in the QGIS application. */ void QRap::initGui() { mToolBarPointer = 0; printf("QRap::initGui\n"); mPoints.clear(); mMouseType = CLEAN; // Create the action for tool cout << "VOOR DataBase Connect" << endl; openDatabaseConnection(); cout << "Na DataBase Connect" << endl; cout << "Voor new Actions" << endl; mQActionPointer = new QAction(QIcon(":/qrap/Data.png"),tr("Q-Rap Database Interface"), this); mSiteAction = new QAction(QIcon(":/qrap/Site.png"),tr("Q-Rap: Place a Site"), this); mSelectSiteAction = new QAction(QIcon(":/qrap/SiteSelect.png"),tr("Q-Rap: Select a Site"), this); mDeleteSiteAction = new QAction(QIcon(":/qrap/SiteDelete.png"),tr("Q-Rap: Delete a Site"), this); mLinkAction = new QAction(QIcon(":/qrap/Link.png"),tr("Q-Rap: Link Analysis"), this); mSelectLinkAction = new QAction(QIcon(":/qrap/LinkSelect.png"),tr("Q-Rap: Select a Link"), this); mDeleteLinkAction = new QAction(QIcon(":/qrap/LinkDelete.png"),tr("Q-Rap: Delete a Link"), this); mMultiLinkAction = new QAction(QIcon(":/qrap/MultiLink.png"),tr("Q-Rap: Establish all Links possible in set of Sites"), this); mRadioAction = new QAction(QIcon(":/qrap/Coverage.png"),tr("Q-Rap: Perform a Prediction"), this); mMeasAnalysisAction = new QAction(QIcon(":/qrap/Measurements.png"),tr("Q-Rap: Compare measurements with predictions"), this); mSpectralAction = new QAction(QIcon(":/qrap/Spectral.png"),tr("Q-Rap: Perform Spectral Interference Analysis"), this); mPreferencesAction = new QAction(QIcon(":/qrap/Preferences.png"),tr("Q-Rap Preferences"), this); mOptimisationAction = new QAction(QIcon(":/qrap/Optimisation.png"),tr("Q-Rap: Optimise link structure in selected area"), this); // mImportExportAction = new QAction(QIcon(":/qrap/ImportExport.png"),tr("Import Export"),this); // mHelpAction = new QAction(QIcon(":/qrap/Help.png"),tr("Q-Rap Help"), this); cout << "Na new Actions" << endl; // Connect the action to the run connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run())); connect(mSiteAction, SIGNAL(activated()), this, SLOT(PlaceSite())); connect(mSelectSiteAction, SIGNAL(activated()), this, SLOT(SelectSite())); connect(mDeleteSiteAction, SIGNAL(activated()), this, SLOT(DeleteSite())); connect(mLinkAction, SIGNAL(activated()), this, SLOT(CreateLinkAnalysis())); connect(mDeleteLinkAction, SIGNAL(activated()), this, SLOT(DeleteLink())); connect(mMultiLinkAction, SIGNAL(activated()), this, SLOT(MultiLink())); connect(mSelectLinkAction, SIGNAL(activated()), this, SLOT(SelectLink())); connect(mRadioAction, SIGNAL(activated()), this, SLOT(Prediction())); connect(mMeasAnalysisAction, SIGNAL(activated()), this, SLOT(Measurements())); connect(mSpectralAction, SIGNAL(activated()), this, SLOT(SpectralAnalysis())); connect(mPreferencesAction, SIGNAL(activated()), this, SLOT(Preferences())); connect(mOptimisationAction, SIGNAL(activated()), this, SLOT(Optimise())); // connect(mImportExportAction,SIGNAL(activated()), this, SLOT(ImportExport())); // connect(mHelpAction,SIGNAL(activated()), this, SLOT(Help())); cout << "Na Connect" << endl; // Add the toolbar to the main window mToolBarPointer = mQGisIface->addToolBar(tr("Q-Rap")); mToolBarPointer->setIconSize(QSize(24,24)); mToolBarPointer->setObjectName("Q-Rap"); // Add the icon to the toolbar mToolBarPointer->addAction(mSiteAction); mToolBarPointer->addAction(mSelectSiteAction); mToolBarPointer->addAction(mDeleteSiteAction); mToolBarPointer->addAction(mLinkAction); mToolBarPointer->addAction(mSelectLinkAction); mToolBarPointer->addAction(mDeleteLinkAction); mToolBarPointer->addAction(mRadioAction); mToolBarPointer->addAction(mMultiLinkAction); mToolBarPointer->addAction(mMeasAnalysisAction); mToolBarPointer->addAction(mSpectralAction); mToolBarPointer->addAction(mOptimisationAction); mToolBarPointer->addAction(mPreferencesAction); mToolBarPointer->addAction(mQActionPointer); // mToolBarPointer->addAction(mImportExportAction); // mToolBarPointer->addAction(mHelpAction); mLoaded = true; // openDatabaseConnection(); // cout << "Na DataBase Connect" << endl; // mQGisIface->addToolBarIcon( mQActionPointer ); // mQGisIface->addPluginToMenu( tr( "Q-Rap Database" ), mQActionPointer ); Mouse = new MouseEvents(mQGisIface->mapCanvas()); cout << "Na Mouse" << endl; connect(Mouse, SIGNAL(RightPoint(QgsPoint&)), this, SLOT(ReceivedRightPoint(QgsPoint&))); connect(Mouse, SIGNAL(LeftPoint(QgsPoint&)), this, SLOT(ReceivedLeftPoint(QgsPoint&))); }