多元非线性回归问题的算法(500分以上求解)

dfkoko 2007-07-26 06:59:53
公式见
http://blog.csdn.net/dfkoko/archive/2007/07/26/1708278.aspx

能够提供完整算法或C++/VC++代码者另开贴500分相送.如需要分可再加



我的Email:dfkoko@163.com
...全文
1208 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Forsure 2010-08-31
  • 打赏
  • 举报
回复
我现在也需要这个,谁有可以发给我一份么luanwpp#163.com
yinxx11 2010-07-08
  • 打赏
  • 举报
回复
学习了,谢谢,楼主有典型相关分析的代码么有的话发给我分行么?yinxx11@yahoo.com.cn谢谢
dfkoko 2007-08-21
  • 打赏
  • 举报
回复
To likeEnglish:
我很需要,发给我,谢先.
  dfkoko@163.com

  交个朋友.
IlikeEnglish 2007-08-12
  • 打赏
  • 举报
回复
曾经编过一个,因为学习数据挖掘,lz需要联系我
dfkoko 2007-08-12
  • 打赏
  • 举报
回复
To expter(My Dream):能解决问题的一个没有
expter 2007-08-09
  • 打赏
  • 举报
回复
up...
google 一大把哇
fire_woods 2007-07-31
  • 打赏
  • 举报
回复
http://www.chinavib.com/forum/archiver/tid-48646.html

先用matlab的工具包测试那种方法的效果好.

如果有有效的方法
你有2个选择,一个是用matlab和c混合编程,把matlab的包编译成dll,这个执行效率低.
另外一个是看对应的matlab的源代码,自己转换成c代码.这个改写有一定的工作量.
NowCan 2007-07-30
  • 打赏
  • 举报
回复
有算法还不会写程序?而且你这个公式怎么和我见到的不同呢?
/*
多元线性回归分析
*/
#include <iostream>
#include <fstream>
#include <math>
#include "matrix.h"

////////////////////////////////

// Note: The following conditional compilation statements are included

// so that you can (likely to) compile this sample, without any

// modification, using a compiler which does not support any or

// all of the ANSI C++ features like NAMEPACE, TEMPLATE, and

// EXCEPTION, used in this class.

//

// If you have a compiler, such as C++ Builder, Borland C++ 5.0,

// MS Visual C++ 5.0 or higher, etc., which supports most of the ANSI

// C++ features used in this class, you do not need to include these

// statements in your program.

//
#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif
#ifndef _NO_TEMPLATE
typedef matrix<double> Matrix;
#else
typedef matrix Matrix;
#endif
#ifndef _NO_EXCEPTION
#define TRYBEGIN() \
try \
{
#define CATCHERROR() \
} \
\
/* */ \
catch(const STD::exception &e) \
{ \
cerr << "Error: " << e.what() << endl; \
}

#else
#define TRYBEGIN()
#define CATCHERROR()
#endif
static Matrix m_x, m_y, m_a;

/*
从数据文件中读取数据,格式如下
第一行是观测点的个数n
第二行是自变量的个数m
然后是n行数据x,自变量x(0)~x(m-1)
然后是n行应变量y
*/
long read_data(char *datfile)
{
long n, m, i, j;
fstream fs(datfile);
fs >> n;
fs >> m;

//cout<<"n="<<n<<",m="<< m<<endl;
m_x.SetSize(n, m); //row=n, col=m
m_y.SetSize(n, 1); //row=n, col=1
fs >> m_x;
fs >> m_y;

//cout << "x=" << endl << m_x << endl;

//cout << "y=" << endl << m_y << endl;
return n;
}

/* */
long solve(void)
{
Matrix c, cct, cy;
long x, y;
x=m_x.ColNo();
y=m_x.RowNo();
m_a.SetSize(x + 1, 1);
c.SetSize(x + 1, y);
for(long i=0; i < x; i++)
{
for(long j=0; j < y; j++)
{
c(i, j)=m_x(j, i);
}
}

for(long j=0; j < y; j++)
{
c(x, j)=1;
}

//cout << "c=" << endl << c << endl;
cct=c *~c;
cy=c * m_y;

//cct*a=cy
m_a=cct.Solve(cy);

//cout << "m_a=" << endl << m_a << endl;
return 0;
}

/* */
void eval(void)
{
double q, s, r, u, y, t, ye, ax;
Matrix v, qm;
long n, m;
m=m_x.ColNo();
n=m_x.RowNo();
v.SetSize(m, 1);
qm.SetSize(m, 1);
q=0;
for(long i=0; i < n; i++)
{
y=0;
for(long j=0; j < m; j++)
{
y+=m_a(j, 0) * m_x(i, j);
}

y+=m_a(m, 0);
q+=(m_y(i, 0) - y) * (m_y(i, 0) - y);
}

cout << "偏差平方和, q=" << q << endl; //偏差平方和
s=sqrt(q / n);
cout << "平均标准差, s=" << s << endl; //平均标准偏差
ye=0;
for(long i=0; i < n; i++)
{
ye+=m_y(i, 0) / n;
}

t=0;
for(long i=0; i < n; i++)
{
t+=(m_y(i, 0) - ye) * (m_y(i, 0) - ye);
}

r=sqrt(1 - q / t);
cout << "复相关系数, r=" << r << endl; //复相关系数
u=0;
for(long i=0; i < n; i++)
{
y=0;
for(long j=0; j < m; j++)
{
y+=m_a(j, 0) * m_x(i, j);
}

y+=m_a(m, 0);
u+=(ye - y) * (ye - y);
}

cout << "回归平方和, u=" << u << endl; //回归平方和
for(long i=0; i < m; i++)
{
qm(i, 0)=0;
for(long j=0; j < n; j++)
{
ax=0;
for(long k=0; k < m; k++)
{
if(k != j)
{
ax+=m_a(k, 0) * m_x(j, k);
}
}

qm(i, 0)+=(m_y(i, 0) - (m_a(m, 0) + ax)) * (m_y(i, 0) - (m_a(m, 0) + ax));
}

v(i, 0)=sqrt(1 - q / qm(i, 0));
}

cout << "偏相关系数, v=" << endl << v << endl; //偏相关系数
}

/* */
int main(int argc, char **argv)
{
if(argc != 2)
{
cout << "mls <datafile name>" << endl;
return 0;
}

TRYBEGIN() //try
read_data(argv[1]);
solve();
cout << "回归系数, a=" << endl << m_a << endl; //回归系数
eval();
CATCHERROR() //catch
return 0;
}

当然,这个程序用了一个矩阵类,用来求解方程组
dfkoko 2007-07-30
  • 打赏
  • 举报
回复
能够解决A0,A1,A2,A3,B,C六个未知数也行,其它的我慢慢做
dfkoko 2007-07-30
  • 打赏
  • 举报
回复
To :fire_woods(风林火山)

没有看见有m,

Ai,B,C,这些都是未知的吗?

有多少组Xi,Y数据?
1)
Ai:最多八个(A0~A8)
B: 一个
C: 一个
2)
m部分我没写,加上m部分太复杂了,暂时先不考虑.
3)
大约有30组以上Xi,Y数据

To: NowCan(城市浪人)
有算法还不会写程序?而且你这个公式怎么和我见到的不同呢?
1)提供算法和代码都可以.
2)你见到的公式是什么样的?

这是多元非线性回归算法.化成线性可能无解(原谅我数学不好)



fire_woods 2007-07-30
  • 打赏
  • 举报
回复
没有看见有m,

Ai,B,C,这些都是未知的吗?

有多少组Xi,Y数据?
bing3joe 2007-07-26
  • 打赏
  • 举报
回复
顶下再看

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧