bool TSData::fromTextFile(QString fileName, TSData **ts) { int count, dim; float **Data; int ok = ReadInputData(&Data, &count, &dim, fileName.toLatin1().data()); if (!ok) { return false; } float **minMax = FindMinMax(Data, count, dim); TRAININGSET generated_ts = WriteData2CB(Data, count, dim, minMax, 1); /* TODO: we're throwing away the minmax file, that isn't nice but shouldn't matter if we don't want to do conversion back to txt */ *ts = new TSData(&generated_ts); fvDeleteSet(Data, count); fvDeleteSet(minMax, dim); FreeCodebook(&generated_ts); return true; }
bool ColorHarmonizationEngineGlobal::Process() { const std::string vec_selectionMethod[ 3 ] = { "fullFrame", "matchedPoints", "KVLD" }; const std::string vec_harmonizeMethod[ 1 ] = { "quantifiedGainCompensation" }; const int harmonizeMethod = 0; //------------------- // Load data //------------------- if( !ReadInputData() ) return false; if( _map_Matches.size() == 0 ) { cout << endl << "Matches file is empty" << endl; return false; } //-- Remove EG with poor support: for (matching::PairWiseMatches::iterator iter = _map_Matches.begin(); iter != _map_Matches.end(); ++iter) { if (iter->second.size() < 120) { _map_Matches.erase(iter); iter = _map_Matches.begin(); } } { graph::indexedGraph putativeGraph(getPairs(_map_Matches)); // Save the graph before cleaning: graph::exportToGraphvizData( stlplus::create_filespec(_sOutDirectory, "input_graph_poor_supportRemoved"), putativeGraph.g); } //------------------- // Keep the largest CC in the image graph //------------------- if (!CleanGraph()) { std::cout << std::endl << "There is no largest CC in the graph" << std::endl; return false; } //------------------- //-- Color Harmonization //------------------- //Choose image reference if( _imgRef == -1 ) { do { cout << "Choose your reference image:\n"; for( int i = 0; i < _vec_fileNames.size(); ++i ) { cout << "id: " << i << "\t" << _vec_fileNames[ i ] << endl; } }while( !( cin >> _imgRef ) || _imgRef < 0 || _imgRef >= _vec_fileNames.size() ); } //Choose selection method if( _selectionMethod == -1 ) { cout << "Choose your selection method:\n" << "- FullFrame: 0\n" << "- Matched Points: 1\n" << "- VLD Segment: 2\n"; while( ! ( cin >> _selectionMethod ) || _selectionMethod < 0 || _selectionMethod > 2 ) { cout << _selectionMethod << " is not accepted.\nTo use: \n- FullFrame enter: 0\n- Matched Points enter: 1\n- VLD Segment enter: 2\n"; } }
TInt DoZipDownload(RFile &aBootFile) { TZipInfo z; z.iRemain=FileSize; InitProgressBar(0,(TUint)FileSize,_L("LOAD")); TInt r=Initialise(z); CHECK(r); RThread t; t.SetHandle(z.iThreadHandle); while (z.iRemain && z.iThreadStatus==KRequestPending) { TRequestStatus dummy; TRequestStatus* pS=&dummy; r=ReadBlockToBuffer(z, aBootFile); if (r != KErrNone) { PrintToScreen(_L("FAULT: Unzip Error %d\r\n"),r); if (z.iFileBufW-z.iFileBufR==z.iFileBufSize) { PrintToScreen(_L("Check there is only one image\n\rin the zip file.\r\n")); } CHECK(r); } UpdateProgressBar(0,(TUint)(FileSize-z.iRemain)); t.RequestComplete(pS,0); // same process while(z.iHeaderDone==0 && z.iThreadStatus==KRequestPending) { DELAY(20000); } if (z.iHeaderDone==1 && z.iThreadStatus==KRequestPending) { // after reading first block, process the header ProcessHeader(z); } } // while User::WaitForRequest(z.iThreadStatus); TInt exitType=t.ExitType(); TInt exitReason=t.ExitReason(); if (z.iRemain || exitType!=EExitKill || exitReason!=KErrNone) { TBuf<32> exitCat=t.ExitCategory(); PrintToScreen(_L("Exit code %d,%d,%S\n"),exitType,exitReason,&exitCat); TEST(0); } PrintToScreen(_L("Unzip complete\r\n")); TUint8* pD=Buffer; TInt len=1024; r=ReadInputData(pD,len); TEST(r==KErrEof); DELAY(20000); Cleanup(z); return KErrNone; }
int main(void) { int i,j,k; int NumberOfCycles; double PressureSum,PressureCount,Pressure; double ChemicalPotentialSum,ChemicalPotentialCount,Dummy1,Dummy2; double EnergySquaredSum,EnergySum,EnergyCount; VECTOR pos; FILE *FilePtrMovie,*FilePtr; printf("**************** Mc_Nvt ***************\n"); // initialize system ReadInputData(); FilePtr=fopen("results.dat","w"); FilePtrMovie=fopen("movie.pdb","w"); NumberOfCycles=0; PressureSum=0.0; PressureCount=0.0; ChemicalPotentialSum=0.0; ChemicalPotentialCount=0.0; EnergySquaredSum=0.0; EnergySum=0.0; EnergyCount=0; // total energy of the system EnergySystem(); printf(" Total Energy Initial Configuration: %lf\n",TotalEnergy); printf(" Total Virial Initial Configuration: %lf\n",TotalVirial); RunningEnergy=TotalEnergy; RunningVirial=TotalVirial; // start MC-cycles for(i=1;i<=2;i++) { // i=1 equilibration // i=2 production if (i==EQUILIBRATION) { NumberOfCycles=NumberOfEquilibrationCycles; if (NumberOfCycles!=0) printf(" Start Equilibration\n"); } else { if(NumberOfCycles!=0) printf(" Start Production\n"); NumberOfCycles=NumberOfProductionCycles; } NumberOfAttempts=0; NumberOfAcceptedMoves=0; // intialize the subroutine that adjust the maximum displacement Adjust(); for(j=0;j<NumberOfCycles;j++) { // attempt to displace a particle for(k=0;k<NumberOfDisplacementsPerCycle;k++) Mcmove(); if(i==PRODUCTION) { // sample averages if((j%SamplingFrequency)==0) { EnergySquaredSum+=SQR(RunningEnergy); EnergySum+=RunningEnergy; EnergyCount+=1.0; Sample(j,RunningEnergy,RunningVirial,&Pressure,FilePtr); PressureSum+=Pressure; PressureCount+=1.0; // calculate the chemical potential: // do 10 trials // calculate the average of [exp(-Beta*Energy)] // you can use the subroutine EnergyParticle for this for(k=0;k<10;k++) { // start modification // end modification } } } if((j%20)==0) WritePdb(FilePtrMovie); if((j%(NumberOfCycles/5))==0) { printf("======>> Done %d out of %d\n",j,NumberOfCycles); // write intermediate configuration to file Store(); // adjust maximum displacements Adjust(); } } if(NumberOfCycles!=0) { if (NumberOfAttempts!=0) { printf("Number Of Att. To Displ. A Part. : %d\n",NumberOfAttempts); printf("Success: %d (%lf)\n",NumberOfAcceptedMoves,100.0*NumberOfAcceptedMoves/NumberOfAttempts); } // test total energy EnergySystem(); if(fabs(TotalEnergy-RunningEnergy)>1.0e-6) printf("######### Problems Energy ################\n"); if(fabs(TotalVirial-RunningVirial)>1.0e-6) printf("######### Problems Virial ################\n"); printf(" Total Energy End Of Simulation : %lf\n",TotalEnergy); printf(" Running Energy : %lf\n",RunningEnergy); printf(" Difference : %lf\n",TotalEnergy-RunningEnergy); printf(" Total Virial End Of Simulation : %lf\n",TotalVirial); printf(" Running Virial : %lf\n",RunningVirial); printf(" Difference : %lf\n",TotalVirial-RunningVirial); // print chemical potential and pressure if(i==PRODUCTION) { printf("Average Pressure : %lf\n", PressureSum/PressureCount); printf("Chemical Potential : %lf\n", -log((ChemicalPotentialSum/ChemicalPotentialCount)*(CUBE(Box)/NumberOfParticles))/Beta); printf("Heat capacity : %lf\n", (EnergySquaredSum/EnergyCount)-SQR(EnergySum/EnergyCount)); } } } Store(); fclose(FilePtrMovie); fclose(FilePtr); return 0; }