25 void mexFunction(
int nlhs, mxArray *plhs[],
26 int nrhs,
const mxArray *prhs[])
30 const mxArray *func_name, *params;
40 CHECK0(nlhs != 2 || nrhs != 3 || nrhs != 5,
41 "wrong number of arguments");
50 if (mxIsChar(func_name))
52 CHECK0(mxGetString(func_name, udata.f, FLEN) == 0,
53 "error reading function name string (too long?)");
58 else if (mxIsFunctionHandle(func_name))
60 udata.prhs[0] = (mxArray *)func_name;
61 strcpy(udata.f,
"feval");
68 mexErrMsgTxt(
"First term should be a function name or function handle");
72 CHECK0(mxIsNumeric(prhs[1]) && !mxIsComplex(prhs[1])
73 && mxGetM(prhs[1]) * mxGetN(prhs[1]) == 1,
74 "nDim must be a scalar");
75 nDim = (
unsigned int) mxGetScalar(prhs[1]);
77 udata.prhs[udata.xrhs] = mxCreateDoubleMatrix(1, nDim, mxREAL);
79 xopt = mxCreateDoubleMatrix(1, nDim, mxREAL);
85 CHECK0(mxIsStruct(prhs[2]),
"3rd element must be a struct");
90 params = mxCreateStructMatrix(1,1,0,NULL);
92 parameters = load_parameters(params);
97 mexPrintf(
"Loading bounds...");
98 CHECK0(mxIsDouble(prhs[3]) && !mxIsComplex(prhs[3])
99 && (mxGetM(prhs[3]) == 1 || mxGetN(prhs[3]) == 1)
100 && (mxGetM(prhs[3]) == nDim || mxGetN(prhs[3]) == nDim),
101 "lowerBound must be real row or column vector");
103 lb = mxGetPr(prhs[3]);
106 CHECK0(mxIsDouble(prhs[4]) && !mxIsComplex(prhs[4])
107 && (mxGetM(prhs[4]) == 1 || mxGetN(prhs[4]) == 1)
108 && (mxGetM(prhs[4]) == nDim || mxGetN(prhs[4]) == nDim),
109 "upperBound must be real row or column vector");
111 ub = mxGetPr(prhs[4]);
112 mexPrintf(
"done. \n");
116 lb = (
double*)(mxCalloc(nDim,
sizeof(
double)));
117 ub = (
double*)(mxCalloc(nDim,
sizeof(
double)));
121 for (ii = 0; ii < nDim; ++ii)
137 mxDestroyArray(udata.prhs[udata.xrhs]);
141 plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
142 *(mxGetPr(plhs[1])) = fmin;
146 plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
147 *(mxGetPr(plhs[2])) = (
double)(error_code);
BAYESOPT_API int bayes_optimization(int nDim, eval_func f, void *f_data, const double *lb, const double *ub, double *x, double *minf, bopt_params parameters)
C wrapper for the Bayesian optimization algorithm.
Configuration parameters.