易截截图软件、单文件、免安装、纯绿色、仅160KB

最小二乘法JAVA代码

在网上找到的代码是错的,自己写了一个
最小二乘法的代码,二个构造方法,一个是不带权的,一个是带权的
/**
* 最小二乘法计算类
*
* @author Administrator
*
*/
public class LeastSquareMethod {
private double[] x;
private double[] y;
private double[] weight;
private int m;
private double[] coefficient;
public LeastSquareMethod(double[] x, double[] y, int m) {
if (x == null || y == null || x.length < 2 || x.length != y.length
|| m < 2)
throw new IllegalArgumentException("无效的参数");
this.x = x;
this.y = y;
this.m = m;
weight = new double[x.length];
for (int i = 0; i < x.length; i++) {
weight[i] = 1;
}
}
public LeastSquareMethod(double[] x, double[] y, double[] weight, int m) {
if (x == null || y == null || weight == null || x.length < 2
|| x.length != y.length || x.length != weight.length || m < 2)
throw new IllegalArgumentException("无效的参数");
this.x = x;
this.y = y;
this.m = m;
this.weight = weight;
}
public double[] getCoefficient() {
if (coefficient == null)
compute();
return coefficient;
}
public double fit(double v) {
if (coefficient == null)
compute();
if (coefficient == null)
return 0;
double sum = 0;
for (int i = 0; i < coefficient.length; i++) {
sum += Math.pow(v, i) * coefficient[i];
}
return sum;
}
private void compute() {
if (x == null || y == null || x.length <= 1 || x.length != y.length
|| x.length < m || m < 2)
return;
double[] s = new double[(m - 1) * 2 + 1];
for (int i = 0; i < s.length; i++) {
for (int j = 0; j < x.length; j++)
s[i] += Math.pow(x[j], i) * weight[j];
}
double[] f = new double[m];
for (int i = 0; i < f.length; i++) {
for (int j = 0; j < x.length; j++)
f[i] += Math.pow(x[j], i) * y[j] * weight[j];
}
double[][] a = new double[m][m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
a[i


相关文档:

ubuntu中java安装

最近一段时间看到了ylmf os 一时手痒安装了。准备把使用中遇到的问题进行记录,已被不时只需。
安装java方法2种:
第一种,在终端执行命令进行下载。
打开终端,执行以下命令,系统会自动下载JDK ,并安装。
sudo apt-get install sun-java6-jdk
如果空间不富裕的话,可以只装JRE
sudo apt-get install sun-java6- ......

JAVA -Cookie和Session专题

一、cookie机制和session机制的区别
*****************************************************************
具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案。
同时我们也看到,由于才服务器端保持状态的方案在客户端也需要保存一个标识,所以session
机制可能需要借 ......

Java多线程之ThreadLocal_1

ThreadLocal的核心思想很简单:为每个独立的线程提供一个变量的副本。
    ThreadLocal则使用了“拷贝副本”的方式,人人有份,你用你的,我用我的,大家互不影响,是“以空间换时间”。每个线程修改变量时,实际上修改的是变量的副本,不怕影响到其它线程。
 
  & ......

Java基础小结(数值类型转换规则)

Java基础小结(数值类型转换规则)
一 数值类型转换规则
数值型数据进行运算时,如果操作数的类型不同或操作数的类型均低于int型,则
会进行自动类型转换处理,具体规则如下:
1)如果两个操作数中有一个是double型,则系统先将另一个操作数的值转换为double
型,然后再进行运算,否则
2)如果两个操作数中有一个是float ......

java api 现在

JAVA在线api
2009年06月07日 17:06
1.Hibernate API Documentation (3.2.2.ga)
http://www.hibernate.org/hib_docs/v3/api/
2.Spring Framework API 2.5
http://static.springframework.org/spring/docs/2.5.x/api/index.html
3.Struts 1.3.8 API
http://struts.apache.org/1.3.8/apidocs/index.html
4.Struts 2 Co ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号