## 5 Online Learning Framework
### Online Training and Evaluation  
Generating training instances online entails translating a stream of file requests into a stream of feature vectors and then appending target variables to them. Given a file request; the file metadata; and the current file, directory, and file format states, a feature vector can be generated (as explained in Section 4.1) containing the features required by the streaming ML models maintained by the system. The target variables are also calculated online and added to the feature vectors as target columns to generate training instances. The target generation process (and thus the training instances generation process) is different for each type of ML model maintained.  
Calculating the _Next Offset_ (and _Next Offset Class_) target requires using the offset of the current read request as the next offset of the previous read request of the same file, as shown in Algorithm 1. For this purpose, we maintain the feature vector computed from the latest read request per file (lines 4-7). When the file is accessed again, the current offset is set as the target of the previous feature vector corresponding to that file (lines 9-12). The offset is normalized using the file size so that the target value is between 0 and 1. In the classification case (not shown in Algorithm 1), if the current request offset equals the end offset of the previous request, then the target is set to '_sequential_'; otherwise, it is set to '_random_'. When a close request is received, the next offset is set equal to 1 to indicate that the file will not be read anymore (lines 13-15). In the classification case, the target is set to '_none_' when a close request is received.  
```
1:\(f\text{e- feature vector generated from current request}\)
2:\(fileID=fv.\text{getFileID}()\)
3:\(operation=fv.\text{getRequestOperation}()\)
4:\(previousFV=\text{NULL}\)
5:if\(\text{not}\ previousFVmap.\text{contains}(fileID)\)then
6:\(operation=\text{READ}\)then
7:\(previousFVmap.\text{put}(fileID,fv)\)
8:endif
9:else
10:\(previousFV=previousFVmap.\text{get}(fileID)\)
11:if\(operation=\text{READ}\)then
12:\(previousFV.\text{setTarget}(fv.\text{getRequestOffsetNorm}())\)
13:\(previousFVmap.\text{put}(fileID,fv)\)
14:elseif\(operation=\text{CLOSE}\)then
15:\(previousFV.\text{setTarget}(1)\)
16:\(previousFVmap.\text{remove}(fileID)\)
17:endif
18:endif
19:endif
20:return\(previousFV\)
```  
**Algorithm 1** Training Instance Generation for Next Offset  
Calculating the _Next File Hotness_ (and _Next File Hotness Class_) target requires computing and storing a set of feature vectors for a small period of time (which is equal, by default, to a time slice interval). Whenever a past feature vector \(v\) becomes older than this period of time, the current file hotness is computed using Equation (6) and set as the Next File Hotness target of \(v\).  
While a streaming ML model is trained online, it can also be evaluated online to assess its performance using the prequential evaluation [67; 68] technique. In prequential evaluation, the processing of individual training instances follows their order of submission,and each individual instance is used to test the model before training the model. This guarantees that the model is always tested on instances that it has never seen before and enforces the usage of all available data. The prediction accuracy of the model is continuously updated with each instance and changes during execution, but tends to increase and stabilize as more instances are processed. The current prediction accuracy is included along with each prediction so that the policies are informed about how accurate the predictions are at any given point in time.