2.2.1 串行版的Credit Review

2013-10-07 15:22:13 · 作者: · 浏览: 74

2.2.1   串行版的Credit Review

下面是信用分析操作的串行化版本:

  1. void UpdatePredictionsSequential(AccountRepository& accounts)  
  2. {  
  3.     for_each(accounts.begin(), accounts.end(),  
  4.         [](AccountRepository::value_type& record)  
  5.     {  
  6.         Account& account = record.second;  
  7.         Trend trend = Fit(account.Balances());  
  8.         double prediction = PredictIntercept(trend,  
  9.             (account.Balances().size() + g_predictionWindow));  
  10.         account.SeqPrediction() = prediction;  
  11.         account.SeqWarning() = prediction < account.GetOverdraft();  
  12.     });  

在这个程序中,UpdatePredictionsSequential方法被用来处理账户库中的每一个账户。而其中的Fit方法是一个工具函数,它通过统计学中的最小二乘法根据一组(用户)数据绘制出趋势线。此外,Fit方法是一个纯函数过程即它不会改变任何东西的状态。注5

该值是根据趋势得出的三个月内的预测。如果预测值越过了负债限制(账户系统中的负债额是个负值),该账户就会被标志为审查状态。