Browse code

handle seed on R side

Tom Sherman authored on 30/04/2018 12:41:20
Showing3 changed files

... ...
@@ -83,6 +83,13 @@ nPumpSamples=0, ...)
83 83
     if (whichMatrixFixed == 'P' & ncol(fixedPatterns) != ncol(D))
84 84
         stop('invalid number of columns for fixedPatterns')
85 85
     thresholdEnum <- c("unique", "cut")
86
+    
87
+    # get seed
88
+    if (seed < 0)
89
+    {
90
+        # TODO get time in milliseconds
91
+        seed <- 0
92
+    }
86 93
 
87 94
     # run algorithm with call to C++ code
88 95
     result <- cogaps_cpp(D, S, nFactor, nEquil, nEquil/10, nSample, nOutputs,
... ...
@@ -13,23 +13,14 @@
13 13
 Rcpp::List cogaps_cpp(const Rcpp::NumericMatrix &D,
14 14
 const Rcpp::NumericMatrix &S, unsigned nFactor, unsigned nEquil,
15 15
 unsigned nEquilCool, unsigned nSample, unsigned nOutputs, unsigned nSnapshots,
16
-float alphaA, float alphaP, float maxGibbmassA, float maxGibbmassP, int seed,
17
-bool messages, bool singleCellRNASeq, char whichMatrixFixed,
16
+float alphaA, float alphaP, float maxGibbmassA, float maxGibbmassP,
17
+unsigned seed, bool messages, bool singleCellRNASeq, char whichMatrixFixed,
18 18
 const Rcpp::NumericMatrix &FP, unsigned checkpointInterval,
19 19
 const std::string &cptFile, unsigned pumpThreshold, unsigned nPumpSamples)
20 20
 {
21
-    // get seed, TODO do this on R side, multiple benefits (same seed in R, C++)
22
-    uint32_t seedUsed = static_cast<uint32_t>(seed);
23
-    if (seed < 0)
24
-    {
25
-        bpt::ptime epoch(boost::gregorian::date(1970,1,1));
26
-        bpt::time_duration diff = bpt_now() - epoch;
27
-        seedUsed = static_cast<uint32_t>(diff.total_milliseconds() % 1000);
28
-    }
29
-
30 21
     // create internal state from parameters and run from there
31 22
     GapsRunner runner(D, S, nFactor, nEquil, nEquilCool, nSample,
32
-        nOutputs, nSnapshots, alphaA, alphaP, maxGibbmassA, maxGibbmassP, seedUsed,
23
+        nOutputs, nSnapshots, alphaA, alphaP, maxGibbmassA, maxGibbmassP, seed,
33 24
         messages, singleCellRNASeq, checkpointInterval, cptFile,
34 25
         whichMatrixFixed, FP);
35 26
     return runner.run();
... ...
@@ -82,6 +82,7 @@ public:
82 82
         unsigned nFactor, unsigned nEquil, unsigned nSample,
83 83
         const std::string &cptFile);
84 84
 
85
+    // run all phases of algorithm
85 86
     Rcpp::List run();
86 87
 };
87 88