00001 #ifndef RF_HPP
00002 #define RF_HPP
00003
00004 #include <math.h>
00005
00006 #include <boost/numeric/ublas/vector_expression.hpp>
00007 #include <boost/numeric/ublas/io.hpp>
00008 #include <boost/program_options.hpp>
00009
00010 #include "types.hpp"
00011 #include "model.hpp"
00012
00018 class RF {
00019
00028
00032 Types::RParam d_def;
00033
00037 #ifndef DIAGONAL_RF
00038 Types::UTMatrix alpha;
00039 #else
00040 Types::vector alpha;
00041 #endif
00042
00047 Types::RParam lambda;
00048
00052 Types::RParam gamma;
00053
00055
00056
00065
00067 Types::vector center;
00068
00069 #ifndef DIAGONAL_RF
00070
00071 Types::SymMatrix D;
00072
00074 Types::UTMatrix M;
00075 #else
00076
00077 Types::vector D;
00078
00080 Types::vector M;
00081 #endif
00082
00084 Model localModel;
00085
00087
00088
00097
00099 Types::RValue W;
00100
00101 Types::vector a_H, a_G;
00102 Types::RValue a_E;
00103
00104 Types::RValue e_cv_2, e_2;
00105
00107
00109 Types::vector z;
00110
00111
00112
00113 Types::vector temp2, q, H_temp;
00114 Types::RValue h, dJ1dw;
00115
00116 #ifndef DIAGONAL_RF
00117 Types::UTMatrix dwdM, dDdM, dJ2dM, dJdM;
00118 #else
00119 Types::vector dwdM, dDdM, dJ2dM, dJdM;
00120 #endif
00121
00122 public:
00123
00125 RF();
00126
00132 RF(Types::Input c);
00133
00137 RF(Types::Input c, const boost::program_options::variables_map& vm);
00138
00145 inline Types::RValue getActivation(Types::Input x) const
00146 {
00147 #ifndef DIAGONAL_RF
00148 const_cast<Types::vector&>(temp2) = prod(M,(x-center));
00149 #else
00150 const_cast<Types::vector&>(temp2) = element_prod(M,(x-center));
00151 #endif
00152
00153 return exp(-0.5 * ublas::inner_prod(temp2,temp2));
00154 };
00155
00161 inline Types::OutputT predict(Types::Input x) const { return localModel.predict(x); };
00162
00168 inline bool trustworthy() const { return localModel.trustworthy(); };
00169
00170
00181 Types::RValue learn(Types::Input x, Types::Output y);
00182
00186 friend std::ostream& operator<<(std::ostream& out, const RF& rf);
00187
00188 };
00189
00190 #endif