Revert "MxFitFunctionMultigroup"
[openmx:openmx.git] / src / omxExpectation.h
1 /*
2  *  Copyright 2007-2013 The OpenMx Project
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 /***********************************************************
18
19 *  omxExpectation.h
20 *
21 *  Created: Timothy R. Brick    Date: 2009-02-17
22 *
23 *       Contains header information for the omxExpectation class
24 *   omxExpectation objects hold necessary information to simplify
25 *       Expectation function calculation.
26 *
27 **********************************************************/
28
29 #ifndef _OMXEXPECTATION_H_
30 #define _OMXEXPECTATION_H_
31
32 #include <R.h>
33 #include <Rinternals.h> 
34 #include <Rdefines.h>
35 #include <R_ext/Rdynload.h> 
36 #include <R_ext/BLAS.h>
37 #include <R_ext/Lapack.h>
38 #include "omxDefines.h"
39
40 typedef struct omxExpectation omxExpectation;
41 typedef struct omxDefinitionVar omxDefinitionVar;
42 typedef struct omxThresholdColumn omxThresholdColumn;
43
44 #include "omxMatrix.h"
45 #include "omxAlgebra.h"
46 #include "omxAlgebraFunctions.h"
47 #include "omxData.h"
48 #include "omxState.h"
49
50 /* Def Var and Threshold Structures */
51 struct omxDefinitionVar {                       // Definition Var
52
53         int data, column;               // Where it comes from
54         omxData* source;                // Data source
55         int numLocations;               // Num locations
56         int* rows;                              // row positions
57         int* cols;                              // column positions
58         int* matrices;                  // matrix numbers
59         int  numDeps;           // number of algebra/matrix dependencies
60         int* deps;              // indices of algebra/matrix dependencies
61
62 };
63
64 struct omxThresholdColumn {                     // Threshold
65
66         omxMatrix* matrix;              // Which Matrix/Algebra it comes from
67         int column;                             // Which column has the thresholds
68         int numThresholds;              // And how many thresholds
69
70 };
71
72 /* Expectation structure itself */
73 struct omxExpectation {                                 // An Expectation
74
75         /* Fields unique to Expectation Functions */
76         void (*initFun)(omxExpectation *ox);
77         void (*destructFun)(omxExpectation* ox);                                                                        // Wrapper for the destructor object
78         void (*computeFun)(omxExpectation* ox);                                                                         // Wrapper for the Expectation function itself
79         void (*printFun)(omxExpectation* ox);                                                                           // Prints the appropriate pieces of the expectation
80         void (*setFitFun)(omxExpectation ox, omxFitFunction* off);                                      // To handle fit interactions
81         void (*repopulateFun)(omxExpectation* ox, double* x, int n);                            // To repopulate any data stored in the Expectation function
82         void (*populateAttrFun)(omxExpectation* ox, SEXP algebra);                                      // Add attributes to the result algebra object
83         omxMatrix* (*componentFun)(omxExpectation*, omxFitFunction*, const char*);              // Return component locations to expectation
84         void (*mutateFun)(omxExpectation*, omxFitFunction*, const char*, omxMatrix*); // Modify/set/mutate components of expectation
85         
86         SEXP rObj;                                                                                                                                      // Original r Object Pointer
87         void* sharedArgs;                                                                                                                       // Common argument structure
88         void* argStruct;                                                                                                                        // Arguments needed for Expectation function
89         const char* expType;   // pointer to a static string, no need to allocate or free
90         unsigned short int isPrepopulated;                                                                                      // Object has had some values prepopulated to allow object sharing
91         omxData* data;                                                                                                                          // Not sure if this is appropriate, but the expectation passes the actual data object
92         omxMatrix* dataColumns;
93         omxThresholdColumn* thresholds;
94         omxDefinitionVar* defVars;
95         int numOrdinal, numDefs;
96         
97         /* Replication of some of the structures from Matrix */
98         unsigned short isComplete;                                                                                                      // Whether or not this expectation has been initialize
99         omxState* currentState;
100         int expNum;
101
102         omxExpectation *container;
103         int numSubmodels;
104         omxExpectation **submodels;
105 };
106
107 omxExpectation *
108 omxNewInternalExpectation(const char *expType, omxState* os);
109
110         void omxCompleteExpectation(omxExpectation *ox);
111         void omxFreeExpectationArgs(omxExpectation* Expectation);                                       // Frees all args
112 omxExpectation* omxExpectationFromIndex(int expIndex, omxState* os);
113         omxExpectation* omxNewIncompleteExpectation(SEXP mxobj, int expNum, omxState* os);
114         
115
116 /* Expectation-specific implementations of matrix functions */
117         void omxExpectationRecompute(omxExpectation *ox);
118         void omxExpectationCompute(omxExpectation *ox);
119         omxExpectation* omxDuplicateExpectation(const omxExpectation *src, omxState* newState);
120         
121         void omxExpectationPrint(omxExpectation *source, char* d);                                      // Pretty-print a (small-form) expectation
122         
123 omxMatrix* omxGetExpectationComponent(omxExpectation *ox, omxFitFunction *off, const char* component);
124         
125 void omxSetExpectationComponent(omxExpectation *ox, omxFitFunction *off, const char* component, omxMatrix *om);
126
127 #endif /* _OMXEXPECTATION_H_ */