auxfactor.h

00001 /*
00002  * All of the documentation and software included in the
00003  * Alchemy Software is copyrighted by Stanley Kok, Parag
00004  * Singla, Matthew Richardson, Pedro Domingos, Marc
00005  * Sumner, Hoifung Poon, Daniel Lowd, and Jue Wang.
00006  * 
00007  * Copyright [2004-09] Stanley Kok, Parag Singla, Matthew
00008  * Richardson, Pedro Domingos, Marc Sumner, Hoifung
00009  * Poon, Daniel Lowd, and Jue Wang. All rights reserved.
00010  * 
00011  * Contact: Pedro Domingos, University of Washington
00012  * (pedrod@cs.washington.edu).
00013  * 
00014  * Redistribution and use in source and binary forms, with
00015  * or without modification, are permitted provided that
00016  * the following conditions are met:
00017  * 
00018  * 1. Redistributions of source code must retain the above
00019  * copyright notice, this list of conditions and the
00020  * following disclaimer.
00021  * 
00022  * 2. Redistributions in binary form must reproduce the
00023  * above copyright notice, this list of conditions and the
00024  * following disclaimer in the documentation and/or other
00025  * materials provided with the distribution.
00026  * 
00027  * 3. All advertising materials mentioning features or use
00028  * of this software must display the following
00029  * acknowledgment: "This product includes software
00030  * developed by Stanley Kok, Parag Singla, Matthew
00031  * Richardson, Pedro Domingos, Marc Sumner, Hoifung
00032  * Poon, Daniel Lowd, and Jue Wang in the Department of
00033  * Computer Science and Engineering at the University of
00034  * Washington".
00035  * 
00036  * 4. Your publications acknowledge the use or
00037  * contribution made by the Software to your research
00038  * using the following citation(s): 
00039  * Stanley Kok, Parag Singla, Matthew Richardson and
00040  * Pedro Domingos (2005). "The Alchemy System for
00041  * Statistical Relational AI", Technical Report,
00042  * Department of Computer Science and Engineering,
00043  * University of Washington, Seattle, WA.
00044  * http://alchemy.cs.washington.edu.
00045  * 
00046  * 5. Neither the name of the University of Washington nor
00047  * the names of its contributors may be used to endorse or
00048  * promote products derived from this software without
00049  * specific prior written permission.
00050  * 
00051  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON
00052  * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00053  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00054  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00055  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
00056  * OF WASHINGTON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00057  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00058  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00059  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00060  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00061  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00062  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00063  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00064  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00065  * 
00066  */
00067 #ifndef AUXFACTOR_H_
00068 #define AUXFACTOR_H_
00069 
00070 #include "factor.h"
00071 
00075 class AuxFactor : public Factor
00076 {
00077  public:
00078   AuxFactor(Array<Predicate* >* formula)
00079   {
00080     msgsArr_ = new Array<double *>;
00081     nextMsgsArr_ = new Array<double *>;
00082     links_ = new Array<Link *>();
00083     formula_ = formula;
00084   }
00085           
00086   ~AuxFactor()
00087   {
00088     for (int i = 0; i < msgsArr_->size(); i++)
00089     {
00090       delete (*msgsArr_)[i];
00091       delete (*nextMsgsArr_)[i];
00092     }
00093     delete links_;
00094     delete msgsArr_;
00095     delete nextMsgsArr_;
00096   }
00097 
00102   double getProb()
00103   {
00104     Node* node;
00105     double prob = 1.0;
00106     for (int lno = 0; lno < links_->size(); lno++)
00107     {
00108       int predIndex = (*links_)[lno]->getPredIndex();
00109       node = (*links_)[lno]->getNode();
00110       double probs[2];
00111       node->getProbs(probs);         
00112 
00113       Predicate *pred = (*formula_)[predIndex];
00114       if (pred->getSense()) prob *= probs[1];
00115       else prob *= probs[0];
00116     }
00117     return prob;
00118   }
00119 
00120   Array<Predicate* >* getFormula()
00121   {
00122     return formula_;
00123   }
00124   
00125  private:
00126   Array<Predicate* >* formula_;
00127   
00128 };
00129 
00130 
00131 
00132 
00133 #endif /*AUXFACTOR_H_*/

Generated on Sun Jun 7 11:55:11 2009 for Alchemy by  doxygen 1.5.1