Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® Integrated Performance Primitives
- Linear Regression in IPP

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

constantine-vassilev

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-25-2008
12:06 PM

101 Views

Linear Regression in IPP

I would like to calculate simple linear regression coefficients with IPP:

Y=a+bX

Where Y is the dependent variable, a is the y intercept, b is the gradient or slope of the line,

X is independent variable

Are there simple example how to do that with IPP?

Thanks in advance,

Constantine

Link Copied

4 Replies

matthieu_darbois

New Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-26-2008
12:17 AM

101 Views

Hi,

you could do that with a few ipps functions. Here is some code which I haven't use for sometime so feel free to check for the exactness of the formula used.

[cpp]void LinearRegression_64f(const Ipp64f* pSrcX, const Ipp64f* pSrcY, int length, Ipp64f *a, Ipp64f *b) { Ipp64f cov_xy; Ipp64f mean_x; Ipp64f mean_y; Ipp64f var_x; ippsMean_64f(pSrcX, length, &mean_x); ippsMean_64f(pSrcY, length, &mean_y); ippsDotProd_64f(pSrcX, pSrcY, length, &cov_xy); cov_xy = (cov_xy / (double)length) - mean_x * mean_y; ippsStdDev_64f(pSrcX, length, &var_x); var_x = var_x * var_x; *a = cov_xy / var_x; *b = mean_y - *a * mean_x; }[/cpp]

matthieu_darbois

New Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-26-2008
12:19 AM

101 Views

Hi again,

A little mistake in the code I gave you. It's for Y = aX+b and not Y = a + bX as you asked.

Regards,

Matthieu

matthieu_darbois

New Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-26-2008
12:30 AM

101 Views

Maybe this implementation would gain in speed over the other one. I'll let you try it.

[cpp]void LinearRegression_64f(const Ipp64f* pSrcX, const Ipp64f* pSrcY, int length, Ipp64f *a, Ipp64f *b) { Ipp64f cov_xy; Ipp64f mean_x; Ipp64f mean_y; Ipp64f var_x; ippsMean_64f(pSrcX, length, &mean_x); ippsMean_64f(pSrcY, length, &mean_y); ippsDotProd_64f(pSrcX, pSrcY, length, &cov_xy); cov_xy = (cov_xy / (double)length) - mean_x * mean_y; ippsDotProd_64f(pSrcX, pSrcX, length, &var_x); var_x = (var_x / (double)length) - mean_x * mean_x; *a = cov_xy / var_x; *b = mean_y - *a * mean_x; }[/cpp]

constantine-vassilev

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-26-2008
08:06 AM

101 Views

Quoting - matthieu.darbois

Maybe this implementation would gain in speed over the other one. I'll let you try it.

void LinearRegression_64f(const Ipp64f* pSrcX, const Ipp64f* pSrcY, int length, Ipp64f *a, Ipp64f *b) { Ipp64f cov_xy; Ipp64f mean_x; Ipp64f mean_y; Ipp64f var_x; ippsMean_64f(pSrcX, length, &mean_x); ippsMean_64f(pSrcY, length, &mean_y); ippsDotProd_64f(pSrcX, pSrcY, length, &cov_xy); cov_xy = (cov_xy / (double)length) - mean_x * mean_y; ippsDotProd_64f(pSrcX, pSrcX, length, &var_x); var_x = (var_x / (double)length) - mean_x * mean_x; *a = cov_xy / var_x; *b = mean_y - *a * mean_x; }

Thanks a lot - I will try it now.

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.