PLearn 0.1
SourceVariable.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PLearn (A C++ Machine Learning Library)
00004 // Copyright (C) 1998 Pascal Vincent
00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 // 
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 // 
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 // 
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 // 
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 
00036  
00037 
00038 /* *******************************************************      
00039  * $Id: SourceVariable.h 9095 2008-06-03 21:10:27Z plearner $
00040  * This file is part of the PLearn library.
00041  ******************************************************* */
00042 
00043 #ifndef SourceVariable_INC
00044 #define SourceVariable_INC
00045 
00046 #include "VarArray.h"
00047 #include <plearn/math/PRandom.h>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00052 class SourceVariable: public Variable
00053 {
00054     typedef Variable inherited;
00055 
00056 public:
00057     // build options
00058     int build_length;
00059     int build_width;
00060 
00061     string random_type;
00062 
00063     real random_a;
00064     real random_b;
00065 
00066     bool random_clear_first_row;
00067 
00068 private:
00069     void build_();
00070 public:
00071     virtual void build();
00072 
00073 protected:
00074     static void declareOptions(OptionList & ol);
00075 
00076 public:
00078     SourceVariable();
00079     SourceVariable(int thelength, int thewidth, bool call_build_ = true);
00080     SourceVariable(const Vec& v, bool vertical=true, bool call_build_ = true);
00081     SourceVariable(const Mat& m, bool call_build_ = true);
00082     SourceVariable(int thelength, int thewidth, string random_type_, 
00083                    real random_a_=0, real random_b_=1, bool clear_first_row_=false,
00084                    bool call_build_ = true);
00085 
00086     virtual void setParents(const VarArray& parents)
00087     { PLERROR("In Variable::setParents  trying to set parents of a SourceVariable..."); }
00088 
00089 
00090     virtual bool markPath();
00091     virtual void buildPath(VarArray& proppath);
00092     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00093     PLEARN_DECLARE_OBJECT(SourceVariable);
00094   
00097     virtual void randomInitialize(PP<PRandom> random_gen);
00098   
00099     virtual void fprop();
00100     virtual void bprop();
00101     virtual void bbprop();
00102     virtual void symbolicBprop();
00103     virtual void rfprop();
00104     virtual VarArray sources();
00105     virtual VarArray random_sources();
00106     virtual VarArray ancestors();
00107     virtual void unmarkAncestors();
00108     virtual VarArray parents();
00109     bool isConstant() { return true; }
00110 
00111     void printInfo(bool print_gradient) { 
00112         pout << getName() << "[" << (void*)this << "] " << *this << " = " << value;
00113         if (print_gradient) pout << " gradient=" << gradient;
00114         pout << endl; 
00115     }
00116 };
00117 
00118 DECLARE_OBJECT_PTR(SourceVariable);
00119 
00120 } // end of namespace PLearn
00121 
00122 #endif
00123 
00124 
00125 /*
00126   Local Variables:
00127   mode:c++
00128   c-basic-offset:4
00129   c-file-style:"stroustrup"
00130   c-file-offsets:((innamespace . 0)(inline-open . 0))
00131   indent-tabs-mode:nil
00132   fill-column:79
00133   End:
00134 */
00135 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines