[Rcpp-commits] r3538 - in pkg/RcppSMC: . deprecated inst/include man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 21 13:13:20 CET 2012


Author: edd
Date: 2012-03-21 13:13:19 +0100 (Wed, 21 Mar 2012)
New Revision: 3538

Added:
   pkg/RcppSMC/deprecated/rng.cpp
   pkg/RcppSMC/deprecated/rng.h
Removed:
   pkg/RcppSMC/inst/include/rng.h
   pkg/RcppSMC/src/rng.cpp
Modified:
   pkg/RcppSMC/ChangeLog
   pkg/RcppSMC/TODO
   pkg/RcppSMC/inst/include/moveset.h
   pkg/RcppSMC/inst/include/rngR.h
   pkg/RcppSMC/inst/include/sampler.h
   pkg/RcppSMC/inst/include/smctc.h
   pkg/RcppSMC/man/pfLineartBS.Rd
Log:
moves old GSL RNGs code to deprecated/
clean up more header files w.r.t. to that RNG change
calls callback-to-R variant of pfLineartBS only iff interactive() is TRUE


Modified: pkg/RcppSMC/ChangeLog
===================================================================
--- pkg/RcppSMC/ChangeLog	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/ChangeLog	2012-03-21 12:13:19 UTC (rev 3538)
@@ -1,8 +1,16 @@
+2012-03-21  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/rng.cpp: Moved old GSL-based RNG code to deprecated/
+	* inst/include/rng.h: Idem
+	* man/pfLineartBS.Rd: Callback-to-R example only if interactive()
+
 2012-03-21  Adam Johansen <a.m.johansen at warwick.ac.uk>
+
 	* R/pfLineartBS.R Added function to dynamically set the range of
 	the online plot.
 
 2012-03-19  Adam Johansen <a.m.johansen at warwick.ac.uk>
+
 	* R/simGaussian.R Added data-simulating function
 	* R/simLineart.R Idem
 	* R/simNonlin.R Idem
@@ -16,7 +24,7 @@
 	* R/pfLineartBS.R: Adjust naming of the two helper functions
 	* man/pfLineartBS.Rd: Idem
 
-2012-03-18 Adam Johansen <a.m.johansen at warwick.ac.uk>
+2012-03-18  Adam Johansen <a.m.johansen at warwick.ac.uk>
 
 	* src/pfEx.cpp renamed to pflineartbs.cpp
 	* inst/include/pffuncs.h renamed to pflineartbs.h

Modified: pkg/RcppSMC/TODO
===================================================================
--- pkg/RcppSMC/TODO	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/TODO	2012-03-21 12:13:19 UTC (rev 3538)
@@ -1,11 +1,6 @@
 
  * Add more examples
 
- * Maybe rename example 1 from the JSS paper -- what would be a good
-   name instead of 'pfEx'? Idem for the C++ code.
-
  * For blockpfGaussianOpt et al, we could be fancy and return an S3 object
    with a plot method.  Maybe later.
 
- * Once we are happy with the GSL -> R rng switch, we can remove all
-   commented-out references to the GSL

Copied: pkg/RcppSMC/deprecated/rng.cpp (from rev 3536, pkg/RcppSMC/src/rng.cpp)
===================================================================
--- pkg/RcppSMC/deprecated/rng.cpp	                        (rev 0)
+++ pkg/RcppSMC/deprecated/rng.cpp	2012-03-21 12:13:19 UTC (rev 3538)
@@ -0,0 +1,248 @@
+#if 0
+#include <iostream>
+#include <cstring>
+
+//! \file
+//! \brief This file contains the untemplated functions used for dealing with random number generation.
+
+#include "rng"
+#include "smctc"
+
+namespace smc {
+    ///The GSL provides a mechanism for obtaining a list of available random number generators.
+    ///
+    ///This class provides a wrapper for this mechanism and makes it simple to implement software which allows
+    ///the nature of the random number generator to be specified at runtime (and to allow it to be a user-specifiable
+    ///parameter).
+    ///
+    ///For example, gslrnginfo::GetNumber can be used to determine how many RNGs are available and gslrnginfo::GetNameByIndex
+    ///can then be used to populate a list box with their names. Once the user has selected on the gslrnginfo::GetPointerByName
+    ///function can be used to obtain a pointer to the appropriate type and this can be used to produce a random number generator
+    ///of the desired type.
+    ///
+    ///There should be exactly one instance of this class in any program, and that instance is created by
+    ///the library. A singleton DP implementation ensures that any additional attempt to instatiate the class simply returns 
+    ///a reference to the existing instance.
+
+    gslrnginfo::gslrnginfo()
+    {
+	typePtArray = gsl_rng_types_setup();
+
+	const gsl_rng_type** ptIndex = typePtArray;
+	nNumber = 0;
+	while(ptIndex[0]) {
+	    ptIndex++;
+	    nNumber++;
+	}
+	return;
+    }
+
+    ///Returns a pointer to a single instance of this class.
+    gslrnginfo* gslrnginfo::GetInstance()
+    {
+	static gslrnginfo ginfo;
+
+	return &ginfo;
+    }
+
+    ///This function returns the number of available generators
+    int gslrnginfo::GetNumber(void)
+    {
+	return nNumber;
+    }
+
+    ///This function returns the name of the specified generator
+    const char* gslrnginfo::GetNameByIndex(int nIndex)
+    {
+	if(0 <= nIndex && nIndex < nNumber)
+	    return typePtArray[nIndex]->name;
+	return NULL;
+    }
+
+    ///This function returns a pointer to the specified generator type
+    const gsl_rng_type* gslrnginfo::GetPointerByIndex(int nIndex)
+    {
+	if(0 <= nIndex && nIndex < nNumber)
+	    return typePtArray[nIndex];
+	return NULL;
+    }
+
+    ///This function returns a pointer to the specified generator type
+    const gsl_rng_type* gslrnginfo::GetPointerByName(const char* szName)
+    {
+	for(int n = 0; n < nNumber; n++)
+	    if(!strcmp(typePtArray[n]->name, szName))
+		return typePtArray[n];
+
+	return NULL;
+    }
+
+
+    ///When called without any arguments, the constructor for the smc::rng class simply allocates a buffer for a
+    ///random number generator of type gsl_rng_default (something which can be set at run-time via an environment
+    ///variable) using its default seed (which again can be over-ridden using an environment variable).
+    rng::rng(void)
+    {
+	gsl_rng_env_setup();
+	type = gsl_rng_default;
+	pWorkspace = gsl_rng_alloc(gsl_rng_default);
+    }
+
+    ///When called with a single argument, the constructor for the smc::rng class allocates a buffer for a
+    ///random number generator of the specified type and initialises it with the default seed (which can be set using
+    ///and environment variable if one wishes to vary it at run-time).
+    ///
+    ///\param Type The type of a GSL random number generator
+    rng::rng(const gsl_rng_type* Type)
+    {
+	gsl_rng_env_setup();
+	type = Type;
+	pWorkspace = gsl_rng_alloc(Type);
+    }
+
+    ///When called with a pair of arguments, the constructor for the smc::rng class allocates a buffer for the specified
+    ///random number generator type and initialises it with the specified seed (note that zero has special significance and
+    ///is used to specify the seed with which the generator was originally used).
+    ///
+    ///\param Type The type of a GSL random number generator
+    ///\param lSeed The value with which the generator is to be seeded
+    rng::rng(const gsl_rng_type* Type, unsigned long int lSeed)
+    {
+	gsl_rng_env_setup();
+	type = Type;
+	pWorkspace = gsl_rng_alloc(Type);
+	gsl_rng_set(pWorkspace, lSeed);
+    }
+
+    ///The destructor presently does no more than call the gsl_rng_free function to deallocate the memory which was
+    ///previously allocate to the random number generator.
+    rng::~rng()
+    {
+	gsl_rng_free(pWorkspace);    
+    }
+
+    ///This function returns a pointer to the underlying GSL random number generator which may be used to provide random
+    ///number facilities which are not explicitly provided by the intermediate layer of smc::rng.
+    gsl_rng* rng::GetRaw(void)
+    {
+	return pWorkspace;
+    }
+
+    ///This function simply passes the relevant arguments on to gsl_ran_multinomial.
+    ///     \param n Number of entities to assign.
+    ///     \param k Number of categories.
+    ///     \param w Weights of category elements
+    ///     \param X Array in which to return the sample values.
+    void rng::Multinomial(unsigned n, unsigned k, const double* w, unsigned* X)
+    {
+	gsl_ran_multinomial(pWorkspace, k, n, w, X);
+    }
+
+
+    ///This function simply calls gsl_rng_uniform_int and shifts the
+    /// result as appropriate such that the result is an integer generated uniformly from those between
+    /// the two arguments (inclusive of those points).
+    ///
+    ///     \param lMin The smallest value which can be returned
+    ///      \param lMax the largest value which can be returned
+    long rng::UniformDiscrete(long lMin, long lMax)
+    {
+	return gsl_rng_uniform_int(pWorkspace, lMax - lMin + 1) + lMin;
+    }
+
+    ///This function simply calls gsl_ran_beta with the specified parameters.
+    ///     \param da The parameter associated with "x".
+    ///     \paran db The parameter associated with "1-x".
+    double rng::Beta(double da, double db)
+    {
+	return gsl_ran_beta(pWorkspace, da, db);
+    }
+
+    ///This function simply calls gsl_ran_cauchy with the specified parameter.
+    ///     \param dScale The scale parameter of the distribution.
+    double rng::Cauchy(double dScale)
+    {
+	return gsl_ran_cauchy(pWorkspace, dScale);
+    }
+
+    ///This function simply calls gsl_ran_exponential with the specified parameters.
+    ///     \param dMean The scale (not rate) (and mean) of the distribution.
+    double rng::Exponential(double dMean)
+    {
+	return gsl_ran_exponential(pWorkspace, dMean);
+    }
+
+    ///This function simply calls gsl_ran_gamma with the specified parameters.
+    ///     \param dAlpha The shape of the distribution (integers lead to Erlang distributions)
+    ///     \param dBeta The scale (not rate) of the distribution.
+    double rng::Gamma(double dAlpha, double dBeta)
+    {
+	return gsl_ran_gamma(pWorkspace, dAlpha, dBeta);
+    }
+
+    ///This function simply calls gsl_ran_laplace with the specified parameters.
+    ///     \param dScale The scale (not rate) of the distribution.
+    ///
+    double rng::Laplacian(double dScale)
+    {
+	return gsl_ran_laplace(pWorkspace, dScale);
+    }
+
+    ///This function simply calls gsl_ran_lognormal with the specified parameters.
+    ///     \param dMu The location parameter of the distribution.
+    ///     \param dSigma The scale parameter of the distribution.
+    double rng::Lognormal(double dMu, double dSigma)
+    {
+	return gsl_ran_lognormal(pWorkspace, dMu, dSigma);
+    }
+
+    ///This function simply calls gsl_ran_gaussian with the specified standard deviation and shifts the result.
+    ///     \param dMean The mean of the distribution.
+    ///     \param dStd  The standard deviation of the distribution
+    double rng::Normal(double dMean, double dStd)
+    {
+	return dMean + gsl_ran_gaussian(pWorkspace, dStd);
+    }
+  
+    ///This function simply calls gsl_ran_ugaussian returns the result. 
+    double rng::NormalS(void)
+    {
+	return gsl_ran_ugaussian(pWorkspace);
+    }
+
+    ///This function simply calls gsl_ran_gaussian_tail with the specified parameters and performs appropriate shifting.
+    ///     \param dMean The mean of the distribution.
+    ///     \param dStd  The standard deviation of the distribution
+    ///     \param dThreshold The lower truncation threshold.
+    double rng::NormalTruncated(double dMean, double dStd, double dThreshold)
+    {
+	return dMean + gsl_ran_gaussian_tail(pWorkspace, dThreshold - dMean, dStd);
+    }
+
+    ///This function simply calls gsl_ran_tdist with the specified number of degrees of freedom.
+    ///     \param dDF The number of degrees of freedom.
+    double rng::StudentT(double dDF)
+    {
+	return gsl_ran_tdist(pWorkspace, dDF);
+    }
+
+    ///This function simply calls gsl_rng_uniform and scales and shifts appropriately. 
+    ///     \param dMin The lowest value with positive density.
+    ///     \param dMax The largest value with positive density.
+    double rng::Uniform(double dMin, double dMax)
+    {
+	double rValue;
+ 
+	rValue = gsl_rng_uniform(pWorkspace);
+	rValue *= (dMax - dMin);
+	rValue += dMin;
+
+	return rValue;
+    }
+
+    ///This function simply calls gsl_rng_uniform. 
+    double rng::UniformS(void) {
+	return gsl_rng_uniform(pWorkspace); 
+    }
+}
+#endif

Copied: pkg/RcppSMC/deprecated/rng.h (from rev 3536, pkg/RcppSMC/inst/include/rng.h)
===================================================================
--- pkg/RcppSMC/deprecated/rng.h	                        (rev 0)
+++ pkg/RcppSMC/deprecated/rng.h	2012-03-21 12:13:19 UTC (rev 3538)
@@ -0,0 +1,124 @@
+#if 0
+//  SMCTC: rng.hh  
+//
+//   Copyright Adam Johansen, 2008-2009.
+// 
+//   This file is part of SMCTC.
+//
+//   SMCTC 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.
+//
+//   SMCTC 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 SMCTC.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+//! \file 
+//! \brief Random number generation.
+//!
+//! This file contains the definitions for the smc::rng and smc::rnginfo class.
+//! It wraps the random number generation facilities provided by the GSL and provides a convenient interfaces to access several of its more commonly-used features.
+
+#ifndef __SMC_RNG_HH
+#define __SMC_RNG_HH 1.0
+
+extern "C" {
+#include <gsl/gsl_randist.h>
+#include <gsl/gsl_rng.h>
+}
+
+namespace smc {
+  ///A gsl-rng information handling class (not templated)
+  class gslrnginfo {
+  private:
+    ///This is a null terminated array of the available random number generators.
+    const gsl_rng_type** typePtArray;
+    ///The number of available random number generators.
+    int nNumber;
+
+  protected:
+    gslrnginfo();
+
+  public:
+    ///Returns a reference to the sole static instance of this class.
+    static gslrnginfo* GetInstance();
+
+    ///Returns the number of available random number generators.
+    int GetNumber();
+    ///Returns the name of random number generator number nIndex.
+    const char* GetNameByIndex(int nIndex);
+    ///Returns a pointer to random number generator nIndex.
+    const gsl_rng_type* GetPointerByIndex(int nIndex);
+    ///Returns a pointer to the random number generator with name szName (or null if it doesn't exist).
+    const gsl_rng_type* GetPointerByName(const char* szName);
+  };
+
+  ///The global application instance of the gslrnginfo class:
+  extern gslrnginfo rngset;
+
+  ///A random number generator class.
+
+  ///    At present this serves as a wrapper for the gsl random number generation code.
+  class rng {
+  private:
+    ///This is the type of random number generator underlying the class.
+    const gsl_rng_type* type;
+    ///This is a pointer to the internal workspace of the rng including its current state.
+    gsl_rng* pWorkspace;
+
+  public:
+    ///Initialise the random number generator using default settings
+    rng();
+    ///Initialise the random number generator using the default seed for the type
+    rng(const gsl_rng_type* Type);
+    ///Initialise the random number generator using specified type and seed
+    rng(const gsl_rng_type* Type,unsigned long int lSeed);
+
+    ///Free the workspace allocated for random number generation
+    ~rng();
+
+
+    ///Provide access to the raw random number generator
+    gsl_rng* GetRaw(void);
+
+    ///Generate a multinomial random vector with parameters (n,w[1:k]) and store it in X
+    void Multinomial(unsigned n, unsigned k, const double* w, unsigned* X);
+    ///Returns a random integer generated uniformly between the minimum and maximum values specified
+    long UniformDiscrete(long lMin, long lMax);
+
+    ///Returns a random number generated from a Beta distribution with the specified parameters.
+    double Beta(double da, double db);
+    ///Returns a random number generated from a Cauchy distribution with the specified scale parameter.
+    double Cauchy(double dScale);
+    ///Returns a random number generated from an exponential distribution with the specified mean.
+    double Exponential(double dMean);
+    ///Return a random number generated from a gamma distribution with shape alpha and scale beta.
+    double Gamma(double dAlpha, double dBeta);
+    ///Returns a random number generated from a Laplacian distribution with the specified scale.
+    double Laplacian(double dScale);
+    ///Returns a random number generated from a Lognormal distribution of location mu and scale sigma
+    double Lognormal(double dMu, double dSigma);
+    ///Return a random number generated from a normal distribution with a specified mean and standard deviation
+    double Normal(double dMean, double dStd);
+    ///Return a random number generated from a standard normal distribution
+    double NormalS(void);
+    ///Returns a random number from a normal distribution, conditional upon it exceeding the specified threshold.
+    double NormalTruncated(double dMean, double dStd, double dThreshold);
+    ///Return a student-t random number generated with a specified number of degrees of freedom
+    double StudentT(double dDF);
+    ///Return a random number generated uniformly between dMin and dMax
+    double Uniform(double dMin, double dMax);    
+    ///Returns a random number generated from the standard uniform[0,1) distribution
+    double UniformS(void);
+  };
+}
+ 
+ 
+#endif
+#endif

Modified: pkg/RcppSMC/inst/include/moveset.h
===================================================================
--- pkg/RcppSMC/inst/include/moveset.h	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/inst/include/moveset.h	2012-03-21 12:13:19 UTC (rev 3538)
@@ -28,7 +28,6 @@
 #define __SMC_MOVESET_HH 1.0
 
 #include "particle.h"
-//#include "rng.hh"
 
 namespace smc {
   /// A template class for a set of moves for use in an SMC samplers framework.

Deleted: pkg/RcppSMC/inst/include/rng.h
===================================================================
--- pkg/RcppSMC/inst/include/rng.h	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/inst/include/rng.h	2012-03-21 12:13:19 UTC (rev 3538)
@@ -1,124 +0,0 @@
-#if 0
-//  SMCTC: rng.hh  
-//
-//   Copyright Adam Johansen, 2008-2009.
-// 
-//   This file is part of SMCTC.
-//
-//   SMCTC 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.
-//
-//   SMCTC 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 SMCTC.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-//! \file 
-//! \brief Random number generation.
-//!
-//! This file contains the definitions for the smc::rng and smc::rnginfo class.
-//! It wraps the random number generation facilities provided by the GSL and provides a convenient interfaces to access several of its more commonly-used features.
-
-#ifndef __SMC_RNG_HH
-#define __SMC_RNG_HH 1.0
-
-extern "C" {
-#include <gsl/gsl_randist.h>
-#include <gsl/gsl_rng.h>
-}
-
-namespace smc {
-  ///A gsl-rng information handling class (not templated)
-  class gslrnginfo {
-  private:
-    ///This is a null terminated array of the available random number generators.
-    const gsl_rng_type** typePtArray;
-    ///The number of available random number generators.
-    int nNumber;
-
-  protected:
-    gslrnginfo();
-
-  public:
-    ///Returns a reference to the sole static instance of this class.
-    static gslrnginfo* GetInstance();
-
-    ///Returns the number of available random number generators.
-    int GetNumber();
-    ///Returns the name of random number generator number nIndex.
-    const char* GetNameByIndex(int nIndex);
-    ///Returns a pointer to random number generator nIndex.
-    const gsl_rng_type* GetPointerByIndex(int nIndex);
-    ///Returns a pointer to the random number generator with name szName (or null if it doesn't exist).
-    const gsl_rng_type* GetPointerByName(const char* szName);
-  };
-
-  ///The global application instance of the gslrnginfo class:
-  extern gslrnginfo rngset;
-
-  ///A random number generator class.
-
-  ///    At present this serves as a wrapper for the gsl random number generation code.
-  class rng {
-  private:
-    ///This is the type of random number generator underlying the class.
-    const gsl_rng_type* type;
-    ///This is a pointer to the internal workspace of the rng including its current state.
-    gsl_rng* pWorkspace;
-
-  public:
-    ///Initialise the random number generator using default settings
-    rng();
-    ///Initialise the random number generator using the default seed for the type
-    rng(const gsl_rng_type* Type);
-    ///Initialise the random number generator using specified type and seed
-    rng(const gsl_rng_type* Type,unsigned long int lSeed);
-
-    ///Free the workspace allocated for random number generation
-    ~rng();
-
-
-    ///Provide access to the raw random number generator
-    gsl_rng* GetRaw(void);
-
-    ///Generate a multinomial random vector with parameters (n,w[1:k]) and store it in X
-    void Multinomial(unsigned n, unsigned k, const double* w, unsigned* X);
-    ///Returns a random integer generated uniformly between the minimum and maximum values specified
-    long UniformDiscrete(long lMin, long lMax);
-
-    ///Returns a random number generated from a Beta distribution with the specified parameters.
-    double Beta(double da, double db);
-    ///Returns a random number generated from a Cauchy distribution with the specified scale parameter.
-    double Cauchy(double dScale);
-    ///Returns a random number generated from an exponential distribution with the specified mean.
-    double Exponential(double dMean);
-    ///Return a random number generated from a gamma distribution with shape alpha and scale beta.
-    double Gamma(double dAlpha, double dBeta);
-    ///Returns a random number generated from a Laplacian distribution with the specified scale.
-    double Laplacian(double dScale);
-    ///Returns a random number generated from a Lognormal distribution of location mu and scale sigma
-    double Lognormal(double dMu, double dSigma);
-    ///Return a random number generated from a normal distribution with a specified mean and standard deviation
-    double Normal(double dMean, double dStd);
-    ///Return a random number generated from a standard normal distribution
-    double NormalS(void);
-    ///Returns a random number from a normal distribution, conditional upon it exceeding the specified threshold.
-    double NormalTruncated(double dMean, double dStd, double dThreshold);
-    ///Return a student-t random number generated with a specified number of degrees of freedom
-    double StudentT(double dDF);
-    ///Return a random number generated uniformly between dMin and dMax
-    double Uniform(double dMin, double dMax);    
-    ///Returns a random number generated from the standard uniform[0,1) distribution
-    double UniformS(void);
-  };
-}
- 
- 
-#endif
-#endif

Modified: pkg/RcppSMC/inst/include/rngR.h
===================================================================
--- pkg/RcppSMC/inst/include/rngR.h	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/inst/include/rngR.h	2012-03-21 12:13:19 UTC (rev 3538)
@@ -2,7 +2,8 @@
 //
 // rngR.h: Rcpp wrapper for SMC library -- R-only RNG class
 //
-// Copyright (C) 2012         Dirk Eddelbuettel
+// Copyright (C) 2008 - 2009  Adam Johansen
+// Copyright (C) 2012         Dirk Eddelbuettel and Adam Johansen
 //
 // This file is part of RcppSMC.
 //
@@ -19,17 +20,6 @@
 // You should have received a copy of the GNU General Public License
 // along with RInside.  If not, see <http://www.gnu.org/licenses/>.
 
-// RcppSMC builds on top of, and wraps, SMCTC which is
-//
-//   Copyright Adam Johansen, 2008-2009.
-//
-// and released under GPL-3, see the copyright headers in inst/include/ 
-//
-// The main reason rngR.h was written was to provide a drop-in replacement,
-// maintaining the same API, but not requiring the GNU GSL -- as GNU R 
-// already provides what we need.  The text below is very lightly edited, and 
-// if it refers to the GSL was probably written by Adam Johansen for SMCTC.
-// I added a few comments with handle 'DEdd'   -- Dirk Eddelbuettel, Jan 2012
 
 //! \file 
 //! \brief Random number generation.
@@ -43,8 +33,8 @@
 #include <Rcpp.h>
 
 namespace smc {
-    ///A gsl-rng information handling class (not templated)
-    ///DEdd: Now essentially empty
+    /// A GSL-RNG information handling class (not templated)
+    /// Now essentially empty as using R RNGs requires less state
     class gslrnginfo {
     private:
         ///This is a null terminated array of the available random number generators.
@@ -54,7 +44,7 @@
 
     protected:
         gslrnginfo() { 
-            // DEdd: nothing to do for us
+            // Nothing to do for us
         }
 
     public:
@@ -78,7 +68,7 @@
     ///A random number generator class.
 
     ///    At present this serves as a wrapper for the gsl random number generation code.
-    ///    DEdd: Rewritten for R package using R's RNGs
+    ///    Rewritten for R package using R's RNGs
     class rng {
     private:
         ///This is the type of random number generator underlying the class.
@@ -86,7 +76,7 @@
         ///This is a pointer to the internal workspace of the rng including its current state.
         //gsl_rng* pWorkspace;
 
-        Rcpp::RNGScope *scopeptr; 	// DEdd: RNGScope saves and later restores R's RNG state 
+        Rcpp::RNGScope *scopeptr; 	// RNGScope saves and later restores R's RNG state 
 
     public:
         ///Initialise the random number generator using default settings

Modified: pkg/RcppSMC/inst/include/sampler.h
===================================================================
--- pkg/RcppSMC/inst/include/sampler.h	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/inst/include/sampler.h	2012-03-21 12:13:19 UTC (rev 3538)
@@ -30,7 +30,7 @@
 #include <cstdlib>
 #include <iostream>
 
-#include "rng.h"
+#include "rngR.h"
 #include "history.h"
 #include "moveset.h"
 #include "particle.h"

Modified: pkg/RcppSMC/inst/include/smctc.h
===================================================================
--- pkg/RcppSMC/inst/include/smctc.h	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/inst/include/smctc.h	2012-03-21 12:13:19 UTC (rev 3538)
@@ -98,7 +98,6 @@
 #include <cstdlib>
 #include <iostream>
 
-//#include <gsl/gsl_rng.h>
 #include "rngR.h"
 
 #include "smc-exception.h"

Modified: pkg/RcppSMC/man/pfLineartBS.Rd
===================================================================
--- pkg/RcppSMC/man/pfLineartBS.Rd	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/man/pfLineartBS.Rd	2012-03-21 12:13:19 UTC (rev 3538)
@@ -63,7 +63,8 @@
 \seealso{The SMCTC paper and code at \url{http://www.jstatsoft.org/v30/i06/paper}.}
 \examples{
   res <- pfLineartBS(plot=TRUE)
-  res <- pfLineartBS(onlinePlot=pfLineartBSOnlinePlot)
+  if (interactive()) ## if not running R CMD check etc
+     res <- pfLineartBS(onlinePlot=pfLineartBSOnlinePlot)
 }
 \author{Adam M. Johansen and Dirk Eddelbuettel}
 \keyword{programming}

Deleted: pkg/RcppSMC/src/rng.cpp
===================================================================
--- pkg/RcppSMC/src/rng.cpp	2012-03-21 11:58:45 UTC (rev 3537)
+++ pkg/RcppSMC/src/rng.cpp	2012-03-21 12:13:19 UTC (rev 3538)
@@ -1,248 +0,0 @@
-#if 0
-#include <iostream>
-#include <cstring>
-
-//! \file
-//! \brief This file contains the untemplated functions used for dealing with random number generation.
-
-#include "rng"
-#include "smctc"
-
-namespace smc {
-    ///The GSL provides a mechanism for obtaining a list of available random number generators.
-    ///
-    ///This class provides a wrapper for this mechanism and makes it simple to implement software which allows
-    ///the nature of the random number generator to be specified at runtime (and to allow it to be a user-specifiable
-    ///parameter).
-    ///
-    ///For example, gslrnginfo::GetNumber can be used to determine how many RNGs are available and gslrnginfo::GetNameByIndex
-    ///can then be used to populate a list box with their names. Once the user has selected on the gslrnginfo::GetPointerByName
-    ///function can be used to obtain a pointer to the appropriate type and this can be used to produce a random number generator
-    ///of the desired type.
-    ///
-    ///There should be exactly one instance of this class in any program, and that instance is created by
-    ///the library. A singleton DP implementation ensures that any additional attempt to instatiate the class simply returns 
-    ///a reference to the existing instance.
-
-    gslrnginfo::gslrnginfo()
-    {
-	typePtArray = gsl_rng_types_setup();
-
-	const gsl_rng_type** ptIndex = typePtArray;
-	nNumber = 0;
-	while(ptIndex[0]) {
-	    ptIndex++;
-	    nNumber++;
-	}
-	return;
-    }
-
-    ///Returns a pointer to a single instance of this class.
-    gslrnginfo* gslrnginfo::GetInstance()
-    {
-	static gslrnginfo ginfo;
-
-	return &ginfo;
-    }
-
-    ///This function returns the number of available generators
-    int gslrnginfo::GetNumber(void)
-    {
-	return nNumber;
-    }
-
-    ///This function returns the name of the specified generator
-    const char* gslrnginfo::GetNameByIndex(int nIndex)
-    {
-	if(0 <= nIndex && nIndex < nNumber)
-	    return typePtArray[nIndex]->name;
-	return NULL;
-    }
-
-    ///This function returns a pointer to the specified generator type
-    const gsl_rng_type* gslrnginfo::GetPointerByIndex(int nIndex)
-    {
-	if(0 <= nIndex && nIndex < nNumber)
-	    return typePtArray[nIndex];
-	return NULL;
-    }
-
-    ///This function returns a pointer to the specified generator type
-    const gsl_rng_type* gslrnginfo::GetPointerByName(const char* szName)
-    {
-	for(int n = 0; n < nNumber; n++)
-	    if(!strcmp(typePtArray[n]->name, szName))
-		return typePtArray[n];
-
-	return NULL;
-    }
-
-
-    ///When called without any arguments, the constructor for the smc::rng class simply allocates a buffer for a
-    ///random number generator of type gsl_rng_default (something which can be set at run-time via an environment
-    ///variable) using its default seed (which again can be over-ridden using an environment variable).
-    rng::rng(void)
-    {
-	gsl_rng_env_setup();
-	type = gsl_rng_default;
-	pWorkspace = gsl_rng_alloc(gsl_rng_default);
-    }
-
-    ///When called with a single argument, the constructor for the smc::rng class allocates a buffer for a
-    ///random number generator of the specified type and initialises it with the default seed (which can be set using
-    ///and environment variable if one wishes to vary it at run-time).
-    ///
-    ///\param Type The type of a GSL random number generator
-    rng::rng(const gsl_rng_type* Type)
-    {
-	gsl_rng_env_setup();
-	type = Type;
-	pWorkspace = gsl_rng_alloc(Type);
-    }
-
-    ///When called with a pair of arguments, the constructor for the smc::rng class allocates a buffer for the specified
-    ///random number generator type and initialises it with the specified seed (note that zero has special significance and
-    ///is used to specify the seed with which the generator was originally used).
-    ///
-    ///\param Type The type of a GSL random number generator
-    ///\param lSeed The value with which the generator is to be seeded
-    rng::rng(const gsl_rng_type* Type, unsigned long int lSeed)
-    {
-	gsl_rng_env_setup();
-	type = Type;
-	pWorkspace = gsl_rng_alloc(Type);
-	gsl_rng_set(pWorkspace, lSeed);
-    }
-
-    ///The destructor presently does no more than call the gsl_rng_free function to deallocate the memory which was
-    ///previously allocate to the random number generator.
-    rng::~rng()
-    {
-	gsl_rng_free(pWorkspace);    
-    }
-
-    ///This function returns a pointer to the underlying GSL random number generator which may be used to provide random
-    ///number facilities which are not explicitly provided by the intermediate layer of smc::rng.
-    gsl_rng* rng::GetRaw(void)
-    {
-	return pWorkspace;
-    }
-
-    ///This function simply passes the relevant arguments on to gsl_ran_multinomial.
-    ///     \param n Number of entities to assign.
-    ///     \param k Number of categories.
-    ///     \param w Weights of category elements
-    ///     \param X Array in which to return the sample values.
-    void rng::Multinomial(unsigned n, unsigned k, const double* w, unsigned* X)
-    {
-	gsl_ran_multinomial(pWorkspace, k, n, w, X);
-    }
-
-
-    ///This function simply calls gsl_rng_uniform_int and shifts the
-    /// result as appropriate such that the result is an integer generated uniformly from those between
-    /// the two arguments (inclusive of those points).
-    ///
-    ///     \param lMin The smallest value which can be returned
-    ///      \param lMax the largest value which can be returned
-    long rng::UniformDiscrete(long lMin, long lMax)
-    {
-	return gsl_rng_uniform_int(pWorkspace, lMax - lMin + 1) + lMin;
-    }
-
-    ///This function simply calls gsl_ran_beta with the specified parameters.
-    ///     \param da The parameter associated with "x".
-    ///     \paran db The parameter associated with "1-x".
-    double rng::Beta(double da, double db)
-    {
-	return gsl_ran_beta(pWorkspace, da, db);
-    }
-
-    ///This function simply calls gsl_ran_cauchy with the specified parameter.
-    ///     \param dScale The scale parameter of the distribution.
-    double rng::Cauchy(double dScale)
-    {
-	return gsl_ran_cauchy(pWorkspace, dScale);
-    }
-
-    ///This function simply calls gsl_ran_exponential with the specified parameters.
-    ///     \param dMean The scale (not rate) (and mean) of the distribution.
-    double rng::Exponential(double dMean)
-    {
-	return gsl_ran_exponential(pWorkspace, dMean);
-    }
-
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rcpp -r 3538


More information about the Rcpp-commits mailing list