00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00043
#include <plearn/math/random.h>
00044
#include "UniformDistribution.h"
00045
00046
namespace PLearn {
00047
using namespace std;
00048
00050
00052 UniformDistribution::UniformDistribution()
00053 {
00054
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
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
00081 inherited::declareOptions(ol);
00082 }
00083
00085
00087 void UniformDistribution::build()
00088 {
00089 inherited::build();
00090
build_();
00091 }
00092
00094
00096 void UniformDistribution::build_()
00097 {
00098
00099
00100
00101
00102
00103
00104
00105
00106
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
00121 real UniformDistribution::cdf(
const Vec& x)
const
00122
{
00123
PLERROR(
"cdf not implemented for UniformDistribution");
return 0;
00124 }
00125
00127
00129 void UniformDistribution::expectation(
Vec& mu)
const
00130
{
00131
PLERROR(
"expectation not implemented for UniformDistribution");
00132 }
00133
00135
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
00148 int UniformDistribution::inputsize()
const {
00149
return min.
length();
00150 }
00151
00153
00155 real UniformDistribution::log_density(
const Vec& x)
const
00156
{
00157
PLERROR(
"density not implemented for UniformDistribution");
return 0;
00158 }
00159
00161
00163 void UniformDistribution::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00164 {
00165 inherited::makeDeepCopyFromShallowCopy(copies);
00166
00167
00168
00169
00170
00171
00172
00173
00174
PLERROR(
"UniformDistribution::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00175 }
00176
00178
00180 void UniformDistribution::resetGenerator(
long g_seed)
const
00181
{
00182
manual_seed(g_seed);
00183 }
00184
00186
00188 real UniformDistribution::survival_fn(
const Vec& x)
const
00189
{
00190
PLERROR(
"survival_fn not implemented for UniformDistribution");
return 0;
00191 }
00192
00194
00196 void UniformDistribution::variance(
Mat& covar)
const
00197
{
00198
PLERROR(
"variance not implemented for UniformDistribution");
00199 }
00200
00201 }
00202