/* * NEURAL_NET neural network simulation function. * * Generated by Neural Network Toolbox function genFunction, 18-Mar-2016 18:06:53. * * [y1] = neural_net(x1) takes these arguments: * x = 12xQ matrix, input #1 * and returns: * y = 5xQ matrix, output #1 * where Q is the number of samples. * Arguments : const float x1[1488] * float b_y1[620] * Return Type : void */ void neural_net(const float x1[1488], float b_y1[620]) { float xp1[1488]; static const double dv0[12] = { 16.132376, -41.92286, -11.763175, 0.26042256, -48.499973, -10.59572, -11.150261, -50.75682, -17.053158, -20.999031, -31.260366, -16.086512 }; static const double dv1[12] = { 0.0872760507447396, 0.0583581858719483, 0.0496593431136582, 0.0621090054882946, 0.0398973259870547, 0.0429406458505015, 0.0418338504206415, 0.0292683416538594, 0.0406196264042357, 0.0324026540430679, 0.0488586616635397, 0.0444680174345756 }; double dv2[620]; double dv3[1240]; float fv0[1240]; int i0; int i1; float f0; int i2; static const float fv1[120] = { -0.482139856F, 0.268292874F, -0.398598433F, -0.492702723F, -5.28534F, -1.3607614F, -1.31324863F, -2.90275884F, 0.57084167F, 0.643586755F, 0.54507637F, 0.229064658F, 0.454308599F, -1.42380536F, -1.41992974F, 3.64180279F, 0.14793165F, 1.11103225F, -0.886625707F, -1.1550293F, 0.21188508F, 2.01851439F, -0.85992837F, -1.96682489F, -0.0088577373F, 3.95469904F, 0.961833417F, 2.36891127F, -0.709682882F, -2.43880248F, 0.912824154F, 1.19552827F, -0.754117072F, -0.0282568727F, -1.58362544F, -0.450968713F, -1.03895199F, 0.997594237F, -0.53181994F, -0.204281747F, -0.679035425F, -0.652160525F, -1.03224313F, 0.574654937F, -0.419399559F, -1.09406209F, -1.95429432F, -1.64093769F, 0.616113186F, 1.53872609F, 0.877005696F, -0.772606075F, 0.965004742F, -0.708744109F, -0.699137F, 0.178787217F, 0.661658704F, 1.50458348F, -1.11914206F, 2.82313919F, 1.04887187F, 1.11462772F, 3.57028317F, 1.90066338F, 1.40841186F, 0.145877808F, -0.734749F, 1.91204357F, -0.942125857F, 0.125358075F, 0.803959668F, -2.41720366F, -0.863904297F, 0.142200008F, -0.480167896F, -3.39202547F, -2.81302428F, -2.2363379F, 0.470471919F, -1.23218513F, -0.235131681F, -3.10341072F, -2.91667509F, -0.866841495F, 0.148358867F, -0.961966038F, -0.191483766F, -2.43185115F, 0.39682892F, -1.77321279F, -0.733736455F, 2.46021F, 1.28283262F, 1.75353122F, 0.896416F, 2.57278728F, 1.11794055F, 3.0823822F, -0.0531957038F, -1.96753991F, 0.432154804F, -0.0155567462F, -2.25758934F, 1.58146751F, -0.0868694782F, -2.00317669F, 0.564771533F, -2.29165697F, 0.0372338742F, 1.49811876F, -0.943119347F, -1.67992508F, 0.932955503F, -2.28386927F, 2.41840959F, 0.486109674F, 2.88024926F, -0.583868921F, 1.52614343F, 1.9853704F }; float fv2[1240]; float fv3[620]; static const float fv4[50] = { 1.92884886F, 0.0791850165F, 0.606354833F, 0.8203246F, -0.852406919F, -2.10267973F, -0.585249543F, -1.96586227F, 5.016222F, -0.959461629F, -3.65689325F, 0.844967902F, 4.3082037F, 1.28906775F, -3.90302444F, 0.817251503F, -3.68290186F, -0.165898442F, 3.55818534F, -1.68369067F, -5.09043407F, 0.936949968F, 2.58750296F, 2.75450921F, 0.50600791F, 5.61685228F, 4.00498772F, -4.83895683F, 1.23465705F, -3.98150063F, -4.74256086F, 4.84532976F, -3.24344039F, 0.342350513F, 4.4398303F, -4.56724262F, 3.84799695F, -1.66734827F, 2.45293832F, -0.163840726F, -1.40159512F, 0.639144599F, 1.05117142F, -0.097580716F, 1.9411335F, 3.98067117F, -2.86589026F, -3.9957943F, -1.48145068F, 2.93353248F }; float fv5[620]; /* ===== NEURAL NETWORK CONSTANTS ===== */ /* Input 1 */ /* Layer 1 */ /* Layer 2 */ /* Output 1 */ /* ===== SIMULATION ======== */ /* Dimensions */ /* samples */ /* Input 1 */ mapminmax_apply(x1, dv1, dv0, xp1); /* Layer 1 */ /* Layer 2 */ b_repmat(dv2); repmat(dv3); for (i0 = 0; i0 < 10; i0++) { for (i1 = 0; i1 < 124; i1++) { f0 = 0.0F; for (i2 = 0; i2 < 12; i2++) { f0 += fv1[i0 + 10 * i2] * xp1[i2 + 12 * i1]; } fv0[i0 + 10 * i1] = (float)dv3[i0 + 10 * i1] + f0; } } tansig_apply(fv0, fv2); for (i0 = 0; i0 < 5; i0++) { for (i1 = 0; i1 < 124; i1++) { f0 = 0.0F; for (i2 = 0; i2 < 10; i2++) { f0 += fv4[i0 + 5 * i2] * fv2[i2 + 10 * i1]; } fv3[i0 + 5 * i1] = (float)dv2[i0 + 5 * i1] + f0; } } /* Output 1 */ softmax_apply(fv3, fv5); mapminmax_reverse(fv5, b_y1); }
/* * function [lp]=gaussmixp(y,m,v,w) * y = cat(1, testSamples(1).mfcc{:}); * m = gmm.M; * v = gmm.V; * w = gmm.W; */ void gaussmixp(const real_T y[2004], const real_T m[108], const real_T v[108], const real_T w[9], real_T lp[167]) { real_T b[108]; real_T dv0[108]; real_T b_b[9]; real_T lvm[9]; int32_T ix; real_T mx[167]; real_T kk[1503]; real_T km[1503]; static real_T b_y[18036]; int32_T iy; real_T dv1[18036]; real_T x[1503]; int32_T i; int32_T ixstart; int32_T ixstop; real_T mtmp; int32_T b_ix; boolean_T exitg1; real_T ps[167]; /* GAUSSMIXP calculate probability densities from a Gaussian mixture model */ /* */ /* Inputs: n data values, k mixtures, p parameters, q data vector size */ /* */ /* Y(n,q) = input data */ /* M(k,p) = mixture means for x(p) */ /* V(k,p) or V(p,p,k) variances (diagonal or full) */ /* W(k,1) = weights */ /* A(q,p), B(q) = transformation: y=x*a'+b' (where y and x are row vectors) */ /* if A is omitted, it is assumed to be the first q rows of the */ /* identity matrix. B defaults to zero. */ /* Note that most commonly, q=p and A and B are omitted entirely. */ /* */ /* Outputs */ /* */ /* LP(n,1) = log probability of each data point */ /* RP(n,k) = relative probability of each mixture */ /* KH(n,1) = highest probability mixture */ /* KP(n,1) = relative probability of highest probability mixture */ /* Copyright (C) Mike Brookes 2000-2009 */ /* Version: $Id: gaussmixp.m,v 1.3 2009/04/08 07:51:21 dmb Exp $ */ /* */ /* VOICEBOX is a MATLAB toolbox for speech processing. */ /* Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html */ /* */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You can obtain a copy of the GNU General Public License from */ /* http://www.gnu.org/copyleft/gpl.html or by writing to */ /* Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* 'gaussmixp:49' [n,q]=size(y); */ /* 'gaussmixp:50' [k,p]=size(m); */ /* 'gaussmixp:51' memsize=voicebox('memsize'); */ voicebox(); /* set memory size to use */ /* 'gaussmixp:53' lp=zeros(n,1); */ memset((void *)&lp[0], 0, 167U * sizeof(real_T)); /* 'gaussmixp:54' wk=ones(k,1); */ /* 'gaussmixp:56' vi=-0.5*v.^(-1); */ power(v, b); /* data-independent scale factor in exponent */ /* 'gaussmixp:57' lvm=log(w)-0.5*sum(log(v),2); */ memcpy((void *)&dv0[0], (void *)&v[0], 108U * sizeof(real_T)); c_log(dv0); sum(dv0, b_b); memcpy((void *)&lvm[0], (void *)&w[0], 9U * sizeof(real_T)); b_log(lvm); for (ix = 0; ix < 9; ix++) { lvm[ix] -= 0.5 * b_b[ix]; } /* log of external scale factor (excluding -0.5*q*log(2pi) term) */ /* 'gaussmixp:58' ii=1:n; */ /* 'gaussmixp:59' wnj=ones(1,n); */ /* 'gaussmixp:60' kk=repmat(ii,k,1); */ for (ix = 0; ix < 167; ix++) { mx[ix] = 1.0 + (real_T)ix; } repmat(mx, kk); /* 'gaussmixp:61' km=repmat(1:k,1,n); */ for (ix = 0; ix < 9; ix++) { b_b[ix] = 1.0 + (real_T)ix; } b_repmat(b_b, km); /* 'gaussmixp:62' py=reshape(sum((y(kk(:),:)-m(km(:),:)).^2.*vi(km(:),:),2),k,n)+lvm(:,wnj); */ for (ix = 0; ix < 12; ix++) { for (iy = 0; iy < 1503; iy++) { b_y[iy + 1503 * ix] = y[((int32_T)kk[iy] + 167 * ix) - 1] - m[((int32_T) km[iy] + 9 * ix) - 1]; } } b_power(b_y, dv1); for (ix = 0; ix < 12; ix++) { for (iy = 0; iy < 1503; iy++) { b_y[iy + 1503 * ix] = dv1[iy + 1503 * ix] * (-0.5 * b[((int32_T)km[iy] + 9 * ix) - 1]); } } b_sum(b_y, x); memcpy((void *)&kk[0], (void *)&x[0], 1503U * sizeof(real_T)); for (ix = 0; ix < 167; ix++) { for (iy = 0; iy < 9; iy++) { km[iy + 9 * ix] = kk[iy + 9 * ix] + lvm[iy]; } } /* 'gaussmixp:63' mx=max(py,[],1); */ ix = -8; iy = -1; for (i = 0; i < 167; i++) { ix += 9; ixstart = ix; ixstop = ix + 8; mtmp = km[ix - 1]; if (rtIsNaN(km[ix - 1])) { b_ix = ix; exitg1 = 0U; while ((exitg1 == 0U) && (b_ix + 1 <= ixstop)) { ixstart = b_ix + 1; if (!rtIsNaN(km[b_ix])) { mtmp = km[b_ix]; exitg1 = 1U; } else { b_ix++; } } } if (ixstart < ixstop) { while (ixstart + 1 <= ixstop) { if (km[ixstart] > mtmp) { mtmp = km[ixstart]; } ixstart++; } } iy++; mx[iy] = mtmp; } /* find normalizing factor for each data point to prevent underflow when using exp() */ /* 'gaussmixp:64' px=exp(py-mx(wk,:)); */ for (ix = 0; ix < 167; ix++) { for (iy = 0; iy < 9; iy++) { kk[iy + 9 * ix] = km[iy + 9 * ix] - mx[ix]; } } b_exp(kk); /* find normalized probability of each mixture for each datapoint */ /* 'gaussmixp:65' ps=sum(px,1); */ c_sum(kk, ps); /* total normalized likelihood of each data point */ /* 'gaussmixp:66' lp(ii)=log(ps)+mx; */ d_log(ps); for (ix = 0; ix < 167; ix++) { /* 'gaussmixp:67' lp=lp-0.5*q*log(2*pi); */ lp[ix] = (ps[ix] + mx[ix]) - 11.027262398456072; } }
// // Arguments : const emxArray_uint8_T *a // signed char direction // emxArray_uint8_T *b // Return Type : void // void b_ConstantPad(const emxArray_uint8_T *a, signed char direction, emxArray_uint8_T *b) { int sizeB[2]; int cdiff; int i37; emxArray_uint8_T *r14; int b_sizeB[2]; int absb; int ndbl; emxArray_real_T *y; emxArray_real_T *b_y; int apnd; for (cdiff = 0; cdiff < 2; cdiff++) { if (direction == 5) { i37 = a->size[cdiff] + 1; sizeB[cdiff] = i37; } else if (direction == 6) { i37 = a->size[cdiff] + 1; sizeB[cdiff] = i37; } else { i37 = a->size[cdiff]; sizeB[cdiff] = (int)((double)i37 + 2.0); } } b_emxInit_uint8_T(&r14, 2); b_sizeB[0] = sizeB[0]; b_sizeB[1] = sizeB[1]; b_repmat(b_sizeB, r14); for (i37 = 0; i37 < 2; i37++) { absb = b->size[0] * b->size[1]; b->size[i37] = r14->size[i37]; emxEnsureCapacity((emxArray__common *)b, absb, (int)sizeof(unsigned char)); } if (direction == 5) { for (cdiff = 0; cdiff < r14->size[0]; cdiff++) { b->data[cdiff] = 0; } i37 = b->size[1]; for (ndbl = 2; ndbl <= i37; ndbl++) { b->data[b->size[0] * (ndbl - 1)] = 0; } } else if (direction == 7) { for (cdiff = 0; cdiff < r14->size[0]; cdiff++) { b->data[cdiff] = 0; } i37 = b->size[1]; for (ndbl = a->size[1] + 1; ndbl + 1 <= i37; ndbl++) { absb = b->size[0]; for (cdiff = 0; cdiff < absb; cdiff++) { b->data[cdiff + b->size[0] * ndbl] = 0; } } for (ndbl = 2; ndbl <= a->size[1] + 1; ndbl++) { b->data[b->size[0] * (ndbl - 1)] = 0; } for (ndbl = 2; ndbl <= a->size[1] + 1; ndbl++) { i37 = b->size[0]; for (cdiff = a->size[0] + 1; cdiff + 1 <= i37; cdiff++) { b->data[cdiff + b->size[0] * (ndbl - 1)] = 0; } } } else { for (ndbl = a->size[1]; ndbl + 1 <= r14->size[1]; ndbl++) { i37 = b->size[0]; for (cdiff = 0; cdiff < i37; cdiff++) { b->data[cdiff + b->size[0] * ndbl] = 0; } } for (ndbl = 0; ndbl < a->size[1]; ndbl++) { i37 = b->size[0]; for (cdiff = a->size[0]; cdiff + 1 <= i37; cdiff++) { b->data[cdiff + b->size[0] * ndbl] = 0; } } } emxFree_uint8_T(&r14); b_emxInit_real_T(&y, 2); b_emxInit_real_T(&b_y, 2); if ((direction == 5) || (direction == 7)) { if (a->size[0] < 1) { absb = -1; apnd = 0; } else { ndbl = (int)floor(((double)a->size[0] - 1.0) + 0.5); apnd = ndbl + 1; cdiff = (ndbl - a->size[0]) + 1; absb = a->size[0]; if (fabs((double)cdiff) < 4.4408920985006262E-16 * (double)absb) { ndbl++; apnd = a->size[0]; } else if (cdiff > 0) { apnd = ndbl; } else { ndbl++; } absb = ndbl - 1; } i37 = y->size[0] * y->size[1]; y->size[0] = 1; y->size[1] = absb + 1; emxEnsureCapacity((emxArray__common *)y, i37, (int)sizeof(double)); if (absb + 1 > 0) { y->data[0] = 1.0; if (absb + 1 > 1) { y->data[absb] = apnd; ndbl = absb / 2; for (cdiff = 1; cdiff < ndbl; cdiff++) { y->data[cdiff] = 1.0 + (double)cdiff; y->data[absb - cdiff] = apnd - cdiff; } if (ndbl << 1 == absb) { y->data[ndbl] = (1.0 + (double)apnd) / 2.0; } else { y->data[ndbl] = 1.0 + (double)ndbl; y->data[ndbl + 1] = apnd - ndbl; } } } if (a->size[1] < 1) { absb = -1; apnd = 0; } else { ndbl = (int)floor(((double)a->size[1] - 1.0) + 0.5); apnd = ndbl + 1; cdiff = (ndbl - a->size[1]) + 1; absb = a->size[1]; if (fabs((double)cdiff) < 4.4408920985006262E-16 * (double)absb) { ndbl++; apnd = a->size[1]; } else if (cdiff > 0) { apnd = ndbl; } else { ndbl++; } absb = ndbl - 1; } i37 = b_y->size[0] * b_y->size[1]; b_y->size[0] = 1; b_y->size[1] = absb + 1; emxEnsureCapacity((emxArray__common *)b_y, i37, (int)sizeof(double)); if (absb + 1 > 0) { b_y->data[0] = 1.0; if (absb + 1 > 1) { b_y->data[absb] = apnd; ndbl = absb / 2; for (cdiff = 1; cdiff < ndbl; cdiff++) { b_y->data[cdiff] = 1.0 + (double)cdiff; b_y->data[absb - cdiff] = apnd - cdiff; } if (ndbl << 1 == absb) { b_y->data[ndbl] = (1.0 + (double)apnd) / 2.0; } else { b_y->data[ndbl] = 1.0 + (double)ndbl; b_y->data[ndbl + 1] = apnd - ndbl; } } } ndbl = a->size[1]; for (i37 = 0; i37 < ndbl; i37++) { cdiff = a->size[0]; for (absb = 0; absb < cdiff; absb++) { b->data[(int)y->data[y->size[0] * absb] + b->size[0] * (int)b_y-> data[b_y->size[0] * i37]] = a->data[absb + a->size[0] * i37]; } } } else { ndbl = a->size[1]; for (i37 = 0; i37 < ndbl; i37++) { cdiff = a->size[0]; for (absb = 0; absb < cdiff; absb++) { b->data[absb + b->size[0] * i37] = a->data[absb + a->size[0] * i37]; } } } emxFree_real_T(&b_y); emxFree_real_T(&y); }