Browse code

dispatcher interface

Tom Sherman authored on 12/06/2018 16:01:10
Showing6 changed files

... ...
@@ -1,8 +1,8 @@
1 1
 # include macros
2
-m4_builtin([include], ax_check_compile_flag.m4)
3
-m4_builtin([include], ax_compiler_vendor.m4)
4
-m4_builtin([include], ax_compiler_version.m4)
5
-m4_builtin([include], ax_openmp.m4)
2
+m4_builtin([include], m4/ax_check_compile_flag.m4)
3
+m4_builtin([include], m4/ax_compiler_vendor.m4)
4
+m4_builtin([include], m4/ax_compiler_version.m4)
5
+m4_builtin([include], m4/ax_openmp.m4)
6 6
 
7 7
 # get version of CoGAPS from DESCRIPTION file
8 8
 AC_INIT(CoGAPS, m4_esyscmd_s([awk -e '/^Version:/ {print $2}' Repo/DESCRIPTION]))
... ...
@@ -1,28 +1,56 @@
1
-#include "GapsRunner.h"
2
-#include "file_parser/MtxParser.h"
1
+#include "GapsDispatcher.h"
3 2
 #include "math/SIMD.h"
4 3
 
5 4
 #include <Rcpp.h>
6 5
 
6
+template <class T>
7
+static Rcpp::List cogapsRun(T data, unsigned nPatterns,
8
+unsigned maxIter, unsigned outputFrequency, unsigned seed, float alphaA,
9
+float alphaP, float maxGibbsMassA, float maxGibbsMassP, bool messages,
10
+bool singleCellRNASeq)
11
+{
12
+    GapsDispatcher dispatcher;
13
+
14
+    dispatcher.setNumPatterns(nPatterns);
15
+    dispatcher.setMaxIterations(maxIter);
16
+    dispatcher.setOutputFrequency(outputFrequency);
17
+    dispatcher.setSeed(seed);
18
+    
19
+    dispatcher.setAlpha(alphaA, alphaP);
20
+    dispatcher.setMaxGibbsMass(maxGibbsmassA, maxGibbsmassP);
21
+
22
+    dispatcher.printMessages(messages);
23
+    dispatcher.singleCellRNASeq(singleCellRNASeq);
24
+    
25
+    dispatcher.loadData(D);
26
+    dispatcher.useDefaultUncertainty(); 
27
+
28
+    return dispatcher.run();
29
+}
30
+
7 31
 // [[Rcpp::export]]
8
-Rcpp::List cogaps_cpp(const Rcpp::NumericMatrix &D,
9
-const Rcpp::NumericMatrix &S, unsigned nFactor, unsigned nEquil,
10
-unsigned nEquilCool, unsigned nSample, unsigned nOutputs, unsigned nSnapshots,
11
-float alphaA, float alphaP, float maxGibbmassA, float maxGibbmassP,
12
-unsigned seed, bool messages, bool singleCellRNASeq, char whichMatrixFixed,
13
-const Rcpp::NumericMatrix &FP, unsigned checkpointInterval,
14
-const std::string &cptFile, unsigned pumpThreshold, unsigned nPumpSamples,
15
-unsigned nCores)
32
+Rcpp::List cogapsFromFile_cpp(const std::string &D, unsigned nPatterns,
33
+unsigned maxIter, unsigned outputFrequency, unsigned seed, float alphaA,
34
+float alphaP, float maxGibbsMassA, float maxGibbsMassP, bool messages,
35
+bool singleCellRNASeq)
16 36
 {
17
-    // create internal state from parameters and run from there
18
-    GapsRunner runner(D, S, nFactor, nEquil, nEquilCool, nSample,
19
-        nOutputs, nSnapshots, alphaA, alphaP, maxGibbmassA, maxGibbmassP, seed,
20
-        messages, singleCellRNASeq, checkpointInterval, cptFile,
21
-        whichMatrixFixed, FP, nCores);
22
-    return runner.run();
37
+    return cogapsRun(D, nPatterns, maxIter, outputFrequency, seed,
38
+        alphaA, alphaP, maxGibbsmassA, maxGibbsMassP, messages,
39
+        singleCellRNASeq);
23 40
 }
24 41
 
25 42
 // [[Rcpp::export]]
43
+Rcpp::List cogaps_cpp(const Rcpp::NumericMatrix &D, unsigned nPatterns,
44
+unsigned maxIter, unsigned outputFrequency, unsigned seed, float alphaA,
45
+float alphaP, float maxGibbsMassA, float maxGibbsMassP, bool messages,
46
+bool singleCellRNASeq)
47
+{
48
+    return cogapsRun(RowMatrix(D), nPatterns, maxIter, outputFrequency, seed,
49
+        alphaA, alphaP, maxGibbsmassA, maxGibbsMassP, messages,
50
+        singleCellRNASeq);
51
+}
52
+
53
+/*
26 54
 Rcpp::List cogapsFromCheckpoint_cpp(const Rcpp::NumericMatrix &D,
27 55
 const Rcpp::NumericMatrix &S, unsigned nFactor, unsigned nEquil,
28 56
 unsigned nSample, const std::string &fileName, const std::string &cptFile)
... ...
@@ -30,12 +58,7 @@ unsigned nSample, const std::string &fileName, const std::string &cptFile)
30 58
     GapsRunner runner(D, S, nFactor, nEquil, nSample, cptFile);
31 59
     return runner.run();
32 60
 }
33
-
34
-// [[Rcpp::export]]
35
-void cogapsFromFile_cpp(const std::string &D)
36
-{
37
-    // TODO implement
38
-}
61
+*/
39 62
 
40 63
 // used to convert defined macro values into strings
41 64
 #define STR_HELPER(x) #x
42 65
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+#include "GapsDispatcher.h"
2
+
3
+#include <string>
4
+
5
+Rcpp::List GapsDispatcher::run()
6
+{
7
+    for (unsigned i = 0; i < mMaxIterations; ++i)
8
+    {
9
+        // run all GapsRunners for K iterations
10
+
11
+        // sync P matrices
12
+
13
+        // broadcast master P and weight
14
+    }
15
+
16
+    // sync all P matrices to same master
17
+
18
+    for (unsigned i = 0; i < mMaxIterations; ++i)
19
+    {
20
+        // runner all samplers with sampling turned on
21
+    }
22
+
23
+    // stitch together matrices
24
+}
0 25
\ No newline at end of file
1 26
new file mode 100644
... ...
@@ -0,0 +1,77 @@
1
+#ifndef __COGAPS_DISPATCHER_H__
2
+#define __COGAPS_DISPATCHER_H__
3
+
4
+#include "GapsRunner.h"
5
+
6
+#include <string>
7
+
8
+struct GapsReturn
9
+{
10
+    ColMatrix Amean;
11
+    ColMatrix Asd;
12
+    RowMatrix Pmean;
13
+    RowMatrix Psd;
14
+    
15
+    float meanChiSq;
16
+    uint32_t seed;
17
+};
18
+
19
+// should be agnostic to external caller (R/Python/CLI)
20
+class GapsDispatcher
21
+{
22
+private:
23
+
24
+    unsigned mNumPatterns;
25
+    unsigned mMaxIterations;
26
+    unsigned mOutputFrequency;
27
+    uint32_t mSeed;
28
+
29
+    float mAlphaA;
30
+    float mAlphaP;
31
+    float mMaxGibbsMassA;
32
+    float mMaxGibbsMassP;
33
+
34
+    bool mPrintMessages;
35
+    bool mSingleCellRnaSeq;
36
+
37
+    std:vector<GapsRunner*> mRunners;
38
+
39
+public:
40
+
41
+    GapsDispatcher() : mNumPatterns(3), mMaxIterations(1000),
42
+        mOutputFrequency(250), mSeed(0), mAlphaA(0.01), mAlphaP(0.01),
43
+        mMaxGibbsMassA(100.f), mMaxGibbsMassP(100.f), mPrintMessages(true),
44
+        mSingleCellRnaSeq(false)
45
+    {}
46
+
47
+    void setNumPatterns(unsigned n)     { mNumPatterns = n; }
48
+    void setMaxIterations(unsigned n)   { mMaxIterations = n; }
49
+    void setOutputFrequency(unsigned n) { mOutputFrequency = n; }
50
+    void setSeed(unsigned seed)         { mSeed = seed; }
51
+
52
+    void printMessages(bool print) { mPrintMessages = print; }
53
+    void singleCellRNASeq(bool sc) { mSingleCellRnaSeq = sc; }
54
+
55
+    void setAlpha(float alphaA, float alphaP)
56
+    {
57
+        mAlphaA = alphaA;
58
+        mAlphaP = alphaP;
59
+    }
60
+
61
+    void setMaxGibbsMass(float maxA, float maxP)
62
+    {
63
+        mMaxGibbsMassA = maxA;
64
+        mMaxGibbsMassP = maxP;
65
+    }
66
+
67
+    void useDefaultUncertainty();
68
+    void setUncertainty(const std::string &pathToMatrix);
69
+    void setUncertainty(const RowMatrix &S);
70
+
71
+    void loadData(const RowMatrix &D);
72
+    void loadData(const std::string &pathToData);    
73
+    
74
+    Rcpp::List run();
75
+};
76
+
77
+#endif
0 78
\ No newline at end of file
... ...
@@ -81,7 +81,10 @@ public:
81 81
 
82 82
 public:
83 83
 
84
-    // construct from parameters
84
+    // construct from file name
85
+    GapsRunner();
86
+
87
+    // construct from R object
85 88
     GapsRunner(const Rcpp::NumericMatrix &D, const Rcpp::NumericMatrix &S,
86 89
         unsigned nFactor, unsigned nEquil, unsigned nCool, unsigned nSample,
87 90
         unsigned nOutputs, unsigned nSnapshots, float alphaA, float alphaP,
... ...
@@ -94,8 +97,22 @@ public:
94 97
         unsigned nFactor, unsigned nEquil, unsigned nSample,
95 98
         const std::string &cptFile);
96 99
 
97
-    // run all phases of algorithm
98
-    Rcpp::List run();
100
+    void run();
101
+    void halt();
102
+
103
+    void startSampling();
104
+
105
+    ColMatrix getAMatrix();
106
+    RowMatrix getPMatrix();
107
+
108
+    ColMatrix
109
+
110
+    void setPMatrix(const RowMatrix &Pmaster, float weight);
111
+
112
+    ColMatrix AMean() const;
113
+    ColMatrix AStd() const;
114
+    RowMatrix PMean() const;
115
+    RowMatrix PStd() const;
99 116
 };
100 117
 
101 118
 #endif // __COGAPS_GAPS_RUNNER_H__
102 119
\ No newline at end of file
... ...
@@ -4,6 +4,7 @@ PKG_LIBS = @GAPS_LIBS@
4 4
 
5 5
 OBJECTS =   AtomicDomain.o \
6 6
             Cogaps.o \
7
+            GapsDispatcher.o \
7 8
             GapsRunner.o \
8 9
             GapsStatistics.o \
9 10
             GibbsSampler.o \