Skip to content

Commit

Permalink
Merge pull request #105 from bab2min/dev
Browse files Browse the repository at this point in the history
fixed GDMR compatibility & update docs
  • Loading branch information
bab2min authored Mar 26, 2021
2 parents 004188a + 6c7da4a commit 7753b26
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 85 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
rm -rf eigen-git-mirror/
git clone https://github.com/bab2min/EigenRand
cd EigenRand
git checkout tags/v0.2.2
git checkout tags/v0.3.2
cd ..
mv EigenRand/EigenRand include/
git clone https://github.com/mapbox/variant
Expand Down Expand Up @@ -71,9 +71,9 @@ jobs:
wget https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz
tar -zxvf 3.3.7.tar.gz
mv eigen-git-mirror-3.3.7 include
wget https://github.com/bab2min/EigenRand/archive/v0.2.2.tar.gz
tar -zxvf v0.2.2.tar.gz
mv EigenRand-0.2.2/EigenRand include/
wget https://github.com/bab2min/EigenRand/archive/v0.3.2.tar.gz
tar -zxvf v0.3.2.tar.gz
mv EigenRand-0.3.2/EigenRand include/
wget https://github.com/mapbox/variant/archive/v1.1.3.tar.gz
tar -zxvf v1.1.3.tar.gz
mv variant-1.1.3/include/mapbox include/
Expand Down Expand Up @@ -110,9 +110,9 @@ jobs:
Invoke-WebRequest -OutFile 3.3.7.tar.gz https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz
tar -zxvf 3.3.7.tar.gz
mv eigen-git-mirror-3.3.7 include
Invoke-WebRequest -OutFile v0.2.2.tar.gz https://github.com/bab2min/EigenRand/archive/v0.2.2.tar.gz
tar -zxvf v0.2.2.tar.gz
mv EigenRand-0.2.2/EigenRand include/
Invoke-WebRequest -OutFile v0.3.2.tar.gz https://github.com/bab2min/EigenRand/archive/v0.3.2.tar.gz
tar -zxvf v0.3.2.tar.gz
mv EigenRand-0.3.2/EigenRand include/
Invoke-WebRequest -OutFile v1.1.3.tar.gz https://github.com/mapbox/variant/archive/v1.1.3.tar.gz
tar -zxvf v1.1.3.tar.gz
mv variant-1.1.3/include/mapbox include/
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
rm -rf eigen-git-mirror/
git clone https://github.com/bab2min/EigenRand
cd EigenRand
git checkout tags/v0.2.2
git checkout tags/v0.3.2
cd ..
mv EigenRand/EigenRand include/
git clone https://github.com/mapbox/variant
Expand Down Expand Up @@ -70,9 +70,9 @@ jobs:
wget https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz
tar -zxvf 3.3.7.tar.gz
mv eigen-git-mirror-3.3.7 include
wget https://github.com/bab2min/EigenRand/archive/v0.2.2.tar.gz
tar -zxvf v0.2.2.tar.gz
mv EigenRand-0.2.2/EigenRand include/
wget https://github.com/bab2min/EigenRand/archive/v0.3.2.tar.gz
tar -zxvf v0.3.2.tar.gz
mv EigenRand-0.3.2/EigenRand include/
wget https://github.com/mapbox/variant/archive/v1.1.3.tar.gz
tar -zxvf v1.1.3.tar.gz
mv variant-1.1.3/include/mapbox include/
Expand Down Expand Up @@ -109,9 +109,9 @@ jobs:
Invoke-WebRequest -OutFile 3.3.7.tar.gz https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz
tar -zxvf 3.3.7.tar.gz
mv eigen-git-mirror-3.3.7 include
Invoke-WebRequest -OutFile v0.2.2.tar.gz https://github.com/bab2min/EigenRand/archive/v0.2.2.tar.gz
tar -zxvf v0.2.2.tar.gz
mv EigenRand-0.2.2/EigenRand include/
Invoke-WebRequest -OutFile v0.3.2.tar.gz https://github.com/bab2min/EigenRand/archive/v0.3.2.tar.gz
tar -zxvf v0.3.2.tar.gz
mv EigenRand-0.3.2/EigenRand include/
Invoke-WebRequest -OutFile v1.1.3.tar.gz https://github.com/mapbox/variant/archive/v1.1.3.tar.gz
tar -zxvf v1.1.3.tar.gz
mv variant-1.1.3/include/mapbox include/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
mv eigen-git-mirror-3.3.7 include
git clone https://github.com/bab2min/EigenRand
cd EigenRand
git checkout tags/v0.2.2
git checkout tags/v0.3.2
cd ..
mv EigenRand/EigenRand include/
git clone https://github.com/mapbox/variant
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/pull_request_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
mv eigen-git-mirror include
git clone https://github.com/bab2min/EigenRand
cd EigenRand
git checkout tags/v0.2.2
git checkout tags/v0.3.2
cd ..
mv EigenRand/EigenRand include/
git clone https://github.com/mapbox/variant
Expand Down Expand Up @@ -68,9 +68,9 @@ jobs:
wget https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz
tar -zxvf 3.3.7.tar.gz
mv eigen-git-mirror-3.3.7 include
wget https://github.com/bab2min/EigenRand/archive/v0.2.2.tar.gz
tar -zxvf v0.2.2.tar.gz
mv EigenRand-0.2.2/EigenRand include/
wget https://github.com/bab2min/EigenRand/archive/v0.3.2.tar.gz
tar -zxvf v0.3.2.tar.gz
mv EigenRand-0.3.2/EigenRand include/
wget https://github.com/mapbox/variant/archive/v1.1.3.tar.gz
tar -zxvf v1.1.3.tar.gz
mv variant-1.1.3/include/mapbox include/
Expand Down Expand Up @@ -107,9 +107,9 @@ jobs:
Invoke-WebRequest -OutFile 3.3.7.tar.gz https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz
tar -zxvf 3.3.7.tar.gz
mv eigen-git-mirror-3.3.7 include
Invoke-WebRequest -OutFile v0.2.2.tar.gz https://github.com/bab2min/EigenRand/archive/v0.2.2.tar.gz
tar -zxvf v0.2.2.tar.gz
mv EigenRand-0.2.2/EigenRand include/
Invoke-WebRequest -OutFile v0.3.2.tar.gz https://github.com/bab2min/EigenRand/archive/v0.3.2.tar.gz
tar -zxvf v0.3.2.tar.gz
mv EigenRand-0.3.2/EigenRand include/
Invoke-WebRequest -OutFile v1.1.3.tar.gz https://github.com/mapbox/variant/archive/v1.1.3.tar.gz
tar -zxvf v1.1.3.tar.gz
mv variant-1.1.3/include/mapbox include/
Expand Down
4 changes: 2 additions & 2 deletions src/TopicModel/CTModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ namespace tomoto
Eigen::Map<Eigen::Array<Float, -1, 1>> m{ ret.data(), this->K };
if (normalize)
{
m = doc.numByTopic.array().template cast<Float>() / doc.getSumWordWeight();
m = (doc.numByTopic.array().template cast<Float>() + this->alphas.array()) / (doc.getSumWordWeight() + this->alphas.sum());
}
else
{
m = doc.numByTopic.array().template cast<Float>();
m = doc.numByTopic.array().template cast<Float>() + this->alphas.array();
}
return ret;
}
Expand Down
4 changes: 4 additions & 0 deletions src/TopicModel/GDMRModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ namespace tomoto
{
BaseClass::BaseClass::initGlobalState(initDocs);
fCont = accumulate(degreeByF.begin(), degreeByF.end(), 1, [](size_t a, size_t b) {return a * (b + 1); });
if (!this->metadataDict.size())
{
this->metadataDict.add("");
}
fCat = this->metadataDict.size();
this->F = fCont * fCat;
if (initDocs) collectMinMaxMetadata();
Expand Down
6 changes: 4 additions & 2 deletions src/TopicModel/LDAModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,12 +708,14 @@ namespace tomoto

struct Generator
{
std::uniform_int_distribution<Tid> theta;
Eigen::Rand::DiscreteGen<int32_t> theta;
};

Generator makeGeneratorForInit(const _DocType*) const
{
return Generator{ std::uniform_int_distribution<Tid>{0, (Tid)(K - 1)} };
Generator g;
g.theta = Eigen::Rand::DiscreteGen<int32_t>{ alphas.data(), alphas.data() + alphas.size() };
return g;
}

template<bool _Infer>
Expand Down
11 changes: 7 additions & 4 deletions src/TopicModel/LLDAModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ namespace tomoto

struct Generator
{
std::discrete_distribution<> theta;
Eigen::Array<Float, -1, 1> p;
Eigen::Rand::DiscreteGen<int32_t> theta;
};

Generator makeGeneratorForInit(const _DocType* doc) const
{
std::discrete_distribution<> theta{ doc->labelMask.data(), doc->labelMask.data() + this->K };
return Generator{ theta };
Generator g;
g.p = doc->labelMask.array().template cast<Float>() * this->alphas.array();
g.theta = Eigen::Rand::DiscreteGen<int32_t>{ g.p.data(), g.p.data() + this->K };
return g;
}

template<bool _Infer>
Expand All @@ -88,7 +91,7 @@ namespace tomoto
if (this->etaByTopicWord.size())
{
Eigen::Array<Float, -1, 1> col = this->etaByTopicWord.col(w);
for (size_t k = 0; k < col.size(); ++k) col[k] *= g.theta.probabilities()[k];
col *= g.p;
z = sample::sampleFromDiscrete(col.data(), col.data() + col.size(), rgs);
}
else
Expand Down
12 changes: 7 additions & 5 deletions src/TopicModel/PLDAModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ namespace tomoto

struct Generator
{
std::discrete_distribution<> theta;
Eigen::Array<Float, -1, 1> p;
Eigen::Rand::DiscreteGen<int32_t> theta;
};

Generator makeGeneratorForInit(const _DocType* doc) const
{
return Generator{
std::discrete_distribution<>{ doc->labelMask.data(), doc->labelMask.data() + doc->labelMask.size() }
};
Generator g;
g.p = doc->labelMask.array().template cast<Float>() * this->alphas.array();
g.theta = Eigen::Rand::DiscreteGen<int32_t>{ g.p.data(), g.p.data() + this->K };
return g;
}

template<bool _Infer>
Expand All @@ -93,7 +95,7 @@ namespace tomoto
if (this->etaByTopicWord.size())
{
Eigen::Array<Float, -1, 1> col = this->etaByTopicWord.col(w);
for (size_t k = 0; k < col.size(); ++k) col[k] *= g.theta.probabilities()[k];
col *= g.p;
z = sample::sampleFromDiscrete(col.data(), col.data() + col.size(), rgs);
}
else
Expand Down
10 changes: 5 additions & 5 deletions src/TopicModel/PTModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ namespace tomoto
struct Generator
{
std::uniform_int_distribution<uint64_t> psi;
std::uniform_int_distribution<Tid> theta;
Eigen::Rand::DiscreteGen<int32_t> theta;
};

Generator makeGeneratorForInit(const _DocType*) const
{
return Generator{
std::uniform_int_distribution<uint64_t>{0, numPDocs - 1},
std::uniform_int_distribution<Tid>{0, (Tid)(this->K - 1)}
};
Generator g;
g.psi = std::uniform_int_distribution<uint64_t>{ 0, numPDocs - 1 };
g.theta = Eigen::Rand::DiscreteGen<int32_t>{ this->alphas.data(), this->alphas.data() + this->alphas.size() };
return g;
}

template<bool _Infer>
Expand Down
Loading

0 comments on commit 7753b26

Please sign in to comment.