📄 selfadjustingpredictor.cpp
字号:
//----------------------------------------------------------------------------------------------
// Sequential Prediction Demo: The positioning pattern
//
// Author: Fri Mommersteeg
// Date: 10-09-2001
// File: SelfAdjustingPredictor.cpp
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
// Include files
//----------------------------------------------------------------------------------------------
#include "stdafx.h"
#include "selfadjustingpredictor.h"
//----------------------------------------------------------------------------------------------
// Constants
//----------------------------------------------------------------------------------------------
const float g_Punishment = 1.1f;
const float g_Reward = 0.9f;
//----------------------------------------------------------------------------------------------
// Update(): overloaded to evaluate previous prediction
//----------------------------------------------------------------------------------------------
void CSelfAdjustingPredictor::Update(int NextElement) {
// did the predictor think the estimation was correct?
if (m_EstimatedCorrect) {
// check if the predictor was wrong
if (NextElement != m_nPrediction) {
// punish the predictor
m_fMinPerformance *= g_Punishment;
} else {
// reward the predictor if the prediction was correct
if (NextElement==m_nPrediction) {
m_fMinPerformance *= g_Reward;
}
}
}
// add next element to the predictor
CImprovedPredictor::Update(NextElement);
}
//----------------------------------------------------------------------------------------------
// GetPrediction(): overloaded to catch the correctness estimation
//----------------------------------------------------------------------------------------------
bool CSelfAdjustingPredictor::GetPrediction(int &Prediction) {
// catch the correctness estimation (for evaluation during next update)
m_EstimatedCorrect = CImprovedPredictor::GetPrediction(Prediction);
return m_EstimatedCorrect;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -