SoftSlopeVariable.h
Go to the documentation of this file.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
00043
#ifndef SoftSlopeVariable_INC
00044
#define SoftSlopeVariable_INC
00045
00046
#include "NaryVariable.h"
00047
#include "SigmoidVariable.h"
00048
#include "Var_operators.h"
00049
00050
namespace PLearn {
00051
using namespace std;
00052
00053
00054
00055
00056
00057
00058 class SoftSlopeVariable:
public NaryVariable
00059 {
00060 typedef NaryVariable inherited;
00061
00062
protected:
00063 bool tabulated;
00064
00065
public:
00067 SoftSlopeVariable() {}
00068
SoftSlopeVariable(
Variable* x,
Variable* smoothness,
Variable* left,
Variable* right,
bool tabulated=
true);
00069
00070
PLEARN_DECLARE_OBJECT(
SoftSlopeVariable);
00071
static void declareOptions(
OptionList &ol);
00072
00073
virtual void recomputeSize(
int& l,
int& w)
const;
00074
virtual void fprop();
00075
virtual void bprop();
00076
virtual void symbolicBprop();
00077 };
00078
00079
DECLARE_OBJECT_PTR(SoftSlopeVariable);
00080
00081 inline Var soft_slope(
Var x,
Var smoothness,
Var left,
Var right)
00082 {
return new SoftSlopeVariable(
x,smoothness,
left,
right); }
00083
00084
00085 inline Var d_soft_slope(
Var x,
Var smoothness,
Var left,
Var right)
00086 {
00087
return (-
sigmoid(-smoothness*(
x-
left))+
sigmoid(-smoothness*(
x-
right)))/(
right-
left);
00088 }
00089
00090
00091 inline Var soft_slope_limit(
Var x,
Var smoothness,
Var left,
Var right)
00092 {
00093
int l=0;
00094
int w=0;
00095
if (
x->length()>l) l=
x->length();
00096
if (
x->width()>w) w=
x->width();
00097
if (smoothness->
length()>l) l=smoothness->
length();
00098
if (smoothness->
width()>w) w=smoothness->
width();
00099
if (
left->length()>l) l=
left->length();
00100
if (
left->width()>w) w=
left->width();
00101
if (
right->length()>l) l=
right->length();
00102
if (
right->width()>w) w=
right->width();
00103
if (
x->length()>l && l!=
x->length())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00104
if (
x->width()>w && w!=
x->width())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00105
if (smoothness->
length()>l && l!=smoothness->
length())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00106
if (smoothness->
width()>w && w!=smoothness->
width())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00107
if (
left->length()>l && l!=
left->length())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00108
if (
left->width()>w && w!=
left->width())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00109
if (
right->length()>l && l!=
right->length())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00110
if (
right->width()>w && w!=
right->width())
PLERROR(
"soft_slope_limit: Each argument should have the same size or size 1");
00111
Var res(l,w);
00112 res->value.fill(0.5);
00113
return res;
00114 }
00115
00116 }
00117
00118
#endif
Generated on Tue Aug 17 16:06:00 2004 for PLearn by
1.3.7