我有array feature_values_2d
。我想在for循环中使用每个数组项并将其值传递给data
变量。并从predict_res
函数得到每个数组的结果。
double features[44];
get_features(ecg_series,csv_data.at(0).size(),features);
union Entry data[44];
float result[4];
char filename[100];
char res[4]={'A','N','O','~'};
double feature_values_2d[6][44] = { {0.0003323988609746907, 0.6412162477054423, 9.545269768297, -1323.6125512135593, -1512.0718516647562, -2073.6020535721273, -2578.302701605687, 0.27304053703708875, 0.5580326301604825, 0.34912544310755905, 0.550917816717867, 49.7455110651867, 1821.15723334093, -61.3700045037962, -49.400686298507, 13.11111111111111, 26.0, 12.222222222222221, 18.0, 0.3111111111111111, 0.325, 0.4148148148148148, 0.43333333333333335, 0.5930328763108722, 0.7343377194812131, 0.23685155593995189, 0.6754530381265557, 0.16582557525922734, 0.009828988419922594, 0.00017475124235758377, 0.0003779194334627987, 0.0008100853061379151, 2.9387129701088046, 0.41880424639672703, 2.639057329615259, 0.0, 2.75, 2.807354922057604, 0.07124096827009982, std::numeric_limits<double>::quiet_NaN() , 0.003, 0.1435385870250432, 0.5547574989867142, 0.1445909953802227}, {0.0003319134302562913, 0.7929794450070728, 15.2022223767956, -1324.4623096241532, -1564.7290144856418, -2072.811780279351, -2666.702363225542, 0.5859238596842989, 0.6458651906156443, 0.6653311587330442, 0.7224068857193096, -335.67722685667883, -213.9683867128032, -355.54058777375315, 1165.3475321746978, 16.0, 17.0, 16.0, 17.0, 0.3222222222222222, 0.35, 0.42962962962962964, 0.4666666666666667, 0.589570374251243, 0.7736541490666196, 0.2280420819404721, 0.6971907886040333, 0.12866172408135787, 0.007040181881348513, 5.555257907060021e-05, 0.00010599893387130747, 0.00026877104522763376, 2.940124947597506, 0.28336596040308054, 2.639057329615259, 0.0, 2.5, 2.807354922057604, 0.12428770066787785, std::numeric_limits<double>::quiet_NaN(), 0.003, 0.06557704017789287, 0.5600332872549691, 0.11879416386108665}, {0.0003319696587372484, 0.7869008694868496, 14.203914569131296, -1352.1213170453232, -1508.238447358561, -2048.136689181262, -2631.8329557541056, 0.5545543642020172, 0.7403327801303516, 0.6272958930300907, 0.7663945747633097, -1364.8716907579374, -246.76079405802452, 2342.9479721019184, 18680.131201385106, 15.7, 19.0, 15.7, 19.0, 0.325, 0.35, 0.4333333333333334, 0.4666666666666667, 0.5841139638204014, 0.7648598462507175, 0.23088201414592333, 0.6891029179910534, 0.13360001647272265, 0.002959731756928553, 8.154855140475393e-05, 0.00016114646898042224, 0.00035036262152966997, 3.294629219023637, 0.3472309767089016, 0.0, 0.0, 3.169925001442312, 2.75, 0.16705096596714886, std::numeric_limits<double>::quiet_NaN(), 0.0033333333333333335, 0.07521188883282451, 0.5547450771008045, 0.12350358336571977} , {0.0003325675859777911, 0.6944504296134095, 6.204576632926887, -1394.4939551997309, -1547.2860104571419, -2061.6582028129314, -2694.1993556592492, 0.1498448235953632, 0.22968626054020513, 0.23898273068904605, 0.3159418291882178, -122.97763666844693, 450.76583666959556, -76.49027857084921, -48.88271979491811, 11.6, 13.0, 11.6, 13.0, 0.305, 0.325, 0.4066666666666666, 0.43333333333333335, 0.5901546020417634, 0.721939415701603, 0.2298921883024647, 0.6650986600990222, 0.1626777904545702, -0.017277248003079025, 0.0026341417812766003, 0.0014024506473683212, 0.002601439741410297, 3.2559238145342686, 0.8933370149225123, 3.58351893845611, 0.0, 3.169925001442312, 3.0, 0.04378953085810617, nan, 0.0036666666666666666, 0.18593093343237618, 0.5591196964233398, 0.1398757876535336 }, { 0.0003324582585743604, 0.5557752459174432, 7.152649427012435, -1349.3312513680705, -1472.1490686048405, -2097.6510661901584, -2692.2715469611962, 0.1640655424915857, 0.23234270420415246, 0.24751133346827286, 0.312506098107964, 884.6651026535972, 3936.2054918558006, -88.57673833335143, -56.95071233179974, 11.3, 12.0, 11.3, 12.0, 0.305, 0.325, 0.4066666666666666, 0.43333333333333335, 0.6052054634816549, 0.7352909579323292, 0.22689650189862218, 0.6812859985415914, 0.1646011611199055, 0.08382457277496998, 0.004337411865175772, 0.0057047278694076775, 0.005221674013881917, 3.235153831659208, 1.0884212371637423, 2.4849066497880004, 0.0, 2.94770277922009, 3.0, 0.04651772601369117, std::numeric_limits<double>::quiet_NaN(), 0.0033333333333333335, 0.14895816126528366, 0.5719981515757585, 0.13959062948762882 }, {0.00033205492521173137, 1.090942243384903, 14.882577985619143, -1331.1710716260511, -1567.3885861029034, -2057.5616448930896, -2610.320572397299, 0.6030837416480512, 0.6918262752325297, 0.6833816771679486, 0.768410123043298, -300.23966913964523, -236.23830636780548, -852.3442142505323, 2469.8227472949607, 15.88888888888889, 18.0, 15.88888888888889, 18.0, 0.325, 0.35, 0.43333333333333335, 0.4666666666666667, 0.5773220243683856, 0.765464485380574, 0.23240741719714628, 0.6874652464521444, 0.13191408250000747, 0.002891844221341426, 0.00012321104024572648, 0.00024017493845414594, 0.0005440091923805191, 2.9393288970039717, 0.3723712890288486, 0.0, 0.0, 3.0, 2.807354922057604, 0.1397003824681847, std::numeric_limits<double>::quiet_NaN(), 0.003, 0.05945671988411736, 0.5497279712212565, 0.12200873831298659} };
for(auto& feature_values : feature_values_2d) {
int index;
for(int i=0;i<44;i++)
{
data[i].missing=-1;
data[i].fvalue=feature_values[i];
printf("feature[%d]=%.8fn",i,feature_values[i]);
}
predict_res(data,0,result);
index=(int)result[0];
endTime = clock();
printf("%C n",res[index]);
}
我是否正确格式化了上面的代码?
当前我正在获取
error: cannot initialize an array element of type 'double' with an lvalue of type 'double (const char *)'
错误表明,当您初始化您的feature_values_2d
数组时,您试图在某些时候使用字符串文字初始化它,罪魁祸首很可能是nan
,您没有显示其声明方式,但错误是明确的,它一定不是字符串文字(const char*
),而是double
。
可以使用stod
:
auto nan = stod(old_nan); // where old_nan is the string literal nan
如果你指的是std::nan
,这是一个函数,它需要一个c字符串参数。