-
Notifications
You must be signed in to change notification settings - Fork 1
/
defcpt.h
123 lines (97 loc) · 4.91 KB
/
defcpt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef DSL_DEFCPT_H
#define DSL_DEFCPT_H
// {{SMILE_PUBLIC_HEADER}}
#include "nodedef.h"
#include "dmatrix.h"
#include "idarray.h"
//-------------------------------------------------------------------------
// CPT
//-------------------------------------------------------------------------
// minimum number of states
#define DSL_CPT_MIN_STATES 2
#define DSL_CPT_EPSILON 0.000005
class DSL_cpt : public DSL_nodeDefinition
{
// represents a discrete & non-deterministic chance node.
// ENTRY VALUES:
// This node is expecting DISCRETE entries from it's parents
// wich means that all it's parents should be discrete (or
// discretized if they are continuous)
public:
DSL_cpt(int myHandle, DSL_network *theNetwork);
DSL_cpt(DSL_nodeDefinition &likeThisOne);
virtual ~DSL_cpt() { CleanUp(); }
int operator =(DSL_nodeDefinition &likeThisOne);
int GetType() const { return DSL_CPT; }
const char *GetTypeName() const { return "CPT"; }
// access methods
DSL_idArray &GetStatesNames() {return(nameStates);}
DSL_Dmatrix &GetProbabilities() {return(table);}
const DSL_Dmatrix* GetTemporalProbabilities(int order) const;
int SetTemporalProbabilities(int order, const DSL_Dmatrix &probs);
int SetTemporalProbabilities(int order, const DSL_doubleArray &probs);
int GetSize() {return(table.GetSize());}
int GetNumberOfStates() {return(numStates);}
int SetProbabilities(DSL_doubleArray &theProbabilities);
int SetProbability(DSL_intArray &theCoordinates, double theProbability);
int GetProbability(DSL_intArray &theCoordinates, double &theProbability);
int RenameState(int stateNumber, char *newName);
int RenameStates(DSL_stringArray &theStateNames);
int NextCoordinates(DSL_intArray &theCoordinates);
int PrevCoordinates(DSL_intArray &theCoordinates);
// methods to deal with changes in my definition
int AddState(const char *thisName);
int InsertState(int here, const char *thisName);
int RemoveState(int stateNumber);
int SetNumberOfStates(int aNumber);
int SetNumberOfStates(DSL_stringArray &theStateNames);
int ChangeOrderOfStates(DSL_intArray &newOrder);
// methods to deal with changes in my relationships
int AddParent(int theParent);
int AbsorbEvidenceFromParent(int theParent);
int MarginalizeParent(int theParent);
int RemoveParent(int theParent);
// methods to deal with changes in the definition of my parents
int DaddyGetsBigger(int daddy, int thisPosition);
int DaddyGetsSmaller(int daddy, int thisPosition);
int DaddyChangedOrderOfOutcomes(int daddy, DSL_intArray &newOrder);
int OrderOfParentsGetsChanged(DSL_intArray &newOrder);
// methods for internal use (no checking at all)
void SetProbability(int thisOne, double theProbability) {table[thisOne] = theProbability;}
double GetProbability(int thisOne) {return(table[thisOne]);}
void CleanUp(int deep = 0);
void CheckReadiness(int deep = 0);
void CheckConsistency(int deep = 0);
int CreateUniqueStateName(char *here);
int ReCreateFromNetworkStructure();
int Clone(DSL_nodeDefinition &thisGuy);
int CheckParentsStructure();
// common interface
int AddOutcome(const char *thisName) {return(AddState(thisName));}
int InsertOutcome(int here, const char *thisName) {return(InsertState(here,thisName));}
int RemoveOutcome(int outcomeNumber) {return(RemoveState(outcomeNumber));}
int GetNumberOfOutcomes() {return(GetNumberOfStates());}
int RenameOutcome(int outcomeNumber, char *newName) {return(RenameState(outcomeNumber,newName));}
int RenameOutcomes(DSL_stringArray &theOutcomeNames) {return(RenameStates(theOutcomeNames));}
DSL_idArray *GetOutcomesNames() {return(&GetStatesNames());}
int SetNumberOfOutcomes(int aNumber) {return(SetNumberOfStates(aNumber));}
int SetNumberOfOutcomes(DSL_stringArray &theOutcomeNames) {return(SetNumberOfStates(theOutcomeNames));}
int ChangeOrderOfOutcomes(DSL_intArray &newOrder) {return(ChangeOrderOfStates(newOrder));}
// get/set definitions in several ways
int GetDefinition(DSL_Dmatrix **here) {*here = &GetProbabilities(); return(DSL_OKAY);}
int GetDefinition(DSL_doubleArray **here) {*here = &GetProbabilities().GetItems(); return(DSL_OKAY);}
int SetDefinition(DSL_Dmatrix &withThis)
{
assert(table.CompatibleWith(withThis));
table = withThis;
return DSL_OKAY;
}
int SetDefinition(DSL_doubleArray &withThis) {table.GetItems().FillFrom(withThis); return(DSL_OKAY);}
int MakeUniform();
protected:
void DoCopyParameters(DSL_nodeDefinition &target) const;
int numStates; // number of states of the node
DSL_idArray nameStates; // names (labels) for all the states of the node
DSL_Dmatrix table; // the table of probabilities
};
#endif