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
00041
#include "SpiralDistribution.h"
00042
#include <plearn/math/random.h>
00043
00044
namespace PLearn {
00045
using namespace std;
00046
00047 SpiralDistribution::SpiralDistribution()
00048 : lambda(0.04),
00049 alpha(1),
00050 tmin(3),
00051 tmax(15),
00052 sigma(0.01),
00053 uniformity(1),
00054 include_t(false)
00055 {
00056
00057 }
00058
00059
PLEARN_IMPLEMENT_OBJECT(
SpiralDistribution,
"Generates samples drawn from a 2D spiral",
00060
"SpiralDistribution is a generative model that generates 2D (x,y) samples in the following manner:\n"
00061
" t ~ uniform([tmin, tmax])^uniformity \n"
00062
" x = lambda*t*sin(alpha*t) + N(0,sigma) \n"
00063
" y = lambda*t*cos(alpha*t) + N(0,sigma) \n");
00064
00065 void SpiralDistribution::declareOptions(
OptionList& ol)
00066 {
00067
declareOption(ol,
"lambda", &SpiralDistribution::lambda, OptionBase::buildoption,
"");
00068
declareOption(ol,
"alpha", &SpiralDistribution::alpha, OptionBase::buildoption,
"");
00069
declareOption(ol,
"tmin", &SpiralDistribution::tmin, OptionBase::buildoption,
"");
00070
declareOption(ol,
"tmax", &SpiralDistribution::tmax, OptionBase::buildoption,
"");
00071
declareOption(ol,
"sigma", &SpiralDistribution::sigma, OptionBase::buildoption,
"");
00072
declareOption(ol,
"uniformity", &SpiralDistribution::uniformity, OptionBase::buildoption,
"");
00073
declareOption(ol,
"include_t", &SpiralDistribution::include_t, OptionBase::buildoption,
00074
"If true, then t will be appended to the generated sample, along with x and y.");
00075
00076 inherited::declareOptions(ol);
00077 }
00078
00079 void SpiralDistribution::build_()
00080 {
00081
00082
00083
00084
00085
00086
00087
00088 }
00089
00090
00091 void SpiralDistribution::build()
00092 {
00093 inherited::build();
00094
build_();
00095 }
00096
00097 void SpiralDistribution::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00098 {
00099 inherited::makeDeepCopyFromShallowCopy(copies);
00100
00101
00102
00103
00104
00105
00106
00107
00108
PLERROR(
"SpiralDistribution::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00109 }
00110
00111 real SpiralDistribution::log_density(
const Vec& x)
const
00112
{
PLERROR(
"density not implemented for SpiralDistribution");
return 0; }
00113
00114 real SpiralDistribution::survival_fn(
const Vec& x)
const
00115
{
PLERROR(
"survival_fn not implemented for SpiralDistribution");
return 0; }
00116
00117 real SpiralDistribution::cdf(
const Vec& x)
const
00118
{
PLERROR(
"cdf not implemented for SpiralDistribution");
return 0; }
00119
00120 void SpiralDistribution::expectation(
Vec& mu)
const
00121
{
PLERROR(
"expectation not implemented for SpiralDistribution"); }
00122
00123 void SpiralDistribution::variance(
Mat& covar)
const
00124
{
PLERROR(
"variance not implemented for SpiralDistribution"); }
00125
00126 void SpiralDistribution::curve(
real t,
real& x,
real& y)
const
00127
{
00128
x =
lambda*t*sin(
alpha*t);
00129 y =
lambda*t*cos(
alpha*t);
00130 }
00131
00132 void SpiralDistribution::generate(
Vec& v)
const
00133
{
00134 v.
resize(
inputsize());
00135
00136
real x, y;
00137
real u =
bounded_uniform(0,1);
00138
real t = (
uniformity==1)?u:
pow(u,uniformity);
00139 t =
tmin+(
tmax-
tmin)*t;
00140
curve(t,
x,y);
00141
x +=
gaussian_mu_sigma(0,
sigma);
00142 y +=
gaussian_mu_sigma(0,
sigma);
00143
00144 v[0] =
x;
00145 v[1] = y;
00146
if(
inputsize()==3)
00147 v[2] = t;
00148 }
00149
00150
00151
00152
00153
00154 int SpiralDistribution::inputsize()
const
00155
{
return include_t ?3 :2; }
00156
00157 void SpiralDistribution::resetGenerator(
long g_seed)
const
00158
{
00159
manual_seed(g_seed);
00160 }
00161
00162
00163 }