PLearn 0.1
ScoreLayerVariable.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ScoreLayerVariable.h
00004 //
00005 // Copyright (C) 2006 Olivier Delalleau
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 // Authors: Olivier Delalleau
00036 
00040 #ifndef ScoreLayerVariable_INC
00041 #define ScoreLayerVariable_INC
00042 
00043 #include "ChemicalICP.h"
00044 #include "Molecule.h"
00045 #include "RunICPVariable.h"
00046 #include <plearn/math/PRandom.h>
00047 #include <plearn/var/NaryVariable.h>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00064 class ScoreLayerVariable : public NaryVariable
00065 {
00066     typedef NaryVariable inherited;
00067 
00068 public:
00069 
00071     PP<RunICPVariable> run_icp_var;
00072 
00073     //#####  Public Build Options  ############################################
00074 
00077 
00078     PP<ChemicalICP> icp_aligner_template;
00079     int n_active_templates;
00080     int n_inactive_templates;
00081     bool normalize_by_n_features;
00082     int32_t seed_;
00083     bool simple_mixture;
00084     VMat templates_source;
00085 
00086 public:
00087 
00088     //#####  Public Member Functions  #########################################
00089 
00091     ScoreLayerVariable();
00092 
00095     PP<MoleculeTemplate> getMoleculeTemplate(real molecule_id,
00096                                              real activity = -1);
00097 
00102     PP<Molecule> getMolecule(real molecule_id);
00103 
00105     void setMappingsSource(const VMat& source_vmat);
00106 
00108     void setScalingCoefficient(int i, real coeff);
00109 
00110     //#####  PLearn::Variable methods #########################################
00111     virtual void recomputeSize(int& l, int& w) const;
00112     virtual void fprop();
00113     virtual void bprop();
00114 
00115     // ### These ones are not always implemented
00116     // virtual void bbprop();
00117     // virtual void symbolicBprop();
00118     // virtual void rfprop();
00119 
00120     //#####  PLearn::Object Protocol  #########################################
00121 
00122     // Declares other standard object methods.
00123     PLEARN_DECLARE_OBJECT(ScoreLayerVariable);
00124 
00125     // Simply calls inherited::build() then build_()
00126     virtual void build();
00127 
00129     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00130 
00131 protected:
00132 
00134     VMat mappings_source;
00135 
00137     PP<PRandom> random_gen;
00138 
00142     VarArray outputs;
00143 
00146     Var final_output;
00147 
00149     hash_map< string, PP<MoleculeTemplate> > molecule_templates;
00150 
00152     hash_map< string, PP<Molecule> > molecules;
00153 
00155     int n_active_in_source;
00156 
00158     int n_inactive_in_source;
00159 
00167     VarArray scaling_coeffs;
00168 
00169     //#####  Protected Options  ###############################################
00170 
00171 protected:
00172     //#####  Protected Member Functions  ######################################
00173 
00177     int getNActiveTemplates();
00178 
00182     int getNInactiveTemplates();
00183 
00185     // (PLEASE IMPLEMENT IN .cc)
00186     static void declareOptions(OptionList& ol);
00187 
00188 private:
00189     //#####  Private Member Functions  ########################################
00190 
00192     // (PLEASE IMPLEMENT IN .cc)
00193     void build_();
00194 
00195 private:
00196     //#####  Private Data Members  ############################################
00197 
00198     // The rest of the private stuff goes here
00199 };
00200 
00201 // Declares a few other classes and functions related to this class
00202 DECLARE_OBJECT_PTR(ScoreLayerVariable);
00203 
00204 // ### Put here a convenient method for building your variable from other
00205 // ### existing ones, or a VarArray.
00206 // ### e.g., if your class is TotoVariable, with two parameters foo_type foo
00207 // ### and bar_type bar, you could write, depending on your constructor:
00208 // inline Var toto(Var v1, Var v2, Var v3,
00209 //                 foo_type foo=default_foo, bar_type bar=default_bar)
00210 // { return new TotoVariable(v1, v2, v3, foo, bar); }
00211 // ### or:
00212 // inline Var toto(Var v1, Var v2, v3
00213 //                 foo_type foo=default_foo, bar_type bar=default_bar)
00214 // { return new TotoVariable(v1 & v2 & v3, foo, bar); }
00215 // ### or:
00216 // inline Var toto(const VarArray& varray, foo_type foo=default_foo,
00217 //                 bar_type bar=default_bar)
00218 // { return new TotoVariable( varray, foo, bar); }
00219 
00220 } // end of namespace PLearn
00221 
00222 #endif
00223 
00224 
00225 /*
00226   Local Variables:
00227   mode:c++
00228   c-basic-offset:4
00229   c-file-style:"stroustrup"
00230   c-file-offsets:((innamespace . 0)(inline-open . 0))
00231   indent-tabs-mode:nil
00232   fill-column:79
00233   End:
00234 */
00235 // 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