25 void mexFunction(
int nlhs, mxArray *plhs[],
26 int nrhs,
const mxArray *prhs[])
30 const mxArray *func_name, *params;
41 CHECK0(nlhs != 2 || nrhs != 3,
42 "wrong number of arguments");
51 if (mxIsChar(func_name))
53 CHECK0(mxGetString(func_name, udata.f, FLEN) == 0,
54 "error reading function name string (too long?)");
59 else if (mxIsFunctionHandle(func_name))
61 udata.prhs[0] = (mxArray *)func_name;
62 strcpy(udata.f,
"feval");
69 mexErrMsgTxt(
"First term should be a function name or function handle");
73 CHECK0(mxIsDouble(prhs[1]) && !mxIsComplex(prhs[1])
74 && ( (mxGetM(prhs[1]) == 1) && (mxGetN(prhs[1]) == nDim)
75 || (mxGetN(prhs[1]) == 1) && (mxGetM(prhs[1]) == nDim)),
76 "categories must be real row or column vector");
78 cat_d = mxGetPr(prhs[3]);
80 nDim = (
unsigned int) mxGetM(prhs[1]) * mxGetN(prhs[1]);
82 cat_i = (
int*)(mxCalloc(nDim,
sizeof(
int)));
83 for (ii = 0; ii < nDim; ++ii)
85 cat_i[ii] = (int)(cat_d[ii]+0.5);
88 udata.prhs[udata.xrhs] = mxCreateDoubleMatrix(1, nDim, mxREAL);
90 xopt = mxCreateDoubleMatrix(1, nDim, mxREAL);
96 CHECK0(mxIsStruct(prhs[2]),
"3rd element must be a struct");
101 params = mxCreateStructMatrix(1,1,0,NULL);
103 parameters = load_parameters(params);
109 mxDestroyArray(udata.prhs[udata.xrhs]);
113 plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
114 *(mxGetPr(plhs[1])) = fmin;
119 plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
120 *(mxGetPr(plhs[2])) = (
double)(error_code);
Configuration parameters.
BAYESOPT_API int bayes_optimization_categorical(int nDim, eval_func f, void *f_data, int *categories, double *x, double *minf, bopt_params parameters)
C wrapper for the Bayesian optimization algorithm.