예제 #1
0
inline
mxArray* to_mxarray(const array_nd<array_nd<T> >& a)
{
	mxArray* mx = mxCreateCellArray(a.ndims(),
		reinterpret_cast<const mwSize*>(a.sizes().get_base_ptr()));

	size_t len = a.length();
	for(size_t i = 0; i < len; i++) {
		mxSetCell(mx, mwIndex(i), to_mxarray(a[i]));
	}

	return mx;
}
예제 #2
0
static void
predict_one (const mxArray*     xtic,
             const mxArray*     oas,
             const mxArray*     filtmat,
             mwIndex            node,
             mwIndex            example,
             const float*       mybias,
             double*            yptr)
{
  const mwIndex* fmir = mxGetIr (filtmat);
  const mwIndex* fmjc = mxGetJc (filtmat);
  const mwIndex* xir = mxGetIr (xtic);
  const mwIndex* xjc = mxGetJc (xtic);
  const double* xs = mxGetPr (xtic);
  mwSize nexamples = mxGetN (xtic);
  mwSize nfeatures = mxGetM (oas);
  mwSize ncandidates = mxGetN (oas);
  const float* oasptr = (const float*) mxGetPr (oas);
  mwIndex argmax[N]; std::fill (argmax, argmax + N, mwIndex (0));
  float max[N]; std::fill (max, max + N, -FLT_MAX);

  for (mwIndex fmk = fmjc[node]; fmk < fmjc[node+1]; ++fmk) { 
    mwIndex candidate = fmir[fmk];
    const float* oascandidate = oasptr + (nfeatures * candidate);
    float pred = 0;

    for (mwIndex hk = xjc[example]; hk < xjc[example+1]; ++hk) {
      mwIndex feature = xir[hk];

      pred += oascandidate[feature] * xs[hk];
    }

    if (mybias) {
      pred += mybias[fmk - fmjc[node]];
    }

    mwIndex arg = 1 + candidate;

    for (unsigned int n = 0; n < N; ++n) {
      if (pred > max[n]) {
        std::swap (argmax[n], arg);
        std::swap (max[n], pred);
      }
    }
  }

  for (unsigned int n = 0; n < N; ++n) { 
    yptr[example + n * nexamples] = argmax[n];
  }
}
예제 #3
0
inline
void assign(array_nd<array<T> >& a, const mxArray* mx)
{
	if(mx::type_class<T>() == mxUNKNOWN_CLASS)
		throw etype();
	if(mxGetClassID(mx) != mx::type_class<T>())
		throw etype();

	size_array sz(mxGetNumberOfDimensions(mx),
		reinterpret_cast<const size_t*>(mxGetDimensions(mx)));
	a.resize(sz);

	size_t len = a.length();

	for(size_t i = 0; i < len; i++) {
		assign(a[i], mxGetCell(mx, mwIndex(i)));
	}
}