pdfbest_KLD.cc
上传用户:l56789
上传日期:2022-02-25
资源大小:2422k
文件大小:2k
源码类别:

图形图像处理

开发平台:

Matlab

  1. //-----------------------------------------------------------------------------
  2. // pdfbest_KLD.cc  -  Estimate the Kullback-Liebler distance using the
  3. //                     Monte Carlo method
  4. //
  5. // input arguments: - model1 - the first THMT model
  6. //                  - model2 - the second THMT model
  7. //                  - N - number of trees to generate
  8. //     
  9. //-----------------------------------------------------------------------------
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <iostream>
  14. #include <math.h>
  15. #include "tree.hh"
  16. #include "pdfbthmt.hh"
  17. #include "mex.h"
  18. //-----------------------------------------------------------------------------
  19. double pdfbest_KLD(const mxArray* model1, const mxArray* model2, int* levndir,
  20.    int N)
  21. {
  22.     // Read initial model
  23.     THMT thmt1(model1, levndir);
  24.     THMT thmt2(model2, levndir);
  25.     return KLD_est(thmt1, thmt2, N);
  26. }
  27. //-----------------------------------------------------------------------------
  28. void mexFunction( int nlhs, mxArray *plhs[], 
  29.   int nrhs, const mxArray *prhs[] )     
  30. {
  31.     double *templevndir, *kldist; 
  32.     int nl, i, *levndir, N; 
  33.     
  34.     /* Check for proper number of arguments */
  35.     
  36.     if (nrhs != 5) { 
  37. mexErrMsgTxt("Wrong number of input arguments."); 
  38.     } 
  39.     else if (nlhs > 1) {
  40. mexErrMsgTxt("Too many output arguments."); 
  41.     } 
  42.  
  43.     nl = (int)mxGetScalar(prhs[0]);
  44.     N = (int)mxGetScalar(prhs[4]);
  45.     levndir = new int[nl];
  46.     templevndir = mxGetPr(prhs[1]);
  47.     for(i = 0; i<nl; i++)
  48.       levndir[i] = (int)(templevndir[i]);
  49.     plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
  50.     kldist = mxGetPr(plhs[0]);
  51.     /* Do the actual computations in a subroutine */
  52.     *kldist = pdfbest_KLD(prhs[2], prhs[3] ,levndir, N);
  53.     return;
  54. }