43 #include <Bpp/Numeric/NumConstants.h> 44 #include <Bpp/Numeric/Prob/Simplex.h> 60 size_t s = stateMap_->getNumberOfModelStates();
61 vector<double> freq(s);
63 for (
size_t i = 0; i < s; ++i)
65 map<int, double>::const_iterator it = frequencies.find(stateMap_->getAlphabetStateAsInt(i));
66 if (it != frequencies.end())
72 for (
size_t i = 0; i < s; ++i)
81 map<int, double> fmap;
82 for (
size_t i = 0; i < stateMap_->getNumberOfModelStates(); ++i) {
83 fmap[stateMap_->getAlphabetStateAsInt(i)] += freq_[i];
93 sFreq_(stateMap->getNumberOfModelStates(), method, allowNullFreqs,
"Full.")
101 sFreq_.setFrequencies(vd);
102 addParameters_(
sFreq_.getParameters());
108 sFreq_(stateMap->getNumberOfModelStates(), method, allowNullFreqs,
"Full.")
110 sFreq_.setFrequencies(initFreqs);
111 addParameters_(
sFreq_.getParameters());
118 sFreq_.setFrequencies(frequencies);
119 setParametersValues(
sFreq_.getParameters());
126 sFreq_.setNamespace(nameSpace);
127 AbstractFrequenciesSet::setNamespace(nameSpace);
132 sFreq_.matchParametersValues(parameters);
138 for (
size_t i = 0; i <
getAlphabet()->getSize(); i++)
148 if (stateMap->getNumberOfModelStates() != initFreqs.size())
149 throw Exception(
"FixedFrequenciesSet::constructor. size of init vector does not match the number of states in the model.");
150 setFrequencies(initFreqs);
157 for (
size_t i = 0; i < n; ++i)
159 getFreq_(i) = 1. /
static_cast<double>(n);
166 throw DimensionException(
"FixedFrequenciesSet::setFrequencies", frequencies.size(),
getNumberOfFrequencies());
168 for (
size_t i = 0; i < frequencies.size(); i++)
170 sum += frequencies[i];
172 if (fabs(1. - sum) > 0.00001)
173 throw Exception(
"FixedFrequenciesSet::setFrequencies. Frequencies sum must equal 1 (sum = " + TextTools::toString(sum) +
").");
180 rateFreqs_(rateFreqs)
182 freqSet_->setNamespace(std::string(
"MarkovModulated.") +
freqSet_->getNamespace());
183 addParameters_(
freqSet_->getParameters());
MarkovModulatedFrequenciesSet(FrequenciesSet *freqSet, const std::vector< double > &rateFreqs)
FixedFrequenciesSet(StateMap *stateMap, const std::vector< double > &initFreqs, const std::string &name="Fixed")
Construction with user-defined frequencies on the states of the model.
virtual size_t getNumberOfModelStates() const =0
void setFrequencies_(const std::vector< double > &frequencies)
void setFrequencies(const std::vector< double > &frequencies)
Set the parameters in order to match a given set of frequencies.
virtual const std::vector< double > getFrequencies() const =0
static IntervalConstraint FREQUENCE_CONSTRAINT_MILLI
void setNamespace(const std::string &nameSpace)
FullFrequenciesSet(StateMap *stateMap, bool allowNullFreqs=false, unsigned short method=1, const std::string &name="Full.")
Construction with uniform frequencies on the states of the alphabet.
Parametrize a set of state frequencies.
const std::map< int, double > getAlphabetStatesFrequencies() const
static IntervalConstraint FREQUENCE_CONSTRAINT_SMALL
const Alphabet * getAlphabet() const
size_t getNumberOfFrequencies() const
double & getFreq_(size_t i)
Simplex sFreq_
Simplex to handle the probabilities and the parameters.
void setFrequencies(const std::vector< double > &frequencies)
Set the parameters in order to match a given set of frequencies.
void setFrequenciesFromAlphabetStatesFrequencies(const std::map< int, double > &frequencies)
Set the Frequencies from the one of the map which keys match with a letter of the Alphabet...
void fireParameterChanged(const ParameterList ¶meters)
This class implements a state map for Markov modulated models.
Map the states of a given alphabet which have a model state.
FrequenciesSet * freqSet_
Basic implementation of the FrequenciesSet interface.