最小回归模式识别和误差
Least Regression Pattern Recognition Sum Error
我正在从事一个需要模式识别程序的项目。我将收到一个包含 50000 多个数据点的数据文件,并且必须识别是否存在某种模式。如果平方回归的总和高于某个值,我就有了模式,否则,我一直循环到文件的末尾。然而,在数据点 1000 ~ 3500 附近,总和稳定下来并且不会改变。我不明白为什么它不会改变。
public class Recognition {
private static final double[] pattern = {102.0909091,
...
-102};
private static double[] temp = new double[161];
private static int[] sums;
private static final int threshold = 2107270;
private static Scanner reader;
private static PrintWriter writer;
public static int[] rec(int[] array) {
sums = new int[array.length];
int[] solution = array;
int sum = 0;
for (int x = 0; x < 161; x++) {
temp[x] = Math.pow((array[x] - pattern[x]), 2);
solution[x] = 0;
sums[x] = sumArray();
}
loop:
for (int x = 161; x < array.length; x++) {
sum = sumArray();
if (sum > threshold) {
solution[x] = 1;
cycleArray();
sums[x] = sum;
continue loop;
}
sums[x] = sum;
solution[x] = 0;
cycleArray();
temp[0] = Math.pow((array[x] - pattern[0]), 2);
}
return solution;
}
private static int sumArray() {
int sum = 0;
for (int x = 0; x < temp.length; x++) {
sum += temp[x];
}
return sum;
}
private static void cycleArray() {
for (int x = (temp.length - 1); x > 0; x--) {
temp[x] = temp[x - 1];
}
}
public static void main(String[] args0) throws FileNotFoundException {
reader = new Scanner(new File("data1.txt");
writer = new PrintWriter(new File("pattern.txt"));
int[] data = new int[50000];
int x = 0;
while (reader.hasNext()) {
data[x] = reader.nextInt();
x++;
}
int[] solutions = rec(data);
for (int y = 0; y < solutions.length; y++) {
writer.printf("%d: %d, Running Sum: %d\n", y + 1, solutions[y], sums[y]);
System.out.println(solutions[y]);
}
}
}
为澄清起见,模式长度为 161 个整数。如果模式被识别,则输出 1,否则输出 0。
感谢您提供任何帮助。
这是我的全部想法,除非达到最大值,否则我不会卡住
public class PatternRecognition {
private double[] pattern = new double[161];
private double[] temp = new double[161];
private int[] sums;
private static final int threshold = 2107270;
public int[] rec(int[] array) {
sums = new int[array.length];
int[] solution = array;
int sum = 0;
for (int x = 0; x < 161; x++) {
temp[x] = Math.pow((array[x] - pattern[x]), 2);
solution[x] = 0;
sums[x] = sumArray(temp);
}
for (int x = 0; x < array.length-temp.length; x++) {
for (int x2 =0; x2<temp.length ; x2++)
temp[x2] = Math.pow((array[x+x2] - pattern[x2]), 2);
sum = sumArray(temp);
if (sum > threshold)
solution[x] = 1;
else solution[x] = 0;
sums[x] = sum;
}
return solution;
}
private int sumArray(double[] temp) {
int sum = 0;
for (int x = 0; x < temp.length; x++) {
sum += temp[x];
}
return sum;
}
private void cycleArray() {
for (int x = (temp.length - 1); x > 0; x--) {
temp[x] = temp[x - 1];
}
}
public static void main(String[] args0) {
int[] data = new int[50000];
int x = 0;
while (x<data.length) {
data[x] = x/2;
x++;
}
PatternRecognition p=new PatternRecognition();
x=0;
while (x<p.pattern.length) {
p.pattern[x] = x+1;
x++;
}
int[] solutions = p.rec(data);
for (int y = 0; y < solutions.length; y++) {
System.out.printf("%d: %d, Running Sum: %d %d\n", y + 1, solutions[y], p.sums[y], Integer.MAX_VALUE);
System.out.println(solutions[y]);
}
}
}
我正在从事一个需要模式识别程序的项目。我将收到一个包含 50000 多个数据点的数据文件,并且必须识别是否存在某种模式。如果平方回归的总和高于某个值,我就有了模式,否则,我一直循环到文件的末尾。然而,在数据点 1000 ~ 3500 附近,总和稳定下来并且不会改变。我不明白为什么它不会改变。
public class Recognition {
private static final double[] pattern = {102.0909091,
...
-102};
private static double[] temp = new double[161];
private static int[] sums;
private static final int threshold = 2107270;
private static Scanner reader;
private static PrintWriter writer;
public static int[] rec(int[] array) {
sums = new int[array.length];
int[] solution = array;
int sum = 0;
for (int x = 0; x < 161; x++) {
temp[x] = Math.pow((array[x] - pattern[x]), 2);
solution[x] = 0;
sums[x] = sumArray();
}
loop:
for (int x = 161; x < array.length; x++) {
sum = sumArray();
if (sum > threshold) {
solution[x] = 1;
cycleArray();
sums[x] = sum;
continue loop;
}
sums[x] = sum;
solution[x] = 0;
cycleArray();
temp[0] = Math.pow((array[x] - pattern[0]), 2);
}
return solution;
}
private static int sumArray() {
int sum = 0;
for (int x = 0; x < temp.length; x++) {
sum += temp[x];
}
return sum;
}
private static void cycleArray() {
for (int x = (temp.length - 1); x > 0; x--) {
temp[x] = temp[x - 1];
}
}
public static void main(String[] args0) throws FileNotFoundException {
reader = new Scanner(new File("data1.txt");
writer = new PrintWriter(new File("pattern.txt"));
int[] data = new int[50000];
int x = 0;
while (reader.hasNext()) {
data[x] = reader.nextInt();
x++;
}
int[] solutions = rec(data);
for (int y = 0; y < solutions.length; y++) {
writer.printf("%d: %d, Running Sum: %d\n", y + 1, solutions[y], sums[y]);
System.out.println(solutions[y]);
}
}
}
为澄清起见,模式长度为 161 个整数。如果模式被识别,则输出 1,否则输出 0。 感谢您提供任何帮助。
这是我的全部想法,除非达到最大值,否则我不会卡住
public class PatternRecognition {
private double[] pattern = new double[161];
private double[] temp = new double[161];
private int[] sums;
private static final int threshold = 2107270;
public int[] rec(int[] array) {
sums = new int[array.length];
int[] solution = array;
int sum = 0;
for (int x = 0; x < 161; x++) {
temp[x] = Math.pow((array[x] - pattern[x]), 2);
solution[x] = 0;
sums[x] = sumArray(temp);
}
for (int x = 0; x < array.length-temp.length; x++) {
for (int x2 =0; x2<temp.length ; x2++)
temp[x2] = Math.pow((array[x+x2] - pattern[x2]), 2);
sum = sumArray(temp);
if (sum > threshold)
solution[x] = 1;
else solution[x] = 0;
sums[x] = sum;
}
return solution;
}
private int sumArray(double[] temp) {
int sum = 0;
for (int x = 0; x < temp.length; x++) {
sum += temp[x];
}
return sum;
}
private void cycleArray() {
for (int x = (temp.length - 1); x > 0; x--) {
temp[x] = temp[x - 1];
}
}
public static void main(String[] args0) {
int[] data = new int[50000];
int x = 0;
while (x<data.length) {
data[x] = x/2;
x++;
}
PatternRecognition p=new PatternRecognition();
x=0;
while (x<p.pattern.length) {
p.pattern[x] = x+1;
x++;
}
int[] solutions = p.rec(data);
for (int y = 0; y < solutions.length; y++) {
System.out.printf("%d: %d, Running Sum: %d %d\n", y + 1, solutions[y], p.sums[y], Integer.MAX_VALUE);
System.out.println(solutions[y]);
}
}
}