5 #include "../Model/RateDistribution/ConstantRateDistribution.h"
6 #include "../Model/RateDistribution/ExponentialDiscreteRateDistribution.h"
7 #include "../Model/RateDistribution/GammaDiscreteRateDistribution.h"
8 #include "../Model/RateDistribution/GaussianDiscreteRateDistribution.h"
27 const std::string& distDescription,
30 unparsedArguments_.clear();
32 map<string, string> args;
34 unique_ptr<DiscreteDistributionInterface> rDist;
36 if (distName ==
"Uniform")
37 throw Exception(
"BppO Warning: Uniform distribution is deprecated, use Constant instead.");
39 if ((distName ==
"InvariantMixed") || (distName ==
"Invariant"))
42 string nestedDistDescription = args[
"dist"];
44 throw Exception(
"BppORateDistributionFormat::read. Missing argument 'dist' for distribution 'Invariant'.");
52 rDist = make_unique<InvariantMixedDiscreteDistribution>(std::move(nestedDistribution), 0.1, 0.000001);
55 for (
auto it : unparsedArgumentsNested)
57 unparsedArguments_[
"Invariant." + it.first] = it.second;
60 if (args.find(
"p") != args.end())
61 unparsedArguments_[
"Invariant.p"] = args[
"p"];
63 else if (distName ==
"Constant")
66 throw Exception(
"BppORateDistributionFormat::read(). Constant distribution not allowed.");
68 if (args.find(
"value") != args.end())
70 rDist = make_unique<ConstantRateDistribution>();
72 else if (distName ==
"Simple")
74 if (args.find(
"values") == args.end())
75 throw Exception(
"Missing argument 'values' in Simple distribution");
76 if (args.find(
"probas") == args.end())
77 throw Exception(
"Missing argument 'probas' in Simple distribution");
78 vector<double> probas, values;
80 string rf = args[
"values"];
90 std::map<size_t, std::vector<double>> ranges;
92 if (args.find(
"ranges") != args.end())
94 string rr = args[
"ranges"];
104 ppv = desc.find(
";");
115 if (ranges.size() == 0)
116 rDist = make_unique<SimpleDiscreteDistribution>(values, probas);
118 rDist = make_unique<SimpleDiscreteDistribution>(values, ranges, probas);
120 vector<string> v = rDist->getParameters().getParameterNames();
122 for (
size_t i = 0; i < v.size(); ++i)
124 unparsedArguments_[v[i]] =
TextTools::toString(rDist->getParameterValue(rDist->getParameterNameWithoutNamespace(v[i])));
127 else if (distName ==
"Mixture")
129 if (args.find(
"probas") == args.end())
130 throw Exception(
"Missing argument 'probas' in Mixture distribution");
131 vector<double> probas;
132 vector<unique_ptr<DiscreteDistributionInterface>> v_pdd;
133 string rf = args[
"probas"];
138 vector<string> v_nestedDistrDescr;
144 if (v_nestedDistrDescr.size() != probas.size())
145 throw Exception(
"Number of distributions (keyword 'dist" +
TextTools::toString(probas.size()) +
"') do not fit the number of probabilities");
147 for (
unsigned i = 0; i < v_nestedDistrDescr.size(); i++)
153 for (
auto& it : unparsedArgumentsNested)
155 unparsedArguments_[distName +
"." +
TextTools::toString(i + 1) +
"_" + it.first] = it.second;
157 v_pdd.push_back(std::move(pdd));
159 rDist = make_unique<MixtureOfDiscreteDistributions>(v_pdd, probas);
163 if (args.find(
"n") == args.end())
164 throw Exception(
"Missing argument 'n' (number of classes) in " + distName
166 size_t nbClasses = TextTools::to<size_t>(args[
"n"]);
168 if (distName ==
"Gamma")
170 rDist = make_unique<GammaDiscreteRateDistribution>(nbClasses, 1.);
172 if (args.find(
"alpha") != args.end())
173 unparsedArguments_[
"Gamma.alpha"] = args[
"alpha"];
174 if (args.find(
"beta") != args.end())
175 throw Exception(
"Found argument 'beta' in Gamma distribution. Gamma distribution is defined to have an average of 1, with beta=alpha.");
177 else if (distName ==
"Gaussian")
179 rDist = make_unique<GaussianDiscreteRateDistribution>(nbClasses, 1);
180 if (args.find(
"mu") != args.end())
181 throw Exception(
"Found argument 'mu' in Gaussian distribution. Gaussian distribution is defined to have an average of 1, with mu=1.");
182 if (args.find(
"sigma") != args.end())
183 unparsedArguments_[
"Gaussian.sigma"] = args[
"sigma"];
185 else if (distName ==
"Exponential")
187 rDist = make_unique<ExponentialDiscreteRateDistribution>(nbClasses);
188 if (args.find(
"lambda") != args.end())
189 throw Exception(
"Found argument 'lambda' in Exponential distribution. Exponential distribution is defined to have an average of 1, with lambda=1.");
193 throw Exception(
"Unsupported rate distribution: " + distName +
".");
212 std::map<std::string, std::string>& globalAliases,
213 std::vector<std::string>& writtenNames)
const
225 writeDiscreteDistribution(pd, out, globalAliases, writtenNames);
234 for (
size_t i = 0; i < nd; ++i)
239 writeDiscreteDistribution(mix.nDistribution(i), out, globalAliases, writtenNames);
243 for (
size_t i = 0; i < nd; ++i)
245 out << mix.getNProbability(i);
250 for (
size_t i = 1; i < nd; ++i)
275 for (
size_t i = 0; i < nd; ++i)
277 out << ps.getCategory(i);
282 for (
size_t i = 0; i < nd; ++i)
284 out << ps.getProbability(i);
290 auto range = ps.getRanges();
291 if (range.size() != 0)
294 auto it = range.begin();
295 while (it != range.end())
300 if (it != range.end())
307 for (
size_t i = 1; i < nd; ++i)
311 for (
size_t i = 1; i < nd + 1; ++i)
size_t getNumberOfCategories() const
virtual size_t getNumberOfCategories() const=0
virtual std::string getName() const=0
const DiscreteDistributionInterface & variableSubDistribution() const
size_t getNumberOfDistributions() const
virtual const ParameterList & getIndependentParameters() const=0
virtual std::vector< std::string > getParameterNames() const
const std::string & nextToken()
bool hasMoreToken() const
int toInt(const std::string &s, char scientificNotation='e')
double toDouble(const std::string &s, char dec='.', char scientificNotation='e')
bool isEmpty(const std::string &s)
std::string toString(T t)
Defines the basic types of data flow nodes.