2 * Copyright 2007-2012 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_
33 #include <Rinternals.h>
35 #include <R_ext/Rdynload.h>
36 #include <R_ext/BLAS.h>
37 #include <R_ext/Lapack.h>
38 #include "omxDefines.h"
40 typedef struct omxFitFunction omxFitFunction;
43 #include "omxMatrix.h"
44 #include "omxAlgebra.h"
45 #include "omxAlgebraFunctions.h"
48 #include "omxExpectation.h"
50 struct omxFitFunction { // A fit function
52 /* Fields unique to FitFunction Functions */
53 void (*initFun)(omxFitFunction *oo, SEXP rObj); // Wrapper for initialization function (probably not needed)
54 void (*destructFun)(omxFitFunction* oo); // Wrapper for the destructor object
55 void (*computeFun)(omxFitFunction* oo); // Wrapper for the fit function itself
56 void (*repopulateFun)(omxFitFunction* oo, double* x, int n); // To repopulate any data stored in the fit function
57 omxRListElement* (*setFinalReturns)(omxFitFunction* oo, int *numVals); // Sets any R returns.
58 double* (*getStandardErrorFun)(omxFitFunction* oo); // To calculate standard errors
59 void (*gradientFun)(omxFitFunction* oo, double* grad); // To calculate gradient
60 void (*populateAttrFun)(omxFitFunction* oo, SEXP algebra); // Add attributes to the result algebra object
62 SEXP rObj; // Original r Object Pointer
63 omxExpectation* expectation; // Data expectation object
64 void* sharedArgs; // Common argument structure
65 void* argStruct; // Arguments needed for fit function
66 // This is always a pointer to a static string.
67 // We do not need to allocate or free it.
68 const char* fitType; // Type of FitFunction Function
69 double* hessian; // Hessian details
70 double* gradient; // Gradient details
71 double* stdError; // Standard Error estimates
72 unsigned short int isPrepopulated; // Object has had some values prepopulated to allow object sharing
74 omxMatrix* matrix; // The (1x1) matrix populated by this fit function
78 /* Initialize and Destroy */
79 void omxInitEmptyFitFunction(omxFitFunction *oo);
80 void omxFillMatrixFromMxFitFunction(omxMatrix* om, SEXP mxobj,
81 unsigned short hasMatrixNumber, int matrixNumber); // Create an omxFitFunction from an R MxFitFunction object
82 void omxFreeFitFunctionArgs(omxFitFunction* fitFunction); // Frees all args
83 void omxGetFitFunctionStandardErrors(omxFitFunction *oo); // Get Standard Errors
85 /* FitFunction-specific implementations of matrix functions */
86 void omxFitFunctionCompute(omxFitFunction *oo);
87 void omxFitFunctionGradient(omxFitFunction* oo, double* gradient); // For gradient calculation. If needed.
88 void omxDuplicateFitMatrix(omxMatrix *tgt, const omxMatrix *src, omxState* targetState);
89 omxFitFunction* omxCreateDuplicateFitFunction(omxFitFunction *tgt, const omxFitFunction *src, omxState* newState);
91 void omxFitFunctionPrint(omxFitFunction *source, char* d); // Pretty-print a (small) matrix
93 /* Helper functions */
94 void omxCalculateStdErrorFromHessian(double scale, omxFitFunction *oo); // Does what it says
96 /* Helpers related to fit function initialization */
97 omxMatrix* omxNewMatrixFromIndexSlot(SEXP rObj, omxState* state, char* const slotName); // Gets a matrix from an R SEXP slot
99 omxData* omxNewDataFromDataSlot(SEXP rObj, omxState* state, char* const dataSlotName); // Gets an mxData object from a data slot
101 #endif /* _OMXFITFUNCTION_H_ */