11 #include "../SubstitutionModel.h"
12 #include "../AbstractBiblioSubstitutionModel.h"
30 size_t s = stateMap_->getNumberOfModelStates();
31 vector<double> freq(s);
33 for (
size_t i = 0; i < s; ++i)
35 map<int, double>::const_iterator it = frequencies.find(stateMap_->getAlphabetStateAsInt(i));
36 if (it != frequencies.end())
44 for (
size_t i = 0; i < s; ++i)
49 for (
size_t i = 0; i < s; ++i)
51 freq[i] = 1.0 / (double)s;
59 map<int, double> fmap;
60 for (
size_t i = 0; i < stateMap_->getNumberOfModelStates(); ++i)
62 fmap[stateMap_->getAlphabetStateAsInt(i)] += freq_[i];
71 std::shared_ptr<const StateMapInterface> stateMap,
73 unsigned short method,
79 sFreq_(stateMap->getNumberOfModelStates(), method, allowNullFreqs,
"Full.")
95 std::shared_ptr<const StateMapInterface> stateMap,
96 const vector<double>& initFreqs,
98 unsigned short method,
104 sFreq_(stateMap->getNumberOfModelStates(), method, allowNullFreqs,
"Full.")
133 for (
size_t i = 0; i <
getAlphabet()->getSize(); i++)
143 std::shared_ptr<const StateMapInterface> stateMap,
144 const vector<double>& initFreqs,
145 const string& name) :
152 throw Exception(
"FixedFrequencySet::constructor. size of init vector does not match the number of states in the model.");
157 std::shared_ptr<const StateMapInterface> stateMap,
158 const string& name) :
173 for (
size_t i = 0; i < frequencies.size(); i++)
175 sum += frequencies[i];
177 if (fabs(1. - sum) > 0.00001)
183 unique_ptr<FrequencySetInterface> freqSet,
184 const std::vector<double>& rateFreqs) :
188 "MarkovModulated." + freqSet->getName()),
189 freqSet_(std::move(freqSet)),
190 rateFreqs_(rateFreqs)
192 freqSet_->setNamespace(std::string(
"MarkovModulated.") +
freqSet_->getNamespace());
203 model_(fmfs.model_->clone())
216 std::shared_ptr<TransitionModelInterface> model) :
217 AbstractFrequencySet(model->getStateMap(),
"FromModel." + (model ? model->getNamespace() :
""),
"FromModel"),
229 model_->setNamespace(name);
235 std::map<int, double> freq;
246 model_->matchParametersValues(pl);
255 std::shared_ptr<const StateMapInterface> stateMap,
256 const std::string& path,
285 throw Exception(
"UserFrequencySet::readFromFile. Frequencies file not found : " +
path_);
287 ifstream in(
path_.c_str(), ios::in);
291 for (
unsigned int i = 0; i <
getAlphabet()->getSize(); i++)
294 throw Exception(
"UserFrequencySet::readFromFile. Missing frequencies in file : " +
path_);
299 for (
unsigned int j = 0; j <
nCol_; j++)
309 if (fabs(sf - 1) > 0.000001)
324 for (
size_t i = 0; i < frequencies.size(); i++)
326 sum += frequencies[i];
328 if (fabs(1. - sum) > 0.00001)
Basic implementation of the FrequencySet interface.
void setFrequencies_(const std::vector< double > &frequencies)
const std::map< int, double > getAlphabetStatesFrequencies() const override
std::shared_ptr< const Alphabet > getAlphabet() const override
void setFrequenciesFromAlphabetStatesFrequencies(const std::map< int, double > &frequencies) override
Set the Frequencies from the one of the map which keys match with a letter of the Alphabet....
size_t getNumberOfFrequencies() const override
double & getFreq_(size_t i)
std::vector< double > & getFrequencies_()
AbstractFrequencySet & operator=(const AbstractFrequencySet &af)
const StateMapInterface & stateMap() const override
void addParameters_(const ParameterList ¶meters)
void setNamespace(const std::string &prefix)
void setParametersValues(const ParameterList ¶meters) override
bool matchParametersValues(const ParameterList ¶meters) override
std::string getNamespace() const override
const ParameterList & getParameters() const override
void setFrequencies(const std::vector< double > &frequencies) override
Set the parameters in order to match a given set of frequencies.
FixedFrequencySet(std::shared_ptr< const StateMapInterface > stateMap, const std::vector< double > &initFreqs, const std::string &name="Fixed")
Construction with user-defined frequencies on the states of the model.
static std::shared_ptr< IntervalConstraint > FREQUENCE_CONSTRAINT_SMALL
static std::shared_ptr< IntervalConstraint > FREQUENCE_CONSTRAINT_MILLI
static std::shared_ptr< IntervalConstraint > FREQUENCE_CONSTRAINT_CENTI
FrequencySet defined from the equilibrium distribution of a given model.
void fireParameterChanged(const ParameterList &pl) override
virtual ~FromModelFrequencySet()
FromModelFrequencySet & operator=(const FromModelFrequencySet &fmfs)
void setFrequencies(const std::vector< double > &frequencies) override
Set the parameters in order to match a given set of frequencies.
void setNamespace(const std::string &name) override
std::shared_ptr< TransitionModelInterface > model_
FromModelFrequencySet(std::shared_ptr< TransitionModelInterface > model)
void fireParameterChanged(const ParameterList ¶meters) override
Simplex sFreq_
Simplex to handle the probabilities and the parameters.
FullFrequencySet(std::shared_ptr< const StateMapInterface > stateMap, bool allowNullFreqs=false, unsigned short method=1, const std::string &name="Full")
Construction with uniform frequencies on the states of the alphabet.
void setNamespace(const std::string &nameSpace) override
void setFrequencies(const std::vector< double > &frequencies) override
Set the parameters in order to match a given set of frequencies.
MarkovModulatedFrequencySet(std::unique_ptr< FrequencySetInterface > freqSet, const std::vector< double > &rateFreqs)
std::unique_ptr< FrequencySetInterface > freqSet_
This class implements a state map for Markov modulated models.
double prob(size_t i) const
void setFrequencies(const std::vector< double > &)
virtual size_t getNumberOfModelStates() const =0
virtual int getAlphabetStateAsInt(size_t index) const =0
const std::string & nextToken()
bool hasMoreToken() const
FrequencySet to be read in a file. More specifically, a frequency set is read in a column of a given ...
void setFrequencies(const std::vector< double > &frequencies) override
Set the parameters in order to match a given set of frequencies.
UserFrequencySet & operator=(const UserFrequencySet &fmfs)
UserFrequencySet(std::shared_ptr< const StateMapInterface > stateMap, const std::string &path, size_t nCol=1)
User.
double toDouble(const std::string &s, char dec='.', char scientificNotation='e')
std::string toString(T t)
Defines the basic types of data flow nodes.