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));
79 const std::vector<std::vector<Label>> & parentsOfPeps,
80 const std::vector<double> & pepEvidences,
81 InferenceGraphBuilder<Label> & igb);
97 assert(0 < alpha_ && alpha_ < 1);
98 assert(0 < beta_ && beta_ < 1);
99 assert(0 < gamma_ && gamma_ < 1);
108 template <
typename L>
110 double prior = gamma;
111 if (nrMissingPeps > 0)
113 double powFactor = std::pow(1.0 - alpha, -nrMissingPeps);
114 prior = -prior/(prior * powFactor - prior - powFactor);
116 double table[] = {1.0 - prior, prior};
117 LabeledPMF<L> lpmf({
id}, PMF({0L}, Tensor<double>::from_array(table)));
118 return TableDependency<L>(lpmf,p);
121 template <
typename L>
123 if (nrMissingPeps > 0)
125 double powFactor = std::pow(1.0 - alpha, -nrMissingPeps);
126 prior = -prior/(prior * powFactor - prior - powFactor);
128 double table[] = {1.0 - prior, prior};
129 LabeledPMF<L> lpmf({
id}, PMF({0L}, Tensor<double>::from_array(table)));
130 return TableDependency<L>(lpmf,p);
133 template <
typename L>
135 double table[] = {1 - prob, prob};
136 LabeledPMF<L> lpmf({
id}, PMF({0L}, Tensor<double>::from_array(table)));
137 return TableDependency<L>(lpmf,p);
141 template <
typename L>
143 Tensor<double> table({nrParents + 1 , 2});
144 for (
unsigned long i=0; i <= nrParents; ++i) {
145 double notConditional = notConditionalGivenSum(i);
146 u_long indexArr[] = {i,0};
147 table[indexArr] = notConditional;
148 u_long indexArr2[] = {i,1};
149 table[indexArr2] = 1.0 - notConditional;
152 LabeledPMF<L> lpmf({nId, pepId}, PMF({0L,0L}, table));
154 return TableDependency<L>(lpmf,p);
157 template <
typename L>
159 Tensor<double> table({nrParents+1});
160 for (
unsigned long i=0; i <= nrParents; ++i) {
161 table[i] = 1.0/(nrParents+1);
164 LabeledPMF<L> lpmf({nId}, PMF({0L}, table));
166 return TableDependency<L>(lpmf,p);
169 template <
typename L>
171 std::vector<std::vector<L>> parents;
172 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const L& l){
return std::vector<L>{l};});
173 return AdditiveDependency<L>(parents, {nId}, p);
176 template <
typename L>
178 std::vector<std::vector<L>> parents;
179 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const L& l){
return std::vector<L>{l};});
180 return AdditiveDependency<L>(parents, {nId}, p);
183 template <
typename L>
185 std::vector<std::vector<L>> parents;
186 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const L& l){
return std::vector<L>{l};});
187 return PseudoAdditiveDependency<L>(parents, {nId}, deps, p);
192 template <
typename L>
194 const std::vector<std::vector<L>> & parentsOfPeps,
195 const std::vector<double> & pepEvidences,
196 InferenceGraphBuilder<L> & igb)
199 assert(parentsOfPeps.size() == pepEvidences.size());
200 for (std::vector<uiint> parents : parentsOfPeps)
201 for (L parent : parents)
202 assert(
std::find(protIDs.begin(), protIDs.end(), parent) != protIDs.end());
204 for (
uiint pid : protIDs)
205 igb.insert_dependency(createProteinFactor(pid));
207 for (
uiint j = 0; j < parentsOfPeps.size(); j++)
209 igb.insert_dependency(createPeptideEvidenceFactor(j,pepEvidences[j]));
210 igb.insert_dependency(createSumEvidenceFactor(parentsOfPeps[j],j,j));
211 igb.insert_dependency(createPeptideProbabilisticAdderFactor(parentsOfPeps[j],j));
279 #endif //OPENMS_ANALYSIS_ID_MESSAGEPASSERFACTORY_HPP double gamma
Definition: MessagePasserFactory.h:48
Label offset
Definition: MessagePasserFactory.h:49
unsigned long int uiint
Definition: MessagePasserFactory.h:42
AdditiveDependency< Label > createPeptideProbabilisticAdderFactor(const std::set< Label > &parentProteinIDs, Label nId)
TableDependency< Label > createPeptideEvidenceFactor(Label id, double prob)
Definition: MessagePasserFactory.h:134
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
Definition: MessagePasserFactory.h:45
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:193
double p
Definition: MessagePasserFactory.h:48
TableDependency< Label > createSumFactor(size_t nrParents, Label nId)
Definition: MessagePasserFactory.h:158
double alpha
Definition: MessagePasserFactory.h:48
double beta
Definition: MessagePasserFactory.h:48
const int minInputsPAF
Definition: MessagePasserFactory.h:47
double notConditionalGivenSum(unsigned long summ)
Definition: MessagePasserFactory.h:51
TableDependency< Label > createProteinFactor(Label id, int nrMissingPeps=0)
MessagePasserFactory(double alpha, double beta, double gamma, double p)
Definition: MessagePasserFactory.h:96
TableDependency< Label > createSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:142
PseudoAdditiveDependency< Label > createBFPeptideProbabilisticAdderFactor(const std::set< Label > &parentProteinIDs, Label nId, const std::vector< TableDependency< Label > > &deps)
Definition: MessagePasserFactory.h:184