The following commit has been merged in the master branch:
commit d8bab84ed864878bb02ae24295403c3575ebbf04
Author: Andrei Zavada <[email protected]>
Date:   Thu Jun 20 20:26:57 2013 +0300

    WIP (make pagesize double; increment profile computations in steps)

diff --git a/src/aghermann/expdesign/primaries.cc 
b/src/aghermann/expdesign/primaries.cc
index 272e8c0..1a75b7c 100644
--- a/src/aghermann/expdesign/primaries.cc
+++ b/src/aghermann/expdesign/primaries.cc
@@ -121,6 +121,7 @@ CExpDesign (const string& session_dir_,
 
        load_settings();
 
+       // that's pretty important: scope is not itself exposed to the user
        mc_params.scope = fft_params.pagesize;
 
 #ifdef _OPENMP
diff --git a/src/libmetrics/mc.cc b/src/libmetrics/mc.cc
index e0cab6c..ee46e95 100644
--- a/src/libmetrics/mc.cc
+++ b/src/libmetrics/mc.cc
@@ -23,10 +23,10 @@ using namespace std;
 
 
 metrics::mc::CProfile::
-CProfile (const sigfile::CTypedSource& F, int sig_no,
+CProfile (const sigfile::CTypedSource& F, const int sig_no,
          const SPPack &params)
       : metrics::CProfile (F, sig_no,
-                          params.pagesize, // acting 'pagesize' for 
metrics::CProfile
+                          params.pagesize, pagesize.step,
                           params.compute_n_bins(F().samplerate(sig_no))),
        Pp (params)
        // *_filter's initialized at compute time
@@ -43,12 +43,11 @@ fname_base() const
 {
        return agh::str::sasprintf(
                  "%s.%s-%lu"
-                 ":%zu-%g_%g" "_%g" "_%g_%g",
+                 ":%g+%g-%g_%g" "_%g" "_%g_%g",
                  _using_F().filename(), 
_using_F().channel_by_id(_using_sig_no).name(),
                  _using_F().dirty_signature( _using_sig_no),
-                 Pp.pagesize,
-                 Pp.scope,
-                 Pp.iir_backpolate,
+                 Pp.pagesize, Pp.step,
+                 Pp.scope, Pp.iir_backpolate,
                  Pp.mc_gain,
                  Pp.f0fc, Pp.bandwidth);
 }
@@ -59,14 +58,13 @@ mirror_fname() const
 {
        return agh::str::sasprintf(
                  "%s-%s-%lu"
-                 ":%zu-%g_%g" "_%g" "_%g_%g" "_%g_%g@%zu"
+                 ":%g+%g-%g_%g" "_%g" "_%g_%g" "_%g_%g@%zu"
                  ".mc",
                  agh::fs::make_fname_base (_using_F().filename(), "", 
true).c_str(),
                  _using_F().channel_by_id(_using_sig_no).name(),
                  _using_F().dirty_signature( _using_sig_no),
-                 Pp.pagesize,
-                 Pp.scope,
-                 Pp.iir_backpolate,
+                 Pp.pagesize, Pp.step,
+                 Pp.scope, Pp.iir_backpolate,
                  Pp.mc_gain,
                  Pp.f0fc, Pp.bandwidth,
                  Pp.freq_from, Pp.freq_inc,
@@ -123,12 +121,12 @@ export_tsv( const string& fname) const
        auto sttm = _using_F().start_time();
        char *asctime_ = asctime( localtime( &sttm));
        fprintf( f, "## Subject: %s;  Session: %s, Episode: %s recorded %.*s;  
Channel: %s\n"
-                "## Total EEG Microcontinuity course (%zu %zu-sec pages) from 
%g up to %g Hz in bins of %g Hz\n"
+                "## Total EEG Microcontinuity course (%zu %g-sec pages, step 
%g sec) from %g up to %g Hz in bins of %g Hz\n"
                 "#Page\t",
                 _using_F().subject().name.c_str(), _using_F().session(), 
_using_F().episode(),
                 (int)strlen(asctime_)-1, asctime_,
                 _using_F().channel_by_id(_using_sig_no).name(),
-                pages(), Pp.pagesize, Pp.freq_from, Pp.freq_from + 
Pp.bandwidth * bins(), Pp.bandwidth);
+                pages(), Pp.pagesize, Pp.step, Pp.freq_from, Pp.freq_from + 
Pp.bandwidth * bins(), Pp.bandwidth);
 
        for ( bin = 0; bin < _bins; ++bin, bum += Pp.bandwidth )
                fprintf( f, "%g%c", bum, bin+1 == _bins ? '\n' : '\t');
@@ -158,11 +156,11 @@ export_tsv( size_t bin,
        char *asctime_ = asctime( localtime( &sttm));
        fprintf( f, "## Microcontinuity profile of\n"
                 "## Subject: %s;  Session: %s, Episode: %s recorded %.*s;  
Channel: %s\n"
-                "## Course (%zu %zu-sec pages) in range %g-%g Hz\n",
+                "## Course (%zu %g-sec pages, step %g sec) in range %g-%g 
Hz\n",
                 _using_F().subject().name.c_str(), _using_F().session(), 
_using_F().episode(),
                 (int)strlen(asctime_)-1, asctime_,
                 _using_F().channel_by_id(_using_sig_no).name(),
-                pages(), Pp.pagesize, Pp.freq_from, Pp.freq_from + (bin+1) * 
Pp.bandwidth);
+                pages(), Pp.pagesize, Pp.step, Pp.freq_from, Pp.freq_from + 
(bin+1) * Pp.bandwidth);
 
        for ( size_t p = 0; p < pages(); ++p )
                fprintf( f, "%zu\t%g\n", p, nmth_bin(p, bin));
diff --git a/src/libmetrics/mc.hh b/src/libmetrics/mc.hh
index 6791507..35e123c 100644
--- a/src/libmetrics/mc.hh
+++ b/src/libmetrics/mc.hh
@@ -76,10 +76,15 @@ struct SPPack
 
        void check() const // throws
                {
-                       if ( mc_gain < 1.0 )
-                               throw invalid_argument ("mc_gain must be >= 
1.0");
-                       // if ( (int)(pagesize/scope) != (double)pagesize / 
(double)scope )
-                       //      throw invalid_argument ("Page size not a 
multiple of MC scope");
+#ifdef _OPENMP
+#pragma omp single
+#endif
+                       {
+                               if ( mc_gain < 1.0 )
+                                       throw invalid_argument ("mc_gain must 
be >= 1.0");
+                               // if ( (int)(pagesize/scope) != 
(double)pagesize / (double)scope )
+                               //      throw invalid_argument ("Page size not 
a multiple of MC scope");
+                       }
                }
 
        void reset()
diff --git a/src/libmetrics/page-metrics-base.cc 
b/src/libmetrics/page-metrics-base.cc
index e1faeab..767777a 100644
--- a/src/libmetrics/page-metrics-base.cc
+++ b/src/libmetrics/page-metrics-base.cc
@@ -30,7 +30,7 @@ using namespace std;
 
 metrics::CProfile::
 CProfile (const sigfile::CTypedSource& F, int sig_no,
-         size_t pagesize, size_t bins)
+         double pagesize, double step, size_t bins)
       : _status (0),
        _bins (bins),
        _signature_when_mirrored (0),
@@ -38,6 +38,7 @@ CProfile (const sigfile::CTypedSource& F, int sig_no,
        _using_sig_no (sig_no)
 {
        Pp.pagesize = pagesize;
+       Pp.step = step;
 }
 
 size_t
@@ -51,7 +52,7 @@ size_t
 metrics::CProfile::
 pages() const
 {
-       return _using_F().recording_time() / Pp.pagesize;
+       return _using_F().recording_time() / Pp.step;
 }
 
 
@@ -59,20 +60,27 @@ void
 metrics::SPPack::
 check() const
 {
-       for ( auto c : {4u, 20u, 30u, 60u} )
+       for ( auto c : {4., 20., 30., 60.} )
                if ( pagesize == c )
                        return;
 #ifdef _OPENMP
 #pragma omp critical
 #endif
        throw invalid_argument (string ("Invalid pagesize: ") + 
to_string(pagesize));
+
+       if ( step <= pagesize )
+               return;
+#ifdef _OPENMP
+#pragma omp critical
+#endif
+       throw invalid_argument (string ("step > pagesize: ") + to_string(step) 
+ " > "+ to_string(pagesize));
 }
 
 void
 metrics::SPPack::
 reset()
 {
-       pagesize = 30;
+       pagesize = step = 30.;
 }
 
 
diff --git a/src/libmetrics/page-metrics-base.hh 
b/src/libmetrics/page-metrics-base.hh
index 61242a0..65ff15e 100644
--- a/src/libmetrics/page-metrics-base.hh
+++ b/src/libmetrics/page-metrics-base.hh
@@ -50,7 +50,8 @@ name( TType t)
 
 
 struct SPPack {
-       size_t  pagesize;
+       double  pagesize,
+               step;
 
        SPPack ()
                {
@@ -59,11 +60,12 @@ struct SPPack {
 
        virtual bool same_as( const SPPack& rv) const
                {
-                       return pagesize == rv.pagesize;
+                       return pagesize == rv.pagesize && step == rv.step;
                }
        virtual void make_same( const SPPack& rv)
                {
                        pagesize = rv.pagesize;
+                       step = rv.step;
                }
 
        void check() const; // throws
@@ -79,7 +81,7 @@ class CProfile {
 
     protected:
        CProfile (const sigfile::CTypedSource&, int sig_no,
-                 size_t pagesize, size_t bins);
+                 double pagesize, double step, size_t bins);
        CProfile (const CProfile&) = default;
     public:
        SPPack  Pp;
diff --git a/src/libmetrics/psd.cc b/src/libmetrics/psd.cc
index eed2da7..0f062fd 100644
--- a/src/libmetrics/psd.cc
+++ b/src/libmetrics/psd.cc
@@ -42,12 +42,12 @@ metrics::psd::TFFTWPlanType
 
 
 metrics::psd::CProfile::
-CProfile (const sigfile::CTypedSource& F, int sig_no,
-         const SPPack &fft_params)
+CProfile (const sigfile::CTypedSource& F, const int sig_no,
+         const SPPack &params)
        : metrics::CProfile (F, sig_no,
-                            fft_params.pagesize,
-                            fft_params.compute_n_bins(F().samplerate(sig_no))),
-         Pp (fft_params)
+                            params.pagesize, params.step,
+                            params.compute_n_bins( F().samplerate(sig_no))),
+         Pp (params)
 {
        Pp.check();
 }
@@ -60,10 +60,10 @@ fname_base() const
 {
        return agh::str::sasprintf(
                  "%s.%s-%lu"
-                 ":%zu-%g-%c%c",
+                 ":%g+%g-%g-%c%c",
                  _using_F().filename(), 
_using_F().channel_by_id(_using_sig_no).name(),
                  _using_F().dirty_signature( _using_sig_no),
-                 Pp.pagesize, Pp.binsize,
+                 Pp.pagesize, Pp.step, Pp.binsize,
                  'a'+(char)Pp.welch_window_type, 'a'+(char)Pp.plan_type);
 }
 
@@ -75,12 +75,12 @@ mirror_fname() const
 {
        return agh::str::sasprintf(
                  "%s.%s-%lu"
-                 ":%zu-%g-%c%c@%zu"
+                 ":%g+%g-%g-%c%c@%zu"
                  ".psd",
                  agh::fs::make_fname_base (_using_F().filename(), "", 
true).c_str(),
                  _using_F().channel_by_id(_using_sig_no).name(),
                  _using_F().dirty_signature( _using_sig_no),
-                 Pp.pagesize, Pp.binsize,
+                 Pp.pagesize, Pp.step, Pp.binsize,
                  'a'+(char)Pp.welch_window_type, 'a'+(char)Pp.plan_type,
                  sizeof(double));
 }
@@ -95,7 +95,8 @@ go_compute()
        _data.resize( pages() * _bins);
 
        size_t  sr = samplerate();
-       size_t  spp = sr * Pp.pagesize;
+       size_t  spp = sr * Pp.pagesize,
+               sps = sr * Pp.step;
 //     double  freq_max = (spp+1)/2 / sr;
 
       // 0. get signal sample; always use double not TFloat
@@ -164,7 +165,7 @@ go_compute()
        }
 
        for ( p = 0; p < pages(); ++p ) {
-               memcpy( fft_Ti, &S[p*spp], spp * sizeof(double));
+               memcpy( fft_Ti, &S[p * sps], spp * sizeof(double));
                for ( size_t s = 0; s < spp; ++s )
                        fft_Ti[s] *= W[s];
 
@@ -219,12 +220,12 @@ export_tsv( const string& fname) const
        auto sttm = _using_F().start_time();
        char *asctime_ = asctime( localtime( &sttm));
        fprintf( f, "## Subject: %s;  Session: %s, Episode: %s recorded %.*s;  
Channel: %s\n"
-                "## Total spectral power course (%zu %zu-sec pages) up to %g 
Hz in bins of %g Hz\n"
+                "## Total spectral power course (%zu %g-sec pages, step %g 
sec) up to %g Hz in bins of %g Hz\n"
                 "#Page\t",
                 _using_F().subject().name.c_str(), _using_F().session(), 
_using_F().episode(),
                 (int)strlen(asctime_)-1, asctime_,
                 _using_F().channel_by_id(_using_sig_no).name(),
-                pages(), Pp.pagesize, _bins*Pp.binsize, Pp.binsize);
+                pages(), Pp.pagesize, Pp.step, _bins*Pp.binsize, Pp.binsize);
 
        for ( bin = 0; bin < _bins; ++bin, bum += Pp.binsize )
                fprintf( f, "%g%c", bum, bin+1 == _bins ? '\n' : '\t');
@@ -256,11 +257,11 @@ export_tsv( float from, float upto,
        char *asctime_ = asctime( localtime( &sttm));
        fprintf( f, "PSD profile of\n"
                 "## Subject: %s;  Session: %s, Episode: %s recorded %.*s;  
Channel: %s\n"
-                "## Course (%zu %zu-sec pages) in range %g-%g Hz\n",
+                "## Course (%zu %g-sec pages, step %g) in range %g-%g Hz\n",
                 _using_F().subject().name.c_str(), _using_F().session(), 
_using_F().episode(),
                 (int)strlen(asctime_)-1, asctime_,
                 _using_F().channel_by_id(_using_sig_no).name(),
-                pages(), Pp.pagesize, from, upto);
+                pages(), Pp.pagesize, Pp.step, from, upto);
 
        valarray<TFloat> crs = course( from, upto);
        for ( size_t p = 0; p < pages(); ++p )
diff --git a/src/libmetrics/psd.hh b/src/libmetrics/psd.hh
index 55eb346..0d1c15c 100644
--- a/src/libmetrics/psd.hh
+++ b/src/libmetrics/psd.hh
@@ -93,23 +93,24 @@ struct SPPack
 
        void check() const
                {
-                       metrics::SPPack::check();
-
-                       if ( welch_window_type > 
sigproc::TWinType::TWinType_total )
-// What was that?
-// #ifdef _OPENMP
-// #pragma omp single
-// #endif
-                               throw invalid_argument ("Invalid window type");
-
-                       if ( plan_type != metrics::psd::TFFTWPlanType::estimate 
&&
-                            plan_type != metrics::psd::TFFTWPlanType::measure )
-                               throw invalid_argument ("Invalid FFTW plan 
type");
-
-                       for ( auto c : {.1, .25, .5} )
-                               if ( binsize == c )
-                                       return;
-                       throw invalid_argument ("Invalid binsize");
+#ifdef _OPENMP
+#pragma omp single
+#endif
+                       {
+                               metrics::SPPack::check();
+
+                               if ( welch_window_type > 
sigproc::TWinType::TWinType_total )
+                                       throw invalid_argument ("Invalid window 
type");
+
+                               if ( plan_type != 
metrics::psd::TFFTWPlanType::estimate &&
+                                    plan_type != 
metrics::psd::TFFTWPlanType::measure )
+                                       throw invalid_argument ("Invalid FFTW 
plan type");
+
+                               for ( auto c : {.1, .25, .5} )
+                                       if ( binsize == c )
+                                               return;
+                               throw invalid_argument ("Invalid binsize");
+                       }
                }
 
        void reset()
diff --git a/src/libmetrics/swu.cc b/src/libmetrics/swu.cc
index 1566c76..eb5d267 100644
--- a/src/libmetrics/swu.cc
+++ b/src/libmetrics/swu.cc
@@ -24,10 +24,10 @@ using namespace std;
 
 
 metrics::swu::CProfile::
-CProfile (const sigfile::CTypedSource& F, int sig_no,
+CProfile (const sigfile::CTypedSource& F, const int sig_no,
          const SPPack &params)
       : metrics::CProfile (F, sig_no,
-                          params.pagesize,
+                          params.pagesize, params.step,
                           params.compute_n_bins(F().samplerate(sig_no))),
        Pp (params)
 {
@@ -42,10 +42,10 @@ fname_base() const
 {
        return agh::str::sasprintf(
                  "%s.%s-%lu"
-                 ":%zu-%g",
+                 ":%g+%g-%g",
                  _using_F().filename(), 
_using_F().channel_by_id(_using_sig_no).name(),
                  _using_F().dirty_signature( _using_sig_no),
-                 Pp.pagesize, Pp.min_upswing_duration);
+                 Pp.pagesize, Pp.step, Pp.min_upswing_duration);
 }
 
 
@@ -55,12 +55,12 @@ mirror_fname() const
 {
        return agh::str::sasprintf(
                  "%s.%s-%lu"
-                 ":%zu-%g@%zu"
+                 ":%g+%g-%g@%zu"
                  ".swu",
                  agh::fs::make_fname_base (_using_F().filename(), "", 
true).c_str(),
                  _using_F().channel_by_id(_using_sig_no).name(),
                  _using_F().dirty_signature( _using_sig_no),
-                 Pp.pagesize, Pp.min_upswing_duration,
+                 Pp.pagesize, p.step, Pp.min_upswing_duration,
                  sizeof(TFloat));
 }
 
@@ -75,10 +75,11 @@ go_compute()
                _using_F().get_signal_filtered( _using_sig_no));
 
        for ( size_t p = 0; p < pages(); ++p ) {
-               auto    a =  p    * (samplerate() * Pp.pagesize),
-                       z = (p+1) * (samplerate() * Pp.pagesize);
+               auto    a = p * (samplerate() * Pp.step),
+                       z = a + (samplerate() * Pp.pagesize);
                auto    la = a, lz = a;
                double  Q = 0.;
+
              // 1. upswing proper
                // find a stretch of uninterrupted positive values
                for ( auto i = a; i < z; ++i ) {
@@ -125,12 +126,12 @@ export_tsv( const string& fname) const
        auto sttm = _using_F().start_time();
        char *asctime_ = asctime( localtime( &sttm));
        fprintf( f, "## Subject: %s;  Session: %s, Episode: %s recorded %.*s;  
Channel: %s\n"
-                "## SWU course (%zu %zu-sec pages)\n"
+                "## SWU course (%zu %g-sec pages, step %g sec)\n"
                 "#Page\tSWU\n",
                 _using_F().subject().name.c_str(), _using_F().session(), 
_using_F().episode(),
                 (int)strlen(asctime_)-1, asctime_,
                 _using_F().channel_by_id(_using_sig_no).name(),
-                pages(), Pp.pagesize);
+                pages(), Pp.pagesize, Pp.step);
 
        for ( size_t p = 0; p < pages(); ++p )
                fprintf( f, "%zu\t%g\n", p, nmth_bin( p, 0));

-- 
Sleep experiment manager

_______________________________________________
debian-med-commit mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit

Reply via email to