-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.cpp
47 lines (39 loc) · 929 Bytes
/
shared.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "shared.hpp"
#include "interdataset.hpp"
void
shared::sampleFromPrior()
{
std::uniform_int_distribution<int> ainit(0,nclus()-1);
for (auto i = 0; i < _alloc.cols(); i++)
for (auto j = 0; j < _alloc.rows(); j++)
_alloc(j, i) = ainit(generator);
}
void
shared::setAlloc(const Eigen::MatrixXi &x)
{
assert(x.rows() == nitems() && x.cols() == nfiles());
assert(x.minCoeff() >= 0 && x.maxCoeff() < nclus());
_alloc = x;
}
void
shared::setAlloc(int k, Eigen::VectorXi file)
{
assert(file.size() == nitems());
assert(file.minCoeff() >= 0 && file.maxCoeff() < nclus());
_alloc.col(k) = file;
}
float
shared::nuConditionalAlpha() const
{
return nitems();
}
float
shared::phiConditionalAlpha(int k, int l) const
{
return (_alloc.col(k).array() == _alloc.col(l).array()).count();
}
float
shared::gammaConditionalAlpha(int k, int j) const
{
return 1 + (_alloc.col(k).array() == j).count();
}