2024-03-20 22:33:02 +00:00
|
|
|
# Algorithm
|
|
|
|
|
|
|
|
- // notation
|
|
|
|
|
|
|
|
- $n$ features ${\cal{X}} = \{X_1, \dots, X_n\}$ and the class $Y$
|
|
|
|
|
|
|
|
- $m$ instances.
|
|
|
|
|
|
|
|
- $D = \{ (x_1^i, \dots, x_n^i, y^i) \}_{i=1}^{m}$
|
|
|
|
|
|
|
|
- $W$ a weights vector. $W_0$ are the initial weights.
|
|
|
|
|
|
|
|
- $D[W]$ dataset with weights $W$ for the instances.
|
|
|
|
|
2024-03-19 10:35:43 +00:00
|
|
|
1. // initialization
|
|
|
|
|
|
|
|
2. $W_0 \leftarrow (w_1, \dots, w_m) \leftarrow 1/m$
|
|
|
|
|
|
|
|
3. $W \leftarrow W_0$
|
|
|
|
|
|
|
|
4. $Vars \leftarrow {\cal{X}}$
|
|
|
|
|
|
|
|
5. $\delta \leftarrow 10^{-4}$
|
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
6. $convergence \leftarrow True$ // hyperparameter
|
|
|
|
|
|
|
|
7. $maxTolerancia \leftarrow 3$ // hyperparameter
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
8. $bisection \leftarrow False$ // hyperparameter
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
9. $finished \leftarrow False$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
10. $AODE \leftarrow \emptyset$ // the ensemble
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
11. $tolerance \leftarrow 0$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
12. $numModelsInPack \leftarrow 0$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
13. $maxAccuracy \leftarrow -1$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
14.
|
2024-03-19 10:35:43 +00:00
|
|
|
|
|
|
|
15. // main loop
|
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
16. While $(\lnot finished)$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
|
|
|
1. $\pi \leftarrow SortFeatures(Vars, criterio, D[W])$
|
|
|
|
|
2024-03-19 13:13:40 +00:00
|
|
|
2. $k \leftarrow 2^{tolerance}$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
3. if ($tolerance == 0$) $numItemsPack \leftarrow0$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
|
|
|
4. $P \leftarrow Head(\pi,k)$ // first k features in order
|
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
5. $spodes \leftarrow \emptyset$
|
|
|
|
|
2024-03-19 10:35:43 +00:00
|
|
|
6. $i \leftarrow 0$
|
|
|
|
|
|
|
|
7. While ($i < size(P)$)
|
|
|
|
|
|
|
|
1. $X \leftarrow P[i]$
|
|
|
|
|
|
|
|
2. $i \leftarrow i + 1$
|
|
|
|
|
|
|
|
3. $numItemsPack \leftarrow numItemsPack + 1$
|
|
|
|
|
|
|
|
4. $Vars.remove(X)$
|
|
|
|
|
|
|
|
5. $spode \leftarrow BuildSpode(X, {\cal{X}}, D[W])$
|
|
|
|
|
2024-04-01 16:37:51 +00:00
|
|
|
6. $\hat{y}[] \leftarrow spode.Predict(D)$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-19 13:13:40 +00:00
|
|
|
7. $\epsilon \leftarrow error(\hat{y}[], y[])$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-19 13:13:40 +00:00
|
|
|
8. $\alpha \leftarrow \frac{1}{2} ln \left ( \frac{1-\epsilon}{\epsilon} \right )$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-19 13:13:40 +00:00
|
|
|
9. if ($\epsilon > 0.5$)
|
2024-03-19 10:35:43 +00:00
|
|
|
|
|
|
|
1. $finished \leftarrow True$
|
|
|
|
|
|
|
|
2. break
|
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
10. $spodes.add( (spode,\alpha_t) )$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-04-01 16:37:51 +00:00
|
|
|
11. $W \leftarrow UpdateWeights(W,\alpha,y[],\hat{y}[])$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
8. $AODE.add( spodes )$
|
|
|
|
|
|
|
|
9. if ($convergence \land \lnot finished$)
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-04-01 16:37:51 +00:00
|
|
|
1. $\hat{y}[] \leftarrow AODE.Predict(D)$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
2. $actualAccuracy \leftarrow accuracy(\hat{y}[], y[])$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
3. $if (maxAccuracy == -1)\; maxAccuracy \leftarrow actualAccuracy$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
4. if $((accuracy - maxAccuracy) < \delta)$ // result doesn't
|
|
|
|
improve enough
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
1. $tolerance \leftarrow tolerance + 1$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
5. else
|
2024-03-19 10:35:43 +00:00
|
|
|
|
|
|
|
1. $tolerance \leftarrow 0$
|
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
2. $numItemsPack \leftarrow 0$
|
|
|
|
|
|
|
|
10. If
|
|
|
|
$(Vars == \emptyset \lor tolerance>maxTolerance) \; finished \leftarrow True$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
11. $lastAccuracy \leftarrow max(lastAccuracy, actualAccuracy)$
|
2024-03-19 10:35:43 +00:00
|
|
|
|
2024-03-20 22:33:02 +00:00
|
|
|
17. if ($tolerance > maxTolerance$) // algorithm finished because of
|
2024-03-19 10:35:43 +00:00
|
|
|
lack of convergence
|
|
|
|
|
|
|
|
1. $removeModels(AODE, numItemsPack)$
|
|
|
|
|
|
|
|
18. Return $AODE$
|