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
00041
00042
00044
#include "Distribution.h"
00045
#include <plearn/ker/NegOutputCostFunction.h>
00046
00047
namespace PLearn {
00048
using namespace std;
00049
00050 Distribution::Distribution()
00051 :
Learner(0,1,1), use_returns_what("l")
00052 {
00053
00054 setTestCostFunctions(
neg_output_costfunc());
00055 }
00056
00057
PLEARN_IMPLEMENT_OBJECT(
Distribution,
00058
"This class is deprecated, use PDistribution instead.",
00059
"NO HELP");
00060
00061 void Distribution::declareOptions(
OptionList& ol)
00062 {
00063
00064
00065
00066
00067
00068
00069
declareOption(ol,
"use_returns_what", &Distribution::use_returns_what, OptionBase::buildoption,
00070
"A string where the characters have the following meaning: \n"
00071
"'l'-> log_density, 'd' -> density, 'c' -> cdf, 's' -> survival_fn, 'e' -> expectation, 'v' -> variance");
00072
00073
00074 inherited::declareOptions(ol);
00075 }
00076
00077 void Distribution::build_()
00078 {
00079
00080
00081
00082
00083
00084
00085
00086
00087 outputsize_ =
use_returns_what.length();
00088 }
00089
00090
00091 void Distribution::build()
00092 {
00093 inherited::build();
00094
build_();
00095 }
00096
00097
00098 void Distribution::train(
VMat training_set)
00099 {
00100
if(training_set->
width() !=
inputsize()+
targetsize())
00101
PLERROR(
"In Distribution::train(VMat training_set) training_set->width() != inputsize()+targetsize()");
00102
00103 setTrainingSet(training_set);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 }
00114
00115 void Distribution::use(
const Vec& input,
Vec& output)
00116 {
00117
int l = (
int)
use_returns_what.length();
00118
for(
int i=0; i<l; i++)
00119 {
00120
switch(
use_returns_what[i])
00121 {
00122
case 'l':
00123 output[i] = (
real)
log_density(input);
00124
break;
00125
case 'd':
00126 output[i] = (
real)
density(input);
00127
break;
00128
case 'c':
00129 output[i] = (
real)
cdf(input);
00130
break;
00131
case 's':
00132 output[i] = (
real)
survival_fn(input);
00133
break;
00134
default:
00135
PLERROR(
"In Distribution::use unknown use_returns_what character");
00136 }
00137 }
00138 }
00139
00140 void Distribution::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00141 {
00142 Learner::makeDeepCopyFromShallowCopy(copies);
00143 }
00144
00145 double Distribution::log_density(
const Vec& x)
const
00146
{
PLERROR(
"density not implemented for this Distribution");
return 0; }
00147
00148 double Distribution::density(
const Vec& x)
const
00149
{
return exp(
log_density(
x)); }
00150
00151 double Distribution::survival_fn(
const Vec& x)
const
00152
{
PLERROR(
"survival_fn not implemented for this Distribution");
return 0; }
00153
00154 double Distribution::cdf(
const Vec& x)
const
00155
{
PLERROR(
"cdf not implemented for this Distribution");
return 0; }
00156
00157 Vec Distribution::expectation()
const
00158
{
PLERROR(
"expectation not implemented for this Distribution");
return Vec(); }
00159
00160 Mat Distribution::variance()
const
00161
{
PLERROR(
"variance not implemented for this Distribution");
return Mat(); }
00162
00163 void Distribution::generate(
Vec& x)
const
00164
{
PLERROR(
"generate not implemented for this Distribution"); }
00165
00166
00167 }