I try to run the Java code on eclipse. There is code like "system.out.print" but when i press run the console show this......
Invalid layout of java.lang.String at value
A fatal error has been detected by the Java Runtime Environment:
Internal Error (javaClasses.cpp:136), pid=2276, tid=2148
fatal error: Invalid layout of preloaded class
JRE version: (7.0_45-b18) (build )
Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode windows-amd64 compressed oops)
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as: C:\\Users\\Administrator\\Workspace\\Present\\Present\\hs_err_pid2276.log
If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
how to fix it. help me please. And here is the code i try to run...
import Jama.Matrix;
import Jama.QRDecomposition;
public class LeastSquare {
private final int N; // number of observations
private final int degree; // degree of the polynomial regression
private final Matrix beta; // the polynomial regression coefficients
private double SSE; // sum of squares due to error
private double SST; // total sum of squares
public LeastSquare(double[] x, double[] y, int degree) {
this.degree = degree;
N = x.length;
// build Vandermonde matrix
double[][] vandermonde = new double[N][degree+1];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= degree; j++) {
vandermonde[i][j] = Math.pow(x[i], j);
}
}
Matrix X = new Matrix(vandermonde);
// create matrix from vector
Matrix Y = new Matrix(y, N);
// find least squares solution
QRDecomposition qr = new QRDecomposition(X);
beta = qr.solve(Y);
// mean of y[] values
double sum = 0.0;
for (int i = 0; i < N; i++)
sum += y[i];
double mean = sum / N;
// total variation to be accounted for
for (int i = 0; i < N; i++) {
double dev = y[i] - mean;
SST += dev*dev;
}
// variation not accounted for
Matrix residuals = X.times(beta).minus(Y);
SSE = residuals.norm2() * residuals.norm2();
}
public double beta(int j) {
return beta.get(j, 0);
}
public int degree() {
return degree;
}
public double R2() {
if (SST == 0.0) return 1.0; // constant function
return 1.0 - SSE/SST;
}
public double predict(double x) {
// horner's method
double y = 0.0;
for (int j = degree; j >= 0; j--)
y = beta(j) + (x * y);
return y;
}
public String toString() {
String s = "";
int j = degree;
// ignoring leading zero coefficients
while (j >= 0 && Math.abs(beta(j)) < 1E-5)
j--;
// create remaining terms
for (j = j; j >= 0; j--) {
if (j == 0) s += String.format("%.2f ", beta(j));
else if (j == 1) s += String.format("%.2f N + ", beta(j));
else s += String.format("%.2f N^%d + ", beta(j), j);
}
return s + " (R^2 = " + String.format("%.3f", R2()) + ")";
}
public static void main(String[] args) {
double[] x = { 10, 20, 40, 80, 160, 200 };//
double[] y = { 100, 350, 1500, 6700, 20160, 40000 };
LeastSquare regression = new LeastSquare(x, y, 3);
System.out.println(regression);
}
}
It looks to me like your toString function may not be working, when you do your System.out.println(...) try this
System.out.println(regression.toString());
If that does not fix the issue then it is most likely something going wrong when setting the string to return from toString()
jamolnng pretty much answered your question. I ran into that problem once. Is your project Maven build? If so, try: Remove maven nature from Right Click Project -> Maven -> Diasble Maven Nature. Go to your terminal/command and pass this from your project directory "mvn clean install"
Go to your IDE and do Build-Clean (the project) And ebable the the project Maven Nature.
And try running that & see if that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.