openmidending-stat.cc
Go to the documentation of this file.
00001 /* show-eval.cc
00002  */
00003 #include "osl/eval/ml/openMidEndingEval.h"
00004 #include "osl/progress/ml/newProgress.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/state/numEffectState.h"
00007 #include "osl/stat/variance.h"
00008 #include "osl/oslConfig.h"
00009 #include <iostream>
00010 #include <iomanip>
00011 #include <cstdlib>
00012 #include <cstdio>
00013 #include <unistd.h>
00014 
00015 using namespace osl;
00016 using namespace osl::eval;
00017 
00018 void usage(const char *prog)
00019 {
00020   using namespace std;
00021   cerr << "Usage: " << prog << " csa-filename"
00022        << endl;
00023   exit(1);
00024 }
00025 
00026 void show(const char *filename);
00027 void finish();
00028 
00029 int main(int argc, char **argv)
00030 {
00031   const char *program_name = argv[0];
00032   bool error_flag = false;
00033 
00034   extern int optind;
00035   char c;
00036   while ((c = getopt(argc, argv, "e:vh")) != EOF)
00037   {
00038     switch(c)
00039     {
00040     default:    error_flag = true;
00041     }
00042   }
00043   argc -= optind;
00044   argv += optind;
00045 
00046   if (error_flag)
00047     usage(program_name);
00048 
00049   eval::ml::OpenMidEndingEval::setUp();
00050   progress::ml::NewProgress::setUp();
00051   
00052   for (int i=0; i<argc; ++i)
00053   {
00054     show(argv[i]);
00055   }
00056   finish();
00057 }
00058 
00059 using namespace osl::eval::ml;
00060 using osl::stat::Variance;
00061 CArray<CArray<Variance,4>, OpenMidEndingEvalDebugInfo::STAGE_FEATURE_LIMIT>
00062 stage_features;
00063 CArray<Variance, OpenMidEndingEvalDebugInfo::PROGRESS_INDEPENDENT_FEATURE_LIMIT>
00064 progress_independent_features;
00065 
00066 void show(const NumEffectState& state)
00067 {
00068   OpenMidEndingEval eval(state);
00069   const OpenMidEndingEvalDebugInfo info = eval.debugInfo(state);
00070   for (int i=0; i<OpenMidEndingEvalDebugInfo::STAGE_FEATURE_LIMIT; ++i)
00071     for (int s=0; s<4; ++s)
00072       stage_features[i][s].add(info.stage_values[i][s]);
00073   for (int i=0; i<OpenMidEndingEvalDebugInfo::PROGRESS_INDEPENDENT_FEATURE_LIMIT; ++i)
00074     progress_independent_features[i].add(info.progress_independent_values[i]);}
00075 
00076 void finish()
00077 {
00078   for (int i=0; i<OpenMidEndingEvalDebugInfo::STAGE_FEATURE_LIMIT; ++i)
00079     for (int s=0; s<4; ++s)
00080       std::cout << OpenMidEndingEvalDebugInfo::name((OpenMidEndingEvalDebugInfo::StageFeature)i)
00081                 << s
00082                 << " " << stage_features[i][s].getAverage()
00083                 << " " << sqrt(stage_features[i][s].variance()) << "\n";
00084   for (int i=0; i<OpenMidEndingEvalDebugInfo::PROGRESS_INDEPENDENT_FEATURE_LIMIT; ++i)
00085     std::cout << OpenMidEndingEvalDebugInfo::name((OpenMidEndingEvalDebugInfo::ProgressIndependentFeature)i)
00086               << " " << progress_independent_features[i].getAverage()
00087               << " " << sqrt(progress_independent_features[i].variance()) << "\n";
00088 }
00089 
00090 void show(const char *filename)
00091 {
00092   CsaFile file(filename);
00093   const vector<osl::Move> moves = file.getRecord().getMoves();
00094   NumEffectState state(file.getInitialState());
00095   for (unsigned int i=0; i<moves.size(); i++)
00096   {
00097     show(state);
00098     const Move m = moves[i];
00099     state.makeMove(m);
00100   }
00101   show(state);
00102 }
00103 
00104 /* ------------------------------------------------------------------------- */
00105 // ;;; Local Variables:
00106 // ;;; mode:c++
00107 // ;;; c-basic-offset:2
00108 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines