Skip to content

Commit

Permalink
Apply COW on some sample spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pfernique committed Apr 15, 2019
1 parent 600fb00 commit 07b5cb8
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 485 deletions.
10 changes: 5 additions & 5 deletions src/cpp/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace statiskit

boost::mt19937 _random_generator = boost::mt19937(0);

boost::mt19937& get_random_generator(void)
boost::mt19937& get_random_generator()
{ return _random_generator; }

std::unordered_map< uintptr_t, unsigned int > iterations = std::unordered_map< uintptr_t, unsigned int >();
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace statiskit
}
}

void set_seed(void)
void set_seed()
{ __impl::_random_generator.seed(); }

void set_seed(const Index& seed)
Expand All @@ -97,7 +97,7 @@ namespace statiskit
nullptr_error::nullptr_error(const std::string& parameter) : parameter_error(parameter, "cannot be set to nullptr")
{}

Schedule::~Schedule(void)
Schedule::~Schedule()
{}

ExponentialSchedule::ExponentialSchedule(const double& theta)
Expand All @@ -106,13 +106,13 @@ namespace statiskit
ExponentialSchedule::ExponentialSchedule(const ExponentialSchedule& schedule)
{ _theta = schedule._theta; }

ExponentialSchedule::~ExponentialSchedule(void)
ExponentialSchedule::~ExponentialSchedule()
{}

double ExponentialSchedule::operator() (const double& stage) const
{ return exp(- stage / _theta); }

const double& ExponentialSchedule::get_theta(void) const
const double& ExponentialSchedule::get_theta() const
{ return _theta; }

void ExponentialSchedule::set_theta(const double& theta)
Expand Down
40 changes: 21 additions & 19 deletions src/cpp/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

#define NOT_IMPLEMENTED() _Pragma("message \"not implemented function\""); throw not_implemented_error(__PRETTY_FUNCTION__, __FILE__, __LINE__)

#define INFOPOINT() std::cout << __PRETTY_FUNCTION__ << "in file '" << __FILE__ << "' at line " << __LINE__ << std::endl

#ifdef NDEBUG
#define BREAKPOINT() _Pragma("message \"breakpoint ignored\"")
#else
Expand All @@ -52,11 +54,11 @@ namespace statiskit

template<class T, class D, class B=T> struct PolymorphicCopy : public B
{
PolymorphicCopy(void);
PolymorphicCopy();
PolymorphicCopy(const PolymorphicCopy<T, D, B>& other);
virtual ~PolymorphicCopy(void) = default;
virtual ~PolymorphicCopy() = default;

virtual std::unique_ptr< T > copy(void) const;
virtual std::unique_ptr< T > copy() const;
};

namespace __impl
Expand All @@ -76,7 +78,7 @@ namespace statiskit
*
* The random generator used is the <a href="http://www.boost.org/doc/libs/1_60_0/doc/html/boost/random/mt19937.html">Mersenne Twister</a> random generator of the Boost.Random library
*/
STATISKIT_CORE_API boost::mt19937& get_random_generator(void);
STATISKIT_CORE_API boost::mt19937& get_random_generator();

STATISKIT_CORE_API unsigned int get_maxits(const uintptr_t& ptr, const unsigned int& maxits);
STATISKIT_CORE_API void set_maxits(const uintptr_t& ptr, const unsigned int& maxits);
Expand All @@ -87,7 +89,7 @@ namespace statiskit
template<class U, class V> std::set< U > keys(const std::map< U, V >& map);
}

STATISKIT_CORE_API void set_seed(void);
STATISKIT_CORE_API void set_seed();
STATISKIT_CORE_API void set_seed(const Index& seed);

struct STATISKIT_CORE_API not_implemented_error : std::runtime_error
Expand Down Expand Up @@ -132,17 +134,17 @@ namespace statiskit
class Optimization : public T
{
public:
Optimization(void);
Optimization();
Optimization(const Optimization< T >& optimization);
virtual ~Optimization(void);
virtual ~Optimization();

const double& get_mindiff(void) const;
const double& get_mindiff() const;
void set_mindiff(const double& mindiff);

unsigned int get_minits(void) const;
unsigned int get_minits() const;
void set_minits(const unsigned int& maxits);

unsigned int get_maxits(void) const;
unsigned int get_maxits() const;
void set_maxits(const unsigned int& maxits);

protected:
Expand All @@ -155,23 +157,23 @@ namespace statiskit

struct STATISKIT_CORE_API Schedule
{
virtual ~Schedule(void) = 0;
virtual ~Schedule() = 0;

virtual double operator() (const double& stage) const = 0;

virtual std::unique_ptr< Schedule > copy(void) const = 0;
virtual std::unique_ptr< Schedule > copy() const = 0;
};

class STATISKIT_CORE_API ExponentialSchedule : public PolymorphicCopy< Schedule, ExponentialSchedule >
{
public:
ExponentialSchedule(const double& theta);
ExponentialSchedule(const ExponentialSchedule& schedule);
virtual ~ExponentialSchedule(void);
virtual ~ExponentialSchedule();

virtual double operator() (const double& stage) const;

const double& get_theta(void) const;
const double& get_theta() const;
void set_theta(const double& theta);

protected:
Expand All @@ -182,17 +184,17 @@ namespace statiskit
class SimulatedAnnealing : public T
{
public:
SimulatedAnnealing(void);
SimulatedAnnealing();
SimulatedAnnealing(const SimulatedAnnealing< T >& simulated_annealing);
virtual ~SimulatedAnnealing(void);
virtual ~SimulatedAnnealing();

const Schedule* get_schedule(void) const;
const Schedule* get_schedule() const;
void set_schedule(const Schedule& schedule);

unsigned int get_minits(void) const;
unsigned int get_minits() const;
void set_minits(const unsigned int& maxits);

unsigned int get_maxits(void) const;
unsigned int get_maxits() const;
void set_maxits(const unsigned int& maxits);

protected:
Expand Down
24 changes: 12 additions & 12 deletions src/cpp/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
namespace statiskit
{
template<class T, class D, class B>
PolymorphicCopy< T, D, B >::PolymorphicCopy(void) : B()
PolymorphicCopy< T, D, B >::PolymorphicCopy() : B()
{}

template<class T, class D, class B>
PolymorphicCopy< T, D, B >::PolymorphicCopy(const PolymorphicCopy< T, D, B>& other) : B(other)
{}

template<class T, class D, class B>
std::unique_ptr< T > PolymorphicCopy< T, D, B >::copy(void) const
std::unique_ptr< T > PolymorphicCopy< T, D, B >::copy() const
{ return std::make_unique< D >(static_cast< const D& >(*this)); }

namespace __impl
Expand Down Expand Up @@ -124,7 +124,7 @@ namespace statiskit
{}

template<typename T>
Optimization< T >::Optimization(void)
Optimization< T >::Optimization()
{
_mindiff = 1e-5;
_minits = 1;
Expand All @@ -140,27 +140,27 @@ namespace statiskit
}

template<typename T>
Optimization< T >::~Optimization(void)
Optimization< T >::~Optimization()
{}

template<typename T>
const double& Optimization< T >::get_mindiff(void) const
const double& Optimization< T >::get_mindiff() const
{ return _mindiff; }

template<typename T>
void Optimization< T >::set_mindiff(const double& mindiff)
{ _mindiff = mindiff; }

template<typename T>
unsigned int Optimization< T >::get_minits(void) const
unsigned int Optimization< T >::get_minits() const
{ return _minits; }

template<typename T>
void Optimization< T >::set_minits(const unsigned int& minits)
{ _minits = minits; }

template<typename T>
unsigned int Optimization< T >::get_maxits(void) const
unsigned int Optimization< T >::get_maxits() const
{ return _maxits; }

template<typename T>
Expand All @@ -182,7 +182,7 @@ namespace statiskit
}

template<typename T>
SimulatedAnnealing< T >::SimulatedAnnealing(void)
SimulatedAnnealing< T >::SimulatedAnnealing()
{
_schedule = new ExponentialSchedule(1.);
_minits = 1;
Expand All @@ -201,7 +201,7 @@ namespace statiskit
}

template<typename T>
SimulatedAnnealing< T >::~SimulatedAnnealing(void)
SimulatedAnnealing< T >::~SimulatedAnnealing()
{
if(_schedule)
{
Expand All @@ -211,23 +211,23 @@ namespace statiskit
}

template<typename T>
const Schedule* SimulatedAnnealing< T >::get_schedule(void) const
const Schedule* SimulatedAnnealing< T >::get_schedule() const
{ return _schedule; }

template<typename T>
void SimulatedAnnealing< T >::set_schedule(const Schedule& schedule)
{ _schedule = schedule.copy().release(); }

template<typename T>
unsigned int SimulatedAnnealing< T >::get_minits(void) const
unsigned int SimulatedAnnealing< T >::get_minits() const
{ return _minits; }

template<typename T>
void SimulatedAnnealing< T >::set_minits(const unsigned int& minits)
{ _minits = minits; }

template<typename T>
unsigned int SimulatedAnnealing< T >::get_maxits(void) const
unsigned int SimulatedAnnealing< T >::get_maxits() const
{ return _maxits; }

template<typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ namespace statiskit
_tree_distribution[it->first] = new NominalDistribution(it->second->get_values());
break;
case TOTAL:
_tree_distribution[it->first] = new OrdinalDistribution(static_cast< OrdinalSampleSpace* >(it->second)->get_ordered());
_tree_distribution[it->first] = new OrdinalDistribution(static_cast< OrdinalSampleSpace* >(it->second.get())->get_ordered());
break;
case PARTIAL:
_tree_distribution[it->first] = new HierarchicalDistribution(*(static_cast< HierarchicalSampleSpace* >(it->second)));
_tree_distribution[it->first] = new HierarchicalDistribution(*(static_cast< HierarchicalSampleSpace* >(it->second.get())));
break;
}
// for(std::set< std::string >::const_iterator it2 = it->second->get_values().cbegin(), it2_end = it->second->get_values().cend(); it2 != it2_end; ++it2)
Expand Down
Loading

0 comments on commit 07b5cb8

Please sign in to comment.