void main () { int i; initiate ();//读入数据,初始化聚类中心,参数设定默认值 for (i = 1 ; ; i++) { input ();//显示、修改参数 allocate ();//完成第2-6步 if (i == I) { Dm = 0; converge (); break; } if (groupnum <= K / 2) diverge (); else { if ((groupnum >= K * 2) | ( i % 2 == 0)) converge (); else diverge (); } renum (); } showresult (); free (datafield); free (ccdhead); for (i = 0 ; i < 100 ; i++) free (group[i].center); }
CompactRealArray findZeroes(Function &f, const RealInterval &i) { CompactRealArray result; RealPoint2DArray pointArray(SEARCHCOUNT); Real step = i.getLength() / (SEARCHCOUNT-1); Real x = i.getFrom(); for(int t = 0; t < SEARCHCOUNT-1; t++, x += step) { try { pointArray.add(RealPoint2D(x,f(x))); } catch (...) { // ignore } } try { pointArray.add(RealPoint2D(i.getTo(), f(i.getTo()))); } catch (...) { // ignore } const size_t n = pointArray.size(); const RealPoint2D *lastp = &pointArray[0]; for(size_t t = 1; t < n; t++) { const RealPoint2D &p = pointArray[t]; if(sign(lastp->y) * sign(p.y) != 1) { if(lastp->y == 0) { result.add(lastp->x); } else if(p.y != 0) { // lastp->y != 0 && p.y != 0 => opposite sign result.add(converge(f,lastp->x, p.x)); } } lastp = &p; } if(lastp->y == 0) { result.add(lastp->x); } return result; }
void Heap::markRoots(double gcStartTime, void* stackOrigin, void* stackTop, MachineThreads::RegisterState& calleeSavedRegisters) { SamplingRegion samplingRegion("Garbage Collection: Marking"); GCPHASE(MarkRoots); ASSERT(isValidThreadState(m_vm)); #if ENABLE(GGC) Vector<const JSCell*> rememberedSet(m_slotVisitor.markStack().size()); m_slotVisitor.markStack().fillVector(rememberedSet); #else Vector<const JSCell*> rememberedSet; #endif #if ENABLE(DFG_JIT) DFG::clearCodeBlockMarks(*m_vm); #endif if (m_operationInProgress == EdenCollection) m_codeBlocks.clearMarksForEdenCollection(rememberedSet); else m_codeBlocks.clearMarksForFullCollection(); // We gather conservative roots before clearing mark bits because conservative // gathering uses the mark bits to determine whether a reference is valid. ConservativeRoots conservativeRoots(&m_objectSpace.blocks(), &m_storageSpace); gatherStackRoots(conservativeRoots, stackOrigin, stackTop, calleeSavedRegisters); gatherJSStackRoots(conservativeRoots); gatherScratchBufferRoots(conservativeRoots); clearLivenessData(); m_sharedData.didStartMarking(); m_slotVisitor.didStartMarking(); HeapRootVisitor heapRootVisitor(m_slotVisitor); { ParallelModeEnabler enabler(m_slotVisitor); visitExternalRememberedSet(); visitSmallStrings(); visitConservativeRoots(conservativeRoots); visitProtectedObjects(heapRootVisitor); visitArgumentBuffers(heapRootVisitor); visitException(heapRootVisitor); visitStrongHandles(heapRootVisitor); visitHandleStack(heapRootVisitor); traceCodeBlocksAndJITStubRoutines(); converge(); } // Weak references must be marked last because their liveness depends on // the liveness of the rest of the object graph. visitWeakHandles(heapRootVisitor); clearRememberedSet(rememberedSet); m_sharedData.didFinishMarking(); updateObjectCounts(gcStartTime); resetVisitors(); }
/*Functions implemnts Gauss-Seidel on a system of equations*/ int gauss_seidel(float a[][max],float x[],int n) { int i,j,p=1; float x1[max]; float s; int diagonal_dominant(float [][max],int); int converge(float [max],float [max],int); if(!diagonal_dominant(a,n))/*Checking the diagonal dominant condition*/ { printf("\nThe system is not diagonally dominant."); return 0;/*The solution cannot be obtained if system is not diagonal-dominant*/ } /*Taking the initial approximation as zero*/ for(i=0;i<n;i++) { x1[i]=0; x[i]=0; } do { printf("\n\n"); printf("Iteration %d :",p); p++; for(i=0;i<n;i++) { s=0; for(j=0;j<n;j++) { if(i!=j) s+=a[i][j]*x[j]; } x[i]=(a[i][n]-s)/a[i][i]; printf("\nx[%d]=%10.6f",i+1,x1[i]); } /*If the present result converges to the last result then we stop */ if(converge(x,x1,n)) break; for(i=0;i<n;i++) x1[i]=x[i]; }while(1); printf("\n"); return 1; }
void QLEARN() { int exploreit(); void newtrial(); void execute(int); void LEARN(); void display_Q(); void display_F(); int converge(); int DONE=-1; int trials=0; newtrial(); while(trials<10000) { ACTION=exploreit(); execute(ACTION); LEARN(); // printf("Current state [%d,%d]\n",current->row,current->column); if(previous->row==-1) { newtrial(); trials++; // printf("TRIAL %d\n",trials); } DONE=converge(); if(DONE==1) { printf("DONE in %d trials\n",trials); break; } } display_Q(); display_F(); }
/** * \return the id of vertex between two corners. * * If it wasn't previously computed, does #converge() and adds vertex to process. */ static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2) { float v[3], no[3]; int vid = getedge(process->edges, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k); if (vid != -1) return vid; /* previously computed */ converge(process, c1, c2, v); /* position */ #ifdef USE_ACCUM_NORMAL zero_v3(no); #else vnormal(process, v, no); #endif addtovertices(process, v, no); /* save vertex */ vid = (int)process->curvertex - 1; setedge(process, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k, vid); return vid; }
void diverge () { float newvar , oldvar , center; int i , j , k , l , flag; flag = 0; for (i = 0 ; i < maxindex ; i++) { if (group[i].flag != 0) { oldvar = 0;//标准差 for (j = 0 , l = 0 ; j < vectorsize ; j++) {//计算同一聚类域中各分量对应的标准差中的最大值 newvar = 0; center = * (group[i].center + j); for (k = 0 ; k < vectornum ; k++) { if (data (k , 0) == i) newvar = newvar +(center - data(k , j+1))*(center - data(k , j+1)); } if (newvar > oldvar) { oldvar = newvar; l = j; } } group[i].variance = (float) sqrt( oldvar / group[i].groupsize); if (group[i].variance > Ds) { if ((groupnum <= K/2) | ((group[i].D > Dst) & (group[i].groupsize > 2 * (Nmin + 1)))) { split (i , l); flag = 1; } } } } if (flag == 0) converge (); }
// getVertexId: return index for vertex on edge: // c1.m_value and c2.m_value are presumed of different sign // return saved index if any; else calculate and save vertex for later use UINT IsoSurfacePolygonizer::getVertexId(const HashedCubeCorner &c1, const HashedCubeCorner &c2) { #ifdef VALIDATE_OPPOSITESIGN if(c1.m_positive == c2.m_positive) { throwException(_T("getVertexId:corners have same sign. c1:%s, c2:%s"), c1.toString().cstr(), c2.toString().cstr()); } #endif const CubeEdgeHashKey edgeKey(c1.m_key, c2.m_key); const int *p = m_edgeMap.get(edgeKey); if(p != NULL) { m_statistics.m_edgeHits++; return *p; // previously computed } IsoSurfaceVertex *v1 = (c1.m_vid >= 0) ? &m_vertexArray[c1.m_vid] : NULL; IsoSurfaceVertex *v2 = (c2.m_vid >= 0) ? &m_vertexArray[c2.m_vid] : NULL; UINT result; if(v1 || v2) { int cdiffDim, vdiffDim; const double dx = fabs(c1.x-c2.x); const double dy = fabs(c1.y-c2.y); const double dz = fabs(c1.z-c2.z); if(dx > dy && dx > dz) cdiffDim = 0; else if(dy > dx && dy > dz) cdiffDim = 1; else cdiffDim = 2; if(v1 && v2) { int fisk = 1; } if(v1) { const double dvx = fabs(c1.x-v1->m_position.x); const double dvy = fabs(c1.y-v1->m_position.y); const double dvz = fabs(c1.z-v1->m_position.z); if(dvx > dvy && dvx > dvz) vdiffDim = 0; else if(dvy > dvx && dvy > dvz) vdiffDim = 1; else vdiffDim = 2; if(vdiffDim == cdiffDim) { result = c1.m_vid; m_edgeMap.put(edgeKey, result); return result; } } else { const double dvx = fabs(c2.x-v2->m_position.x); const double dvy = fabs(c2.y-v2->m_position.y); const double dvz = fabs(c2.z-v2->m_position.z); if(dvx > dvy && dvx > dvz) vdiffDim = 0; else if(dvy > dvx && dvy > dvz) vdiffDim = 1; else vdiffDim = 2; if(vdiffDim == cdiffDim) { result = c2.m_vid; m_edgeMap.put(edgeKey, result); return result; } } } IsoSurfaceVertex vertex; vertex.m_position = converge(c1, c2); // position; vertex.m_normal = getNormal(vertex.m_position); // normal result = (UINT)m_vertexArray.size(); m_vertexArray.add(vertex); m_edgeMap.put(edgeKey, result); return result; }