void Flock::update(float dt_){ calcDistances(); for (int i=0; i< NUM_FISH_PER_FLOCK; i++){ members[i]->update(dt_); } }
polyLine::polyLine(const pointField& ps) : controlPoints_(ps), distances_(ps.size()) { if (ps.size()) { calcDistances(); } }
void Clustering::clusterConfidentIndices() { int numConfidentIndices = detectionResult->confidentIndices.size(); std::vector<float> distances; distances.resize(numConfidentIndices*(numConfidentIndices-1)/2); calcDistances(distances.data()); std::vector<int> clusterIndices; clusterIndices.resize(numConfidentIndices); cluster(distances.data(), clusterIndices.data()); if(detectionResult->numClusters == 1) { calcMeanRect(&detectionResult->confidentIndices); //TODO: Take the maximum confidence as the result confidence. } }
void Clustering::clusterConfidentIndices() { int numConfidentIndices = detectionResult->confidentIndices->size(); float * distances = new float[numConfidentIndices*(numConfidentIndices-1)/2]; calcDistances(distances); int * clusterIndices = new int[numConfidentIndices]; cluster(distances, clusterIndices); if(detectionResult->numClusters == 1) { calcMeanRect(detectionResult->confidentIndices); //TODO: Take the maximum confidence as the result confidence. } }
void *computeDistance(void *thread_ID) { struct microDataDistance *geneDistArray = NULL; struct microDataDistance *geneDistPtr; struct microData *curGene; int baseGenesPerThread, genesPerThread, rmdrPerThread, rmdr, xtra; int subListSize; int geneIx; int i; /* offset = thread ID */ int offset = *((int *)thread_ID); /* create subList size for each thread to process */ baseGenesPerThread = geneCount / numThreads; rmdr = geneCount % numThreads; rmdrPerThread = rmdr / numThreads; xtra = rmdr % numThreads; genesPerThread = baseGenesPerThread + rmdrPerThread; subListSize = (offset == numThreads-1) ? genesPerThread + xtra : genesPerThread; /* each thread positions initial current gene */ curGene = geneList; for (i = 0; i < offset*genesPerThread; i++) curGene = curGene->next; AllocArray(geneDistArray, geneCount); /* compute the pairwise experiment distances */ for (i = 0; i < subListSize; i++, curGene = curGene->next) { calcDistances(geneDistArray, curGene, geneList, weights); qsort(geneDistArray, geneCount, sizeof(geneDistArray[0]), cmpMicroDataDistance); /* Print out closest 1000 in tab file. */ pthread_mutex_lock( &mutexfilehandle ); geneDistPtr = geneDistArray; for (geneIx=0; geneIx < 1000 && geneIx < geneCount; ++geneIx, geneDistPtr++) fprintf(f, "%s\t%s\t%f\n", geneDistPtr->name1, geneDistPtr->name2, geneDistPtr->distance); dotOut(); pthread_mutex_unlock( &mutexfilehandle ); } freez( &geneDistArray ); pthread_exit(NULL); }
void Clustering::clusterConfidentIndices() { size_t numConfidentIndices = detectionResult->confidentIndices->size(); size_t numDistances = numConfidentIndices * (numConfidentIndices - 1) / 2; float* distances = new float[numDistances] {}; calcDistances(distances); cluster(distances); if (detectionResult->numClusters == 1) { calcMeanRect(detectionResult->confidentIndices); //TODO: Take the maximum confidence as the result confidence. } delete[]distances; distances = NULL; }
int main() { int i; while(scanf("%d",&n)!=EOF){ for(i=0;i<n;i++) scanf("%d %d",&places[i][0],&places[i][1]); calcDistances(); for(i=0;i<n;i++) shortPath(i,0); printf("%.3f\n",best); } return 0; }
Foam::polySplineEdge::polySplineEdge ( const pointField& points, Istream& is ) : curvedEdge(points, is), polyLine(pointField(0)), otherKnots_(is) { label nInterKnots(20); vector fstend(is); vector sndend(is); controlPoints_.setSize(nsize(otherKnots_.size(), nInterKnots)); distances_.setSize(controlPoints_.size()); controlPoints_ = intervening(otherKnots_, nInterKnots, fstend, sndend); calcDistances(); }
void *computeDistance(void *thread_ID) { struct microDataDistance *geneDistArray = NULL; struct microData *curGene; int baseGenesPerThread, genesPerThread, rmdrPerThread, rmdr, xtra; int subListSize; int i; /* offset = thread ID */ int offset = *((int *)thread_ID); /* create subList size for each thread to process */ baseGenesPerThread = geneCount / numThreads; rmdr = geneCount % numThreads; rmdrPerThread = rmdr / numThreads; xtra = rmdr % numThreads; genesPerThread = baseGenesPerThread + rmdrPerThread; subListSize = (offset == numThreads-1) ? genesPerThread + xtra : genesPerThread; /* each thread positions initial current gene */ curGene = geneList; for (i = 0; i < offset*genesPerThread; i++) curGene = curGene->next; /* compute the pairwise experiment distances */ for (i = 0; i < subListSize; i++, curGene = curGene->next) { AllocArray(geneDistArray, geneCount); calcDistances(geneDistArray, curGene, geneList, weights); qsort(geneDistArray, geneCount, sizeof(geneDistArray[0]), cmpMicroDataDistance); synQueuePut( synQ, geneDistArray ); pthread_mutex_lock( &mutexDotOut ); dotOut(); pthread_mutex_unlock( &mutexDotOut ); } pthread_exit(NULL); }
void hgExpDistance(char *database, char *posTable, char *expTable, char *outTable) /* hgExpDistance - Create table that measures expression distance between pairs. */ { struct sqlConnection *conn = sqlConnect(database); struct sqlResult *sr; char query[256]; char **row; struct hash *expHash = hashNew(16); int realExpCount = -1; struct microData *geneList = NULL, *curGene, *gene; int geneIx, geneCount = 0; struct microData **geneArray = NULL; float *weights = NULL; char *tempDir = "."; FILE *f = hgCreateTabFile(tempDir, outTable); /* Get list/hash of all items with expression values. */ sqlSafef(query, sizeof(query), "select name,expCount,expScores from %s", posTable); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *name = row[0]; if (!hashLookup(expHash, name)) { int expCount = sqlUnsigned(row[1]); int commaCount; float *expScores = NULL; sqlFloatDynamicArray(row[2], &expScores, &commaCount); if (expCount != commaCount) errAbort("expCount and expScores don't match on %s in %s", name, posTable); if (realExpCount == -1) realExpCount = expCount; if (expCount != realExpCount) errAbort("In %s some rows have %d experiments others %d", name, expCount, realExpCount); AllocVar(gene); gene->expCount = expCount; gene->expScores = expScores; hashAddSaveName(expHash, name, gene, &gene->name); slAddHead(&geneList, gene); } } sqlFreeResult(&sr); conn = sqlConnect(database); slReverse(&geneList); geneCount = slCount(geneList); printf("Have %d elements in %s\n", geneCount, posTable); weights = getWeights(realExpCount); if (optionExists("lookup")) geneList = lookupGenes(conn, optionVal("lookup", NULL), geneList); geneCount = slCount(geneList); printf("Got %d unique elements in %s\n", geneCount, posTable); sqlDisconnect(&conn); /* Disconnect because next step is slow. */ if (geneCount < 1) errAbort("ERROR: unique gene count less than one ?"); /* Get an array for sorting. */ AllocArray(geneArray, geneCount); for (gene = geneList,geneIx=0; gene != NULL; gene = gene->next, ++geneIx) geneArray[geneIx] = gene; /* Print out closest 1000 in tab file. */ for (curGene = geneList; curGene != NULL; curGene = curGene->next) { calcDistances(curGene, geneList, weights); qsort(geneArray, geneCount, sizeof(geneArray[0]), cmpMicroDataDistance); for (geneIx=0; geneIx < 1000 && geneIx < geneCount; ++geneIx) { gene = geneArray[geneIx]; fprintf(f, "%s\t%s\t%f\n", curGene->name, gene->name, gene->distance); } dotOut(); } printf("Made %s.tab\n", outTable); /* Create and load table. */ conn = sqlConnect(database); distanceTableCreate(conn, outTable); hgLoadTabFile(conn, tempDir, outTable, &f); printf("Loaded %s\n", outTable); /* Add indices. */ sqlSafef(query, sizeof(query), "alter table %s add index(query)", outTable); sqlUpdate(conn, query); printf("Made query index\n"); if (optionExists("targetIndex")) { sqlSafef(query, sizeof(query), "alter table %s add index(target)", outTable); sqlUpdate(conn, query); printf("Made target index\n"); } hgRemoveTabFile(tempDir, outTable); }