Skip to content

Commit 80b673a

Browse files
committed
add WILS model
1 parent c3b4da9 commit 80b673a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

intvalpy/models/WILS.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
3+
from ..linear.Tol import Tol
4+
from ..linear.Uss import Uss
5+
from ..linear.Uni import Uni
6+
7+
8+
class WILS(object):
9+
10+
def init(self, alpha=0, beta=1):
11+
self.alpha = alpha
12+
self.beta = beta
13+
14+
def fit(self, X_train, y_train, weight=None, rec_func='Tol', **kwargs):
15+
if weight is None:
16+
weight = np.ones(len(y_train))
17+
18+
# делаем сглаживание
19+
weight[0] = self.beta * weight[0]*(1 - self.alpha)
20+
for k in range(1, len(weight)):
21+
weight[k] = self.beta * (weight[k]*(1 - self.alpha) + self.alpha*weight[k-1])
22+
23+
if rec_func == 'Tol':
24+
RecFunc = Tol
25+
elif rec_func == 'Uni':
26+
RecFunc = Uni
27+
elif rec_func == 'Uss':
28+
RecFunc = Uss
29+
30+
self.estimator = RecFunc.maximize(
31+
X_train,
32+
y_train,
33+
weight=weight,
34+
**kwargs
35+
)
36+
37+
def predict(self, X_test):
38+
return X_test @ self.estimator[0]

0 commit comments

Comments
 (0)