📄 abstractcurvefitting.java
字号:
/**
* Description: Curve fitting function
*
* @ Author Create/Modi Note
* Xiaofeng Xie Jun 26, 2008
*
* @version 1.0
* @Since MAOS1.0
*
*/
package problem.custom;
import problem.*;
import Global.*;
public abstract class AbstractCurveFitting extends UnconstrainedProblemEncoder {
protected double[] oneDparamPoints;
protected double[] responseValues;
protected String fileStr = "D:\\temp\\fitpotential\\fitpotential.200\\cosangl.200\\cosadf.PHGLE2.avg.dat";
public AbstractCurveFitting(int NX) throws Exception {
super(NX);
}
abstract protected double getFuncValue(double x, double[] VX);
private double getDifference(int row, double[] VX) {
return (responseValues[row]-getFuncValue(oneDparamPoints[row], VX));
}
protected double getDifferenceSquareSum(double[] VX) {
double value = 0;
double tempDiff = 0;
for(int i=0; i<responseValues.length; i++) {
tempDiff = getDifference(i, VX);
value += tempDiff*tempDiff;
}
value /= responseValues.length;
value = Math.sqrt(value);
return value;
}
public double calcTarget(double[] VX) {
return getDifferenceSquareSum(VX);
}
public String getYValues(double[] VX) {
String yValuesStr ="";
for(int i=0; i<responseValues.length; i++) {
yValuesStr+=getFuncValue(oneDparamPoints[i], VX)+"\n";
}
return yValuesStr;
}
public void outputResponseString(double[] VX) {
System.out.println(getYValues(VX));
}
public void initEncoder() throws Exception {
super.initEncoder();
readDataContent(GlobalFile.getStringFromFile(fileStr));
}
public boolean setParameter(String name, String value) {
if (super.setParameter(name, value)) return true;
else if (name.equalsIgnoreCase("fileStr")) fileStr=value;
else return false;
return true;
}
private void readDataContent(String dataContent) throws Exception {
String[] contents = GlobalString.getMeaningfulLines(dataContent);
oneDparamPoints = new double[contents.length];
responseValues = new double[contents.length];
for (int i=0; i<contents.length; i++) {
String[] lineContents = GlobalString.tokenize(contents[i], " \t");
oneDparamPoints[i] = new Double(lineContents[0]).doubleValue();
responseValues[i] = new Double(lineContents[1]).doubleValue();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -