| 1393 | return float(a0*x*x*x+a1*x*x+a2*x+a3); |
| 1394 | } |
| 1395 | float runEM_linear (const vector<float>& x,const vector<float>& y,double & a0,double & a1, int maximalNumberOfIterations,int ploidy, int maximalNumberOfCopies) { |
| 1396 | |
| 1397 | float rmserror = -1; |
| 1398 | |
| 1399 | if (x.size() != y.size()) { |
| 1400 | cerr << "Error: object size is different"; |
| 1401 | return 0; |
| 1402 | } |
| 1403 | vector <int> cluster (x.size()); |
| 1404 | vector <float> res (maximalNumberOfCopies+1); |
| 1405 | |
| 1406 | int count = 0; |
| 1407 | |
| 1408 | for (count = 0; count < maximalNumberOfIterations; count++) { |
| 1409 | |
| 1410 | for (int i = 0; i <(int)x.size(); i++) { |
| 1411 | for (int j = 0; j <= maximalNumberOfCopies; j++) |
| 1412 | res[j] = fabs(j*a0/ploidy*x[i]+ j*a1/ploidy -y[i]); |
| 1413 | cluster[i] = get_min_index(res); |
| 1414 | } |
| 1415 | int npoints = 0; |
| 1416 | for (int i = 0; i <(int)x.size(); i++) |
| 1417 | if (cluster[i] == ploidy) |
| 1418 | npoints++; |
| 1419 | int nvars = 1; //fit by linear function |
| 1420 | ap::real_2d_array xy; |
| 1421 | xy.setlength(npoints,nvars+1); |
| 1422 | int pos = 0; |
| 1423 | for (int i = 0; i <(int)x.size(); i++) { |
| 1424 | if (cluster[i] == ploidy){ |
| 1425 | xy(pos,0) = x[i]; |
| 1426 | xy(pos,1) = y[i]; |
| 1427 | pos++; |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | linearmodel lm; |
| 1432 | int info; |
| 1433 | lrreport ar; |
| 1434 | lrbuildz(xy,npoints,nvars,info,lm,ar); |
| 1435 | if (info != 1) { |
| 1436 | cerr << "Error in linear regression, code: " << info <<"\n"; |
| 1437 | break; |
| 1438 | } |
| 1439 | rmserror = float(ar.rmserror); |
| 1440 | ap::real_1d_array v; |
| 1441 | v.setlength(nvars+1); |
| 1442 | lrunpack(lm,v,nvars); |
| 1443 | //cout << v(0); //x |
| 1444 | //cout << v(1); //x^3 |
| 1445 | //cout << v(2); //x^2 |
| 1446 | //cout << v(3); //intercept |
| 1447 | |
| 1448 | cout << a0 - v(0) << "\t"; //x |
| 1449 | //cout << a1 - v(1) << "\n"; //intercept |
| 1450 | //if (fabs(a0 - v(0)) + fabs(a1 - v(1)) == 0) { |
| 1451 | if (fabs(a0 - v(0)) == 0) { |
| 1452 | break; |
nothing calls this directly
no test coverage detected