Borrar filtros
Borrar filtros

What is the meaning of the variables in the C generated code of a Linear Discriminant Analysis model trained in MATLAB?

11 visualizaciones (últimos 30 días)
I have exported an LDA classifier to C code (5 classes, 8 features, diagonal) and as far as I can tell there are four vectors/matrices in the generated C code that contain the classifier coefficients:
in the "myclassifiername_predict" function:
C code:
void myclassifiername_predict(const double X[8], cell_wrap_0 label[1],double score[5])
{
static const double dv[8] = {22.242777113313874, 10091.972043688236,
18.120065167575063, 1.6703515441084688E+6,
24.467860977243351, 10578.886659888578,
19.515843697095619, 1.9037831242647208E+6};
static const double dv1[5] = {0.19444444444444445, 0.19791666666666666,
0.20254629629629631, 0.18865740740740741,
0.21643518518518517};
// rest of function body...
}
void DiagonalDiscriminant(const double X[8], double mah[5])
{
static const double dv[40] = {
92.058756510416757, 428.55436769005888, 99.445223214285761,
121.16319976993877, 28.000396891711258, 12736.000000000013,
81355.60233918138, 19612.525714285723, 16993.374233128856,
3436.1497326203244, 143.11044456845252, 72.791255482456208,
144.52926339285719, 196.37662960122714, 29.916151403743349,
5.2292266666666726E+6, 3.3097596257309979E+6, 7.8175085714285746E+6,
7.0232076564417249E+6, 894724.10695187247, 480.39411272321479,
26.045367324561425, 53.19522321428574, 239.98229006901863,
20.971883355614992, 80371.8095238096, 2976.1871345029267,
8478.720000000003, 52414.036809816, 2602.4385026737991,
325.64160156250028, 34.383543494152079, 84.338125000000034,
72.35264091257676, 33.127548462566885, 1.6916089904761918E+7,
1.5491024093567266E+6, 3.7583959771428583E+6, 4.3856852024539923E+6,
1.6065081497326223E+6};
static const double dv1[8] = {0.044958414810596169, 9.9088661331104676E-5,
0.0551874394905295, 5.9867637056829179E-7,
0.040869939588510124, 9.4527905643572937E-5,
0.051240418580971815, 5.2526991507303129E-7};
// rest of function body...
}
When I look at the LDA classifier object in Matlab, I can see that
  • dv (in the predict function) is "d" in the compact Matlab classifier object
  • dv1 (in the predict function) is "classWeights" in the compact Matlab classifier object ("Prior" in the non-compact model)
  • dv (in the "DiagonalDiscrimant" function) is "mu" in the compact Matlab classifier object (5x8 Matrix)
What I can't figure out is where dv1 (in the "DiagonalDiscrimant" function) comes from?
The compact classifier object still has the 1x8 vector s and 8x8 matrix v, dv1 might be derived from that?
compactStruct.Impl.s =
1.4238
1.1705
1.0736
1.0486
0.9416
0.7696
0.6899
0.6289
compactStruct.Impl.v =
-0.3052 0.4804 -0.4588 -0.0729 -0.0968 0.4692 -0.4536 0.1580
-0.2068 0.4571 -0.1782 -0.5754 0.2103 -0.4734 0.3155 -0.1324
-0.4628 0.2472 0.1387 0.4526 -0.0425 0.2732 0.5113 -0.4034
-0.2834 0.3263 0.5855 0.2610 0.2132 -0.3524 -0.4367 0.2047
-0.4229 -0.4231 -0.3445 0.1189 -0.0292 -0.3675 -0.3760 -0.4816
-0.2237 -0.0354 0.3379 -0.3487 -0.8434 -0.0306 -0.0262 -0.0052
-0.5272 -0.3569 -0.1467 0.0226 0.0751 -0.0506 0.2940 0.6914
-0.2506 -0.2915 0.3759 -0.5043 0.4258 0.4673 -0.1189 -0.2069
The original (non-compact) model doesn't have dv1 either.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 4 de En. de 2024
The meanings of these variables are:
  • Under the function "myLDApredict", "dv" means "D", which represents the standard deviations for all predictors.
  • Under the function "myLDApredict", "dv1" represents the class prior.
  • Under the function "DiagonalDiscriminant", "dv" means "Mu", which represents the k-by-p matrix with class means for k classes and p predictors.
  • Under the function "DiagonalDiscriminant", "dv1" means "invD", which represents the inverse values of predictor standard deviations (computed after centering by class means). It is calculated by the inverse of the standard deviations "D".

Más respuestas (1)

Bill Chou
Bill Chou el 6 de Oct. de 2023
Hi Handyman,
I checked with our development team and they would need to know a bit more about your code to answer your question.
Can you contact technical support and reference this MATLAB Answers post? We can then work to help answer your question that way.
Thank you,
Bill Chou

Categorías

Más información sobre Deep Learning Toolbox en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by