diff options
-rw-r--r-- | src/aig/gia/giaGen.c | 26 | ||||
-rw-r--r-- | src/base/abci/abc.c | 27 |
2 files changed, 41 insertions, 12 deletions
diff --git a/src/aig/gia/giaGen.c b/src/aig/gia/giaGen.c index affcba37..f79e4c5f 100644 --- a/src/aig/gia/giaGen.c +++ b/src/aig/gia/giaGen.c @@ -293,6 +293,20 @@ void Gia_ManDumpPlaFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, cha SeeAlso [] ***********************************************************************/ +void Gia_ManSimLogStats( Gia_Man_t * p, char * pDumpFile, int Total, int Correct ) +{ + FILE * pTable = fopen( pDumpFile, "wb" ); + fprintf( pTable, "{\n" ); + fprintf( pTable, " \"name\" : \"%s\",\n", p->pName ); + fprintf( pTable, " \"input\" : %d,\n", Gia_ManCiNum(p) ); + fprintf( pTable, " \"output\" : %d,\n", Gia_ManCoNum(p) ); + fprintf( pTable, " \"and\" : %d,\n", Gia_ManAndNum(p) ); + fprintf( pTable, " \"level\" : %d\n", Gia_ManLevelNum(p) ); + fprintf( pTable, " \"total\" : %d\n", Total ); + fprintf( pTable, " \"correct\" : %d\n", Correct ); + fprintf( pTable, "}\n" ); + fclose( pTable ); +} int Gia_ManSimParamRead( char * pFileName, int * pnIns, int * pnWords ) { int c, nIns = -1, nLines = 0, Count = 0, fReadDot = 0; @@ -376,9 +390,9 @@ void Gia_ManSimFileRead( char * pFileName, int nIns, int nWords, Vec_Wrd_t * vSi } assert( nPats == 64*nWords ); fclose( pFile ); - printf( "Read %d simulation patterns for %d inputs. Probability of 1 at the output is %6.2f %%.\n", 64*nWords, nIns, 100.0*Vec_IntSum(vValues)/nPats ); + printf( "Finished reading %d simulation patterns for %d inputs. Probability of 1 at the output is %6.2f %%.\n", 64*nWords, nIns, 100.0*Vec_IntSum(vValues)/nPats ); } -void Gia_ManCompareValues( Gia_Man_t * p, Vec_Wrd_t * vSimsIn, Vec_Int_t * vValues ) +void Gia_ManCompareValues( Gia_Man_t * p, Vec_Wrd_t * vSimsIn, Vec_Int_t * vValues, char * pDumpFile ) { int i, Value, Guess, Count = 0, nWords = Vec_WrdSize(vSimsIn) / Gia_ManCiNum(p); word * pSims; @@ -394,6 +408,10 @@ void Gia_ManCompareValues( Gia_Man_t * p, Vec_Wrd_t * vSimsIn, Vec_Int_t * vValu Vec_IntSize(vValues), Vec_IntSize(vValues) - Count, Count, 100.0*Count/Vec_IntSize(vValues), Guess, 100.0*Guess/Vec_IntSize(vValues)); + if ( pDumpFile == NULL ) + return; + Gia_ManSimLogStats( p, pDumpFile, Vec_IntSize(vValues), Count ); + printf( "Finished dumping statistics into file \"%s\".\n", pDumpFile ); } /**Function************************************************************* @@ -407,7 +425,7 @@ void Gia_ManCompareValues( Gia_Man_t * p, Vec_Wrd_t * vSimsIn, Vec_Int_t * vValu SeeAlso [] ***********************************************************************/ -void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName ) +void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName, char * pDumpFile ) { Vec_Wrd_t * vSimsIn; Vec_Int_t * vValues; @@ -422,7 +440,7 @@ void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName ) vSimsIn = Vec_WrdStart( nIns * nWords ); vValues = Vec_IntAlloc( nWords * 64 ); Gia_ManSimFileRead( pFileName, nIns, nWords, vSimsIn, vValues ); - Gia_ManCompareValues( p, vSimsIn, vValues ); + Gia_ManCompareValues( p, vSimsIn, vValues, pDumpFile ); Vec_WrdFree( vSimsIn ); Vec_IntFree( vValues ); } diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 732974ce..da87214c 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -32651,15 +32651,25 @@ usage: ***********************************************************************/ int Abc_CommandAbc9MLTest( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName ); + extern void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName, char * pDumpFile ); int c, fVerbose = 0; + char * pDumpFile = NULL; char ** pArgvNew; int nArgcNew; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "Dvh" ) ) != EOF ) { switch ( c ) { + case 'D': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-D\" should be followed by a file name.\n" ); + goto usage; + } + pDumpFile = argv[globalUtilOptind]; + globalUtilOptind++; + break; case 'v': fVerbose ^= 1; break; @@ -32687,15 +32697,16 @@ int Abc_CommandAbc9MLTest( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( -1, "Abc_CommandAbc9MLTest(): Expecting data file name on the command line.\n" ); return 0; } - Gia_ManTestOneFile( pAbc->pGia, pArgvNew[0] ); + Gia_ManTestOneFile( pAbc->pGia, pArgvNew[0], pDumpFile ); return 0; usage: - Abc_Print( -2, "usage: &mltest [-vh] <file>\n" ); - Abc_Print( -2, "\t testing command for machine learning data\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); - Abc_Print( -2, "\t<file> : file with input simulation info\n"); + Abc_Print( -2, "usage: &mltest [-vh] [-D file] <file>\n" ); + Abc_Print( -2, "\t testing command for machine learning data\n" ); + Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); + Abc_Print( -2, "\t-h : print the command usage\n"); + Abc_Print( -2, "\t-D file : file name to dump statistics [default = none]\n" ); + Abc_Print( -2, "\tfile : file with input simulation info\n"); return 1; } |