2 * Copyright 2007-2014 The OpenMx Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /***********************************************************
21 * Created: Timothy R. Brick Date: 2009-02-17
23 * Contains header information for the omxFitFunction class
24 * omxFitFunction objects hold necessary information to simplify
25 * fit function calculation.
27 **********************************************************/
29 #ifndef _OMXFITFUNCTION_H_
30 #define _OMXFITFUNCTION_H_
34 #include <Rinternals.h>
35 #include <R_ext/Rdynload.h>
36 #include <R_ext/BLAS.h>
37 #include <R_ext/Lapack.h>
39 #include "omxDefines.h"
40 #include "omxMatrix.h"
41 #include "omxAlgebra.h"
42 #include "omxAlgebraFunctions.h"
45 #include "omxExpectation.h"
55 struct omxFitFunction { // A fit function
57 /* Fields unique to FitFunction Functions */
58 void (*initFun)(omxFitFunction *oo);
59 void (*destructFun)(omxFitFunction* oo); // Wrapper for the destructor object
60 // ffcompute is somewhat redundent because grad=NULL when gradients are unwanted
61 void (*computeFun)(omxFitFunction* oo, int ffcompute, FitContext *fc);
63 omxRListElement* (*setFinalReturns)(omxFitFunction* oo, int *numVals); // DEPRECATED, use addOutput instead
65 // addOutput should only be used for returning global results
66 void (*addOutput)(omxFitFunction* oo, MxRList *out);
68 // populateAttrFun should be used for returning results specific to fit functions or expectations
69 void (*populateAttrFun)(omxFitFunction* oo, SEXP algebra);
71 void (*setVarGroup)(omxFitFunction*, FreeVarGroup *);
73 SEXP rObj; // Original r Object Pointer
74 omxExpectation* expectation; // Data expectation object
75 void* argStruct; // Arguments needed for fit function
76 // This is always a pointer to a static string.
77 // We do not need to allocate or free it.
78 const char* fitType; // Type of FitFunction Function
80 omxMatrix* matrix; // The (1x1) matrix populated by this fit function
82 FreeVarGroup *freeVarGroup;
83 bool gradientAvailable;
84 bool hessianAvailable;
87 /* Initialize and Destroy */
88 void omxFillMatrixFromMxFitFunction(omxMatrix* om, const char *fitType, int matrixNumber);
89 void omxCompleteFitFunction(omxMatrix *om);
90 void setFreeVarGroup(omxFitFunction *ff, FreeVarGroup *fvg);
92 void omxFreeFitFunctionArgs(omxFitFunction* fitFunction); // Frees all args
93 void omxGetFitFunctionStandardErrors(omxFitFunction *oo); // Get Standard Errors
95 /* FitFunction-specific implementations of matrix functions */
96 void omxFitFunctionCompute(omxFitFunction *off, int want, FitContext *fc);
97 void omxDuplicateFitMatrix(omxMatrix *tgt, const omxMatrix *src, omxState* targetState);
99 void omxFitFunctionPrint(omxFitFunction *source, const char* d);
101 omxMatrix* omxNewMatrixFromSlot(SEXP rObj, omxState* state, const char* slotName);
103 void omxFitFunctionCreateChildren(omxState *globalState);
105 void omxInitFIMLFitFunction(omxFitFunction* off);
106 void omxInitAlgebraFitFunction(omxFitFunction *off);
107 void omxInitWLSFitFunction(omxFitFunction *off);
108 void omxInitRowFitFunction(omxFitFunction *off);
109 void omxInitMLFitFunction(omxFitFunction *off);
110 void omxInitRFitFunction(omxFitFunction *off);
111 void omxInitFitFunctionBA81(omxFitFunction* oo);
112 void ba81SetFreeVarGroup(omxFitFunction *oo, FreeVarGroup *fvg);
114 void ComputeFit(omxMatrix *fitMat, int want, FitContext *fc);
116 #endif /* _OMXFITFUNCTION_H_ */