Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

BinaryVariable.cc

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, 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: BinaryVariable.cc,v 1.13 2004/02/20 21:11:49 chrish42 Exp $ 00040 * This file is part of the PLearn library. 00041 ******************************************************* */ 00042 00043 #include "BinaryVariable.h" 00044 00045 namespace PLearn { 00046 00047 using namespace std; 00048 00051 BinaryVariable::BinaryVariable(Variable* v1, Variable* v2, int thelength,int thewidth) 00052 :Variable(thelength,thewidth), input1(v1), input2(v2) 00053 { 00054 input1->disallowPartialUpdates(); 00055 input2->disallowPartialUpdates(); 00056 } 00057 00058 00059 PLEARN_IMPLEMENT_ABSTRACT_OBJECT(BinaryVariable, "ONE LINE DESCR", "NO HELP"); 00060 00061 void BinaryVariable::declareOptions(OptionList& ol) 00062 { 00063 declareOption(ol, "input1", &BinaryVariable::input1, OptionBase::buildoption, 00064 "The first parent variable that this one depends on\n"); 00065 00066 declareOption(ol, "input2", &BinaryVariable::input2, OptionBase::buildoption, 00067 "The second parent variable that this one depends on\n"); 00068 00069 inherited::declareOptions(ol); 00070 } 00071 00072 void BinaryVariable::setParents(const VarArray& parents) 00073 { 00074 if(parents.length() != 2) 00075 PLERROR("In BinaryVariable::setParents VarArray length must be 2;" 00076 " you are trying to set %d parents for this BinaryVariable...", parents.length()); 00077 00078 input1= parents[0]; 00079 input2= parents[1]; 00080 00081 int dummy_l, dummy_w; 00082 recomputeSize(dummy_l, dummy_w); 00083 } 00084 00085 00086 00087 00088 00089 00090 00091 00092 extern void varDeepCopyField(Var& field, CopiesMap& copies); 00093 00094 void BinaryVariable::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00095 { 00096 Variable::makeDeepCopyFromShallowCopy(copies); 00097 //deepCopyField(input1, copies); 00098 varDeepCopyField(input1, copies); 00099 //deepCopyField(input2, copies); 00100 varDeepCopyField(input2, copies); 00101 } 00102 00103 00104 bool BinaryVariable::markPath() 00105 { 00106 if(!marked) 00107 marked = input1->markPath() | input2->markPath(); 00108 return marked; 00109 } 00110 00111 00112 void BinaryVariable::buildPath(VarArray& proppath) 00113 { 00114 if(marked) 00115 { 00116 input1->buildPath(proppath); 00117 input2->buildPath(proppath); 00118 proppath &= Var(this); 00119 //cout<<"proppath="<<this->getName()<<endl; 00120 clearMark(); 00121 } 00122 } 00123 00124 00125 VarArray BinaryVariable::sources() 00126 { 00127 if (marked) 00128 return VarArray(0,0); 00129 marked = true; 00130 return input1->sources() & input2->sources(); 00131 } 00132 00133 00134 VarArray BinaryVariable::random_sources() 00135 { 00136 if (marked) 00137 return VarArray(0,0); 00138 marked = true; 00139 return input1->random_sources() & input2->random_sources(); 00140 } 00141 00142 00143 VarArray BinaryVariable::ancestors() 00144 { 00145 if (marked) 00146 return VarArray(0,0); 00147 marked = true; 00148 return input1->ancestors() & input2->ancestors() & Var(this) ; 00149 } 00150 00151 00152 void BinaryVariable::unmarkAncestors() 00153 { 00154 if (marked) 00155 { 00156 marked = false; 00157 input1->unmarkAncestors(); 00158 input2->unmarkAncestors(); 00159 } 00160 } 00161 00162 00163 VarArray BinaryVariable::parents() 00164 { 00165 VarArray unmarked_parents; 00166 if (!input1->marked) 00167 unmarked_parents.append(input1); 00168 if (!input2->marked) 00169 unmarked_parents.append(input2); 00170 return unmarked_parents; 00171 } 00172 00173 00174 void BinaryVariable::resizeRValue() 00175 { 00176 inherited::resizeRValue(); 00177 if (!input1->rvaluedata) input1->resizeRValue(); 00178 if (!input2->rvaluedata) input2->resizeRValue(); 00179 } 00180 00181 00182 00183 } // end of namespace PLearn 00184 00185

Generated on Tue Aug 17 15:48:53 2004 for PLearn by doxygen 1.3.7