<commit_before>#pragma once

#include "../DataLoggers/DataLogger.h"
#include "../Histogram.h"
#include "../Models/BaseModel.h"
#include "../Rand.h"
#include "Ensemble.h"
#include <vector>

namespace Ensembles
{
	// Abstract class for density of states based sampling using flat histogram
	// method.
	template<typename T>
	class DensityOfStatesEnsemble : public Ensemble<T>
	{
		private:

			// Flatness threshold.
			double _targetFlatness = 0.8;

			// Densities of state pointer.
			std::vector<double>* _DOS;

			// Histogram counts.
			std::vector<double>* _counts;

			// Flatness measure.
			double _flatness;

			// Lower outliers.
			double _lowerOutliers = 0;

			// Upper outliers.
			double _upperOutliers = 0;

			// Log of scaling factor for density of states.
			double _scaleFactor = 1;

		protected:
			// Random number generator.
			Rand rand;

			// Histogram
			Histogram hist;

			// Current energy of the model.
			double _energy;

			// Calculates the total energy of the model.
			double CalculateTotalEnergy();

			// Registers loggable properties with logger.
			void RegisterLoggableProperties(DataLogger& logger);

		public:

			// Initializes a DOS ensemble for a specified model. The binning will
			// be performed according to the specified minimum and maxiumum parameter and
			// the bin count.
			DensityOfStatesEnsemble(BaseModel& model,
			                        double minP,
			                        double maxP,
			                        int binCount) :
				Ensemble<T>(model), rand(15), hist(minP, maxP, binCount)
			{
				_counts = hist.GetHistogramPointer();
				_DOS = hist.GetValuesPointer();

				// Calculate initial energy.
				_energy = CalculateTotalEnergy();
			};

			// Runs multiple DOS simulations, between each subsequent iteration is
			// a re-normalization step involving resetting of the hisogram and reduction of
			// the scaling factor.
			void Run(int iterations);

			// Performs one DOS iteration. This constitutes sampling phase space
			// until the density of states histogram is determined to be flat.
			// Performs one Monte-Carlo iteration. This is precisely one random draw
			// from the model (one function call to model->DrawSample()).
			void Sweep();

			// Performs one Monte-Carlo iteration. This is precisely one random draw
			// from the model (one function call to model->DrawSample()).
			virtual void Iterate() = 0;

			// Gets the current energy of the system.
			double GetEnergy()
			{
				return _energy;
			}

			// Gets the density of states scaling factor.
			double GetScaleFactor()
			{
				return _scaleFactor;
			}

			// Sets the density of states scaling factor.
			double SetScaleFactor(double sf)
			{
				return _scaleFactor = sf;
			}

			double GetTargetFlatness()
			{
				return _targetFlatness;
			}

			double SetTargetFlatness(double f)
			{
				return _targetFlatness = f;
			}

			// Resets the histogram.
			void ResetHistogram()
			{
				hist.ResetHistogram();
			}

			// Reduces the scaling factor order by a specified multiple.
			double ReduceScaleFactor(double order = 0.5)
			{
				// We store log of scale factor. So we simply multiply.
				return _scaleFactor = _scaleFactor*order;
			}

			// Acceptance probability based on density of states.
			virtual double AcceptanceProbability(double prevH, double currH) = 0;
	};
}<commit_msg>Added interval to DOSEnsembles<commit_after>#pragma once

#include "../DataLoggers/DataLogger.h"
#include "../Histogram.h"
#include "../Models/BaseModel.h"
#include "../Rand.h"
#include "Ensemble.h"
#include <vector>

namespace Ensembles
{
	typedef std::pair<double, double> Interval;

	// Abstract class for density of states based sampling using flat histogram
	// method.
	template<typename T>
	class DensityOfStatesEnsemble : public Ensemble<T>
	{
		private:

			// Flatness threshold.
			double _targetFlatness = 0.8;

			// Densities of state pointer.
			std::vector<double>* _DOS;

			// Histogram counts.
			std::vector<double>* _counts;

			// Flatness measure.
			double _flatness;

			// Lower outliers.
			double _lowerOutliers = 0;

			// Upper outliers.
			double _upperOutliers = 0;

			// Log of scaling factor for density of states.
			double _scaleFactor = 1;

			// Parameter histogram interval.
			Interval _interval;

		protected:
			// Random number generator.
			Rand rand;

			// Histogram
			Histogram hist;

			// Current energy of the model.
			double _energy;

			// Calculates the total energy of the model.
			double CalculateTotalEnergy();

			// Registers loggable properties with logger.
			void RegisterLoggableProperties(DataLogger& logger);

		public:

			// Initializes a DOS ensemble for a specified model. The binning will
			// be performed according to the specified minimum and maxiumum parameter and
			// the bin count.
			DensityOfStatesEnsemble(BaseModel& model,
			                        double minP,
			                        double maxP,
			                        int binCount) :
				Ensemble<T>(model), rand(15), hist(minP, maxP, binCount)
			{
				_interval = Interval(minP, maxP);

				_counts = hist.GetHistogramPointer();
				_DOS = hist.GetValuesPointer();

				// Calculate initial energy.
				_energy = CalculateTotalEnergy();
			};

			// Runs multiple DOS simulations, between each subsequent iteration is
			// a re-normalization step involving resetting of the hisogram and reduction of
			// the scaling factor.
			void Run(int iterations);

			// Performs one DOS iteration. This constitutes sampling phase space
			// until the density of states histogram is determined to be flat.
			// Performs one Monte-Carlo iteration. This is precisely one random draw
			// from the model (one function call to model->DrawSample()).
			void Sweep();

			// Performs one Monte-Carlo iteration. This is precisely one random draw
			// from the model (one function call to model->DrawSample()).
			virtual void Iterate() = 0;

			// Gets the current energy of the system.
			double GetEnergy()
			{
				return _energy;
			}

			// Gets the density of states scaling factor.
			double GetScaleFactor()
			{
				return _scaleFactor;
			}

			// Sets the density of states scaling factor.
			double SetScaleFactor(double sf)
			{
				return _scaleFactor = sf;
			}

			double GetTargetFlatness()
			{
				return _targetFlatness;
			}

			double SetTargetFlatness(double f)
			{
				return _targetFlatness = f;
			}

			// Resets the histogram.
			void ResetHistogram()
			{
				hist.ResetHistogram();
			}

			// Gets the interval over which the DOS is computed.
			Interval GetParameterInterval()
			{
				return _interval;
			}

			// Reduces the scaling factor order by a specified multiple.
			double ReduceScaleFactor(double order = 0.5)
			{
				// We store log of scale factor. So we simply multiply.
				return _scaleFactor = _scaleFactor*order;
			}

			// Acceptance probability based on density of states.
			virtual double AcceptanceProbability(double prevH, double currH) = 0;
	};
}
{'fraction_non_alphanumeric': 0.0874964316300314, 'fraction_numerical': 0.003140165572366543, 'mean_word_length': 2.6937269372693726, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5512309', 'n_tokens_mistral': 2479, 'n_tokens_neox': 1940, 'n_words': 698}