PLearn 0.1
|
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, Rejean Ducharme and University of Montreal 00006 // Copyright (C) 2001-2002 Nicolas Chapados, Ichiro Takeuchi, Jean-Sebastien Senecal 00007 // Copyright (C) 2002 Xiangdong Wang, Christian Dorion 00008 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are met: 00011 // 00012 // 1. Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // 00015 // 2. Redistributions in binary form must reproduce the above copyright 00016 // notice, this list of conditions and the following disclaimer in the 00017 // documentation and/or other materials provided with the distribution. 00018 // 00019 // 3. The name of the authors may not be used to endorse or promote 00020 // products derived from this software without specific prior written 00021 // permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00024 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00025 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00026 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00028 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00029 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00030 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00031 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00032 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 // 00034 // This file is part of the PLearn library. For more information on the PLearn 00035 // library, go to the PLearn Web site at www.plearn.org 00036 00037 00038 /* ******************************************************* 00039 * $Id: NaryVariable.cc 10201 2009-05-12 17:57:00Z plearner $ 00040 * This file is part of the PLearn library. 00041 ******************************************************* */ 00042 00043 #include "NaryVariable.h" 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00050 PLEARN_IMPLEMENT_ABSTRACT_OBJECT(NaryVariable, 00051 "A Variable that may take more than two other Variables as input.", 00052 "" 00053 ); 00054 00056 // NaryVariable // 00058 NaryVariable::NaryVariable(const VarArray& the_varray, int thelength, 00059 int thewidth, bool call_build_): 00060 inherited(thelength, thewidth, call_build_), 00061 varray(the_varray) 00062 { 00063 if (call_build_) 00064 build_(); 00065 } 00066 00068 // declareOptions // 00070 void NaryVariable::declareOptions(OptionList& ol) 00071 { 00072 declareOption(ol, "varray", &NaryVariable::varray, OptionBase::buildoption, 00073 "The array of parent variables that this one depends on."); 00074 00075 inherited::declareOptions(ol); 00076 } 00077 00079 // build // 00081 void NaryVariable::build() 00082 { 00083 inherited::build(); 00084 build_(); 00085 } 00086 00088 // build_ // 00090 void NaryVariable::build_() 00091 { 00092 // Nothing to do here. 00093 } 00094 00096 // makeDeepCopyFromShallowCopy // 00098 void NaryVariable::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00099 { 00100 inherited::makeDeepCopyFromShallowCopy(copies); 00101 deepCopyField(varray, copies); 00102 } 00103 00104 void NaryVariable::setParents(const VarArray& parents) 00105 { 00106 varray = parents; 00107 sizeprop(); 00108 } 00109 00110 bool NaryVariable::markPath() 00111 { 00112 if(!marked) 00113 { 00114 for(int i=0; i<varray.size(); i++) 00115 if (!varray[i].isNull()) 00116 marked |= varray[i]->markPath(); 00117 } 00118 return marked; 00119 } 00120 00121 00122 void NaryVariable::buildPath(VarArray& proppath) 00123 { 00124 if(marked) 00125 { 00126 for(int i=0; i<varray.size(); i++) 00127 if (!varray[i].isNull()) 00128 varray[i]->buildPath(proppath); 00129 proppath &= Var(this); 00130 clearMark(); 00131 } 00132 } 00133 00134 00135 VarArray NaryVariable::sources() 00136 { 00137 VarArray a(0,0); 00138 if (!marked) 00139 { 00140 marked = true; 00141 for(int i=0; i<varray.size(); i++) 00142 if (!varray[i].isNull()) 00143 a &= varray[i]->sources(); 00144 //if (a.size()==0) 00145 // a &= Var(this); 00146 } 00147 return a; 00148 } 00149 00150 00151 VarArray NaryVariable::random_sources() 00152 { 00153 VarArray a(0,0); 00154 if (!marked) 00155 { 00156 marked = true; 00157 for(int i=0; i<varray.size(); i++) 00158 if (!varray[i].isNull()) 00159 a &= varray[i]->random_sources(); 00160 } 00161 return a; 00162 } 00163 00164 00165 VarArray NaryVariable::ancestors() 00166 { 00167 VarArray a(0,0); 00168 if (marked) 00169 return a; 00170 marked = true; 00171 for(int i=0; i<varray.size(); i++) 00172 if (!varray[i].isNull()) 00173 a &= varray[i]->ancestors(); 00174 a &= Var(this); 00175 return a; 00176 } 00177 00178 00179 void NaryVariable::unmarkAncestors() 00180 { 00181 if (marked) 00182 { 00183 marked = false; 00184 for(int i=0; i<varray.size(); i++) 00185 if (!varray[i].isNull()) 00186 varray[i]->unmarkAncestors(); 00187 } 00188 } 00189 00190 00191 VarArray NaryVariable::parents() 00192 { 00193 VarArray unmarked_parents; 00194 for(int i=0; i<varray.size(); i++) 00195 if (!varray[i].isNull() && !varray[i]->marked) 00196 unmarked_parents.append(varray[i]); 00197 return unmarked_parents; 00198 } 00199 00200 00201 void NaryVariable::resizeRValue() 00202 { 00203 inherited::resizeRValue(); 00204 for (int i=0; i<varray.size(); i++) 00205 if (!varray[i]->rvaluedata) varray[i]->resizeRValue(); 00206 } 00207 00208 00209 00210 } // end of namespace PLearn 00211 00212 00213 /* 00214 Local Variables: 00215 mode:c++ 00216 c-basic-offset:4 00217 c-file-style:"stroustrup" 00218 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00219 indent-tabs-mode:nil 00220 fill-column:79 00221 End: 00222 */ 00223 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :