2.2.1 串行版的Credit Review
下面是信用分析操作的串行化版本:
- void UpdatePredictionsSequential(AccountRepository& accounts)
- {
- for_each(accounts.begin(), accounts.end(),
- [](AccountRepository::value_type& record)
- {
- Account& account = record.second;
- Trend trend = Fit(account.Balances());
- double prediction = PredictIntercept(trend,
- (account.Balances().size() + g_predictionWindow));
- account.SeqPrediction() = prediction;
- account.SeqWarning() = prediction < account.GetOverdraft();
- });
- }
在这个程序中,UpdatePredictionsSequential方法被用来处理账户库中的每一个账户。而其中的Fit方法是一个工具函数,它通过统计学中的最小二乘法根据一组(用户)数据绘制出趋势线。此外,Fit方法是一个纯函数过程即它不会改变任何东西的状态。注5
该值是根据趋势得出的三个月内的预测。如果预测值越过了负债限制(账户系统中的负债额是个负值),该账户就会被标志为审查状态。