35 #ifndef OPENMS_ANALYSIS_ID_MESSAGEPASSERFACTORY_HPP 36 #define OPENMS_ANALYSIS_ID_MESSAGEPASSERFACTORY_HPP 39 #include <Evergreen/evergreen.hpp> 40 #include <Utility/inference_utilities.hpp> 42 typedef unsigned long int uiint;
44 template <
typename Label>
53 return pow(2., log2(1. -
beta) + summ * log2(1. -
alpha));
80 const std::vector<std::vector<Label>> & parentsOfPeps,
81 const std::vector<double> & pepEvidences,
82 InferenceGraphBuilder<Label> & igb);
98 assert(0. < alpha_ && alpha_ < 1.);
99 assert(0. < beta_ && beta_ < 1.);
100 assert(0. < gamma_ && gamma_ < 1.);
103 assert(0. < pep_prior_ && pep_prior_ < 1.);
108 pepPrior = pep_prior_;
111 template <
typename L>
113 double prior = gamma;
114 if (nrMissingPeps > 0)
116 double powFactor = std::pow(1.0 - alpha, -nrMissingPeps);
117 prior = -prior/(prior * powFactor - prior - powFactor);
119 double table[] = {1.0 - prior, prior};
120 LabeledPMF<L> lpmf({
id}, PMF({0L}, Tensor<double>::from_array(table)));
121 return TableDependency<L>(lpmf,p);
124 template <
typename L>
126 if (nrMissingPeps > 0)
128 double powFactor = std::pow(1.0 - alpha, -nrMissingPeps);
129 prior = -prior/(prior * powFactor - prior - powFactor);
131 double table[] = {1.0 - prior, prior};
132 LabeledPMF<L> lpmf({
id}, PMF({0L}, Tensor<double>::from_array(table)));
133 return TableDependency<L>(lpmf,p);
136 template <
typename L>
138 double table[] = {(1 - prob) * (1 - pepPrior), prob * pepPrior};
139 LabeledPMF<L> lpmf({
id}, PMF({0L}, Tensor<double>::from_array(table)));
140 return TableDependency<L>(lpmf,p);
144 template <
typename L>
146 Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
147 for (
unsigned long i=0; i <= nrParents; ++i) {
148 double notConditional = notConditionalGivenSum(i);
149 unsigned long indexArr[2] = {i,0ul};
150 table[indexArr] = notConditional;
151 unsigned long indexArr2[2] = {i,1ul};
152 table[indexArr2] = 1.0 - notConditional;
155 LabeledPMF<L> lpmf({nId, pepId}, PMF({0L,0L}, table));
157 return TableDependency<L>(lpmf,p);
160 template <
typename L>
162 Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
163 unsigned long z[2]{0ul,0ul};
164 unsigned long z1[2]{0ul,1ul};
165 table[z] = 1. - beta;
167 for (
unsigned long i=1; i <= nrParents; ++i) {
168 double notConditional = notConditionalGivenSum(i);
169 unsigned long indexArr[2] = {i,0ul};
170 table[indexArr] = notConditional / i;
171 unsigned long indexArr2[2] = {i,1ul};
172 table[indexArr2] = (1.0 - notConditional) / i;
175 LabeledPMF<L> lpmf({nId, pepId}, PMF({0L,0L}, table));
177 return TableDependency<L>(lpmf,p);
180 template <
typename L>
182 Tensor<double> table({nrParents+1});
183 for (
unsigned long i=0; i <= nrParents; ++i) {
184 table[i] = 1.0/(nrParents+1);
187 LabeledPMF<L> lpmf({nId}, PMF({0L}, table));
189 return TableDependency<L>(lpmf,p);
192 template <
typename L>
194 std::vector<std::vector<L>> parents;
195 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const L& l){
return std::vector<L>{l};});
196 return AdditiveDependency<L>(parents, {nId}, p);
199 template <
typename L>
201 std::vector<std::vector<L>> parents;
202 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const L& l){
return std::vector<L>{l};});
203 return AdditiveDependency<L>(parents, {nId}, p);
206 template <
typename L>
208 std::vector<std::vector<L>> parents;
209 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const L& l){
return std::vector<L>{l};});
210 return PseudoAdditiveDependency<L>(parents, {nId}, deps, p);
215 template <
typename L>
217 const std::vector<std::vector<L>> & parentsOfPeps,
218 const std::vector<double> & pepEvidences,
219 InferenceGraphBuilder<L> & igb)
222 assert(parentsOfPeps.size() == pepEvidences.size());
223 for (std::vector<uiint> parents : parentsOfPeps)
224 for (L parent : parents)
225 assert(
std::find(protIDs.begin(), protIDs.end(), parent) != protIDs.end());
227 for (
uiint pid : protIDs)
228 igb.insert_dependency(createProteinFactor(pid));
230 for (
uiint j = 0; j < parentsOfPeps.size(); j++)
232 igb.insert_dependency(createPeptideEvidenceFactor(j,pepEvidences[j]));
233 igb.insert_dependency(createSumEvidenceFactor(parentsOfPeps[j],j,j));
234 igb.insert_dependency(createPeptideProbabilisticAdderFactor(parentsOfPeps[j],j));
302 #endif //OPENMS_ANALYSIS_ID_MESSAGEPASSERFACTORY_HPP unsigned long int uiint
Definition: MessagePasserFactory.h:42
TableDependency< Label > createRegularizingSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:161
double notConditionalGivenSum(unsigned long summ)
Definition: MessagePasserFactory.h:51
TableDependency< Label > createSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:145
double p
Definition: MessagePasserFactory.h:48
TableDependency< Label > createSumFactor(size_t nrParents, Label nId)
Definition: MessagePasserFactory.h:181
double pepPrior
Definition: MessagePasserFactory.h:48
void fillVectorsOfMessagePassers(const std::vector< Label > &protIDs, const std::vector< std::vector< Label >> &parentsOfPeps, const std::vector< double > &pepEvidences, InferenceGraphBuilder< Label > &igb)
Works on a vector of protein indices (potentially not consecutive)
Definition: MessagePasserFactory.h:216
double gamma
Definition: MessagePasserFactory.h:48
Definition: MessagePasserFactory.h:45
Label offset
Definition: MessagePasserFactory.h:49
PseudoAdditiveDependency< Label > createBFPeptideProbabilisticAdderFactor(const std::set< Label > &parentProteinIDs, Label nId, const std::vector< TableDependency< Label > > &deps)
Definition: MessagePasserFactory.h:207
double beta
Definition: MessagePasserFactory.h:48
const int minInputsPAF
Definition: MessagePasserFactory.h:47
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
double alpha
Definition: MessagePasserFactory.h:48
TableDependency< Label > createProteinFactor(Label id, int nrMissingPeps=0)
AdditiveDependency< Label > createPeptideProbabilisticAdderFactor(const std::set< Label > &parentProteinIDs, Label nId)
TableDependency< Label > createPeptideEvidenceFactor(Label id, double prob)
Definition: MessagePasserFactory.h:137
MessagePasserFactory(double alpha, double beta, double gamma, double p, double pepPrior)
Definition: MessagePasserFactory.h:97