Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

UniformDistribution.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // UniformDistribution.cc 00004 // 00005 // Copyright (C) 2004 Olivier Delalleau 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: UniformDistribution.cc,v 1.5 2004/07/21 16:30:56 chrish42 Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00043 #include <plearn/math/random.h> 00044 #include "UniformDistribution.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00050 // UniformDistribution // 00052 UniformDistribution::UniformDistribution() 00053 { 00054 // Default = generate points uniformly in [0,1]. 00055 min.resize(1); 00056 max.resize(1); 00057 min[0] = 0; 00058 max[0] = 1; 00059 } 00060 00061 PLEARN_IMPLEMENT_OBJECT(UniformDistribution, 00062 "Implements uniform distribution over intervals.", 00063 "Currently, only very few methods are implemented.\n" 00064 "For example, to sample points in 2D in [a,b] x [c,d], use\n" 00065 " min = [a c]\n" 00066 " max = [b d]\n" 00067 ); 00068 00070 // declareOptions // 00072 void UniformDistribution::declareOptions(OptionList& ol) 00073 { 00074 declareOption(ol, "min", &UniformDistribution::min, OptionBase::buildoption, 00075 "The inferior bound for all intervals."); 00076 00077 declareOption(ol, "max", &UniformDistribution::max, OptionBase::buildoption, 00078 "The superior bound for all intervals."); 00079 00080 // Now call the parent class' declareOptions(). 00081 inherited::declareOptions(ol); 00082 } 00083 00085 // build // 00087 void UniformDistribution::build() 00088 { 00089 inherited::build(); 00090 build_(); 00091 } 00092 00094 // build_ // 00096 void UniformDistribution::build_() 00097 { 00098 // ### This method should do the real building of the object, 00099 // ### according to set 'options', in *any* situation. 00100 // ### Typical situations include: 00101 // ### - Initial building of an object from a few user-specified options 00102 // ### - Building of a "reloaded" object: i.e. from the complete set of all serialised options. 00103 // ### - Updating or "re-building" of an object after a few "tuning" options have been modified. 00104 // ### You should assume that the parent class' build_() has already been called. 00105 00106 // Check consistency of intervals. 00107 if (min.length() != max.length()) { 00108 PLERROR("In UniformDistribution::build_ - 'min' and 'max' should have the same size"); 00109 } 00110 int n_dim = min.length(); 00111 for (int i = 0; i < n_dim; i++) { 00112 if (min[i] > max[i]) { 00113 PLERROR("In UniformDistribution::build_ - 'min' should be always <= 'max'"); 00114 } 00115 } 00116 } 00117 00119 // cdf // 00121 real UniformDistribution::cdf(const Vec& x) const 00122 { 00123 PLERROR("cdf not implemented for UniformDistribution"); return 0; 00124 } 00125 00127 // expectation // 00129 void UniformDistribution::expectation(Vec& mu) const 00130 { 00131 PLERROR("expectation not implemented for UniformDistribution"); 00132 } 00133 00135 // generate // 00137 void UniformDistribution::generate(Vec& x) const 00138 { 00139 x.resize(min.length()); 00140 for (int i = 0; i < min.length(); i++) { 00141 x[i] = bounded_uniform(min[i], max[i]); 00142 } 00143 } 00144 00146 // inputsize // 00148 int UniformDistribution::inputsize() const { 00149 return min.length(); 00150 } 00151 00153 // log_density // 00155 real UniformDistribution::log_density(const Vec& x) const 00156 { 00157 PLERROR("density not implemented for UniformDistribution"); return 0; 00158 } 00159 00161 // makeDeepCopyFromShallowCopy // 00163 void UniformDistribution::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00164 { 00165 inherited::makeDeepCopyFromShallowCopy(copies); 00166 00167 // ### Call deepCopyField on all "pointer-like" fields 00168 // ### that you wish to be deepCopied rather than 00169 // ### shallow-copied. 00170 // ### ex: 00171 // deepCopyField(trainvec, copies); 00172 00173 // ### Remove this line when you have fully implemented this method. 00174 PLERROR("UniformDistribution::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00175 } 00176 00178 // resetGenerator // 00180 void UniformDistribution::resetGenerator(long g_seed) const 00181 { 00182 manual_seed(g_seed); 00183 } 00184 00186 // survival_fn // 00188 real UniformDistribution::survival_fn(const Vec& x) const 00189 { 00190 PLERROR("survival_fn not implemented for UniformDistribution"); return 0; 00191 } 00192 00194 // variance // 00196 void UniformDistribution::variance(Mat& covar) const 00197 { 00198 PLERROR("variance not implemented for UniformDistribution"); 00199 } 00200 00201 } // end of namespace PLearn 00202

Generated on Tue Aug 17 16:09:48 2004 for PLearn by doxygen 1.3.7