... | ... |
@@ -15,7 +15,7 @@ matrix_data_t gaps::algo::sum(const Vector &vec) |
15 | 15 |
matrix_data_t sum = 0.0; |
16 | 16 |
for (unsigned i = 0; i < vec.size(); ++i) |
17 | 17 |
{ |
18 |
- sum += vec(i); |
|
18 |
+ sum += vec[i]; |
|
19 | 19 |
} |
20 | 20 |
return sum; |
21 | 21 |
} |
... | ... |
@@ -72,13 +72,13 @@ ColMatrix gaps::algo::computeStdDev(const ColMatrix &stdMat, |
72 | 72 |
const ColMatrix &meanMat, unsigned nUpdates) |
73 | 73 |
{ |
74 | 74 |
ColMatrix retMat(stdMat.nRow(), stdMat.nCol()); |
75 |
- double meanTerm = 0.0; |
|
75 |
+ float meanTerm = 0.0; |
|
76 | 76 |
for (unsigned r = 0; r < retMat.nRow(); ++r) |
77 | 77 |
{ |
78 | 78 |
for (unsigned c = 0; c < retMat.nCol(); ++c) |
79 | 79 |
{ |
80 |
- meanTerm = meanMat(r,c) * meanMat(r,c) / (double)nUpdates; |
|
81 |
- retMat(r,c) = std::sqrt((stdMat(r,c) - meanTerm) / ((double)nUpdates - 1.0)); |
|
80 |
+ meanTerm = meanMat(r,c) * meanMat(r,c) / (float)nUpdates; |
|
81 |
+ retMat(r,c) = std::sqrt((stdMat(r,c) - meanTerm) / ((float)nUpdates - 1.0)); |
|
82 | 82 |
} |
83 | 83 |
} |
84 | 84 |
return retMat; |
... | ... |
@@ -88,13 +88,13 @@ RowMatrix gaps::algo::computeStdDev(const RowMatrix &stdMat, |
88 | 88 |
const RowMatrix &meanMat, unsigned nUpdates) |
89 | 89 |
{ |
90 | 90 |
RowMatrix retMat(stdMat.nRow(), stdMat.nCol()); |
91 |
- double meanTerm = 0.0; |
|
91 |
+ float meanTerm = 0.0; |
|
92 | 92 |
for (unsigned r = 0; r < retMat.nRow(); ++r) |
93 | 93 |
{ |
94 | 94 |
for (unsigned c = 0; c < retMat.nCol(); ++c) |
95 | 95 |
{ |
96 |
- meanTerm = meanMat(r,c) * meanMat(r,c) / (double)nUpdates; |
|
97 |
- retMat(r,c) = std::sqrt((stdMat(r,c) - meanTerm) / ((double)nUpdates - 1.0)); |
|
96 |
+ meanTerm = meanMat(r,c) * meanMat(r,c) / (float)nUpdates; |
|
97 |
+ retMat(r,c) = std::sqrt((stdMat(r,c) - meanTerm) / ((float)nUpdates - 1.0)); |
|
98 | 98 |
} |
99 | 99 |
} |
100 | 100 |
return retMat; |
... | ... |
@@ -108,7 +108,7 @@ const RowMatrix &B) |
108 | 108 |
{ |
109 | 109 |
for (unsigned j = 0; j < C.nCol(); ++j) |
110 | 110 |
{ |
111 |
- double sum = 0.0; |
|
111 |
+ float sum = 0.0; |
|
112 | 112 |
for (unsigned k = 0; k < A.nCol(); ++k) |
113 | 113 |
{ |
114 | 114 |
sum += A(i,k) * B(k,j); |
... | ... |
@@ -118,37 +118,37 @@ const RowMatrix &B) |
118 | 118 |
} |
119 | 119 |
} |
120 | 120 |
|
121 |
-Vector gaps::algo::scalarMultiple(const Vector &vec, double n) |
|
121 |
+Vector gaps::algo::scalarMultiple(const Vector &vec, float n) |
|
122 | 122 |
{ |
123 | 123 |
Vector retVec(vec.size()); |
124 | 124 |
for (unsigned i = 0; i < vec.size(); ++i) |
125 | 125 |
{ |
126 |
- retVec(i) = vec(i) * n; |
|
126 |
+ retVec[i] = vec[i] * n; |
|
127 | 127 |
} |
128 | 128 |
return retVec; |
129 | 129 |
} |
130 | 130 |
|
131 |
-Vector gaps::algo::squaredScalarMultiple(const Vector &vec, double n) |
|
131 |
+Vector gaps::algo::squaredScalarMultiple(const Vector &vec, float n) |
|
132 | 132 |
{ |
133 | 133 |
Vector retVec(vec.size()); |
134 | 134 |
for (unsigned i = 0; i < vec.size(); ++i) |
135 | 135 |
{ |
136 |
- retVec(i) = GAPS_SQ(vec(i) * n); |
|
136 |
+ retVec[i] = GAPS_SQ(vec[i] * n); |
|
137 | 137 |
} |
138 | 138 |
return retVec; |
139 | 139 |
} |
140 | 140 |
|
141 |
-Vector gaps::algo::squaredScalarDivision(const Vector &vec, double n) |
|
141 |
+Vector gaps::algo::squaredScalarDivision(const Vector &vec, float n) |
|
142 | 142 |
{ |
143 | 143 |
Vector retVec(vec.size()); |
144 | 144 |
for (unsigned i = 0; i < vec.size(); ++i) |
145 | 145 |
{ |
146 |
- retVec(i) = GAPS_SQ(vec(i) / n); |
|
146 |
+ retVec[i] = GAPS_SQ(vec[i] / n); |
|
147 | 147 |
} |
148 | 148 |
return retVec; |
149 | 149 |
} |
150 | 150 |
|
151 |
-ColMatrix gaps::algo::scalarDivision(const ColMatrix &mat, double n) |
|
151 |
+ColMatrix gaps::algo::scalarDivision(const ColMatrix &mat, float n) |
|
152 | 152 |
{ |
153 | 153 |
ColMatrix retMat(mat.nRow(), mat.nCol()); |
154 | 154 |
for (unsigned r = 0; r < retMat.nRow(); ++r) |
... | ... |
@@ -166,12 +166,12 @@ Vector gaps::algo::scalarDivision(const Vector &vec, matrix_data_t n) |
166 | 166 |
Vector temp(vec.size()); |
167 | 167 |
for (unsigned i = 0; i < vec.size(); ++i) |
168 | 168 |
{ |
169 |
- temp(i) = vec(i) / n; |
|
169 |
+ temp[i] = vec[i] / n; |
|
170 | 170 |
} |
171 | 171 |
return temp; |
172 | 172 |
} |
173 | 173 |
|
174 |
-RowMatrix gaps::algo::scalarDivision(const RowMatrix &mat, double n) |
|
174 |
+RowMatrix gaps::algo::scalarDivision(const RowMatrix &mat, float n) |
|
175 | 175 |
{ |
176 | 176 |
RowMatrix retMat(mat.nRow(), mat.nCol()); |
177 | 177 |
for (unsigned r = 0; r < retMat.nRow(); ++r) |
... | ... |
@@ -187,7 +187,7 @@ RowMatrix gaps::algo::scalarDivision(const RowMatrix &mat, double n) |
187 | 187 |
matrix_data_t gaps::algo::loglikelihood(const TwoWayMatrix &D, |
188 | 188 |
const TwoWayMatrix &S, const TwoWayMatrix &AP) |
189 | 189 |
{ |
190 |
- double chi2 = 0.0; |
|
190 |
+ float chi2 = 0.0; |
|
191 | 191 |
for (unsigned r = 0; r < D.nRow(); ++r) |
192 | 192 |
{ |
193 | 193 |
for (unsigned c = 0; c < D.nCol(); ++c) |
... | ... |
@@ -208,12 +208,12 @@ bool gaps::algo::isColZero(const ColMatrix &mat, unsigned col) |
208 | 208 |
return gaps::algo::sum(mat.getCol(col)) == 0; |
209 | 209 |
} |
210 | 210 |
|
211 |
-static double deltaLL_A(const TwoWayMatrix &D, const TwoWayMatrix &S, |
|
211 |
+static float deltaLL_A(const TwoWayMatrix &D, const TwoWayMatrix &S, |
|
212 | 212 |
const RowMatrix &P, const TwoWayMatrix &AP, unsigned row, |
213 |
-unsigned col1, double delta1, unsigned col2=0, double delta2=0.0, |
|
213 |
+unsigned col1, float delta1, unsigned col2=0, float delta2=0.0, |
|
214 | 214 |
bool twoChanges=false) |
215 | 215 |
{ |
216 |
- double numer = 0.0, denom = 0.0, delLL = 0.0, d1 = 0.0, d2 = 0.0; |
|
216 |
+ float numer = 0.0, denom = 0.0, delLL = 0.0, d1 = 0.0, d2 = 0.0; |
|
217 | 217 |
const Vector &Drow = D.getRow(row); |
218 | 218 |
const Vector &AProw = AP.getRow(row); |
219 | 219 |
const Vector &Srow = S.getRow(row); |
... | ... |
@@ -221,21 +221,21 @@ bool twoChanges=false) |
221 | 221 |
const Vector &Prow2 = P.getRow(col2); |
222 | 222 |
for (unsigned j = 0; j < D.nCol(); ++j) |
223 | 223 |
{ |
224 |
- d1 = delta1 * Prow1(j); |
|
225 |
- d2 = twoChanges ? delta2 * Prow2(j) : 0.0; |
|
226 |
- numer = 2.0 * (Drow(j) - AProw(j)) * (d1 + d2) - GAPS_SQ(d1 + d2); |
|
227 |
- denom = 2.0 * GAPS_SQ(Srow(j)); |
|
224 |
+ d1 = delta1 * Prow1[j]; |
|
225 |
+ d2 = twoChanges ? delta2 * Prow2[j] : 0.0; |
|
226 |
+ numer = 2.0 * (Drow[j] - AProw[j]) * (d1 + d2) - GAPS_SQ(d1 + d2); |
|
227 |
+ denom = 2.0 * GAPS_SQ(Srow[j]); |
|
228 | 228 |
delLL += numer / denom; |
229 | 229 |
} |
230 | 230 |
return delLL; |
231 | 231 |
} |
232 | 232 |
|
233 |
-static double deltaLL_P(const TwoWayMatrix &D, const TwoWayMatrix &S, |
|
233 |
+static float deltaLL_P(const TwoWayMatrix &D, const TwoWayMatrix &S, |
|
234 | 234 |
const ColMatrix &A, const TwoWayMatrix &AP, unsigned col, |
235 |
-unsigned row1, double delta1, unsigned row2=0, double delta2=0.0, |
|
235 |
+unsigned row1, float delta1, unsigned row2=0, float delta2=0.0, |
|
236 | 236 |
bool twoChanges=false) |
237 | 237 |
{ |
238 |
- double numer = 0.0, denom = 0.0, delLL = 0.0, d1 = 0.0, d2 = 0.0; |
|
238 |
+ float numer = 0.0, denom = 0.0, delLL = 0.0, d1 = 0.0, d2 = 0.0; |
|
239 | 239 |
const Vector &Dcol = D.getCol(col); |
240 | 240 |
const Vector &APcol = AP.getCol(col); |
241 | 241 |
const Vector &Scol = S.getCol(col); |
... | ... |
@@ -243,16 +243,16 @@ bool twoChanges=false) |
243 | 243 |
const Vector &Acol2 = A.getCol(row2); |
244 | 244 |
for (unsigned i = 0; i < D.nRow(); ++i) |
245 | 245 |
{ |
246 |
- d1 = delta1 * Acol1(i); |
|
247 |
- d2 = twoChanges ? delta2 * Acol2(i) : 0.0; |
|
248 |
- numer = 2.0 * (Dcol(i) - APcol(i)) * (d1 + d2) - GAPS_SQ(d1 + d2); |
|
249 |
- denom = 2.0 * GAPS_SQ(Scol(i)); |
|
246 |
+ d1 = delta1 * Acol1[i]; |
|
247 |
+ d2 = twoChanges ? delta2 * Acol2[i] : 0.0; |
|
248 |
+ numer = 2.0 * (Dcol[i] - APcol[i]) * (d1 + d2) - GAPS_SQ(d1 + d2); |
|
249 |
+ denom = 2.0 * GAPS_SQ(Scol[i]); |
|
250 | 250 |
delLL += numer / denom; |
251 | 251 |
} |
252 | 252 |
return delLL; |
253 | 253 |
} |
254 | 254 |
|
255 |
-double gaps::algo::deltaLL(const MatrixChange &ch, const TwoWayMatrix &D, |
|
255 |
+float gaps::algo::deltaLL(const MatrixChange &ch, const TwoWayMatrix &D, |
|
256 | 256 |
const TwoWayMatrix &S, const ColMatrix &A, const RowMatrix &P, |
257 | 257 |
const TwoWayMatrix &AP) |
258 | 258 |
{ |
... | ... |
@@ -285,7 +285,7 @@ static AlphaParameters alphaParameters_A(const TwoWayMatrix &D, |
285 | 285 |
const TwoWayMatrix &S, const RowMatrix &P, const TwoWayMatrix &AP, |
286 | 286 |
unsigned row, unsigned col1, unsigned col2=0, bool twoChanges=false) |
287 | 287 |
{ |
288 |
- double s = 0.0, su = 0.0, ratio = 0.0, p2 = 0.0; |
|
288 |
+ float s = 0.0, su = 0.0, ratio = 0.0, p2 = 0.0; |
|
289 | 289 |
const Vector &Drow = D.getRow(row); |
290 | 290 |
const Vector &AProw = AP.getRow(row); |
291 | 291 |
const Vector &Srow = S.getRow(row); |
... | ... |
@@ -293,10 +293,10 @@ unsigned row, unsigned col1, unsigned col2=0, bool twoChanges=false) |
293 | 293 |
const Vector &Prow2 = P.getRow(col2); |
294 | 294 |
for (unsigned j = 0; j < D.nCol(); ++j) |
295 | 295 |
{ |
296 |
- p2 = twoChanges ? Prow2(j) : 0.0; |
|
297 |
- ratio = (Prow1(j) - p2) / Srow(j); |
|
296 |
+ p2 = twoChanges ? Prow2[j] : 0.0; |
|
297 |
+ ratio = (Prow1[j] - p2) / Srow[j]; |
|
298 | 298 |
s += GAPS_SQ(ratio); |
299 |
- su += ratio * (Drow(j) - AProw(j)) / Srow(j); |
|
299 |
+ su += ratio * (Drow[j] - AProw[j]) / Srow[j]; |
|
300 | 300 |
} |
301 | 301 |
return AlphaParameters(s, su); |
302 | 302 |
} |
... | ... |
@@ -305,7 +305,7 @@ static AlphaParameters alphaParameters_P(const TwoWayMatrix &D, |
305 | 305 |
const TwoWayMatrix &S, const ColMatrix &A, const TwoWayMatrix &AP, |
306 | 306 |
unsigned col, unsigned row1, unsigned row2=0, bool twoChanges=false) |
307 | 307 |
{ |
308 |
- double s = 0.0, su = 0.0, ratio = 0.0, a2 = 0.0; |
|
308 |
+ float s = 0.0, su = 0.0, ratio = 0.0, a2 = 0.0; |
|
309 | 309 |
const Vector &Dcol = D.getCol(col); |
310 | 310 |
const Vector &APcol = AP.getCol(col); |
311 | 311 |
const Vector &Scol = S.getCol(col); |
... | ... |
@@ -313,10 +313,10 @@ unsigned col, unsigned row1, unsigned row2=0, bool twoChanges=false) |
313 | 313 |
const Vector &Acol2 = A.getCol(row2); |
314 | 314 |
for (unsigned i = 0; i < D.nRow(); ++i) |
315 | 315 |
{ |
316 |
- a2 = twoChanges ? Acol2(i) : 0.0; |
|
317 |
- ratio = (Acol1(i) - a2) / Scol(i); |
|
316 |
+ a2 = twoChanges ? Acol2[i] : 0.0; |
|
317 |
+ ratio = (Acol1[i] - a2) / Scol[i]; |
|
318 | 318 |
s += GAPS_SQ(ratio); |
319 |
- su += ratio * (Dcol(i) - APcol(i)) / Scol(i); |
|
319 |
+ su += ratio * (Dcol[i] - APcol[i]) / Scol[i]; |
|
320 | 320 |
} |
321 | 321 |
return AlphaParameters(s, su); |
322 | 322 |
} |
... | ... |
@@ -2,13 +2,14 @@ |
2 | 2 |
#define __COGAPS_ALGORITHMS_H__ |
3 | 3 |
|
4 | 4 |
#include "Matrix.h" |
5 |
+#include <xmmintrin.h> |
|
5 | 6 |
|
6 | 7 |
struct AlphaParameters |
7 | 8 |
{ |
8 |
- double s; |
|
9 |
- double su; |
|
9 |
+ float s; |
|
10 |
+ float su; |
|
10 | 11 |
|
11 |
- AlphaParameters(double inS, double inSU) |
|
12 |
+ AlphaParameters(float inS, float inSU) |
|
12 | 13 |
: s(inS), su(inSU) |
13 | 14 |
{} |
14 | 15 |
|
... | ... |
@@ -20,6 +21,41 @@ struct AlphaParameters |
20 | 21 |
} |
21 | 22 |
}; |
22 | 23 |
|
24 |
+class vec4f |
|
25 |
+{ |
|
26 |
+private: |
|
27 |
+ |
|
28 |
+ __m128 mValue; |
|
29 |
+ |
|
30 |
+public: |
|
31 |
+ |
|
32 |
+ inline vec4f() {} |
|
33 |
+ inline vec4f(float f) : mValue(_mm_set1_ps(f)) {} |
|
34 |
+ inline vec4f(float f0, float f1, float f2, float f3) |
|
35 |
+ : mValue(_mm_setr_ps(f0,f1,f2,f3)) |
|
36 |
+ {} |
|
37 |
+ inline vec4f(const __m128 &rhs) : mValue(rhs) {} |
|
38 |
+ |
|
39 |
+ inline vec4f& operator=(const __m128 &rhs) |
|
40 |
+ { |
|
41 |
+ mValue = rhs; |
|
42 |
+ return *this; |
|
43 |
+ } |
|
44 |
+ |
|
45 |
+ inline operator __m128() const {return mValue;} |
|
46 |
+ |
|
47 |
+ inline vec4f& operator+=(const vec4f &rhs) |
|
48 |
+ { |
|
49 |
+ *this = *this + rhs; |
|
50 |
+ return *this; |
|
51 |
+ } |
|
52 |
+}; |
|
53 |
+ |
|
54 |
+inline vec4f operator+(const vec4f &lhs, const vec4f &rhs) |
|
55 |
+{ |
|
56 |
+ return _mm_add_ps(lhs,rhs); |
|
57 |
+} |
|
58 |
+ |
|
23 | 59 |
namespace gaps |
24 | 60 |
{ |
25 | 61 |
|
... | ... |
@@ -56,7 +92,7 @@ namespace algo |
56 | 92 |
matrix_data_t loglikelihood(const TwoWayMatrix &D, const TwoWayMatrix &S, |
57 | 93 |
const TwoWayMatrix &AP); |
58 | 94 |
|
59 |
- double deltaLL(const MatrixChange &ch, const TwoWayMatrix &D, |
|
95 |
+ float deltaLL(const MatrixChange &ch, const TwoWayMatrix &D, |
|
60 | 96 |
const TwoWayMatrix &S, const ColMatrix &A, |
61 | 97 |
const RowMatrix &P, const TwoWayMatrix &AP); |
62 | 98 |
|
... | ... |
@@ -1,9 +1,9 @@ |
1 | 1 |
#include "AtomicSupport.h" |
2 | 2 |
|
3 |
-static const double EPSILON = 1.e-10; |
|
3 |
+static const float EPSILON = 1.e-10; |
|
4 | 4 |
|
5 | 5 |
AtomicSupport::AtomicSupport(char label, uint64_t nrow, uint64_t ncol, |
6 |
-double alpha, double lambda) |
|
6 |
+float alpha, float lambda) |
|
7 | 7 |
: |
8 | 8 |
mNumRows(nrow), mNumCols(ncol), mNumBins(nrow * ncol), |
9 | 9 |
mNumAtoms(0), mTotalMass(0.0), mLabel(label), mAlpha(alpha), |
... | ... |
@@ -36,7 +36,7 @@ uint64_t AtomicSupport::randomFreePosition() const |
36 | 36 |
uint64_t AtomicSupport::randomAtomPosition() const |
37 | 37 |
{ |
38 | 38 |
uint64_t num = gaps::random::uniform64(0, mNumAtoms - 1); |
39 |
- std::map<uint64_t, double>::const_iterator it = mAtomicDomain.begin(); |
|
39 |
+ std::map<uint64_t, float>::const_iterator it = mAtomicDomain.begin(); |
|
40 | 40 |
std::advance(it, num); |
41 | 41 |
return it->first; |
42 | 42 |
} |
... | ... |
@@ -44,14 +44,14 @@ uint64_t AtomicSupport::randomAtomPosition() const |
44 | 44 |
AtomicProposal AtomicSupport::proposeDeath() const |
45 | 45 |
{ |
46 | 46 |
uint64_t location = randomAtomPosition(); |
47 |
- double mass = mAtomicDomain.at(location); |
|
47 |
+ float mass = mAtomicDomain.at(location); |
|
48 | 48 |
return AtomicProposal(mLabel, 'D', location, -mass); |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
AtomicProposal AtomicSupport::proposeBirth() const |
52 | 52 |
{ |
53 | 53 |
uint64_t location = randomFreePosition(); |
54 |
- double mass = gaps::random::exponential(mLambda); |
|
54 |
+ float mass = gaps::random::exponential(mLambda); |
|
55 | 55 |
return AtomicProposal(mLabel, 'B', location, mass); |
56 | 56 |
} |
57 | 57 |
|
... | ... |
@@ -60,10 +60,10 @@ AtomicProposal AtomicSupport::proposeMove() const |
60 | 60 |
{ |
61 | 61 |
// get random atom |
62 | 62 |
uint64_t location = randomAtomPosition(); |
63 |
- double mass = mAtomicDomain.at(location); |
|
63 |
+ float mass = mAtomicDomain.at(location); |
|
64 | 64 |
|
65 | 65 |
// get an iterator to this atom |
66 |
- std::map<uint64_t, double>::const_iterator it, left, right; |
|
66 |
+ std::map<uint64_t, float>::const_iterator it, left, right; |
|
67 | 67 |
it = mAtomicDomain.find(location); |
68 | 68 |
left = it; right = it; |
69 | 69 |
uint64_t rbound = mMaxNumAtoms - 1, lbound = 0; |
... | ... |
@@ -86,10 +86,10 @@ AtomicProposal AtomicSupport::proposeExchange() const |
86 | 86 |
{ |
87 | 87 |
// get random atom |
88 | 88 |
uint64_t pos1 = randomAtomPosition(); |
89 |
- double mass1 = mAtomicDomain.at(pos1); |
|
89 |
+ float mass1 = mAtomicDomain.at(pos1); |
|
90 | 90 |
|
91 | 91 |
// find atom to the right, wrap around the end |
92 |
- std::map<uint64_t, double>::const_iterator it; |
|
92 |
+ std::map<uint64_t, float>::const_iterator it; |
|
93 | 93 |
it = ++(mAtomicDomain.find(pos1)); |
94 | 94 |
if (it == mAtomicDomain.end()) |
95 | 95 |
{ |
... | ... |
@@ -98,22 +98,22 @@ AtomicProposal AtomicSupport::proposeExchange() const |
98 | 98 |
|
99 | 99 |
// get adjacent atom info |
100 | 100 |
uint64_t pos2 = it->first; |
101 |
- double mass2 = it->second; |
|
101 |
+ float mass2 = it->second; |
|
102 | 102 |
|
103 | 103 |
// calculate new mass |
104 |
- double pupper = gaps::random::p_gamma(mass1 + mass2, 2.0, 1.0 / mLambda); |
|
105 |
- double newMass = gaps::random::q_gamma(gaps::random::uniform(0.0, pupper), |
|
104 |
+ float pupper = gaps::random::p_gamma(mass1 + mass2, 2.0, 1.0 / mLambda); |
|
105 |
+ float newMass = gaps::random::q_gamma(gaps::random::uniform(0.0, pupper), |
|
106 | 106 |
2.0, 1.0 / mLambda); |
107 | 107 |
|
108 | 108 |
// calculate mass changes |
109 |
- double delta1 = mass1 > mass2 ? newMass - mass1 : mass2 - newMass; |
|
110 |
- double delta2 = mass2 > mass1 ? newMass - mass2 : mass1 - newMass; |
|
109 |
+ float delta1 = mass1 > mass2 ? newMass - mass1 : mass2 - newMass; |
|
110 |
+ float delta2 = mass2 > mass1 ? newMass - mass2 : mass1 - newMass; |
|
111 | 111 |
|
112 | 112 |
// preserve total mass |
113 | 113 |
return AtomicProposal(mLabel, 'E', pos1, delta1, pos2, delta2); |
114 | 114 |
} |
115 | 115 |
|
116 |
-double AtomicSupport::updateAtomMass(char type, uint64_t pos, double delta) |
|
116 |
+float AtomicSupport::updateAtomMass(char type, uint64_t pos, float delta) |
|
117 | 117 |
{ |
118 | 118 |
if (mAtomicDomain.count(pos)) // update atom if it exists |
119 | 119 |
{ |
... | ... |
@@ -121,7 +121,7 @@ double AtomicSupport::updateAtomMass(char type, uint64_t pos, double delta) |
121 | 121 |
} |
122 | 122 |
else // create a new atom if it doesn't exist |
123 | 123 |
{ |
124 |
- mAtomicDomain.insert(std::pair<uint64_t, double>(pos, delta)); |
|
124 |
+ mAtomicDomain.insert(std::pair<uint64_t, float>(pos, delta)); |
|
125 | 125 |
mNumAtoms++; |
126 | 126 |
} |
127 | 127 |
|
... | ... |
@@ -142,7 +142,7 @@ AtomicProposal AtomicSupport::makeProposal() const |
142 | 142 |
return proposeBirth(); |
143 | 143 |
} |
144 | 144 |
|
145 |
- double unif = gaps::random::uniform(); |
|
145 |
+ float unif = gaps::random::uniform(); |
|
146 | 146 |
if ((mNumAtoms < 2 && unif <= 0.6667) || unif <= 0.5) // birth/death |
147 | 147 |
{ |
148 | 148 |
if (mNumAtoms >= mMaxNumAtoms) |
... | ... |
@@ -150,19 +150,19 @@ AtomicProposal AtomicSupport::makeProposal() const |
150 | 150 |
return proposeDeath(); |
151 | 151 |
} |
152 | 152 |
|
153 |
- double pDelete = 0.5; // default uniform prior for mAlpha == 0 |
|
153 |
+ float pDelete = 0.5; // default uniform prior for mAlpha == 0 |
|
154 | 154 |
if (mAlpha > 0) // poisson prior |
155 | 155 |
{ |
156 |
- double dMax = (double)mMaxNumAtoms; |
|
157 |
- double dNum = (double)mNumAtoms; |
|
158 |
- double maxTerm = (dMax - dNum) / dMax; |
|
156 |
+ float dMax = (float)mMaxNumAtoms; |
|
157 |
+ float dNum = (float)mNumAtoms; |
|
158 |
+ float maxTerm = (dMax - dNum) / dMax; |
|
159 | 159 |
|
160 |
- pDelete = dNum / (dNum + mAlpha * (double)mNumBins * maxTerm); |
|
160 |
+ pDelete = dNum / (dNum + mAlpha * (float)mNumBins * maxTerm); |
|
161 | 161 |
} |
162 | 162 |
else if (mAlpha < 0) // geometric prior |
163 | 163 |
{ |
164 |
- double c = -mAlpha * mNumBins / (-mAlpha * mNumBins + 1.0); |
|
165 |
- pDelete = (double)mNumAtoms / ((mNumAtoms + 1) * c + (double)mNumAtoms); |
|
164 |
+ float c = -mAlpha * mNumBins / (-mAlpha * mNumBins + 1.0); |
|
165 |
+ pDelete = (float)mNumAtoms / ((mNumAtoms + 1) * c + (float)mNumAtoms); |
|
166 | 166 |
} |
167 | 167 |
return gaps::random::uniform() < pDelete ? proposeDeath() : proposeBirth(); |
168 | 168 |
} |
... | ... |
@@ -16,16 +16,16 @@ struct AtomicProposal |
16 | 16 |
unsigned nChanges; |
17 | 17 |
|
18 | 18 |
uint64_t pos1; |
19 |
- double delta1; |
|
19 |
+ float delta1; |
|
20 | 20 |
|
21 | 21 |
uint64_t pos2; |
22 |
- double delta2; |
|
22 |
+ float delta2; |
|
23 | 23 |
|
24 |
- AtomicProposal(char l, char t, uint64_t p1, double m1) |
|
24 |
+ AtomicProposal(char l, char t, uint64_t p1, float m1) |
|
25 | 25 |
: label(l), type(t), nChanges(1), pos1(p1), delta1(m1), pos2(0), delta2(0.0) |
26 | 26 |
{} |
27 | 27 |
|
28 |
- AtomicProposal(char l, char t, uint64_t p1, double m1, uint64_t p2, double m2) |
|
28 |
+ AtomicProposal(char l, char t, uint64_t p1, float m1, uint64_t p2, float m2) |
|
29 | 29 |
: label(l), type(t), nChanges(2), pos1(p1), delta1(m1), pos2(p2), delta2(m2) |
30 | 30 |
{} |
31 | 31 |
}; |
... | ... |
@@ -42,12 +42,12 @@ public: |
42 | 42 |
char mLabel; |
43 | 43 |
|
44 | 44 |
// storage of the atomic domain |
45 |
- std::map<uint64_t, double> mAtomicDomain; |
|
45 |
+ std::map<uint64_t, float> mAtomicDomain; |
|
46 | 46 |
uint64_t mNumAtoms; |
47 | 47 |
uint64_t mMaxNumAtoms; |
48 | 48 |
|
49 | 49 |
// total mass of all atoms |
50 |
- double mTotalMass; |
|
50 |
+ float mTotalMass; |
|
51 | 51 |
|
52 | 52 |
// matrix information |
53 | 53 |
uint64_t mNumRows; |
... | ... |
@@ -56,10 +56,10 @@ public: |
56 | 56 |
uint64_t mBinSize; |
57 | 57 |
|
58 | 58 |
// average number of atoms per bin (must be > 0) |
59 |
- double mAlpha; |
|
59 |
+ float mAlpha; |
|
60 | 60 |
|
61 | 61 |
// expected magnitude of each atom (must be > 0) |
62 |
- double mLambda; |
|
62 |
+ float mLambda; |
|
63 | 63 |
|
64 | 64 |
// convert atomic position to row/col of the matrix |
65 | 65 |
uint64_t getRow(uint64_t pos) const; |
... | ... |
@@ -76,13 +76,13 @@ public: |
76 | 76 |
AtomicProposal proposeExchange() const; |
77 | 77 |
|
78 | 78 |
// update the mass of an atom, return the total amount changed |
79 |
- double updateAtomMass(char type, uint64_t pos, double delta); |
|
79 |
+ float updateAtomMass(char type, uint64_t pos, float delta); |
|
80 | 80 |
|
81 | 81 |
public: |
82 | 82 |
|
83 | 83 |
// constructor |
84 |
- AtomicSupport(char label, uint64_t nrow, uint64_t ncol, double alpha=1.0, |
|
85 |
- double lambda=1.0); |
|
84 |
+ AtomicSupport(char label, uint64_t nrow, uint64_t ncol, float alpha=1.0, |
|
85 |
+ float lambda=1.0); |
|
86 | 86 |
|
87 | 87 |
// create and accept a proposal |
88 | 88 |
AtomicProposal makeProposal() const; |
... | ... |
@@ -92,15 +92,15 @@ public: |
92 | 92 |
MatrixChange getMatrixChange(const AtomicProposal &prop) const; |
93 | 93 |
|
94 | 94 |
// getters |
95 |
- double alpha() const {return mAlpha;} |
|
96 |
- double lambda() const {return mLambda;} |
|
97 |
- double totalMass() const {return mTotalMass;} |
|
95 |
+ float alpha() const {return mAlpha;} |
|
96 |
+ float lambda() const {return mLambda;} |
|
97 |
+ float totalMass() const {return mTotalMass;} |
|
98 | 98 |
uint64_t numAtoms() const {return mNumAtoms;} |
99 |
- double at(uint64_t loc) const {return mAtomicDomain.at(loc);} |
|
99 |
+ float at(uint64_t loc) const {return mAtomicDomain.at(loc);} |
|
100 | 100 |
|
101 | 101 |
// setters |
102 |
- void setAlpha(double alpha) {mAlpha = alpha;} |
|
103 |
- void setLambda(double lambda) {mLambda = lambda;} |
|
102 |
+ void setAlpha(float alpha) {mAlpha = alpha;} |
|
103 |
+ void setLambda(float lambda) {mLambda = lambda;} |
|
104 | 104 |
//void setMaxNumAtoms(uint64_t max) {mMaxNumAtoms = max;} |
105 | 105 |
}; |
106 | 106 |
|
... | ... |
@@ -21,9 +21,9 @@ unsigned numSnapshots); |
21 | 21 |
|
22 | 22 |
// [[Rcpp::export]] |
23 | 23 |
Rcpp::List cogaps(Rcpp::NumericMatrix DMatrix, Rcpp::NumericMatrix SMatrix, |
24 |
-unsigned nFactor, double alphaA, double alphaP, unsigned nEquil, |
|
25 |
-unsigned nEquilCool, unsigned nSample, double maxGibbsMassA, |
|
26 |
-double maxGibbsMassP, Rcpp::NumericMatrix fixedPatterns, |
|
24 |
+unsigned nFactor, float alphaA, float alphaP, unsigned nEquil, |
|
25 |
+unsigned nEquilCool, unsigned nSample, float maxGibbsMassA, |
|
26 |
+float maxGibbsMassP, Rcpp::NumericMatrix fixedPatterns, |
|
27 | 27 |
char whichMatrixFixed, int seed, bool messages, bool singleCellRNASeq, |
28 | 28 |
unsigned numOutputs, unsigned numSnapshots) |
29 | 29 |
{ |
... | ... |
@@ -92,13 +92,13 @@ unsigned& nIterA, unsigned& nIterP, Vector& chi2Vec, Vector& aAtomVec, |
92 | 92 |
Vector& pAtomVec, GapsPhase phase, unsigned numOutputs, bool messages, |
93 | 93 |
unsigned numSnapshots) |
94 | 94 |
{ |
95 |
- double tempDenom = (double)nIterTotal / 2.0; |
|
95 |
+ float tempDenom = (float)nIterTotal / 2.f; |
|
96 | 96 |
|
97 | 97 |
for (unsigned i = 0; i < nIterTotal; ++i) |
98 | 98 |
{ |
99 | 99 |
if (phase == GAPS_CALIBRATION) |
100 | 100 |
{ |
101 |
- sampler.setAnnealingTemp(std::min(((double)i + 2.0) / tempDenom, 1.0)); |
|
101 |
+ sampler.setAnnealingTemp(std::min(((float)i + 2.f) / tempDenom, 1.f)); |
|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
for (unsigned j = 0; j < nIterA; ++j) |
... | ... |
@@ -121,11 +121,11 @@ unsigned numSnapshots) |
121 | 121 |
} |
122 | 122 |
} |
123 | 123 |
|
124 |
- double numAtomsA = sampler.totalNumAtoms('A'); |
|
125 |
- double numAtomsP = sampler.totalNumAtoms('P'); |
|
126 |
- aAtomVec(i) = numAtomsA; |
|
127 |
- pAtomVec(i) = numAtomsP; |
|
128 |
- chi2Vec(i) = sampler.chi2(); |
|
124 |
+ float numAtomsA = sampler.totalNumAtoms('A'); |
|
125 |
+ float numAtomsP = sampler.totalNumAtoms('P'); |
|
126 |
+ aAtomVec[i] = numAtomsA; |
|
127 |
+ pAtomVec[i] = numAtomsP; |
|
128 |
+ chi2Vec[i] = sampler.chi2(); |
|
129 | 129 |
|
130 | 130 |
if (phase != GAPS_COOLING) |
131 | 131 |
{ |
... | ... |
@@ -137,8 +137,8 @@ unsigned numSnapshots) |
137 | 137 |
<< sampler.chi2() << '\n'; |
138 | 138 |
} |
139 | 139 |
|
140 |
- nIterA = gaps::random::poisson(std::max(numAtomsA, 10.0)); |
|
141 |
- nIterP = gaps::random::poisson(std::max(numAtomsP, 10.0)); |
|
140 |
+ nIterA = gaps::random::poisson(std::max(numAtomsA, 10.f)); |
|
141 |
+ nIterP = gaps::random::poisson(std::max(numAtomsP, 10.f)); |
|
142 | 142 |
} |
143 | 143 |
} |
144 | 144 |
} |
145 | 145 |
\ No newline at end of file |
... | ... |
@@ -3,11 +3,11 @@ |
3 | 3 |
|
4 | 4 |
#include <Rcpp.h> |
5 | 5 |
|
6 |
-static const double EPSILON = 1.e-10; |
|
6 |
+static const float EPSILON = 1.e-10; |
|
7 | 7 |
|
8 | 8 |
GibbsSampler::GibbsSampler(Rcpp::NumericMatrix D, Rcpp::NumericMatrix S, |
9 |
-unsigned int nFactor, double alphaA, double alphaP, double maxGibbsMassA, |
|
10 |
-double maxGibbsMassP, bool singleCellRNASeq, Rcpp::NumericMatrix fixedPat, |
|
9 |
+unsigned int nFactor, float alphaA, float alphaP, float maxGibbsMassA, |
|
10 |
+float maxGibbsMassP, bool singleCellRNASeq, Rcpp::NumericMatrix fixedPat, |
|
11 | 11 |
char whichMat) |
12 | 12 |
: |
13 | 13 |
mDMatrix(D), mSMatrix(S), mAMatrix(D.nrow(), nFactor), |
... | ... |
@@ -19,7 +19,7 @@ mAMeanMatrix(D.nrow(), nFactor), mAStdMatrix(D.nrow(), nFactor), |
19 | 19 |
mPMeanMatrix(nFactor, D.ncol()), mPStdMatrix(nFactor, D.ncol()), |
20 | 20 |
mStatUpdates(0), mFixedMat(whichMat) |
21 | 21 |
{ |
22 |
- double meanD = mSingleCellRNASeq ? gaps::algo::nonZeroMean(mDMatrix) |
|
22 |
+ float meanD = mSingleCellRNASeq ? gaps::algo::nonZeroMean(mDMatrix) |
|
23 | 23 |
: gaps::algo::mean(mDMatrix); |
24 | 24 |
|
25 | 25 |
mADomain.setAlpha(alphaA); |
... | ... |
@@ -59,10 +59,10 @@ Rcpp::NumericMatrix GibbsSampler::getNormedMatrix(char mat) |
59 | 59 |
Vector normVec(mPMatrix.nRow()); |
60 | 60 |
for (unsigned r = 0; r < mPMatrix.nRow(); ++r) |
61 | 61 |
{ |
62 |
- normVec(r) = gaps::algo::sum(mPMatrix.getRow(r)); |
|
63 |
- if (normVec(r) == 0) |
|
62 |
+ normVec[r] = gaps::algo::sum(mPMatrix.getRow(r)); |
|
63 |
+ if (normVec[r] == 0) |
|
64 | 64 |
{ |
65 |
- normVec(r) = 1.0; |
|
65 |
+ normVec[r] = 1.0; |
|
66 | 66 |
} |
67 | 67 |
} |
68 | 68 |
|
... | ... |
@@ -72,7 +72,7 @@ Rcpp::NumericMatrix GibbsSampler::getNormedMatrix(char mat) |
72 | 72 |
for (unsigned c = 0; c < normedA.nCol(); ++c) |
73 | 73 |
{ |
74 | 74 |
normedA.getCol(c) += gaps::algo::scalarMultiple(normedA.getCol(c), |
75 |
- normVec(c)); |
|
75 |
+ normVec[c]); |
|
76 | 76 |
} |
77 | 77 |
return normedA.rMatrix(); |
78 | 78 |
} |
... | ... |
@@ -82,13 +82,13 @@ Rcpp::NumericMatrix GibbsSampler::getNormedMatrix(char mat) |
82 | 82 |
for (unsigned r = 0; r < normedP.nRow(); ++r) |
83 | 83 |
{ |
84 | 84 |
normedP.getRow(r) += gaps::algo::scalarDivision(normedP.getRow(r), |
85 |
- normVec(r)); |
|
85 |
+ normVec[r]); |
|
86 | 86 |
} |
87 | 87 |
return normedP.rMatrix(); |
88 | 88 |
} |
89 | 89 |
} |
90 | 90 |
|
91 |
-double GibbsSampler::getGibbsMass(const MatrixChange &change) |
|
91 |
+float GibbsSampler::getGibbsMass(const MatrixChange &change) |
|
92 | 92 |
{ |
93 | 93 |
// check if this change is death (only called in birth/death) |
94 | 94 |
bool death = change.delta1 < 0; |
... | ... |
@@ -100,25 +100,25 @@ double GibbsSampler::getGibbsMass(const MatrixChange &change) |
100 | 100 |
// calculate mean and standard deviation |
101 | 101 |
alphaParam.s *= mAnnealingTemp / 2.0; |
102 | 102 |
alphaParam.su *= mAnnealingTemp / 2.0; |
103 |
- double lambda = change.label == 'A' ? mADomain.lambda() : mPDomain.lambda(); |
|
104 |
- double mean = (2.0 * alphaParam.su - lambda) / (2.0 * alphaParam.s); |
|
105 |
- double sd = 1.0 / std::sqrt(2.0 * alphaParam.s); |
|
103 |
+ float lambda = change.label == 'A' ? mADomain.lambda() : mPDomain.lambda(); |
|
104 |
+ float mean = (2.0 * alphaParam.su - lambda) / (2.0 * alphaParam.s); |
|
105 |
+ float sd = 1.0 / std::sqrt(2.0 * alphaParam.s); |
|
106 | 106 |
|
107 | 107 |
// note: is bounded below by zero so have to use inverse sampling! |
108 | 108 |
// based upon algorithm in DistScalarRmath.cc (scalarRandomSample) |
109 |
- double plower = gaps::random::p_norm(0.0, mean, sd); |
|
110 |
- double u = gaps::random::uniform(plower, 1.0); |
|
109 |
+ float plower = gaps::random::p_norm(0.f, mean, sd); |
|
110 |
+ float u = gaps::random::uniform(plower, 1.f); |
|
111 | 111 |
|
112 | 112 |
// if the likelihood is flat and nonzero, sample strictly from the prior |
113 |
- double newMass = 0.0; |
|
114 |
- if (plower == 1 || alphaParam.s < 1.e-5) |
|
113 |
+ float newMass = 0.f; |
|
114 |
+ if (plower == 1.f || alphaParam.s < 0.00001f) |
|
115 | 115 |
{ |
116 |
- newMass = death ? std::abs(change.delta1) : 0.0; |
|
116 |
+ newMass = death ? std::abs(change.delta1) : 0.f; |
|
117 | 117 |
} |
118 |
- else if (plower >= 0.99) |
|
118 |
+ else if (plower >= 0.99f) |
|
119 | 119 |
{ |
120 |
- double tmp1 = gaps::random::d_norm(0, mean, sd); |
|
121 |
- double tmp2 = gaps::random::d_norm(10 * lambda, mean, sd); |
|
120 |
+ float tmp1 = gaps::random::d_norm(0.f, mean, sd); |
|
121 |
+ float tmp2 = gaps::random::d_norm(10.f * lambda, mean, sd); |
|
122 | 122 |
|
123 | 123 |
if (tmp1 > EPSILON && std::abs(tmp1 - tmp2) < EPSILON) |
124 | 124 |
{ |
... | ... |
@@ -133,10 +133,10 @@ double GibbsSampler::getGibbsMass(const MatrixChange &change) |
133 | 133 |
newMass = (change.label == 'A' ? std::min(newMass, mMaxGibbsMassA) |
134 | 134 |
: std::min(newMass, mMaxGibbsMassP)); |
135 | 135 |
|
136 |
- return std::max(newMass, 0.0); |
|
136 |
+ return std::max(newMass, 0.f); |
|
137 | 137 |
} |
138 | 138 |
|
139 |
-double GibbsSampler::computeDeltaLL(const MatrixChange &change) |
|
139 |
+float GibbsSampler::computeDeltaLL(const MatrixChange &change) |
|
140 | 140 |
{ |
141 | 141 |
return gaps::algo::deltaLL(change, mDMatrix, mSMatrix, mAMatrix, |
142 | 142 |
mPMatrix, mAPMatrix); |
... | ... |
@@ -178,26 +178,26 @@ uint64_t GibbsSampler::totalNumAtoms(char matrixLabel) const |
178 | 178 |
return matrixLabel == 'A' ? mADomain.numAtoms() : mPDomain.numAtoms(); |
179 | 179 |
} |
180 | 180 |
|
181 |
-void GibbsSampler::setChi2(double chi2) |
|
181 |
+void GibbsSampler::setChi2(float chi2) |
|
182 | 182 |
{ |
183 | 183 |
mChi2 = chi2; |
184 | 184 |
} |
185 | 185 |
|
186 |
-double GibbsSampler::chi2() const |
|
186 |
+float GibbsSampler::chi2() const |
|
187 | 187 |
{ |
188 | 188 |
return mChi2; |
189 | 189 |
} |
190 | 190 |
|
191 |
-void GibbsSampler::setAnnealingTemp(double temp) |
|
191 |
+void GibbsSampler::setAnnealingTemp(float temp) |
|
192 | 192 |
{ |
193 | 193 |
mAnnealingTemp = temp; |
194 | 194 |
} |
195 | 195 |
|
196 | 196 |
bool GibbsSampler::evaluateChange(AtomicSupport &domain, |
197 |
-const AtomicProposal &proposal, double threshold, bool accept) |
|
197 |
+const AtomicProposal &proposal, float threshold, bool accept) |
|
198 | 198 |
{ |
199 | 199 |
MatrixChange change = domain.getMatrixChange(proposal); |
200 |
- double delLL = computeDeltaLL(change); |
|
200 |
+ float delLL = computeDeltaLL(change); |
|
201 | 201 |
if (accept || delLL * mAnnealingTemp >= threshold) |
202 | 202 |
{ |
203 | 203 |
change = domain.acceptProposal(proposal); |
... | ... |
@@ -209,23 +209,23 @@ const AtomicProposal &proposal, double threshold, bool accept) |
209 | 209 |
return false; |
210 | 210 |
} |
211 | 211 |
|
212 |
-void GibbsSampler::updateAPMatrix_A(unsigned row, unsigned col, double delta) |
|
212 |
+void GibbsSampler::updateAPMatrix_A(unsigned row, unsigned col, float delta) |
|
213 | 213 |
{ |
214 | 214 |
const Vector &APvec = mAPMatrix.getRow(row); |
215 | 215 |
const Vector &Pvec = mPMatrix.getRow(col); |
216 | 216 |
for (unsigned j = 0; j < mAPMatrix.nCol(); ++j) |
217 | 217 |
{ |
218 |
- mAPMatrix.set(row, j, APvec(j) + delta * Pvec(j)); |
|
218 |
+ mAPMatrix.set(row, j, APvec[j] + delta * Pvec[j]); |
|
219 | 219 |
} |
220 | 220 |
} |
221 | 221 |
|
222 |
-void GibbsSampler::updateAPMatrix_P(unsigned row, unsigned col, double delta) |
|
222 |
+void GibbsSampler::updateAPMatrix_P(unsigned row, unsigned col, float delta) |
|
223 | 223 |
{ |
224 | 224 |
const Vector &APvec = mAPMatrix.getCol(col); |
225 | 225 |
const Vector &Avec = mAMatrix.getCol(row); |
226 | 226 |
for (unsigned i = 0; i < mAPMatrix.nRow(); ++i) |
227 | 227 |
{ |
228 |
- mAPMatrix.set(i, col, APvec(i) + delta * Avec(i)); |
|
228 |
+ mAPMatrix.set(i, col, APvec[i] + delta * Avec[i]); |
|
229 | 229 |
} |
230 | 230 |
} |
231 | 231 |
|
... | ... |
@@ -271,7 +271,7 @@ bool GibbsSampler::death(AtomicSupport &domain, AtomicProposal &proposal) |
271 | 271 |
|
272 | 272 |
// rebirth |
273 | 273 |
MatrixChange ch = domain.getMatrixChange(proposal); |
274 |
- double newMass = canUseGibbs(ch) ? getGibbsMass(ch) : 0.0; |
|
274 |
+ float newMass = canUseGibbs(ch) ? getGibbsMass(ch) : 0.0; |
|
275 | 275 |
proposal.delta1 = newMass < EPSILON ? -proposal.delta1 : newMass; |
276 | 276 |
|
277 | 277 |
// attempt to accept rebirth |
... | ... |
@@ -309,11 +309,11 @@ bool GibbsSampler::exchange(AtomicSupport &domain, AtomicProposal &proposal) |
309 | 309 |
uint64_t pos1 = proposal.delta1 > 0 ? proposal.pos1 : proposal.pos2; |
310 | 310 |
uint64_t pos2 = proposal.delta1 > 0 ? proposal.pos2 : proposal.pos1; |
311 | 311 |
|
312 |
- double mass1 = domain.at(pos1); |
|
313 |
- double mass2 = domain.at(pos2); |
|
312 |
+ float mass1 = domain.at(pos1); |
|
313 |
+ float mass2 = domain.at(pos2); |
|
314 | 314 |
|
315 |
- double newMass1 = mass1 + std::max(proposal.delta1, proposal.delta2); |
|
316 |
- double newMass2 = mass2 + std::min(proposal.delta1, proposal.delta2); |
|
315 |
+ float newMass1 = mass1 + std::max(proposal.delta1, proposal.delta2); |
|
316 |
+ float newMass2 = mass2 + std::min(proposal.delta1, proposal.delta2); |
|
317 | 317 |
|
318 | 318 |
unsigned row1 = change.delta1 > 0 ? change.row1 : change.row2; |
319 | 319 |
unsigned row2 = change.delta1 > 0 ? change.row2 : change.row1; |
... | ... |
@@ -337,14 +337,14 @@ bool GibbsSampler::exchange(AtomicSupport &domain, AtomicProposal &proposal) |
337 | 337 |
|
338 | 338 |
if (alphaParam.s > EPSILON) |
339 | 339 |
{ |
340 |
- double mean = alphaParam.su / alphaParam.s; |
|
341 |
- double sd = 1.0 / std::sqrt(alphaParam.s); |
|
340 |
+ float mean = alphaParam.su / alphaParam.s; |
|
341 |
+ float sd = 1.f / std::sqrt(alphaParam.s); |
|
342 | 342 |
|
343 |
- double plower = gaps::random::p_norm(-mass1, mean, sd); |
|
344 |
- double pupper = gaps::random::p_norm(mass2, mean, sd); |
|
345 |
- double u = gaps::random::uniform(plower, pupper); |
|
343 |
+ float plower = gaps::random::p_norm(-mass1, mean, sd); |
|
344 |
+ float pupper = gaps::random::p_norm(mass2, mean, sd); |
|
345 |
+ float u = gaps::random::uniform(plower, pupper); |
|
346 | 346 |
|
347 |
- if (!(plower > 0.95 || pupper < 0.05)) |
|
347 |
+ if (!(plower > 0.95f || pupper < 0.05f)) |
|
348 | 348 |
{ |
349 | 349 |
proposal.delta1 = gaps::random::q_norm(u, mean, sd); |
350 | 350 |
proposal.delta1 = std::max(proposal.delta1, -mass1); |
... | ... |
@@ -358,11 +358,11 @@ bool GibbsSampler::exchange(AtomicSupport &domain, AtomicProposal &proposal) |
358 | 358 |
} |
359 | 359 |
} |
360 | 360 |
|
361 |
- double pnewMass = mass1 > mass2 ? newMass1 : newMass2; |
|
362 |
- double poldMass = newMass1 > newMass2 ? mass1 : mass2; |
|
361 |
+ float pnewMass = mass1 > mass2 ? newMass1 : newMass2; |
|
362 |
+ float poldMass = newMass1 > newMass2 ? mass1 : mass2; |
|
363 | 363 |
|
364 |
- double pnew = gaps::random::d_gamma(pnewMass, 2.0, 1.0 / domain.lambda()); |
|
365 |
- double pold = gaps::random::d_gamma(poldMass, 2.0, 1.0 / domain.lambda()); |
|
364 |
+ float pnew = gaps::random::d_gamma(pnewMass, 2.0, 1.f / domain.lambda()); |
|
365 |
+ float pold = gaps::random::d_gamma(poldMass, 2.0, 1.f / domain.lambda()); |
|
366 | 366 |
|
367 | 367 |
proposal.pos1 = pos1; |
368 | 368 |
proposal.delta1 = newMass1 - mass1; |
... | ... |
@@ -375,7 +375,7 @@ bool GibbsSampler::exchange(AtomicSupport &domain, AtomicProposal &proposal) |
375 | 375 |
} |
376 | 376 |
else |
377 | 377 |
{ |
378 |
- double priorLL = pold == 0.0 ? 0.0 : log(pnew / pold); |
|
378 |
+ float priorLL = pold == 0.0 ? 0.0 : log(pnew / pold); |
|
379 | 379 |
return evaluateChange(domain, proposal, std::log(gaps::random::uniform()) |
380 | 380 |
- priorLL); |
381 | 381 |
} |
... | ... |
@@ -412,28 +412,28 @@ void GibbsSampler::updateStatistics() |
412 | 412 |
|
413 | 413 |
for (unsigned r = 0; r < mPMatrix.nRow(); ++r) |
414 | 414 |
{ |
415 |
- normVec(r) = gaps::algo::sum(mPMatrix.getRow(r)); |
|
416 |
- if (normVec(r) == 0) |
|
415 |
+ normVec[r] = gaps::algo::sum(mPMatrix.getRow(r)); |
|
416 |
+ if (normVec[r] == 0) |
|
417 | 417 |
{ |
418 |
- normVec(r) = 1.0; |
|
418 |
+ normVec[r] = 1.0; |
|
419 | 419 |
} |
420 | 420 |
} |
421 | 421 |
|
422 | 422 |
for (unsigned c = 0; c < mAMeanMatrix.nCol(); ++c) |
423 | 423 |
{ |
424 | 424 |
mAMeanMatrix.getCol(c) += gaps::algo::scalarMultiple(mAMatrix.getCol(c), |
425 |
- normVec(c)); |
|
425 |
+ normVec[c]); |
|
426 | 426 |
|
427 | 427 |
mAStdMatrix.getCol(c) += gaps::algo::squaredScalarMultiple(mAMatrix.getCol(c), |
428 |
- normVec(c)); |
|
428 |
+ normVec[c]); |
|
429 | 429 |
} |
430 | 430 |
|
431 | 431 |
for (unsigned r = 0; r < mPMeanMatrix.nRow(); ++r) |
432 | 432 |
{ |
433 | 433 |
mPMeanMatrix.getRow(r) += gaps::algo::scalarDivision(mPMatrix.getRow(r), |
434 |
- normVec(r)); |
|
434 |
+ normVec[r]); |
|
435 | 435 |
|
436 | 436 |
mPStdMatrix.getRow(r) += gaps::algo::squaredScalarDivision(mPMatrix.getRow(r), |
437 |
- normVec(r)); |
|
437 |
+ normVec[r]); |
|
438 | 438 |
} |
439 | 439 |
} |
440 | 440 |
\ No newline at end of file |
... | ... |
@@ -23,11 +23,11 @@ public: |
23 | 23 |
ColMatrix mAMeanMatrix, mAStdMatrix; |
24 | 24 |
unsigned mStatUpdates; |
25 | 25 |
|
26 |
- double mMaxGibbsMassA; |
|
27 |
- double mMaxGibbsMassP; |
|
26 |
+ float mMaxGibbsMassA; |
|
27 |
+ float mMaxGibbsMassP; |
|
28 | 28 |
|
29 |
- double mAnnealingTemp; |
|
30 |
- double mChi2; |
|
29 |
+ float mAnnealingTemp; |
|
30 |
+ float mChi2; |
|
31 | 31 |
|
32 | 32 |
bool mSingleCellRNASeq; |
33 | 33 |
|
... | ... |
@@ -40,30 +40,30 @@ public: |
40 | 40 |
bool exchange(AtomicSupport &domain, AtomicProposal &proposal); |
41 | 41 |
|
42 | 42 |
bool evaluateChange(AtomicSupport &domain, const AtomicProposal &proposal, |
43 |
- double threshold, bool accept=false); |
|
43 |
+ float threshold, bool accept=false); |
|
44 | 44 |
|
45 |
- double computeDeltaLL(const MatrixChange &change); |
|
45 |
+ float computeDeltaLL(const MatrixChange &change); |
|
46 | 46 |
|
47 |
- double getGibbsMass(const MatrixChange &change); |
|
47 |
+ float getGibbsMass(const MatrixChange &change); |
|
48 | 48 |
|
49 |
- void updateAPMatrix_A(unsigned row, unsigned col, double delta); |
|
50 |
- void updateAPMatrix_P(unsigned row, unsigned col, double delta); |
|
49 |
+ void updateAPMatrix_A(unsigned row, unsigned col, float delta); |
|
50 |
+ void updateAPMatrix_P(unsigned row, unsigned col, float delta); |
|
51 | 51 |
void updateAPMatrix(const MatrixChange &change); |
52 | 52 |
|
53 | 53 |
bool canUseGibbs(const MatrixChange &ch); |
54 |
- void setChi2(double chi2); |
|
54 |
+ void setChi2(float chi2); |
|
55 | 55 |
|
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
GibbsSampler(Rcpp::NumericMatrix D, Rcpp::NumericMatrix S, unsigned nFactor, |
59 |
- double alphaA, double alphaP, double maxGibbsMassA, double maxGibbsMassP, |
|
59 |
+ float alphaA, float alphaP, float maxGibbsMassA, float maxGibbsMassP, |
|
60 | 60 |
bool singleCellRNASeq, Rcpp::NumericMatrix fixedPat, char whichMat); |
61 | 61 |
|
62 | 62 |
void update(char matrixLabel); |
63 | 63 |
|
64 | 64 |
uint64_t totalNumAtoms(char matrixLabel) const; |
65 |
- void setAnnealingTemp(double temp); |
|
66 |
- double chi2() const; |
|
65 |
+ void setAnnealingTemp(float temp); |
|
66 |
+ float chi2() const; |
|
67 | 67 |
|
68 | 68 |
Rcpp::NumericMatrix AMeanRMatrix() const; |
69 | 69 |
Rcpp::NumericMatrix AStdRMatrix() const; |
... | ... |
@@ -2,11 +2,11 @@ |
2 | 2 |
|
3 | 3 |
#include <stdexcept> |
4 | 4 |
|
5 |
-static const double EPSILON = 1.e-10; |
|
5 |
+static const float EPSILON = 1.e-10; |
|
6 | 6 |
|
7 | 7 |
/******************************** HELPER *******************************/ |
8 | 8 |
|
9 |
-static void updateHelper(double& val, double delta) |
|
9 |
+static void updateHelper(float& val, float delta) |
|
10 | 10 |
{ |
11 | 11 |
val += delta; |
12 | 12 |
if (std::abs(val) < EPSILON) |
... | ... |
@@ -46,7 +46,7 @@ RowMatrix::RowMatrix(const Rcpp::NumericMatrix &rmat) |
46 | 46 |
mRows.push_back(Vector(mNumCols)); |
47 | 47 |
for (unsigned j = 0; j < mNumCols; ++j) |
48 | 48 |
{ |
49 |
- mRows[i](j) = rmat(i,j); |
|
49 |
+ this->operator()(i,j) = rmat(i,j); |
|
50 | 50 |
} |
51 | 51 |
} |
52 | 52 |
} |
... | ... |
@@ -97,7 +97,7 @@ void Vector::operator+=(const Vector &vec) |
97 | 97 |
{ |
98 | 98 |
for (unsigned i = 0; i < size(); ++i) |
99 | 99 |
{ |
100 |
- mValues[i] += vec(i); |
|
100 |
+ mValues[i] += vec[i]; |
|
101 | 101 |
} |
102 | 102 |
} |
103 | 103 |
|
... | ... |
@@ -120,7 +120,7 @@ ColMatrix::ColMatrix(const Rcpp::NumericMatrix &rmat) |
120 | 120 |
mCols.push_back(Vector(mNumRows)); |
121 | 121 |
for (unsigned i = 0; i < mNumRows; ++i) |
122 | 122 |
{ |
123 |
- mCols[j](i) = rmat(i,j); |
|
123 |
+ this->operator()(i,j) = rmat(i,j); |
|
124 | 124 |
} |
125 | 125 |
} |
126 | 126 |
} |
... | ... |
@@ -4,8 +4,10 @@ |
4 | 4 |
#include <Rcpp.h> |
5 | 5 |
#include <vector> |
6 | 6 |
|
7 |
+// use CRTP for different matrix types? |
|
8 |
+ |
|
7 | 9 |
// temporary: used for testing performance of float vs double |
8 |
-typedef double matrix_data_t; |
|
10 |
+typedef float matrix_data_t; |
|
9 | 11 |
|
10 | 12 |
struct MatrixChange |
11 | 13 |
{ |
... | ... |
@@ -20,13 +22,13 @@ struct MatrixChange |
20 | 22 |
unsigned col2; |
21 | 23 |
matrix_data_t delta2; |
22 | 24 |
|
23 |
- MatrixChange(char l, unsigned r, unsigned c, double d) |
|
25 |
+ MatrixChange(char l, unsigned r, unsigned c, float d) |
|
24 | 26 |
: label(l), nChanges(1), row1(r), col1(c), delta1(d), row2(0), |
25 | 27 |
col2(0), delta2(0.0) |
26 | 28 |
{} |
27 | 29 |
|
28 |
- MatrixChange(char l, unsigned r1, unsigned c1, double d1, unsigned r2, |
|
29 |
- unsigned c2, double d2) |
|
30 |
+ MatrixChange(char l, unsigned r1, unsigned c1, float d1, unsigned r2, |
|
31 |
+ unsigned c2, float d2) |
|
30 | 32 |
: label(l), nChanges(2), row1(r1), col1(c1), delta1(d1), row2(r2), |
31 | 33 |
col2(c2), delta2(d2) |
32 | 34 |
{} |
... | ... |
@@ -51,8 +53,6 @@ public: |
51 | 53 |
Vector(unsigned size) : mValues(std::vector<matrix_data_t>(size, 0.0)) {} |
52 | 54 |
Vector(const std::vector<matrix_data_t>& v) : mValues(v) {} |
53 | 55 |
|
54 |
- matrix_data_t& operator()(unsigned i) {return mValues[i];} |
|
55 |
- matrix_data_t operator()(unsigned i) const {return mValues[i];} |
|
56 | 56 |
matrix_data_t& operator[](unsigned i) {return mValues[i];} |
57 | 57 |
matrix_data_t operator[](unsigned i) const {return mValues[i];} |
58 | 58 |
unsigned size() const {return mValues.size();} |
... | ... |
@@ -79,8 +79,8 @@ public: |
79 | 79 |
unsigned nRow() const {return mNumRows;} |
80 | 80 |
unsigned nCol() const {return mNumCols;} |
81 | 81 |
|
82 |
- matrix_data_t& operator()(unsigned r, unsigned c) {return mRows[r](c);} |
|
83 |
- matrix_data_t operator()(unsigned r, unsigned c) const {return mRows[r](c);} |
|
82 |
+ matrix_data_t& operator()(unsigned r, unsigned c) {return mRows[r][c];} |
|
83 |
+ matrix_data_t operator()(unsigned r, unsigned c) const {return mRows[r][c];} |
|
84 | 84 |
|
85 | 85 |
Vector& getRow(unsigned row); |
86 | 86 |
const Vector& getRow(unsigned row) const; |
... | ... |
@@ -105,8 +105,8 @@ public: |
105 | 105 |
unsigned nRow() const {return mNumRows;} |
106 | 106 |
unsigned nCol() const {return mNumCols;} |
107 | 107 |
|
108 |
- matrix_data_t& operator()(unsigned r, unsigned c) {return mCols[c](r);} |
|
109 |
- matrix_data_t operator()(unsigned r, unsigned c) const {return mCols[c](r);} |
|
108 |
+ matrix_data_t& operator()(unsigned r, unsigned c) {return mCols[c][r];} |
|
109 |
+ matrix_data_t operator()(unsigned r, unsigned c) const {return mCols[c][r];} |
|
110 | 110 |
|
111 | 111 |
Vector& getCol(unsigned col); |
112 | 112 |
const Vector& getCol(unsigned col) const; |
... | ... |
@@ -144,7 +144,7 @@ public: |
144 | 144 |
const Vector& getRow(unsigned row) const {return mRowMatrix.getRow(row);} |
145 | 145 |
const Vector& getCol(unsigned col) const {return mColMatrix.getCol(col);} |
146 | 146 |
|
147 |
- void set(unsigned row, unsigned col, double value) |
|
147 |
+ void set(unsigned row, unsigned col, float value) |
|
148 | 148 |
{ |
149 | 149 |
mRowMatrix(row, col) = value; |
150 | 150 |
mColMatrix(row, col) = value; |
... | ... |
@@ -27,31 +27,31 @@ void gaps::random::setSeed(uint32_t seed) |
27 | 27 |
rng.seed(seed); |
28 | 28 |
} |
29 | 29 |
|
30 |
-double gaps::random::normal(double mean, double var) |
|
30 |
+float gaps::random::normal(float mean, float var) |
|
31 | 31 |
{ |
32 |
- boost::random::normal_distribution<double> dist(mean, var); |
|
32 |
+ boost::random::normal_distribution<float> dist(mean, var); |
|
33 | 33 |
return dist(rng); |
34 | 34 |
} |
35 | 35 |
|
36 |
-int gaps::random::poisson(double lambda) |
|
36 |
+int gaps::random::poisson(float lambda) |
|
37 | 37 |
{ |
38 | 38 |
boost::random::poisson_distribution<> dist(lambda); |
39 | 39 |
return dist(rng); |
40 | 40 |
} |
41 | 41 |
|
42 |
-double gaps::random::exponential(double lambda) |
|
42 |
+float gaps::random::exponential(float lambda) |
|
43 | 43 |
{ |
44 | 44 |
boost::random::exponential_distribution<> dist(lambda); |
45 | 45 |
return dist(rng); |
46 | 46 |
} |
47 | 47 |
|
48 |
-double gaps::random::uniform() |
|
48 |
+float gaps::random::uniform() |
|
49 | 49 |
{ |
50 | 50 |
boost::random::uniform_01<RNGType&> dist(rng); // could be moved out |
51 | 51 |
return dist(); |
52 | 52 |
} |
53 | 53 |
|
54 |
-double gaps::random::uniform(double a, double b) |
|
54 |
+float gaps::random::uniform(float a, float b) |
|
55 | 55 |
{ |
56 | 56 |
if (a == b) |
57 | 57 |
{ |
... | ... |
@@ -84,19 +84,19 @@ uint64_t gaps::random::uniform64(uint64_t a, uint64_t b) |
84 | 84 |
} |
85 | 85 |
} |
86 | 86 |
|
87 |
-double gaps::random::d_gamma(double d, double shape, double scale) |
|
87 |
+float gaps::random::d_gamma(float d, float shape, float scale) |
|
88 | 88 |
{ |
89 | 89 |
boost::math::gamma_distribution<> gam(shape, scale); |
90 | 90 |
return pdf(gam, d); |
91 | 91 |
} |
92 | 92 |
|
93 |
-double gaps::random::p_gamma(double p, double shape, double scale) |
|
93 |
+float gaps::random::p_gamma(float p, float shape, float scale) |
|
94 | 94 |
{ |
95 | 95 |
boost::math::gamma_distribution<> gam(shape, scale); |
96 | 96 |
return cdf(gam, p); |
97 | 97 |
} |
98 | 98 |
|
99 |
-double gaps::random::q_gamma(double q, double shape, double scale) |
|
99 |
+float gaps::random::q_gamma(float q, float shape, float scale) |
|
100 | 100 |
{ |
101 | 101 |
if (q < Q_GAMMA_THRESHOLD) |
102 | 102 |
{ |
... | ... |
@@ -109,19 +109,19 @@ double gaps::random::q_gamma(double q, double shape, double scale) |
109 | 109 |
} |
110 | 110 |
} |
111 | 111 |
|
112 |
-double gaps::random::d_norm(double d, double mean, double sd) |
|
112 |
+float gaps::random::d_norm(float d, float mean, float sd) |
|
113 | 113 |
{ |
114 | 114 |
boost::math::normal_distribution<> norm(mean, sd); |
115 | 115 |
return pdf(norm, d); |
116 | 116 |
} |
117 | 117 |
|
118 |
-double gaps::random::q_norm(double q, double mean, double sd) |
|
118 |
+float gaps::random::q_norm(float q, float mean, float sd) |
|
119 | 119 |
{ |
120 | 120 |
boost::math::normal_distribution<> norm(mean, sd); |
121 | 121 |
return quantile(norm, q); |
122 | 122 |
} |
123 | 123 |
|
124 |
-double gaps::random::p_norm(double p, double mean, double sd) |
|
124 |
+float gaps::random::p_norm(float p, float mean, float sd) |
|
125 | 125 |
{ |
126 | 126 |
boost::math::normal_distribution<> norm(mean, sd); |
127 | 127 |
return cdf(norm, p); |
... | ... |
@@ -11,22 +11,22 @@ namespace random |
11 | 11 |
{ |
12 | 12 |
void setSeed(uint32_t seed); |
13 | 13 |
|
14 |
- int poisson(double lambda); |
|
14 |
+ int poisson(float lambda); |
|
15 | 15 |
int uniformInt(int a, int b); |
16 | 16 |
uint64_t uniform64(); |
17 | 17 |
uint64_t uniform64(uint64_t a, uint64_t b); |
18 | 18 |
|
19 |
- double uniform(); |
|
20 |
- double uniform(double a, double b); |
|
21 |
- double normal(double mean, double var); |
|
22 |
- double exponential(double lambda); |
|
23 |
- |
|
24 |
- double d_gamma(double d, double shape, double scale); |
|
25 |
- double p_gamma(double p, double shape, double scale); |
|
26 |
- double q_gamma(double q, double shape, double scale); |
|
27 |
- double d_norm(double d, double mean, double sd); |
|
28 |
- double q_norm(double q, double mean, double sd); |
|
29 |
- double p_norm(double p, double mean, double sd); |
|
19 |
+ float uniform(); |
|
20 |
+ float uniform(float a, float b); |
|
21 |
+ float normal(float mean, float var); |
|
22 |
+ float exponential(float lambda); |
|
23 |
+ |
|
24 |
+ float d_gamma(float d, float shape, float scale); |
|
25 |
+ float p_gamma(float p, float shape, float scale); |
|
26 |
+ float q_gamma(float q, float shape, float scale); |
|
27 |
+ float d_norm(float d, float mean, float sd); |
|
28 |
+ float q_norm(float q, float mean, float sd); |
|
29 |
+ float p_norm(float p, float mean, float sd); |
|
30 | 30 |
} |
31 | 31 |
|
32 | 32 |
} |
... | ... |
@@ -6,7 +6,7 @@ |
6 | 6 |
using namespace Rcpp; |
7 | 7 |
|
8 | 8 |
// cogaps |
9 |
-Rcpp::List cogaps(Rcpp::NumericMatrix DMatrix, Rcpp::NumericMatrix SMatrix, unsigned nFactor, double alphaA, double alphaP, unsigned nEquil, unsigned nEquilCool, unsigned nSample, double maxGibbsMassA, double maxGibbsMassP, Rcpp::NumericMatrix fixedPatterns, char whichMatrixFixed, int seed, bool messages, bool singleCellRNASeq, unsigned numOutputs, unsigned numSnapshots); |
|
9 |
+Rcpp::List cogaps(Rcpp::NumericMatrix DMatrix, Rcpp::NumericMatrix SMatrix, unsigned nFactor, float alphaA, float alphaP, unsigned nEquil, unsigned nEquilCool, unsigned nSample, float maxGibbsMassA, float maxGibbsMassP, Rcpp::NumericMatrix fixedPatterns, char whichMatrixFixed, int seed, bool messages, bool singleCellRNASeq, unsigned numOutputs, unsigned numSnapshots); |
|
10 | 10 |
RcppExport SEXP _CoGAPS_cogaps(SEXP DMatrixSEXP, SEXP SMatrixSEXP, SEXP nFactorSEXP, SEXP alphaASEXP, SEXP alphaPSEXP, SEXP nEquilSEXP, SEXP nEquilCoolSEXP, SEXP nSampleSEXP, SEXP maxGibbsMassASEXP, SEXP maxGibbsMassPSEXP, SEXP fixedPatternsSEXP, SEXP whichMatrixFixedSEXP, SEXP seedSEXP, SEXP messagesSEXP, SEXP singleCellRNASeqSEXP, SEXP numOutputsSEXP, SEXP numSnapshotsSEXP) { |
11 | 11 |
BEGIN_RCPP |
12 | 12 |
Rcpp::RObject rcpp_result_gen; |
... | ... |
@@ -14,13 +14,13 @@ BEGIN_RCPP |
14 | 14 |
Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type DMatrix(DMatrixSEXP); |
15 | 15 |
Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type SMatrix(SMatrixSEXP); |
16 | 16 |
Rcpp::traits::input_parameter< unsigned >::type nFactor(nFactorSEXP); |
17 |
- Rcpp::traits::input_parameter< double >::type alphaA(alphaASEXP); |
|
18 |
- Rcpp::traits::input_parameter< double >::type alphaP(alphaPSEXP); |
|
17 |
+ Rcpp::traits::input_parameter< float >::type alphaA(alphaASEXP); |
|
18 |
+ Rcpp::traits::input_parameter< float >::type alphaP(alphaPSEXP); |
|
19 | 19 |
Rcpp::traits::input_parameter< unsigned >::type nEquil(nEquilSEXP); |
20 | 20 |
Rcpp::traits::input_parameter< unsigned >::type nEquilCool(nEquilCoolSEXP); |
21 | 21 |
Rcpp::traits::input_parameter< unsigned >::type nSample(nSampleSEXP); |
22 |
- Rcpp::traits::input_parameter< double >::type maxGibbsMassA(maxGibbsMassASEXP); |
|
23 |
- Rcpp::traits::input_parameter< double >::type maxGibbsMassP(maxGibbsMassPSEXP); |
|
22 |
+ Rcpp::traits::input_parameter< float >::type maxGibbsMassA(maxGibbsMassASEXP); |
|
23 |
+ Rcpp::traits::input_parameter< float >::type maxGibbsMassP(maxGibbsMassPSEXP); |
|
24 | 24 |
Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type fixedPatterns(fixedPatternsSEXP); |
25 | 25 |
Rcpp::traits::input_parameter< char >::type whichMatrixFixed(whichMatrixFixedSEXP); |
26 | 26 |
Rcpp::traits::input_parameter< int >::type seed(seedSEXP); |
... | ... |
@@ -15,7 +15,7 @@ TEST_CASE("Test Algorithms.h") |
15 | 15 |
|
16 | 16 |
for (unsigned r = 0; r < nrow; ++r) |
17 | 17 |
{ |
18 |
- v(r) = r; |
|
18 |
+ v[r] = r; |
|
19 | 19 |
for (unsigned c = 0; c < ncol; ++c) |
20 | 20 |
{ |
21 | 21 |
D.set(r, c, r + c); |
... | ... |
@@ -36,7 +36,7 @@ TEST_CASE("Test Algorithms.h") |
36 | 36 |
|
37 | 37 |
SECTION("mean") |
38 | 38 |
{ |
39 |
- double dTotal = 300 * 10 + 45 * 25; |
|
39 |
+ float dTotal = 300 * 10 + 45 * 25; |
|
40 | 40 |
|
41 | 41 |
REQUIRE(gaps::algo::mean(D) == gaps::algo::mean(S) * 100.0); |
42 | 42 |
REQUIRE(gaps::algo::mean(D) == dTotal / (nrow * ncol)); |
... | ... |
@@ -48,7 +48,7 @@ TEST_CASE("Test Algorithms.h") |
48 | 48 |
REQUIRE(gaps::algo::sum(gaps::algo::scalarMultiple(v, 3.5)) |
49 | 49 |
== 3.5 * 300.0); |
50 | 50 |
|
51 |
- double vsqSum = 24.0 * 25.0 * (2.0 * 24.0 + 1.0) / 6.0; |
|
51 |
+ float vsqSum = 24.0 * 25.0 * (2.0 * 24.0 + 1.0) / 6.0; |
|
52 | 52 |
REQUIRE(gaps::algo::sum(gaps::algo::squaredScalarMultiple(v, 4.0)) |
53 | 53 |
== 16.0 * vsqSum); |
54 | 54 |
/* |
... | ... |
@@ -49,7 +49,7 @@ TEST_CASE("Test AtomicSupport.h") |
49 | 49 |
REQUIRE(change.delta1 == prop.delta1); |
50 | 50 |
REQUIRE(change.delta2 == prop.delta2); |
51 | 51 |
|
52 |
- double oldMass = domain.totalMass(); |
|
52 |
+ float oldMass = domain.totalMass(); |
|
53 | 53 |
|
54 | 54 |
uint64_t nOld = domain.numAtoms(); |
55 | 55 |
|
... | ... |
@@ -166,7 +166,7 @@ TEST_CASE("Internal AtomicSupport Tests") |
166 | 166 |
|
167 | 167 |
/* SECTION("updateAtomMass") |
168 | 168 |
{ |
169 |
- double oldMass = 0.0; |
|
169 |
+ float oldMass = 0.0; |
|
170 | 170 |
uint64_t posA = 0, posP = 0; |
171 | 171 |
for (unsigned i = 0; i < 1000; ++i) |
172 | 172 |
{ |
... | ... |
@@ -71,16 +71,16 @@ TEST_CASE("Test Matrix.h") |
71 | 71 |
|
72 | 72 |
REQUIRE(rm(3,4) == 3.0); |
73 | 73 |
REQUIRE(cm(1,2) == 13.0); |
74 |
- REQUIRE(rm.getRow(3)(4) == 3.0); |
|
75 |
- REQUIRE(cm.getCol(2)(1) == 13.0); |
|
74 |
+ REQUIRE(rm.getRow(3)[4] == 3.0); |
|
75 |
+ REQUIRE(cm.getCol(2)[1] == 13.0); |
|
76 | 76 |
|
77 | 77 |
rm.update(MatrixChange('A', 3, 4, 3.0)); |
78 | 78 |
cm.update(MatrixChange('P', 1, 2, 5.0)); |
79 | 79 |
|
80 | 80 |
REQUIRE(rm(3,4) == 6.0); |
81 | 81 |
REQUIRE(cm(1,2) == 18.0); |
82 |
- REQUIRE(rm.getRow(3)(4) == 6.0); |
|
83 |
- REQUIRE(cm.getCol(2)(1) == 18.0); |
|
82 |
+ REQUIRE(rm.getRow(3)[4] == 6.0); |
|
83 |
+ REQUIRE(cm.getCol(2)[1] == 18.0); |
|
84 | 84 |
} |
85 | 85 |
|
86 | 86 |
SECTION("TwoWayMatrix set") |
... | ... |
@@ -88,8 +88,8 @@ TEST_CASE("Test Matrix.h") |
88 | 88 |
TwoWayMatrix mat(100, 300); |
89 | 89 |
mat.set(0,299,54.0); |
90 | 90 |
|
91 |
- REQUIRE(mat.getRow(0)(299) == 54.0); |
|
92 |
- REQUIRE(mat.getCol(299)(0) == 54.0); |
|
91 |
+ REQUIRE(mat.getRow(0)[299] == 54.0); |
|
92 |
+ REQUIRE(mat.getCol(299)[0] == 54.0); |
|
93 | 93 |
} |
94 | 94 |
} |
95 | 95 |
|
... | ... |
@@ -12,8 +12,8 @@ TEST_CASE("Test Random.h - Random Number Generation") |
12 | 12 |
|
13 | 13 |
SECTION("Test uniform distribution over unit interval") |
14 | 14 |
{ |
15 |
- double min = 1, max = 0; |
|
16 |
- double sum = 0.0; |
|
15 |
+ float min = 1, max = 0; |
|
16 |
+ float sum = 0.0; |
|
17 | 17 |
unsigned N = 10000; |
18 | 18 |
for (unsigned i = 0; i < N; ++i) |
19 | 19 |
{ |
... | ... |
@@ -37,7 +37,7 @@ TEST_CASE("Test Random.h - Random Number Generation") |
37 | 37 |
REQUIRE(gaps::random::uniform(4.3,4.3) == 4.3); |
38 | 38 |
|
39 | 39 |
// full range possible |
40 |
- double min = 10., max = 0.; |
|
40 |
+ float min = 10., max = 0.; |
|
41 | 41 |
for (unsigned i = 0; i < 1000; ++i) |
42 | 42 |
{ |
43 | 43 |
min = std::min(gaps::random::uniform(0.0,10.0), min); |
... | ... |
@@ -60,8 +60,8 @@ TEST_CASE("Test Random.h - Random Number Generation") |
60 | 60 |
SECTION("Test normal distribution") |
61 | 61 |
{ |
62 | 62 |
// sample distribution |
63 |
- double mean = 0.0, var = 0.0; |
|
64 |
- double norm[1024]; |
|
63 |
+ float mean = 0.0, var = 0.0; |
|
64 |
+ float norm[1024]; |
|
65 | 65 |
for (unsigned i = 0; i < 1024; ++i) |
66 | 66 |
{ |
67 | 67 |
norm[i] = gaps::random::normal(0, 1); |
... | ... |
@@ -81,30 +81,30 @@ TEST_CASE("Test Random.h - Random Number Generation") |
81 | 81 |
|
82 | 82 |
SECTION("Test poisson distribution") |
83 | 83 |
{ |
84 |
- double total = 0; |
|
84 |
+ float total = 0; |
|
85 | 85 |
for (unsigned i = 0; i < 10000; ++i) |
86 | 86 |
{ |
87 |
- double num = gaps::random::poisson(4); |
|
87 |
+ float num = gaps::random::poisson(4); |
|
88 | 88 |
total += num; |
89 | 89 |
|
90 | 90 |
REQUIRE((int)num == num); // should be integer |
91 | 91 |
REQUIRE(num >= 0.0); // should be non-negative |
92 | 92 |
} |
93 |
- double mean = total / 10000; |
|
93 |
+ float mean = total / 10000; |
|
94 | 94 |
REQUIRE(mean == Approx(4).epsilon(0.025)); |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
SECTION("Test exponential distribution") |
98 | 98 |
{ |
99 |
- double total = 0; |
|
99 |
+ float total = 0; |
|
100 | 100 |
for (unsigned i = 0; i < 10000; ++i) |
101 | 101 |
{ |
102 |
- double num = gaps::random::exponential(1); |
|
102 |
+ float num = gaps::random::exponential(1); |
|
103 | 103 |
total += num; |
104 | 104 |
|
105 | 105 |
REQUIRE(num >= 0.0); // should be non-negative |
106 | 106 |
} |
107 |
- double mean = total / 10000; |
|
107 |
+ float mean = total / 10000; |
|
108 | 108 |
REQUIRE(mean == Approx(1).epsilon(0.025)); |
109 | 109 |
} |
110 | 110 |
} |