最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Apache Commons Math3探索之多項(xiàng)式曲線擬合實(shí)現(xiàn)代碼

 更新時(shí)間:2017年10月19日 15:09:54   作者:狐帝  
這篇文章主要介紹了Apache Commons Math3探索之多項(xiàng)式曲線擬合實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,這里分享給大家,供需要的朋友參考。

上一篇文章我們介紹了Apache Commons Math3學(xué)習(xí)之?dāng)?shù)值積分實(shí)例代碼,這里給大家分享math3多項(xiàng)式曲線擬合的相關(guān)內(nèi)容,具體如下。

多項(xiàng)式曲線擬合:org.apache.commons.math3.fitting.PolynomialCurveFitter類。

用法示例代碼:

// ... 創(chuàng)建并初始化輸入數(shù)據(jù): 
double[] x = new double[...]; 
double[] y = new double[...]; 
將原始的x-y數(shù)據(jù)序列合成帶權(quán)重的觀察點(diǎn)數(shù)據(jù)序列: 
WeightedObservedPoints points = new WeightedObservedPoints(); 
// 將x-y數(shù)據(jù)元素調(diào)用points.add(x[i], y[i])加入到觀察點(diǎn)序列中 
// ... 
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);  // degree 指定多項(xiàng)式階數(shù) 
double[] result = fitter.fit(points.toList());  // 曲線擬合,結(jié)果保存于雙精度數(shù)組中,由常數(shù)項(xiàng)至最高次冪系數(shù)排列 

首先要準(zhǔn)備好待擬合的曲線數(shù)據(jù)x和y,這是兩個(gè)double數(shù)組,然后把這兩個(gè)數(shù)組合并到WeightedObservedPoints對(duì)象實(shí)例中,可以調(diào)用WeightedObservedPoints.add(x[i], y[i])將x和y序列中的數(shù)據(jù)逐個(gè)添加到觀察點(diǎn)序列對(duì)象中。隨后創(chuàng)建PolynomialCurveFitter對(duì)象,創(chuàng)建時(shí)要指定擬合多項(xiàng)式的階數(shù),注意階數(shù)要選擇適當(dāng),不是越高越好,否則擬合誤差會(huì)很大。最后調(diào)用PolynomialCurveFitter的fit方法即可完成多項(xiàng)式曲線擬合,fit方法的參數(shù)通過WeightedObservedPoints.toList()獲得。擬合結(jié)果通過一個(gè)double數(shù)組返回,按元素順序依次是常數(shù)項(xiàng)、一次項(xiàng)、二次項(xiàng)、……。

完整的演示代碼如下:

interface TestCase 
{ 
  public Object run(List<Object> params) throws Exception; 
  public List<Object> getParams(); 
  public void printResult(Object result); 
} 
class CalcCurveFitting implements TestCase 
{ 
  public CalcCurveFitting() 
  { 
   System.out.print("本算例用于計(jì)算多項(xiàng)式曲線擬合。正在初始化 計(jì)算數(shù)據(jù)(" + arrayLength + "點(diǎn), " + degree + "階)... ..."); 
   inputDataX = new double[arrayLength]; 
   //   inputDataX = new double[] {1, 2, 3, 4, 5, 6, 7}; 
   inputDataY = new double[inputDataX.length]; 
   double[] factor = new double[degree + 1];  // N階多項(xiàng)式會(huì)有N+1個(gè)系數(shù),其中之一為常數(shù)項(xiàng) 
   for(int index = 0; index < factor.length; index ++) 
   { 
     factor[index] = index + 1; 
   } 
   for(int index = 0; index < inputDataY.length; index ++) 
   { 
     inputDataX[index] = index * 0.00001; 
     inputDataY[index] = calcPoly(inputDataX[index], factor);  // y = sum(x[n) * fact[n]) 
     // System.out.print(inputDataY[index] + ", "); 
   } 
   points = new WeightedObservedPoints(); 
   for(int index = 0; index < inputDataX.length; index ++) 
   { 
     points.add(inputDataX[index], inputDataY[index]); 
   } 
   System.out.println("初始化完成"); 
  } 
  @Override 
  public List<Object> getParams() 
  { 
   List<Object> params = new ArrayList<Object>(); 
   params.add(points); 
   return params; 
  } 
  @Override 
  public Object run(List<Object> params) throws Exception 
  { 
   PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree); 
   WeightedObservedPoints points = (WeightedObservedPoints)params.get(0); 
   double[] result = fitter.fit(points.toList()); 
   return result; 
  } 
  @Override 
  public void printResult(Object result) 
  { 
   for(double data : (double[])result) 
   { 
     System.out.println(data); 
   } 
  } 
  private double calcPoly(double x, double[] factor) 
  { 
   double y = 0; 
   for(int deg = 0; deg < factor.length; deg ++) 
   { 
     y += Math.pow(x, deg) * factor[deg]; 
   } 
   return y; 
  } 
  private double[] inputDataX = null; 
  private double[] inputDataY = null; 
  private WeightedObservedPoints points = null; 
  private final int arrayLength = 200000; 
  private final int degree = 5;  // 階數(shù) 
} 
public class TimeCostCalculator 
{ 
  public TimeCostCalculator() 
  { 
  } 
  /** 
  * 計(jì)算指定對(duì)象的運(yùn)行時(shí)間開銷。 
  * 
  * @param testCase 指定被測(cè)對(duì)象。 
  * @return 返回sub.run的時(shí)間開銷,單位為s。 
  * @throws Exception 
  */ 
  public double calcTimeCost(TestCase testCase) throws Exception 
  { 
   List<Object> params = testCase.getParams(); 
   long startTime = System.nanoTime(); 
   Object result = testCase.run(params); 
   long stopTime = System.nanoTime(); 
   testCase.printResult(result); 
   System.out.println("start: " + startTime + " / stop: " + stopTime); 
   double timeCost = (stopTime - startTime) * 1.0e-9; 
   return timeCost; 
  } 
  public static void main(String[] args) throws Exception 
  { 
   TimeCostCalculator tcc = new TimeCostCalculator(); 
   double timeCost; 
   System.out.println("--------------------------------------------------------------------------"); 
   timeCost = tcc.calcTimeCost(new CalcCurveFitting()); 
   System.out.println("time cost is: " + timeCost + "s"); 
   System.out.println("--------------------------------------------------------------------------"); 
  } 
} 

總結(jié)

以上就是本文關(guān)于Apache Commons Math3探索之多項(xiàng)式曲線擬合實(shí)現(xiàn)代碼的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:Apache Commons Math3學(xué)習(xí)之?dāng)?shù)值積分實(shí)例代碼、apache zookeeper使用方法實(shí)例詳解等,有什么問題可以隨時(shí)留言,小編會(huì)及時(shí)回復(fù)大家。下面推薦幾本Java方面的書籍,供大家學(xué)習(xí),免費(fèi)的哦。

7天學(xué)會(huì)spring+cloud教程 pdf格式

m.fzitv.net/books/575161.html

Java核心技術(shù):基礎(chǔ)知識(shí) 卷I(原書第10版) (凱S.霍斯特曼) 中文pdf完整版

http://m.fzitv.net/books/569792.html

更多精彩內(nèi)容,盡在http://m.fzitv.net/

相關(guān)文章

  • Java Collections.EMPTY_LIST與Collections.emptyList()的區(qū)別

    Java Collections.EMPTY_LIST與Collections.emptyList()的區(qū)別

    這篇文章主要介紹了Java Collections.EMPTY_LIST與Collections.emptyList()的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • PowerJob的OhMyClassLoader工作流程源碼解讀

    PowerJob的OhMyClassLoader工作流程源碼解讀

    這篇文章主要介紹了PowerJob的OhMyClassLoader工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • Spring Security基于json登錄實(shí)現(xiàn)過程詳解

    Spring Security基于json登錄實(shí)現(xiàn)過程詳解

    這篇文章主要介紹了Spring Security基于json登錄實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 異常排查記錄amqp協(xié)議鏈接陷阱

    異常排查記錄amqp協(xié)議鏈接陷阱

    這篇文章主要介紹了一次關(guān)于amqp協(xié)議鏈接陷阱-An?unexpected?connection?driver?error?occured的異常排查記錄,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2022-02-02
  • 詳細(xì)Java批量獲取微信公眾號(hào)方法

    詳細(xì)Java批量獲取微信公眾號(hào)方法

    本篇文章給大家講解了用JAVA如何實(shí)現(xiàn)向爬蟲一樣獲取微信公眾號(hào)和其基本信息等,需要你正巧需要,那跟著學(xué)習(xí)參考下吧。
    2017-12-12
  • SpringBoot項(xiàng)目中新增脫敏功能的實(shí)例代碼

    SpringBoot項(xiàng)目中新增脫敏功能的實(shí)例代碼

    項(xiàng)目中,由于使用端有兩個(gè),對(duì)于兩個(gè)端的數(shù)據(jù)權(quán)限并不一樣。Web端可以查看所有數(shù)據(jù),小程序端只能查看脫敏后的數(shù)據(jù),這篇文章主要介紹了SpringBoot項(xiàng)目中新增脫敏功能,需要的朋友可以參考下
    2022-11-11
  • 使用AOP攔截Controller獲取@PathVariable注解傳入的參數(shù)

    使用AOP攔截Controller獲取@PathVariable注解傳入的參數(shù)

    這篇文章主要介紹了使用AOP攔截Controller獲取@PathVariable注解傳入的參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Mybatisplus自動(dòng)填充實(shí)現(xiàn)方式及代碼示例

    Mybatisplus自動(dòng)填充實(shí)現(xiàn)方式及代碼示例

    這篇文章主要介紹了Mybatisplus自動(dòng)填充實(shí)現(xiàn)方式及代碼示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • springboot項(xiàng)目數(shù)據(jù)庫(kù)密碼如何加密

    springboot項(xiàng)目數(shù)據(jù)庫(kù)密碼如何加密

    在我們?nèi)粘i_發(fā)中,我們可能很隨意把數(shù)據(jù)庫(kù)密碼直接明文暴露在配置文件中,今天就來聊聊在springboot項(xiàng)目中如何對(duì)數(shù)據(jù)庫(kù)密碼進(jìn)行加密,感興趣的可以了解一下
    2021-07-07
  • Nacos配合SpringBoot實(shí)現(xiàn)動(dòng)態(tài)線程池的基本步驟

    Nacos配合SpringBoot實(shí)現(xiàn)動(dòng)態(tài)線程池的基本步驟

    使用Nacos配合Spring Boot實(shí)現(xiàn)動(dòng)態(tài)線程池,可以讓你的應(yīng)用動(dòng)態(tài)地調(diào)整線程池參數(shù)而無需重啟,這對(duì)于需要高度可配置且需要適應(yīng)不同負(fù)載情況的應(yīng)用來說非常有用,本文給大家介紹實(shí)現(xiàn)動(dòng)態(tài)線程池的基本步驟,需要的朋友可以參考下
    2024-02-02

最新評(píng)論

萝北县| 康乐县| 岢岚县| 宜宾市| 盘山县| 搜索| 葫芦岛市| 武陟县| 丽江市| 凌云县| 东台市| 邯郸市| 米脂县| 观塘区| 黔东| 安陆市| 霞浦县| 新竹市| 红河县| 宜昌市| 海安县| 五常市| 贞丰县| 阳泉市| 新蔡县| 黎川县| 大渡口区| 泰来县| 广东省| 灵宝市| 荆门市| 鲁山县| 合作市| 肃宁县| 尉氏县| 翁源县| 肥西县| 无极县| 丹棱县| 揭东县| 黄浦区|