42 #include <Bpp/Text/TextTools.h> 52 NumericAlphabet::NumericAlphabet(
const UniformDiscreteDistribution& pd) :
57 size_t size =
pdd_->getNumberOfCategories();
59 Vdouble vd =
pdd_->getCategories();
61 for (
size_t i = 0; i < size; ++i){
68 pdd_(na.pdd_->clone()),
86 if (values_.find(x) == values_.end())
87 values_[x] = stateIndex;
88 }
catch(std::bad_cast&) {
89 throw Exception(
"NumericAlphabet::setState. Incorrect alphabet type.");
98 if (values_.find(x) == values_.end())
99 values_[x] = getSize();
100 }
catch(std::bad_cast&) {
101 throw Exception(
"NumericAlphabet::registerState. Incorrect alphabet type.");
144 return static_cast<unsigned int>(
values_.size());
149 return static_cast<unsigned int>(
values_.size());
156 for (
size_t pos = 0 ; pos <
getSize() ; pos++) {
167 return (
pdd_->getUpperBound() -
pdd_->getLowerBound()) / static_cast<double>(
pdd_->getNumberOfCategories());
177 map<double, size_t>::const_iterator it =
values_.find(
pdd_->getValueCategory(value));
This is the base class to describe states in an Alphabet.
bool isUnresolved(int state) const
An alphabet exception thrown when trying to specify a bad char to the alphabet.
unsigned int getNumberOfTypes() const
Get the number of distinct states in alphabet (e.g. return 15 for DNA alphabet). This is the number o...
bool isGap(int state) const
This alphabet is used to deal NumericAlphabet.
unsigned int getSize() const
Get the number of resolved states in the alphabet (e.g. return 4 for DNA alphabet). This is the method you'll need in most cases.
double intToValue(int state) const
Returns the value for the character number.
std::map< double, size_t > values_
double getDelta() const
Returns the difference between successive values.
const UniformDiscreteDistribution * pdd_
bool containsGap(const std::string &state) const
AbstractAlphabet & operator=(const AbstractAlphabet &alph)
void remap()
Re-update the maps.
NumericAlphabet & operator=(const NumericAlphabet &)
NumericAlphabet(const UniformDiscreteDistribution &)
virtual void setState(size_t pos, AlphabetState *st)
Set a state in the Alphabet.
void setState(size_t pos, AlphabetState *st)
Set a state in the Alphabet.
void registerState(AlphabetState *st)
Add a state to the Alphabet.
A partial implementation of the Alphabet interface.
void remap()
Re-update the maps using the alphabet_ vector content.
AlphabetNumericState & getStateAt(size_t stateIndex)
Get a state at a position in the alphabet_ vector.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
States that do have a double value.
virtual AlphabetState & getStateAt(size_t stateIndex)
Get a state at a position in the alphabet_ vector.
virtual void registerState(AlphabetState *st)
Add a state to the Alphabet.
size_t getValueIndex(double value) const
Returns the CategoryIndex of the category to which the value belongs.
std::vector< int > getAlias(int state) const
Get all resolved states that match a generic state.
double getValue() const
Get the state value.