diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/MonteCarloAbsorption.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/MonteCarloAbsorption.h index 40d575ab1b8e0fd2fd885bca5f3f965546f87a18..95276c99d82be1d403b551adfab79b1bdad9cf26 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/MonteCarloAbsorption.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/MonteCarloAbsorption.h @@ -5,7 +5,7 @@ // Includes //------------------------------------------------------------------------------ #include "MantidAPI/Algorithm.h" -#include "MantidKernel/RandomNumberGenerator.h" +#include "MantidKernel/PseudoRandomNumberGenerator.h" #include "MantidGeometry/IComponent.h" namespace Mantid @@ -126,7 +126,7 @@ namespace Mantid //@} /// A pointer to the random number generator - Kernel::RandomNumberGenerator *m_randGen; + Kernel::PseudoRandomNumberGenerator *m_randGen; }; } diff --git a/Code/Mantid/Framework/Algorithms/src/MonteCarloAbsorption.cpp b/Code/Mantid/Framework/Algorithms/src/MonteCarloAbsorption.cpp index 5df9a261452c8a22c353971476a24f439e849948..409cda65b59e181e8e84ecd2693cfc319db42489 100644 --- a/Code/Mantid/Framework/Algorithms/src/MonteCarloAbsorption.cpp +++ b/Code/Mantid/Framework/Algorithms/src/MonteCarloAbsorption.cpp @@ -255,9 +255,9 @@ namespace Mantid int nattempts(0); while( nattempts < MaxRandPointAttempts ) { - const double x = m_bbox_halflength*(2.0*m_randGen->next() - 1.0); - const double y = m_bbox_halfwidth*(2.0*m_randGen->next() - 1.0); - const double z = m_bbox_halfheight*(2.0*m_randGen->next() - 1.0); + const double x = m_bbox_halflength*(2.0*m_randGen->nextValue() - 1.0); + const double y = m_bbox_halfwidth*(2.0*m_randGen->nextValue() - 1.0); + const double z = m_bbox_halfheight*(2.0*m_randGen->nextValue() - 1.0); scatterPoint(x,y,z); ++nattempts; if( m_sampleShape->isValid(scatterPoint) || @@ -433,9 +433,8 @@ namespace Mantid { if( !m_randGen ) { - m_randGen = new Kernel::MersenneTwister; - int seedValue = getProperty("SeedValue"); - m_randGen->setSeed(seedValue); + const int seedValue = getProperty("SeedValue"); + m_randGen = new Kernel::MersenneTwister(seedValue); } m_samplePos = m_inputWS->getInstrument()->getSample()->getPos(); diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FakeEventDataListener.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FakeEventDataListener.h index 49e59106e31ea123101158951a76379c343e6644..e45fc6e4e46f3223e3f054a912ffe410eeaa8593 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FakeEventDataListener.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FakeEventDataListener.h @@ -6,7 +6,7 @@ //---------------------------------------------------------------------- #include "MantidAPI/ILiveListener.h" #include "MantidDataObjects/EventWorkspace.h" -#include "MantidKernel/RandomNumberGenerator.h" +#include "MantidKernel/PseudoRandomNumberGenerator.h" #include <Poco/Timer.h> #include "MantidKernel/MultiThreaded.h" #include "MantidKernel/DateAndTime.h" @@ -56,7 +56,7 @@ namespace Mantid void generateEvents(Poco::Timer&); DataObjects::EventWorkspace_sptr m_buffer; ///< Used to buffer events between calls to extractData() - Kernel::RandomNumberGenerator * m_rand; ///< Used in generation of random events + Kernel::PseudoRandomNumberGenerator * m_rand; ///< Used in generation of random events Poco::Timer m_timer; ///< Used to call the event-generating function on a schedule int m_datarate; ///< The data rate to (attempt to) generate in events/sec int m_callbackloop; ///< Number of times to loop within each generateEvents() call diff --git a/Code/Mantid/Framework/DataHandling/src/FakeEventDataListener.cpp b/Code/Mantid/Framework/DataHandling/src/FakeEventDataListener.cpp index c7d96c3a45797470eedd631b1cef43d6c8d59837..7a430bdf275cc4bbbca0525a1fa2f7bc7184497e 100644 --- a/Code/Mantid/Framework/DataHandling/src/FakeEventDataListener.cpp +++ b/Code/Mantid/Framework/DataHandling/src/FakeEventDataListener.cpp @@ -17,7 +17,7 @@ namespace DataHandling /// Constructor FakeEventDataListener::FakeEventDataListener() : ILiveListener(), - m_buffer(), m_rand(new Kernel::MersenneTwister), m_timer(), m_callbackloop(1), + m_buffer(), m_rand(new Kernel::MersenneTwister(5489)), m_timer(), m_callbackloop(1), m_runNumber(1) { if ( ! ConfigService::Instance().getValue("fakeeventdatalistener.datarate",m_datarate) ) @@ -125,8 +125,8 @@ namespace DataHandling Mutex::ScopedLock _lock(m_mutex); for (long i = 0; i < m_callbackloop; ++i) { - m_buffer->getEventList(0).addEventQuickly(DataObjects::TofEvent(m_rand->next())); - m_buffer->getEventList(1).addEventQuickly(DataObjects::TofEvent(m_rand->next())); + m_buffer->getEventList(0).addEventQuickly(DataObjects::TofEvent(m_rand->nextValue())); + m_buffer->getEventList(1).addEventQuickly(DataObjects::TofEvent(m_rand->nextValue())); } return; diff --git a/Code/Mantid/Framework/DataHandling/test/TestDataListener.cpp b/Code/Mantid/Framework/DataHandling/test/TestDataListener.cpp index 2176e901269eebde1cdf9d9c6198b9b7161e1323..fbf6c3c19c9cae3eccccc89d91b22c9f1c721c19 100644 --- a/Code/Mantid/Framework/DataHandling/test/TestDataListener.cpp +++ b/Code/Mantid/Framework/DataHandling/test/TestDataListener.cpp @@ -20,14 +20,11 @@ namespace DataHandling /// Constructor TestDataListener::TestDataListener() : ILiveListener(), - m_buffer(), m_rand(new Kernel::MersenneTwister), + m_buffer(), m_rand(new Kernel::MersenneTwister(Kernel::DateAndTime::getCurrentTime().totalNanoseconds(),40000,60000)), m_changeStatusAfter(0), m_newStatus(ILiveListener::EndRun) { // Set up the first workspace buffer this->createEmptyWorkspace(); - // Set a sample tof range - m_rand->setRange(40000,60000); - m_rand->setSeed(Kernel::DateAndTime::getCurrentTime().totalNanoseconds()); m_timesCalled = 0; m_dataReset = false; @@ -105,8 +102,8 @@ namespace DataHandling EventList & el2 = m_buffer->getEventList(1); for (int i = 0; i < 100; ++i) { - el1.addEventQuickly(TofEvent(m_rand->next())); - el2.addEventQuickly(TofEvent(m_rand->next())); + el1.addEventQuickly(TofEvent(m_rand->nextValue())); + el2.addEventQuickly(TofEvent(m_rand->nextValue())); } // Copy the workspace pointer to a temporary variable diff --git a/Code/Mantid/Framework/DataHandling/test/TestDataListener.h b/Code/Mantid/Framework/DataHandling/test/TestDataListener.h index 7350bbaa5ef753c9084c37abaa20953b6c6b91d3..d837c96d1a8367f20a04f67d7c510d8535e3fa93 100644 --- a/Code/Mantid/Framework/DataHandling/test/TestDataListener.h +++ b/Code/Mantid/Framework/DataHandling/test/TestDataListener.h @@ -6,7 +6,7 @@ //---------------------------------------------------------------------- #include "MantidAPI/ILiveListener.h" #include "MantidDataObjects/EventWorkspace.h" -#include "MantidKernel/RandomNumberGenerator.h" +#include "MantidKernel/PseudoRandomNumberGenerator.h" namespace Mantid { @@ -34,7 +34,7 @@ namespace Mantid private: DataObjects::EventWorkspace_sptr m_buffer; - Kernel::RandomNumberGenerator * m_rand; + Kernel::PseudoRandomNumberGenerator * m_rand; void createEmptyWorkspace(); diff --git a/Code/Mantid/Framework/Geometry/CMakeLists.txt b/Code/Mantid/Framework/Geometry/CMakeLists.txt index ca376fa21dbed188d04f4f5b2bbc27174125e55e..38abbe14697d66764721fe5cac2ed3e1022d2595 100644 --- a/Code/Mantid/Framework/Geometry/CMakeLists.txt +++ b/Code/Mantid/Framework/Geometry/CMakeLists.txt @@ -310,7 +310,7 @@ set_target_properties ( Geometry PROPERTIES OUTPUT_NAME MantidGeometry # Add to the 'Framework' group in VS set_property ( TARGET Geometry PROPERTY FOLDER "MantidFramework" ) -target_link_libraries ( Geometry ${MANTIDLIBS} ${OPENGL_LIBRARIES} ${GSL_LIBRARIES} ) +target_link_libraries ( Geometry ${MANTIDLIBS} ${OPENGL_LIBRARIES} ) if (NOT NO_OPENCASCADE) target_link_libraries ( Geometry ${OPENCASCADE_LIBRARIES} ) diff --git a/Code/Mantid/Framework/Kernel/CMakeLists.txt b/Code/Mantid/Framework/Kernel/CMakeLists.txt index c69eea2d5e8497ab9abb98ec4446b704986a83eb..2a58cbff447a423f0fad57ec2e702d7cb6b32f71 100644 --- a/Code/Mantid/Framework/Kernel/CMakeLists.txt +++ b/Code/Mantid/Framework/Kernel/CMakeLists.txt @@ -1,5 +1,5 @@ set ( SRC_FILES - src/ANN_complete.cpp + src/ANN_complete.cpp src/ArrayBoundedValidator.cpp src/ArrayLengthValidator.cpp src/ArrayProperty.cpp @@ -53,12 +53,14 @@ set ( SRC_FILES src/PropertyManager.cpp src/PropertyManagerOwner.cpp src/PropertyWithValue.cpp + src/PseudoRandomNumberGenerator.cpp src/Quat.cpp src/ReadLock.cpp src/RebinParamsValidator.cpp src/RegexStrings.cpp src/SignalChannel.cpp src/SingletonHolder.cpp + src/SobolSequence.cpp src/Statistics.cpp src/Strings.cpp src/TestChannel.cpp @@ -152,6 +154,7 @@ set ( INC_FILES inc/MantidKernel/MultiFileNameParser.h inc/MantidKernel/MultiThreaded.h inc/MantidKernel/MultiFileValidator.h + inc/MantidKernel/NDRandomNumberGenerator.h inc/MantidKernel/NeutronAtom.h inc/MantidKernel/NexusTestHelper.h inc/MantidKernel/NullValidator.h @@ -163,14 +166,16 @@ set ( INC_FILES inc/MantidKernel/PropertyManager.h inc/MantidKernel/PropertyManagerOwner.h inc/MantidKernel/PropertyWithValue.h + inc/MantidKernel/PseudoRandomNumberGenerator.h inc/MantidKernel/Quat.h - inc/MantidKernel/RandomNumberGenerator.h + inc/MantidKernel/QuasiRandomNumberSequence.h inc/MantidKernel/ReadLock.h inc/MantidKernel/RebinParamsValidator.h inc/MantidKernel/RegexStrings.h inc/MantidKernel/RegistrationHelper.h inc/MantidKernel/SignalChannel.h inc/MantidKernel/SingletonHolder.h + inc/MantidKernel/SobolSequence.h inc/MantidKernel/Statistics.h inc/MantidKernel/Strings.h inc/MantidKernel/System.h @@ -245,6 +250,7 @@ set ( TEST_FILES test/MultiFileValidatorTest.h test/MutexTest.h test/NeutronAtomTest.h + test/NDRandomNumberGeneratorTest.h test/NullValidatorTest.h test/ProgressBaseTest.h test/ProgressTextTest.h @@ -253,12 +259,12 @@ set ( TEST_FILES test/PropertyTest.h test/PropertyWithValueTest.h test/QuatTest.h - test/RandomNumberGeneratorTest.h test/ReadLockTest.h test/RebinHistogramTest.h test/RebinParamsValidatorTest.h test/RegexStringsTest.h test/SignalChannelTest.h + test/SobolSequenceTest.h test/StatisticsTest.h test/StringsTest.h test/TaskTest.h @@ -287,6 +293,7 @@ if(UNITY_BUILD) enable_unity_build(Kernel SRC_FILES SRC_UNITY_IGNORE_FILES 10) endif(UNITY_BUILD) +include_directories ( ${GSL_INCLUDE_DIR} ) # Add a precompiled header where they are supported ADD_PRECOMPILED_HEADER ( inc/MantidKernel/PrecompiledHeader.h MantidKernel src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) @@ -298,7 +305,7 @@ set_target_properties ( Kernel PROPERTIES OUTPUT_NAME MantidKernel # Add to the 'Framework' group in VS set_property ( TARGET Kernel PROPERTY FOLDER "MantidFramework" ) -target_link_libraries ( Kernel ${MANTIDLIBS} ) +target_link_libraries ( Kernel ${MANTIDLIBS} ${GSL_LIBRARIES} ) if ( WIN32 ) target_link_libraries ( Kernel Psapi.lib ) # For memory usage queries endif() diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ClassMacros.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ClassMacros.h new file mode 100644 index 0000000000000000000000000000000000000000..83bcf6e558900d91412858859e1105f53ae5a750 --- /dev/null +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ClassMacros.h @@ -0,0 +1,39 @@ +#ifndef MANTID_KERNEL_CLASSMACROS_H_ +#define MANTID_KERNEL_CLASSMACROS_H_ +/** + Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + +/** + * This file defines macros for altering class behaviour, i.e. disabling copying etc + */ + +/// Disable default construction +#define DISABLE_DEFAULT_CONSTRUCT(ClassType) \ + ClassType(); + +/// Disable copy & assign +#define DISABLE_COPY_AND_ASSIGN(ClassType) \ + ClassType(const ClassType&);\ + ClassType& operator=(const ClassType&); + + +#endif /* MANTID_KERNEL_CLASSMACROS_H_ */ diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/MersenneTwister.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/MersenneTwister.h index d669257cafa6043834dd2ce43a348140ce12c92d..56157188c3ccd773056b782815714a5408f53776 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/MersenneTwister.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/MersenneTwister.h @@ -4,7 +4,9 @@ //------------------------------------------------------------------------------ // Includes //------------------------------------------------------------------------------ -#include "RandomNumberGenerator.h" +#include "MantidKernel/PseudoRandomNumberGenerator.h" +#include "MantidKernel/ClassMacros.h" + #include <boost/random/mersenne_twister.hpp> #include <boost/random/uniform_real.hpp> #include <boost/random/variate_generator.hpp> @@ -15,7 +17,7 @@ namespace Mantid { /** This implements the the Mersenne Twister 19937 pseudo-random number - generator algorithm as a specialzation of the RandomNumberGenerator + generator algorithm as a specialzation of the PseudoRandomNumberGenerator interface. Further documentation can be found here: @@ -45,30 +47,39 @@ namespace Mantid File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ - class MANTID_KERNEL_DLL MersenneTwister : public RandomNumberGenerator + class MANTID_KERNEL_DLL MersenneTwister : public PseudoRandomNumberGenerator { /// Typedef for a uniform distribution of doubles typedef boost::uniform_real<double> uniform_double; - /// Typedef for a variate generator tieing together the Mersenne Twister + /// Typedef for a variate generator tying together the Mersenne Twister /// algorithm with a uniform disribution - typedef boost::variate_generator<boost::mt19937&, - boost::uniform_real<double> > uniform_generator; + typedef boost::variate_generator<boost::mt19937&, + boost::uniform_real<double> > uniform_generator; public: - /// Default constructor - MersenneTwister(); + /// Construct the generator with an initial seed. It can be reseeded using setSeed. + explicit MersenneTwister(const size_t seedValue); + /// Construct the generator with an initial seed and range. + MersenneTwister(const size_t seedValue, const double start, const double end); /// Set the random number seed - virtual void setSeed(size_t seed); + virtual void setSeed(const size_t seed); /// Sets the range of the subsequent calls to next - virtual void setRange(double start, double end); + virtual void setRange(const double start, const double end); /// Generate the next random number in the sequence within the given range, (default=[0.0,1.0]). - virtual double next(); + virtual double nextValue(); + /// Resets the generator + virtual void reset(); private: + DISABLE_DEFAULT_CONSTRUCT(MersenneTwister); + DISABLE_COPY_AND_ASSIGN(MersenneTwister); + /// The boost Mersenne Twister generator boost::mt19937 m_generator; /// A boost distribution class to produce uniform numbers between a range uniform_double m_uniform_dist; + /// The current seed + boost::mt19937::result_type m_currentSeed; }; } diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/RandomNumberGenerator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/NDRandomNumberGenerator.h similarity index 70% rename from Code/Mantid/Framework/Kernel/inc/MantidKernel/RandomNumberGenerator.h rename to Code/Mantid/Framework/Kernel/inc/MantidKernel/NDRandomNumberGenerator.h index ad392ebfeab32981959d2362d0759013bdf3594a..0bd64195d06876874fbe70554f92337a786883d3 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/RandomNumberGenerator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/NDRandomNumberGenerator.h @@ -1,20 +1,22 @@ -#ifndef MANTID_KERNEL_RANDOMNUMBERGENERATOR_H_ -#define MANTID_KERNEL_RANDOMNUMBERGENERATOR_H_ +#ifndef MANTID_KERNEL_NDRANDOMNUMBERGENERATOR_H_ +#define MANTID_KERNEL_NDRANDOMNUMBERGENERATOR_H_ //------------------------------------------------------------------------------ // Includes //------------------------------------------------------------------------------ #include "DllConfig.h" +#include <vector> namespace Mantid { namespace Kernel { /** - This class defines an interface for random number generators. + This class defines an interface for N dimensional random number generators. + A call to next produces N points in an ND space @author Martyn Gigg, Tessella plc - @date 19/11/2007 + @date 19/05/2012 Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory @@ -36,20 +38,16 @@ namespace Mantid File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ - class MANTID_KERNEL_DLL RandomNumberGenerator + class MANTID_KERNEL_DLL NDRandomNumberGenerator { - public: /// Virtual destructor to ensure that all inheriting classes have one - virtual ~RandomNumberGenerator() {}; - /// Set the random number seed - virtual void setSeed(size_t seedValue) = 0; - /// Sets the range of the subsequent calls to next; - virtual void setRange(double start, double end) = 0; - /// Generate the next random number in the sequence within the given range. - virtual double next() = 0; + virtual ~NDRandomNumberGenerator() {}; + /// Generate the next set of values that form a point in ND space + virtual std::vector<double> nextPoint() = 0; + /// Reset the generator + virtual void reset() = 0; }; - } } diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PseudoRandomNumberGenerator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PseudoRandomNumberGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..deadf6c3a1b314637dd48243cf770442042cf384 --- /dev/null +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PseudoRandomNumberGenerator.h @@ -0,0 +1,54 @@ +#ifndef MANTID_KERNEL_PSEUDORANDOMNUMBERGENERATOR_H_ +#define MANTID_KERNEL_PSEUDORANDOMNUMBERGENERATOR_H_ +/** + Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +//------------------------------------------------------------------------------ +// Includes +//------------------------------------------------------------------------------ +#include "MantidKernel/NDRandomNumberGenerator.h" + +namespace Mantid +{ + namespace Kernel + { + /** + * + * Defines a 1D pseudo-random number generator, i.e. a generator + * that takes an initial seed and produces a set of numbers. It specialises + * the interface for a general random number generator. + */ + class PseudoRandomNumberGenerator : NDRandomNumberGenerator + { + public: + /// Set the random number seed + virtual void setSeed(const size_t seedValue) = 0; + /// Sets the range of the subsequent calls to nextValue; + virtual void setRange(const double start, const double end) = 0; + /// Return the next number in the sequence + virtual double nextValue() = 0; + /// Returns the 1D point + virtual std::vector<double> nextPoint(); + }; + } +} + +#endif /* MANTID_KERNEL_PSEUDORANDOMNUMBERGENERATOR_H_ */ diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/QuasiRandomNumberSequence.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/QuasiRandomNumberSequence.h new file mode 100644 index 0000000000000000000000000000000000000000..1b52c89e81a5fe6d2b5bfc4aaa66f66a99a5e52e --- /dev/null +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/QuasiRandomNumberSequence.h @@ -0,0 +1,45 @@ +#ifndef MANTID_KERNEL_QUASIRANDOMNUMBERSEQUENCE_H_ +#define MANTID_KERNEL_QUASIRANDOMNUMBERSEQUENCE_H_ +/** + Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +//------------------------------------------------------------------------------ +// Includes +//------------------------------------------------------------------------------ +#include "MantidKernel/NDRandomNumberGenerator.h" + +namespace Mantid +{ + namespace Kernel + { + /** + * + * Defines an interface to a quasi-random number sequence. A quasi-random sequence + * progressively covers a d-dimensional space with a set of points that are + * uniformly distributed. + */ + class QuasiRandomNumberSequence : NDRandomNumberGenerator + { + }; + } +} + +#endif /* MANTID_KERNEL_QUASIRANDOMNUMBERSEQUENCE_H_ */ diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/SobolSequence.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/SobolSequence.h new file mode 100644 index 0000000000000000000000000000000000000000..30436e12c516879b0b7f41aa9c62b116610e0891 --- /dev/null +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/SobolSequence.h @@ -0,0 +1,75 @@ +#ifndef MANTID_KERNEL_SOBOLSEQUENCE_H_ +#define MANTID_KERNEL_SOBOLSEQUENCE_H_ +/** + Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +//------------------------------------------------------------------------------ +// Includes +//------------------------------------------------------------------------------ +#include "MantidKernel/QuasiRandomNumberSequence.h" +#include "MantidKernel/ClassMacros.h" +#include <gsl/gsl_qrng.h> + +//------------------------------------------------------------------------------ +// Forward declarations +//------------------------------------------------------------------------------ + +namespace Mantid +{ + namespace Kernel + { + /** + * + * Defines a generator that produces quasi-random numbers according + * to a Sobol sequence http://en.wikipedia.org/wiki/Sobol_sequence + */ + class SobolSequence : public QuasiRandomNumberSequence + { + public: + /// Constructor taking the number of dimensions + explicit SobolSequence(const unsigned int ndims); + /// Destructor + ~SobolSequence(); + /// Returns the next value in the sequence + std::vector<double> nextPoint(); + /// Reset the sequence + void reset(); + + private: + DISABLE_DEFAULT_CONSTRUCT(SobolSequence); + DISABLE_COPY_AND_ASSIGN(SobolSequence); + + /// Set the number of dimensions + void setNumberOfDimensions(const unsigned int ndims); + /// Frees resources allocated by current generator + void deleteCurrentGenerator(); + + /// GSL quasi-random number state + gsl_qrng *m_gslGenerator; + /// Number of dimensions of current generator + unsigned int m_numDims; + /// A n-dimensional vector holding the current coordinate points + std::vector<double> m_currentPoint; + }; + } +} + +#endif /* MANTID_KERNEL_SOBOLSEQUENCE_H_ */ diff --git a/Code/Mantid/Framework/Kernel/src/Matrix.cpp b/Code/Mantid/Framework/Kernel/src/Matrix.cpp index 1febbc83fa9fbaa4622138f04f66a041030eb1a4..e44a44e4254a0736ac40e5711b90db7c38d2cfbb 100644 --- a/Code/Mantid/Framework/Kernel/src/Matrix.cpp +++ b/Code/Mantid/Framework/Kernel/src/Matrix.cpp @@ -1752,15 +1752,13 @@ template<typename T> void Matrix<T>::setRandom(size_t seed,double rMin,double rMax) { - MersenneTwister rng; - rng.setSeed(seed); - rng.setRange(rMin,rMax); + MersenneTwister rng(seed, rMin, rMax); for(size_t i=0;i<nx;i++) { for(size_t j=0;j<ny;j++) { - V[i][j] =static_cast<T>(rng.next()); + V[i][j] =static_cast<T>(rng.nextValue()); } } } diff --git a/Code/Mantid/Framework/Kernel/src/MersenneTwister.cpp b/Code/Mantid/Framework/Kernel/src/MersenneTwister.cpp index b16351c0e1436084a5a838383369bdf57f0df781..42b63560710b846f4978f7b07c5ebafe2c0d7cd1 100644 --- a/Code/Mantid/Framework/Kernel/src/MersenneTwister.cpp +++ b/Code/Mantid/Framework/Kernel/src/MersenneTwister.cpp @@ -13,30 +13,47 @@ namespace Mantid //------------------------------------------------------------------------------ /** - * Default constructor. Sets the range to [0.0,1.0] + * Constructor taking a seed value. Sets the range to [0.0,1.0] + * @param seedValue :: The initial seed */ - MersenneTwister::MersenneTwister() : - m_generator(), m_uniform_dist(0.0, 1.0) + MersenneTwister::MersenneTwister(const size_t seedValue) : + m_generator(), m_uniform_dist(), m_currentSeed(0) { + setSeed(seedValue); + setRange(0.0, 1.0); + } + + /** + * Constructor taking a seed value and a range + * @param seedValue :: The initial seed + * @param start :: The minimum value a generated number should take + * @param end :: The maximum value a generated number should take + */ + MersenneTwister::MersenneTwister(const size_t seedValue, const double start, const double end) : + m_generator(), m_uniform_dist(), m_currentSeed() + { + setSeed(seedValue); + setRange(start,end); } /** * (Re-)seed the generator * @param seedValue :: A seed for the generator */ - void MersenneTwister::setSeed(size_t seedValue) + void MersenneTwister::setSeed(const size_t seedValue) { // Bug in earlier versions of this implementation meant // that a unsigned int could not be past to the seed function - m_generator.seed((boost::mt19937::result_type)seedValue); + m_currentSeed = (boost::mt19937::result_type)seedValue; + m_generator.seed(m_currentSeed); } /** - * Sets the range of the subsequent calls to next() - * @param start :: The lowest value a call to next() will produce - * @param end :: The largest value a call to next() will produce + * Sets the range of the subsequent calls to nextValue() + * @param start :: The lowest value a call to nextValue() will produce + * @param end :: The largest value a call to nextValue() will produce */ - void MersenneTwister::setRange(double start, double end) + void MersenneTwister::setRange(const double start, const double end) { m_uniform_dist = uniform_double(start,end); } @@ -46,13 +63,21 @@ namespace Mantid * the Mersenne Twister 19937 algorithm. * @returns The next number in the pseudo-random sequence */ - double MersenneTwister::next() + double MersenneTwister::nextValue() { /// A variate generator to combine a random number generator with a distribution - uniform_generator uniform_rand(m_generator, m_uniform_dist); + uniform_generator uniform_rand(m_generator, m_uniform_dist); // There is no reason why this call shouldn't be considered const return uniform_rand(); } + /** + * Resets the generator using the value given at the last call to setSeed + */ + void MersenneTwister::reset() + { + setSeed(m_currentSeed); + } + } } diff --git a/Code/Mantid/Framework/Kernel/src/PseudoRandomNumberGenerator.cpp b/Code/Mantid/Framework/Kernel/src/PseudoRandomNumberGenerator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5ba88491efe4b5da72254ccf492ae40593bee0e3 --- /dev/null +++ b/Code/Mantid/Framework/Kernel/src/PseudoRandomNumberGenerator.cpp @@ -0,0 +1,19 @@ +//------------------------------------------------------------------- +// Includes +//------------------------------------------------------------------- +#include "MantidKernel/PseudoRandomNumberGenerator.h" + +namespace Mantid +{ + namespace Kernel + { + /** + * Returns the next value in the 1D sequence as a point to be + * compatible with the NDRandomNumberGenerator interface + */ + std::vector<double> PseudoRandomNumberGenerator::nextPoint() + { + return std::vector<double>(1, this->nextValue()); + } + } +} diff --git a/Code/Mantid/Framework/Kernel/src/SobolSequence.cpp b/Code/Mantid/Framework/Kernel/src/SobolSequence.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c21edd02eafc9b288c1921d9f315209591f70bdd --- /dev/null +++ b/Code/Mantid/Framework/Kernel/src/SobolSequence.cpp @@ -0,0 +1,83 @@ +//------------------------------------------------------------------- +// Includes +//------------------------------------------------------------------- +#include "MantidKernel/SobolSequence.h" +#include <stdexcept> + +namespace Mantid +{ + namespace Kernel + { + /** + * Constructor taking the number of dimensions for the sequence + */ + SobolSequence::SobolSequence(const unsigned int ndims) : + m_gslGenerator(NULL), m_numDims(0), m_currentPoint() + { + setNumberOfDimensions(ndims); + } + + /** + * Destructor + */ + SobolSequence::~SobolSequence() + { + deleteCurrentGenerator(); + } + + /** + * Returns the next number in the sequence + * @returns A double giving the next number in the Sobol sequence for the current dimension + */ + std::vector<double> SobolSequence::nextPoint() + { + gsl_qrng_get(m_gslGenerator, m_currentPoint.data()); + return m_currentPoint; + } + + /** + * Reset state back to the start of the sequence + */ + void SobolSequence::reset() + { + if(m_gslGenerator) + { + gsl_qrng_init(m_gslGenerator); + } + } + + /** + * Sets the number of dimensions for the generator. Note this destroys + * any previous state information + */ + void SobolSequence::setNumberOfDimensions(const unsigned int ndims) + { + gsl_qrng *generator = gsl_qrng_alloc(gsl_qrng_sobol, static_cast<unsigned int>(ndims)); + if(generator) + { + deleteCurrentGenerator(); + m_gslGenerator = generator; + m_numDims = ndims; + m_currentPoint = std::vector<double>(ndims, 0.0); + } + else + { + throw std::invalid_argument("SobolSequence::setNumberOfDimensions - " + "Error initializing sequence, insufficient memory."); + } + } + + /** + * Frees resources allocated by current generator + */ + void SobolSequence::deleteCurrentGenerator() + { + if(m_gslGenerator) + { + gsl_qrng_free(m_gslGenerator); + } + m_gslGenerator = NULL; + } + + } +} diff --git a/Code/Mantid/Framework/Kernel/test/MersenneTwisterTest.h b/Code/Mantid/Framework/Kernel/test/MersenneTwisterTest.h index 37dd9bee925c6e0818207ffeb521c8639086f7cf..7cf022953433d664893114064b40ec3a01aacfd1 100644 --- a/Code/Mantid/Framework/Kernel/test/MersenneTwisterTest.h +++ b/Code/Mantid/Framework/Kernel/test/MersenneTwisterTest.h @@ -15,67 +15,88 @@ public: void test_That_Object_Construction_Does_Not_Throw() { - TS_ASSERT_THROWS_NOTHING(MersenneTwister()); + TS_ASSERT_THROWS_NOTHING(MersenneTwister(1)); } void test_That_Next_For_Given_Seed_Returns_Same_Value() { - MersenneTwister gen_1, gen_2; size_t seed(212437999); - gen_1.setSeed(seed); - gen_2.setSeed(seed); + MersenneTwister gen_1(seed), gen_2(seed); - TS_ASSERT_EQUALS(gen_1.next(), gen_2.next()); + TS_ASSERT_EQUALS(gen_1.nextValue(), gen_2.nextValue()); } void test_That_Next_For_Different_Seeds_Returns_Different_Values() { - MersenneTwister gen_1, gen_2; long seed_1(212437999), seed_2(247021340); - gen_1.setSeed(seed_1); - gen_2.setSeed(seed_2); + MersenneTwister gen_1(seed_1), gen_2(seed_2); - TS_ASSERT_DIFFERS(gen_1.next(), gen_2.next()); + TS_ASSERT_DIFFERS(gen_1.nextValue(), gen_2.nextValue()); } void test_That_A_Given_Seed_Produces_Expected_Sequence() { - MersenneTwister randGen; + MersenneTwister randGen(1); randGen.setSeed(39857239); - double expectedValues[10] = - { 0.203374452656,0.597970068222,0.120683325687,0.92372657801,0.734524340136, - 0.467380537419,0.0712658402044,0.204503614921,0.487210249063,0.885743656661 }; - // Check 10 numbers - for( std::size_t i = 0; i < 10; ++i ) - { - TS_ASSERT_DELTA(randGen.next(), expectedValues[i], 1e-12); - } + assertSequenceCorrectForSeed_39857239(randGen); } + + void test_That_A_Reset_Gives_Same_Sequence_Again_From_Start() + { + MersenneTwister randGen(1); + randGen.setSeed(39857239); + assertSequenceCorrectForSeed_39857239(randGen); + randGen.reset(); + assertSequenceCorrectForSeed_39857239(randGen); + } + void test_That_Default_Range_Produces_Numbers_Between_Zero_And_One() { - MersenneTwister randGen; + MersenneTwister randGen(12345); // Test 20 numbers for( std::size_t i = 0; i < 20; ++i ) { - double r = randGen.next(); + double r = randGen.nextValue(); TS_ASSERT( r >= 0.0 && r <= 1.0 ); } } void test_That_A_Given_Range_Produces_Numbers_Within_This_Range() { + long seed(15423894); const double start(2.5), end(5.); - MersenneTwister randGen; - randGen.setSeed(15423894); - randGen.setRange(start,end); + MersenneTwister randGen(seed, start, end); // Test 20 numbers for( std::size_t i = 0; i < 20; ++i ) { - const double r = randGen.next(); + const double r = randGen.nextValue(); TS_ASSERT(r >= start && r <= end); } + } + + void test_That_nextPoint_returns_1_Value() + { + MersenneTwister randGen(12345); + // Test 20 numbers + for( std::size_t i = 0; i < 20; ++i ) + { + const std::vector<double> point = randGen.nextPoint(); + TS_ASSERT_EQUALS(point.size(), 1); + } + } +private: + void assertSequenceCorrectForSeed_39857239(MersenneTwister &randGen) + { + double expectedValues[10] = + { 0.203374452656,0.597970068222,0.120683325687,0.92372657801,0.734524340136, + 0.467380537419,0.0712658402044,0.204503614921,0.487210249063,0.885743656661 }; + // Check 10 numbers + for( std::size_t i = 0; i < 10; ++i ) + { + TS_ASSERT_DELTA(randGen.nextValue(), expectedValues[i], 1e-12); + } } }; diff --git a/Code/Mantid/Framework/Kernel/test/NDRandomNumberGeneratorTest.h b/Code/Mantid/Framework/Kernel/test/NDRandomNumberGeneratorTest.h new file mode 100644 index 0000000000000000000000000000000000000000..db77917935fa4eac62af57037c2b859954fb4cbe --- /dev/null +++ b/Code/Mantid/Framework/Kernel/test/NDRandomNumberGeneratorTest.h @@ -0,0 +1,44 @@ +#ifndef NDRandomNumberGeneratorTEST_H_ +#define NDRandomNumberGeneratorTEST_H_ + +#include <cxxtest/TestSuite.h> +#include "MantidKernel/NDRandomNumberGenerator.h" + +class NDRandomNumberGeneratorTest : public CxxTest::TestSuite +{ + +private: + // RandomNumberGenerator is an interface so provide a trivial implementation + // for the test + class FakeNDRandomNumberGenerator : public Mantid::Kernel::NDRandomNumberGenerator + { + public: + std::vector<double> nextPoint() + { + return std::vector<double>(); + } + void reset() + { + } + }; + +public: + + void test_That_Next_Returns_Empty() + { + FakeNDRandomNumberGenerator rand_gen; + std::vector<double> point = rand_gen.nextPoint(); + TS_ASSERT(point.empty()); + } + + void test_That_Reset_Does_Nothing() + { + FakeNDRandomNumberGenerator rand_gen; + TS_ASSERT_THROWS_NOTHING(rand_gen.reset()); + } + +}; + + + +#endif diff --git a/Code/Mantid/Framework/Kernel/test/RandomNumberGeneratorTest.h b/Code/Mantid/Framework/Kernel/test/RandomNumberGeneratorTest.h deleted file mode 100644 index 3d80a9d928b47848dad7c42f975c084321caf186..0000000000000000000000000000000000000000 --- a/Code/Mantid/Framework/Kernel/test/RandomNumberGeneratorTest.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef RANDOMNUMBERGENERATORTEST_H_ -#define RANDOMNUMBERGENERATORTEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidKernel/RandomNumberGenerator.h" - -class RandomNumberGeneratorTest : public CxxTest::TestSuite -{ - -private: - // RandomNumberGenerator is an interface so provide a trivial implementation - // for the test - class FakeRandomNumberGenerator : public Mantid::Kernel::RandomNumberGenerator - { - public: - void setSeed(size_t seedValue) - { - UNUSED_ARG(seedValue); - } - void setRange(double start, double end) - { - UNUSED_ARG(start); UNUSED_ARG(end); - } - double next() - { - return 0.0; - } - }; - -public: - - void test_That_Next_Returns_Zero() - { - FakeRandomNumberGenerator rand_gen; - TS_ASSERT_EQUALS(rand_gen.next(), 0.0); - } - - void test_That_SetSeed_Does_Not_Throw() - { - FakeRandomNumberGenerator rand_gen; - TS_ASSERT_THROWS_NOTHING(rand_gen.setSeed(10239048)); - } - - void test_That_Set_Range_Does_Not_Throw() - { - FakeRandomNumberGenerator rand_gen; - TS_ASSERT_THROWS_NOTHING(rand_gen.setRange(0.,1.0)); - } - -}; - - - -#endif diff --git a/Code/Mantid/Framework/Kernel/test/SobolSequenceTest.h b/Code/Mantid/Framework/Kernel/test/SobolSequenceTest.h new file mode 100644 index 0000000000000000000000000000000000000000..b410f78b5b455e78e7577955f210f66e7a5b1eb1 --- /dev/null +++ b/Code/Mantid/Framework/Kernel/test/SobolSequenceTest.h @@ -0,0 +1,79 @@ +#ifndef SOBOLSEQUENCETEST_H_ +#define SOBOLSEQUENCETEST_H_ + +#include <cxxtest/TestSuite.h> +#include "MantidKernel/SobolSequence.h" +#include <iostream> +#include <iomanip> + +using Mantid::Kernel::SobolSequence; + +class SobolSequenceTest : public CxxTest::TestSuite +{ + +public: + + void test_That_Object_Construction_Does_Not_Throw() + { + TS_ASSERT_THROWS_NOTHING(SobolSequence(1)); + } + + void test_That_Next_For_Two_Generators_Returns_Same_Value() + { + SobolSequence gen_1(3), gen_2(3); + const std::vector<double> seq1 = gen_1.nextPoint(); + const std::vector<double> seq2 = gen_2.nextPoint(); + assertVectorValuesEqual(seq1,seq2); + } + + void test_That_A_Given_Seed_Produces_Expected_Sequence() + { + SobolSequence randGen(5); + double expectedValues[3][5] = \ + { + {0.5,0.5,0.5,0.5,0.5}, + {0.75,0.25,0.75,0.25,0.75}, + {0.25,0.75,0.25,0.75,0.25}, + }; + // Check 10 numbers + for( std::size_t i = 0; i < 3; ++i ) + { + const std::vector<double> randPoint = randGen.nextPoint(); + for( std::size_t j = 0; j < 5; ++j) + { + TS_ASSERT_DELTA(randPoint[j], expectedValues[i][j], 1e-12); + } + } + } + +private: + void assertVectorValuesEqual(const std::vector<double> lhs, const std::vector<double> rhs) + { + TS_ASSERT_EQUALS(lhs.size(), rhs.size()); + assertVectorValuesOp(lhs, rhs, true); + } + + void assertVectorValuesDiffer(const std::vector<double> lhs, const std::vector<double> rhs) + { + return assertVectorValuesOp(lhs, rhs, false); + } + + void assertVectorValuesOp(const std::vector<double> lhs, const std::vector<double> rhs, const bool same) + { + for(size_t i = 0; i < lhs.size(); ++i) + { + if(same) + { + TS_ASSERT_EQUALS(lhs[i], rhs[i]); + } + else + { + TS_ASSERT_DIFFERS(lhs[i], rhs[i]); + } + } + } + +}; + + +#endif diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateMDD.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateMDD.h index 2ce5d9e02c7dc4dc7427033655b8fd55e69739a8..50c78d9154c4a2ac616d82e4d2fb83f892f7e76f 100644 --- a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateMDD.h +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateMDD.h @@ -6,7 +6,6 @@ //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidAPI/IMDWorkspace.h" -#include "MantidKernel/RandomNumberGenerator.h" #include "MantidKernel/Tolerance.h" #include "MantidGeometry/Math/mathSupport.h" diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateResolution.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateResolution.h index e52ed474ef96c1704ba2c978879d0013ba9c2aa8..e8c74ec5ea6201d24be41f45de6428a1cb75f531 100644 --- a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateResolution.h +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SimulateResolution.h @@ -5,7 +5,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/ParamFunction.h" -#include "MantidKernel/RandomNumberGenerator.h" +#include "MantidKernel/PseudoRandomNumberGenerator.h" #include "MantidAPI/IFunctionMD.h" #include "MantidAPI/IMDWorkspace.h" #include "MantidAPI/IMDIterator.h" @@ -128,7 +128,7 @@ namespace Mantid /// Reset random number generators void resetRandomNumbers(); /// A pointer to the random number generator - Kernel::RandomNumberGenerator *m_randGen; + Kernel::PseudoRandomNumberGenerator *m_randGen; /// function to evaluate y/(1-exp(-y)) including y=0 and large -ve y double pop(const double) const; /// function to calculate bose factor diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TobyFitSimulate.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TobyFitSimulate.h index d8f0d2f605bea398e484c32fa0947e43c05842c0..ad40c1d1b96a3945f424947c5928fa8846cc1e93 100644 --- a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TobyFitSimulate.h +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TobyFitSimulate.h @@ -5,7 +5,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/IMDWorkspace.h" -#include "MantidKernel/RandomNumberGenerator.h" +#include "MantidKernel/PseudoRandomNumberGenerator.h" #include "MantidMDAlgorithms/RunParam.h" #include "MantidKernel/Tolerance.h" @@ -68,7 +68,7 @@ namespace Mantid /// Reset random number generators void resetRandomNumbers(); /// A pointer to the random number generator - Kernel::RandomNumberGenerator *m_randGen; + Kernel::PseudoRandomNumberGenerator *m_randGen; /// Sample S(Q,eps) function from tobyfit double sqwBroad601(const std::vector<double> &, const std::vector<double> & , const double, const Kernel::Matrix<double> & ); diff --git a/Code/Mantid/Framework/MDAlgorithms/src/SimulateResolution.cpp b/Code/Mantid/Framework/MDAlgorithms/src/SimulateResolution.cpp index 307b603e436eb0d61a3d5e7baf7e50056edfc392..81e9ebf2fad2503747686a8637779e19008ba77a 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/SimulateResolution.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/SimulateResolution.cpp @@ -33,9 +33,8 @@ namespace Mantid m_magForm = boost::shared_ptr<MDAlgorithms::MagneticFormFactor>( new MagneticFormFactor(0,0,500) ); if( !m_randGen ) { - m_randGen = new Kernel::MersenneTwister; int seedValue = 12345; - m_randGen->setSeed(seedValue); + m_randGen = new Kernel::MersenneTwister(seedValue); } m_mcOptVec.resize(9,true);; // Nine processes are modelled in current implementation m_mcVarCount.resize(m_mcOptVec.size()); @@ -233,7 +232,7 @@ namespace Mantid point.resize(m_randSize); if(m_random==mTwister) { for(size_t i=0;i<point.size();i++) - point[i]=m_randGen->next(); + point[i]=m_randGen->nextValue(); } else { @@ -260,8 +259,9 @@ namespace Mantid else //Non Sobol random numbers { if( !m_randGen ) - m_randGen = new Kernel::MersenneTwister; - m_randGen->setSeed(m_randSeed); + m_randGen = new Kernel::MersenneTwister(m_randSeed); + else + m_randGen->setSeed(m_randSeed); } } diff --git a/Code/Mantid/Framework/MDAlgorithms/src/TobyFitSimulate.cpp b/Code/Mantid/Framework/MDAlgorithms/src/TobyFitSimulate.cpp index 39269ff0b46a9b69130f8766f25221bb661ce4bd..afebf64026f7c4b966c095809d7996e90ea8484d 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/TobyFitSimulate.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/TobyFitSimulate.cpp @@ -4,7 +4,6 @@ #include "MantidMDAlgorithms/TobyFitSimulate.h" #include <math.h> -// @todo: This needs a factory (copied from MC Absorbtion algo) #include "MantidKernel/MersenneTwister.h" #include <gsl/gsl_errno.h> @@ -76,7 +75,7 @@ namespace Mantid { if(!m_sobol) { for(int i=0;i<count;i++) - point[i]=m_randGen->next(); + point[i]=m_randGen->nextValue(); } } @@ -87,8 +86,7 @@ namespace Mantid { if( !m_randGen ) { - m_randGen = new Kernel::MersenneTwister; - m_randGen->setSeed(m_randSeed); + m_randGen = new Kernel::MersenneTwister(m_randSeed); } }