... | ... |
@@ -198,22 +198,21 @@ float delta2) |
198 | 198 |
return delLL; |
199 | 199 |
} |
200 | 200 |
|
201 |
-/* |
|
202 | 201 |
// horribly slow, don't call often |
203 |
-void gaps::algo::matrixMultiplication(TwoWayMatrix &C, const ColMatrix &A, |
|
204 |
-const RowMatrix &B) |
|
202 |
+RowMatrix gaps::algo::matrixMultiplication(const ColMatrix &A, const RowMatrix &B) |
|
205 | 203 |
{ |
206 |
- for (unsigned i = 0; i < C.nRow(); ++i) |
|
204 |
+ RowMatrix temp(A.nRow(), B.nCol()); |
|
205 |
+ for (unsigned i = 0; i < A.nRow(); ++i) |
|
207 | 206 |
{ |
208 |
- for (unsigned j = 0; j < C.nCol(); ++j) |
|
207 |
+ for (unsigned j = 0; j < B.nCol(); ++j) |
|
209 | 208 |
{ |
210 | 209 |
float sum = 0.0; |
211 | 210 |
for (unsigned k = 0; k < A.nCol(); ++k) |
212 | 211 |
{ |
213 | 212 |
sum += A(i,k) * B(k,j); |
214 | 213 |
} |
215 |
- C.set(i, j, sum); |
|
214 |
+ temp(i, j) = sum; |
|
216 | 215 |
} |
217 | 216 |
} |
218 |
-} |
|
219 |
-*/ |
|
217 |
+ return temp; |
|
218 |
+} |
|
220 | 219 |
\ No newline at end of file |
... | ... |
@@ -16,9 +16,7 @@ struct AlphaParameters |
16 | 16 |
|
17 | 17 |
AlphaParameters operator+(const AlphaParameters &other) const |
18 | 18 |
{ |
19 |
- float rs = s + other.s; |
|
20 |
- float rsu = su - other.su; // weird |
|
21 |
- return AlphaParameters(rs, rsu); |
|
19 |
+ return AlphaParameters(s + other.s, su - other.su); |
|
22 | 20 |
} |
23 | 21 |
}; |
24 | 22 |
|
... | ... |
@@ -54,8 +52,7 @@ namespace algo |
54 | 52 |
// specific matrix algorithms |
55 | 53 |
bool isRowZero(const RowMatrix &mat, unsigned row); // TODO take pointer |
56 | 54 |
bool isColZero(const ColMatrix &mat, unsigned col); |
57 |
- //void matrixMultiplication(TwoWayMatrix &C, const ColMatrix &A, |
|
58 |
- // const RowMatrix &B); |
|
55 |
+ RowMatrix matrixMultiplication(const ColMatrix &A, const RowMatrix &B); |
|
59 | 56 |
|
60 | 57 |
// chiSq / 2 |
61 | 58 |
template <class Matrix> |
... | ... |
@@ -72,7 +72,7 @@ Rcpp::List GapsRunner::run() |
72 | 72 |
chi2Vec.concat(mChiSqSample); |
73 | 73 |
|
74 | 74 |
// print final chi-sq value |
75 |
- float meanChiSq = mStatistics.meanChiSq(); |
|
75 |
+ float meanChiSq = mStatistics.meanChiSq(mASampler); |
|
76 | 76 |
if (mPrintMessages) |
77 | 77 |
{ |
78 | 78 |
Rprintf("Chi-Squared of Mean: %.2f\n", meanChiSq); |
... | ... |
@@ -50,11 +50,12 @@ Rcpp::NumericMatrix GapsStatistics::PStd() const |
50 | 50 |
mStatUpdates).rMatrix(); |
51 | 51 |
} |
52 | 52 |
|
53 |
-float GapsStatistics::meanChiSq() const |
|
53 |
+float GapsStatistics::meanChiSq(const AmplitudeGibbsSampler &ASampler) const |
|
54 | 54 |
{ |
55 |
- //ColMatrix A = mAMeanMatrix / mStatUpdates; |
|
56 |
- //RowMatrix P = mPMeanMatrix / mStatUpdates; |
|
57 |
- //RowMatrix M(A * P); |
|
58 |
- return 0.f; |
|
55 |
+ ColMatrix A = mAMeanMatrix / mStatUpdates; |
|
56 |
+ RowMatrix P = mPMeanMatrix / mStatUpdates; |
|
57 |
+ RowMatrix M(gaps::algo::matrixMultiplication(A, P)); |
|
58 |
+ return 2.f * gaps::algo::loglikelihood(ASampler.mDMatrix, ASampler.mSMatrix, |
|
59 |
+ M); |
|
59 | 60 |
} |
60 | 61 |
|
... | ... |
@@ -25,7 +25,7 @@ public: |
25 | 25 |
Rcpp::NumericMatrix PMean() const; |
26 | 26 |
Rcpp::NumericMatrix PStd() const; |
27 | 27 |
|
28 |
- float meanChiSq() const; |
|
28 |
+ float meanChiSq(const AmplitudeGibbsSampler &ASampler) const; |
|
29 | 29 |
|
30 | 30 |
void update(const AmplitudeGibbsSampler &ASampler, |
31 | 31 |
const PatternGibbsSampler &PSampler); |
... | ... |
@@ -154,7 +154,8 @@ mAnnealingTemp(0.f), mNumRows(nrow), mNumCols(ncol) |
154 | 154 |
/ static_cast<uint64_t>(mNumRows * mNumCols); |
155 | 155 |
uint64_t remain = std::numeric_limits<uint64_t>::max() |
156 | 156 |
% static_cast<uint64_t>(mNumRows * mNumCols); |
157 |
- mQueue.setDomainSize(std::numeric_limits<uint64_t>::max() - remain); |
|
157 |
+ //mQueue.setDomainSize(std::numeric_limits<uint64_t>::max() - remain); |
|
158 |
+ mQueue.setDomainSize(std::numeric_limits<uint64_t>::max()); |
|
158 | 159 |
} |
159 | 160 |
|
160 | 161 |
template <class T, class MatA, class MatB> |
... | ... |
@@ -35,7 +35,7 @@ AtomicProposal ProposalQueue::makeProposal(const AtomicDomain &domain) |
35 | 35 |
|
36 | 36 |
float bdProb = domain.size() < 2 ? 0.6667f : 0.5f; |
37 | 37 |
float u = gaps::random::uniform(); |
38 |
- if (u < bdProb) |
|
38 |
+ if (u <= bdProb) |
|
39 | 39 |
{ |
40 | 40 |
return gaps::random::uniform() < deathProb(domain.size()) ? |
41 | 41 |
death(domain) : birth(domain); |
... | ... |
@@ -68,7 +68,7 @@ AtomicProposal ProposalQueue::move(const AtomicDomain &domain) |
68 | 68 |
Atom a = domain.randomAtom(); |
69 | 69 |
uint64_t lbound = domain.hasLeft(a) ? domain.left(a).pos : 0; |
70 | 70 |
uint64_t rbound = domain.hasRight(a) ? domain.right(a).pos : mDomainSize; |
71 |
- uint64_t newLocation = gaps::random::uniform64(lbound + 1, rbound - 1); |
|
71 |
+ uint64_t newLocation = gaps::random::uniform64(lbound, rbound - 1); |
|
72 | 72 |
GAPS_ASSERT(domain.test(a.pos)); |
73 | 73 |
return AtomicProposal('M', a.pos, a.mass, newLocation); |
74 | 74 |
} |