This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/CLPBN/horus/Parfactor.h

129 lines
2.8 KiB
C
Raw Normal View History

2013-02-07 17:50:02 +00:00
#ifndef YAP_PACKAGES_CLPBN_HORUS_PARFACTOR_H_
#define YAP_PACKAGES_CLPBN_HORUS_PARFACTOR_H_
2012-05-23 14:56:01 +01:00
2013-02-07 20:09:10 +00:00
#include <vector>
#include <string>
2012-12-27 12:54:58 +00:00
#include "Factor.h"
2012-05-23 14:56:01 +01:00
#include "ProbFormula.h"
#include "ConstraintTree.h"
#include "LiftedUtils.h"
#include "Horus.h"
2013-02-07 23:53:13 +00:00
namespace horus {
2012-05-23 14:56:01 +01:00
class Parfactor : public TFactor<ProbFormula>
{
public:
Parfactor (
const ProbFormulas&,
const Params&,
const Tuples&,
2012-05-24 23:38:44 +01:00
unsigned distId);
2012-05-23 14:56:01 +01:00
Parfactor (const Parfactor*, const Tuple&);
Parfactor (const Parfactor*, ConstraintTree*);
Parfactor (const Parfactor&);
~Parfactor (void);
ConstraintTree* constr (void) { return constr_; }
const ConstraintTree* constr (void) const { return constr_; }
const LogVars& logVars (void) const { return constr_->logVars(); }
2012-12-17 18:39:42 +00:00
2012-05-23 14:56:01 +01:00
const LogVarSet& logVarSet (void) const { return constr_->logVarSet(); }
LogVarSet countedLogVars (void) const;
LogVarSet uncountedLogVars (void) const;
2012-12-17 18:39:42 +00:00
2012-05-23 14:56:01 +01:00
LogVarSet elimLogVars (void) const;
2012-12-17 18:39:42 +00:00
2012-05-24 22:55:20 +01:00
LogVarSet exclusiveLogVars (size_t fIdx) const;
2012-12-17 18:39:42 +00:00
2012-05-25 20:15:05 +01:00
void sumOutIndex (size_t fIdx);
2012-05-23 14:56:01 +01:00
void multiply (Parfactor&);
2012-12-17 18:39:42 +00:00
2012-05-23 14:56:01 +01:00
bool canCountConvert (LogVar X);
void countConvert (LogVar);
void expand (LogVar, LogVar, LogVar);
void fullExpand (LogVar);
void reorderAccordingGrounds (const Grounds&);
void absorveEvidence (const ProbFormula&, unsigned);
void setNewGroups (void);
void applySubstitution (const Substitution&);
2012-06-14 11:57:00 +01:00
size_t indexOfGround (const Ground&) const;
2012-05-24 23:38:44 +01:00
PrvGroup findGroup (const Ground&) const;
2012-05-23 14:56:01 +01:00
bool containsGround (const Ground&) const;
2012-06-14 11:57:00 +01:00
bool containsGrounds (const Grounds&) const;
2012-05-24 23:38:44 +01:00
bool containsGroup (PrvGroup) const;
2012-06-14 11:57:00 +01:00
2013-02-07 13:37:15 +00:00
bool containsGroups (std::vector<PrvGroup>) const;
2012-12-17 18:39:42 +00:00
2012-05-23 14:56:01 +01:00
unsigned nrFormulas (LogVar) const;
int indexOfLogVar (LogVar) const;
2012-05-24 23:38:44 +01:00
int indexOfGroup (PrvGroup) const;
2012-05-23 14:56:01 +01:00
2012-05-24 23:38:44 +01:00
unsigned nrFormulasWithGroup (PrvGroup) const;
2012-05-23 14:56:01 +01:00
2013-02-07 13:37:15 +00:00
std::vector<PrvGroup> getAllGroups (void) const;
2012-05-23 14:56:01 +01:00
void print (bool = false) const;
void printParameters (void) const;
void printProjections (void) const;
2013-02-07 13:37:15 +00:00
std::string getLabel (void) const;
2012-05-23 14:56:01 +01:00
void simplifyGrounds (void);
static bool canMultiply (Parfactor*, Parfactor*);
private:
2012-05-24 22:55:20 +01:00
void simplifyCountingFormulas (size_t fIdx);
2012-05-23 14:56:01 +01:00
2012-05-24 22:55:20 +01:00
void simplifyParfactor (size_t fIdx1, size_t fIdx2);
2012-05-23 14:56:01 +01:00
static std::pair<LogVars, LogVars> getAlignLogVars (
Parfactor* g1, Parfactor* g2);
2012-05-24 22:55:20 +01:00
void expandPotential (size_t fIdx, unsigned newRange,
2013-02-07 13:37:15 +00:00
const std::vector<unsigned>& sumIndexes);
2012-05-23 14:56:01 +01:00
static void alignAndExponentiate (Parfactor*, Parfactor*);
static void alignLogicalVars (Parfactor*, Parfactor*);
2012-12-17 18:39:42 +00:00
ConstraintTree* constr_;
2012-12-20 23:19:10 +00:00
2012-12-27 22:25:45 +00:00
DISALLOW_ASSIGN (Parfactor);
2012-05-23 14:56:01 +01:00
};
2013-02-07 13:37:15 +00:00
typedef std::vector<Parfactor*> Parfactors;
2012-05-23 14:56:01 +01:00
2013-02-07 23:53:13 +00:00
} // namespace horus
2013-02-08 00:20:01 +00:00
#endif // YAP_PACKAGES_CLPBN_HORUS_PARFACTOR_H_
2012-05-23 14:56:01 +01:00