Skip to content

Commit

Permalink
Merge pull request #65 from topsframework/refactoring/infinity_alias
Browse files Browse the repository at this point in the history
Close #53 (Infinity alias)
  • Loading branch information
igorbonadio committed May 14, 2016
2 parents 98180a8 + 1dd04c6 commit bc93d54
Show file tree
Hide file tree
Showing 53 changed files with 425 additions and 424 deletions.
2 changes: 1 addition & 1 deletion include/model/CachedCalculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CachedCalculator : public SimpleCalculator<Model> {
}

// Overriden methods
Probability
LogProbability
calculate(const Calculator::direction& chosen_direction) const override {
lazyInitializeCache();
CALL_MEMBER_FUNCTION_DELEGATOR(calculate, chosen_direction);
Expand Down
10 changes: 5 additions & 5 deletions include/model/CachedEvaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class CachedEvaluator : public SimpleEvaluator<Decorator, Model> {
}

// Overriden methods
Probability evaluateSymbol(unsigned int pos,
unsigned int phase) const override {
LogProbability evaluateSymbol(unsigned int pos,
unsigned int phase) const override {
const_cast<Self*>(this)->lazyInitializeCache(phase);
CALL_MEMBER_FUNCTION_DELEGATOR(evaluateSymbol, pos, phase);
}

Probability evaluateSequence(unsigned int begin,
unsigned int end,
unsigned int phase) const override {
LogProbability evaluateSequence(unsigned int begin,
unsigned int end,
unsigned int phase) const override {
const_cast<Self*>(this)->lazyInitializeCache(phase);
CALL_MEMBER_FUNCTION_DELEGATOR(evaluateSequence, begin, end, phase);
}
Expand Down
2 changes: 1 addition & 1 deletion include/model/Calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Calculator : public std::enable_shared_from_this<Calculator> {
enum class direction { forward, backward };

// Purely virtual methods
virtual Probability calculate(const direction& direction) const = 0;
virtual LogProbability calculate(const direction& direction) const = 0;

virtual Sequence& sequence() = 0;
virtual const Sequence& sequence() const = 0;
Expand Down
34 changes: 17 additions & 17 deletions include/model/DecodableModelCrtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ class DecodableModelCrtp
virtual void initializeCache(CEPtr<Labeling> evaluator,
unsigned int phase) = 0;

virtual Probability evaluateSymbol(SEPtr<Labeling> evaluator,
unsigned int pos,
unsigned int phase) const = 0;
virtual Probability evaluateSequence(SEPtr<Labeling> evaluator,
unsigned int begin,
unsigned int end,
unsigned int phase) const = 0;

virtual Probability evaluateSymbol(CEPtr<Labeling> evaluator,
unsigned int pos,
unsigned int phase) const = 0;
virtual Probability evaluateSequence(CEPtr<Labeling> evaluator,
unsigned int begin,
unsigned int end,
unsigned int phase) const = 0;
virtual LogProbability evaluateSymbol(SEPtr<Labeling> evaluator,
unsigned int pos,
unsigned int phase) const = 0;
virtual LogProbability evaluateSequence(SEPtr<Labeling> evaluator,
unsigned int begin,
unsigned int end,
unsigned int phase) const = 0;

virtual LogProbability evaluateSymbol(CEPtr<Labeling> evaluator,
unsigned int pos,
unsigned int phase) const = 0;
virtual LogProbability evaluateSequence(CEPtr<Labeling> evaluator,
unsigned int begin,
unsigned int end,
unsigned int phase) const = 0;

virtual Labeling<Symbol> drawSymbol(SGPtr<Labeling> generator,
unsigned int pos,
Expand All @@ -160,10 +160,10 @@ class DecodableModelCrtp

virtual void initializeCache(CCPtr calculator) = 0;

virtual Probability
virtual LogProbability
calculate(SCPtr calculator, const Calculator::direction& direction) const = 0;

virtual Probability
virtual LogProbability
calculate(CCPtr calculator, const Calculator::direction& direction) const = 0;

virtual void posteriorProbabilities(const Sequence& xs,
Expand Down
8 changes: 4 additions & 4 deletions include/model/DecodableModelCrtp.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ DecodableModelCrtp<Derived>::labelingTrainer(Tag, Args&&... args) {

template<typename Derived>
EvaluatorPtr<Labeling> DecodableModelCrtp<Derived>::labelingEvaluator(
const Labeling<Sequence> &sequence, bool cached) {
const Labeling<Sequence>& sequence, bool cached) {
if (cached)
return CachedEvaluator<Labeling, Derived>::make(make_shared(), sequence);
return SimpleEvaluator<Labeling, Derived>::make(make_shared(), sequence);
Expand All @@ -95,7 +95,7 @@ GeneratorPtr<Labeling> DecodableModelCrtp<Derived>::labelingGenerator(

template<typename Derived>
LabelerPtr DecodableModelCrtp<Derived>::labeler(
const Standard<Sequence> &sequence, bool cached) {
const Standard<Sequence>& sequence, bool cached) {
if (cached)
return CachedLabeler<Derived>::make(make_shared(), sequence);
return SimpleLabeler<Derived>::make(make_shared(), sequence);
Expand All @@ -105,7 +105,7 @@ LabelerPtr DecodableModelCrtp<Derived>::labeler(

template<typename Derived>
CalculatorPtr DecodableModelCrtp<Derived>::calculator(
const Standard<Sequence> &sequence, bool cached) {
const Standard<Sequence>& sequence, bool cached) {
if (cached)
return CachedCalculator<Derived>::make(make_shared(), sequence);
return SimpleCalculator<Derived>::make(make_shared(), sequence);
Expand Down Expand Up @@ -156,7 +156,7 @@ auto DecodableModelCrtp<Derived>::states() const
template<typename Derived>
auto DecodableModelCrtp<Derived>::make_shared() -> DerivedPtr {
return std::static_pointer_cast<Derived>(
static_cast<Derived *>(this)->shared_from_this());
static_cast<Derived*>(this)->shared_from_this());
}

/*----------------------------------------------------------------------------*/
Expand Down
18 changes: 9 additions & 9 deletions include/model/DiscreteIIDModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DiscreteIIDModel : public ProbabilisticModelCrtp<DiscreteIIDModel> {
* @see trainSmoothedHistogramStanke()
* @see trainSmoothedHistogramKernelDensity()
*/
explicit DiscreteIIDModel(std::vector<Probability> probabilities);
explicit DiscreteIIDModel(std::vector<LogProbability> probabilities);

// Static methods

Expand Down Expand Up @@ -159,8 +159,8 @@ class DiscreteIIDModel : public ProbabilisticModelCrtp<DiscreteIIDModel> {
smoothed_histogram_kernel_density_algorithm,
unsigned int max_length);

static std::vector<Probability> normalize(
std::vector<Probability> probabilities);
static std::vector<LogProbability> normalize(
std::vector<LogProbability> probabilities);

// Overriden methods

Expand All @@ -170,9 +170,9 @@ class DiscreteIIDModel : public ProbabilisticModelCrtp<DiscreteIIDModel> {
* @param pos position within standardEvaluator's sequence to be evaluated
* @return \f$Pr(s[i])\f$
*/
Probability evaluateSymbol(SEPtr<Standard> evaluator,
unsigned int pos,
unsigned int phase) const override;
LogProbability evaluateSymbol(SEPtr<Standard> evaluator,
unsigned int pos,
unsigned int phase) const override;

/**
* Draws a new symbol in the ith position.
Expand All @@ -199,21 +199,21 @@ class DiscreteIIDModel : public ProbabilisticModelCrtp<DiscreteIIDModel> {
* Gets the probability of this model draws the given symbol.
* @return \f$Pr(s)\f$
*/
virtual Probability probabilityOf(Symbol s) const;
virtual LogProbability probabilityOf(Symbol s) const;

// Concrete methods

/**
* Gets the probabilities this model draws each symbol.
* @return \f$\{Pr(x)\},\ x \in X\f$
*/
std::vector<Probability> probabilities();
std::vector<LogProbability> probabilities();

int alphabetSize() const;

private:
// Instance variables
std::vector<Probability> _probabilities;
std::vector<LogProbability> _probabilities;

// Static methods
static double kernel_normal(double x, double h);
Expand Down
2 changes: 1 addition & 1 deletion include/model/Duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Duration {

virtual RangePtr range() const = 0;
virtual unsigned int maximumSize() const = 0;
virtual Probability probabilityOfLenght(unsigned int length) const = 0;
virtual LogProbability probabilityOfLenght(unsigned int length) const = 0;

// Destructor
virtual ~Duration() = default;
Expand Down
15 changes: 9 additions & 6 deletions include/model/Estimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,38 @@
#ifndef TOPS_MODEL_ESTIMATION_
#define TOPS_MODEL_ESTIMATION_

// Internal headers
#include "model/Probability.hpp"

namespace tops {
namespace model {

// Forward declaration
template<typename Target, typename Probability>
template<typename Target>
class Estimation;

/**
* @class Estimation
* @brief TODO
*/
template<typename Target, typename Probability = double>
template<typename Target>
class Estimation {
public:
// Constructors
Estimation() = default;
Estimation(Target estimated, Probability probability);
Estimation(Target estimated, LogProbability probability);

// Concrete methods
const Target& estimated() const;
Target& estimated();

const Probability& probability() const;
Probability& probability();
const LogProbability& probability() const;
LogProbability& probability();

private:
// Instance variables
Target _estimated;
Probability _probability;
LogProbability _probability;
};

} // namespace model
Expand Down
32 changes: 16 additions & 16 deletions include/model/Estimation.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@ namespace model {
/* CONSTRUCTORS */
/*----------------------------------------------------------------------------*/

template<typename Target, typename Probability>
Estimation<Target, Probability>::Estimation(Target estimated,
Probability probability)
: _estimated(std::move(estimated)), _probability(std::move(probability)) {
template<typename Target>
Estimation<Target>::Estimation(Target estimated,
LogProbability probability)
: _estimated(std::move(estimated)), _probability(probability) {
}

/*----------------------------------------------------------------------------*/
/* CONCRETE METHODS */
/*----------------------------------------------------------------------------*/

template<typename Target, typename Probability>
const Target& Estimation<Target, Probability>::estimated() const {
template<typename Target>
const Target& Estimation<Target>::estimated() const {
return _estimated;
}

/*----------------------------------------------------------------------------*/

template<typename Target, typename Probability>
Target& Estimation<Target, Probability>::estimated() {
return const_cast<Target &>(
static_cast<const Estimation *>(this)->estimated());
template<typename Target>
Target& Estimation<Target>::estimated() {
return const_cast<Target&>(
static_cast<const Estimation*>(this)->estimated());
}

/*----------------------------------------------------------------------------*/

template<typename Target, typename Probability>
const Probability& Estimation<Target, Probability>::probability() const {
template<typename Target>
const LogProbability& Estimation<Target>::probability() const {
return _probability;
}

/*----------------------------------------------------------------------------*/

template<typename Target, typename Probability>
Probability& Estimation<Target, Probability>::probability() {
return const_cast<Probability &>(
static_cast<const Estimation *>(this)->probability());
template<typename Target>
LogProbability& Estimation<Target>::probability() {
return const_cast<LogProbability&>(
static_cast<const Estimation*>(this)->probability());
}

/*----------------------------------------------------------------------------*/
Expand Down
10 changes: 5 additions & 5 deletions include/model/Evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class Evaluator
: public std::enable_shared_from_this<Evaluator<Decorator>> {
public:
// Purely virtual methods
virtual Probability evaluateSymbol(unsigned int pos,
unsigned int phase = 0) const = 0;
virtual LogProbability evaluateSymbol(unsigned int pos,
unsigned int phase = 0) const = 0;

virtual Probability evaluateSequence(unsigned int begin,
unsigned int end,
unsigned int phase = 0) const = 0;
virtual LogProbability evaluateSequence(unsigned int begin,
unsigned int end,
unsigned int phase = 0) const = 0;

virtual Decorator<Sequence>& sequence() = 0;
virtual const Decorator<Sequence>& sequence() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/model/ExplicitDuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ExplicitDuration : public DurationCrtp<ExplicitDuration> {
// Overriden methods
RangePtr range() const override;
unsigned int maximumSize() const override;
Probability probabilityOfLenght(unsigned int length) const override;
LogProbability probabilityOfLenght(unsigned int length) const override;

private:
// Instance variables
Expand Down
8 changes: 4 additions & 4 deletions include/model/FixedSequenceAtPosition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class FixedSequenceAtPosition
DiscreteIIDModelPtr distr);

// Overriden methods
Probability evaluateSequence(SEPtr<Standard> evaluator,
unsigned int begin,
unsigned int end,
unsigned int phase) const override;
LogProbability evaluateSequence(SEPtr<Standard> evaluator,
unsigned int begin,
unsigned int end,
unsigned int phase) const override;

Standard<Sequence> drawSequence(SGPtr<Standard> generator,
unsigned int size,
Expand Down
Loading

0 comments on commit bc93d54

Please sign in to comment.