9
9
ELMRegressor, SimpleELMRegressor, SimpleELMClassifier).
10
10
11
11
An Extreme Learning Machine (ELM) is a single layer feedforward
12
- network with a random hidden layer components and least-squares fitting
13
- of the hidden->output weights by default. [1][2]
12
+ network with a random hidden layer components and ordinary linear
13
+ least squares fitting of the hidden->output weights by default.
14
+ [1][2]
14
15
15
16
References
16
17
----------
23
24
from abc import ABCMeta , abstractmethod
24
25
25
26
import numpy as np
26
- from scipy .linalg import pinv2
27
27
28
28
from sklearn .utils import as_float_array
29
- from sklearn .utils .extmath import safe_sparse_dot
30
29
from sklearn .base import BaseEstimator , ClassifierMixin , RegressorMixin
31
30
from sklearn .preprocessing import LabelBinarizer
31
+ from sklearn .linear_model import LinearRegression
32
32
33
33
from random_hidden_layer import SimpleRandomHiddenLayer
34
34
@@ -96,18 +96,19 @@ class ELMRegressor(BaseELM, RegressorMixin):
96
96
ELMRegressor is a regressor based on the Extreme Learning Machine.
97
97
98
98
An Extreme Learning Machine (ELM) is a single layer feedforward
99
- network with a random hidden layer components and least-squares fitting
100
- of the hidden->output weights by default. [1][2]
99
+ network with a random hidden layer components and ordinary linear
100
+ least squares fitting of the hidden->output weights by default.
101
+ [1][2]
101
102
102
103
Parameters
103
104
----------
104
105
`hidden_layer` : random_hidden_layer instance, optional
105
106
(default=SimpleRandomHiddenLayer(random_state=0))
106
107
107
- `regressor` : linear_model instance, optional (default=None)
108
+ `regressor` : regressor instance, optional (default=None)
108
109
If provided, this object is used to perform the regression from hidden
109
110
unit activations to the outputs and subsequent predictions. If not
110
- present, a simple least squares fit is performed internally.
111
+ present, an ordinary linear least squares fit is performed
111
112
112
113
Attributes
113
114
----------
@@ -139,14 +140,19 @@ def __init__(self,
139
140
140
141
super (ELMRegressor , self ).__init__ (hidden_layer , regressor )
141
142
142
- self .coefs_ = None
143
143
self .fitted_ = False
144
144
self .hidden_activations_ = None
145
+ self ._lin_reg = LinearRegression (copy_X = False ,
146
+ normalize = False ,
147
+ fit_intercept = False )
145
148
146
149
def _fit_regression (self , y ):
147
- """fit regression using internal least squares/supplied regressor"""
150
+ """
151
+ fit regression using internal linear regression
152
+ or supplied regressor
153
+ """
148
154
if (self .regressor is None ):
149
- self .coefs_ = safe_sparse_dot ( pinv2 ( self .hidden_activations_ ) , y )
155
+ self ._lin_reg . fit ( self .hidden_activations_ , y )
150
156
else :
151
157
self .regressor .fit (self .hidden_activations_ , y )
152
158
@@ -183,7 +189,7 @@ def fit(self, X, y):
183
189
def _get_predictions (self , X ):
184
190
"""get predictions using internal least squares/supplied regressor"""
185
191
if (self .regressor is None ):
186
- preds = safe_sparse_dot ( self .hidden_activations_ , self .coefs_ )
192
+ preds = self ._lin_reg . predict ( self .hidden_activations_ )
187
193
else :
188
194
preds = self .regressor .predict (self .hidden_activations_ )
189
195
@@ -219,18 +225,19 @@ class ELMClassifier(BaseELM, ClassifierMixin):
219
225
ELMClassifier is a classifier based on the Extreme Learning Machine.
220
226
221
227
An Extreme Learning Machine (ELM) is a single layer feedforward
222
- network with a random hidden layer components and least-squares fitting
223
- of the hidden->output weights by default. [1][2]
228
+ network with a random hidden layer components and ordinary linear
229
+ least squares fitting of the hidden->output weights by default.
230
+ [1][2]
224
231
225
232
Parameters
226
233
----------
227
234
`hidden_layer` : random_hidden_layer instance, optional
228
235
(default=SimpleRandomHiddenLayer(random_state=0))
229
236
230
- `regressor` : linear_model instance, optional (default=None)
237
+ `regressor` : regressor instance, optional (default=None)
231
238
If provided, this object is used to perform the regression from hidden
232
239
unit activations to the outputs and subsequent predictions. If not
233
- present, a simple least squares fit is performed internally.
240
+ present, an ordinary linear least squares fit is performed
234
241
235
242
Attributes
236
243
----------
@@ -333,8 +340,9 @@ class SimpleELMRegressor(BaseEstimator, RegressorMixin):
333
340
SimpleELMRegressor is a regressor based on the Extreme Learning Machine.
334
341
335
342
An Extreme Learning Machine (ELM) is a single layer feedforward
336
- network with a random hidden layer components and least-squares fitting
337
- of the hidden->output weights by default. [1][2]
343
+ network with a random hidden layer components and ordinary linear
344
+ least squares fitting of the hidden->output weights by default.
345
+ [1][2]
338
346
339
347
SimpleELMRegressor is a wrapper for an ELMRegressor that uses a
340
348
SimpleRandomHiddenLayer and passes the __init__ parameters through
@@ -345,14 +353,14 @@ class SimpleELMRegressor(BaseEstimator, RegressorMixin):
345
353
`n_hidden` : int, optional (default=20)
346
354
Number of units to generate in the SimpleRandomHiddenLayer
347
355
348
- `xfer_func ` : {callable, string} optional (default='tanh')
356
+ `activation_func ` : {callable, string} optional (default='tanh')
349
357
Function used to transform input activation
350
358
It must be one of 'tanh', 'sine', 'tribas', 'sigmoid', 'hardlim' or
351
359
a callable. If none is given, 'tanh' will be used. If a callable
352
360
is given, it will be used to compute the hidden unit activations.
353
361
354
- `xfer_args ` : dictionary, optional (default=None)
355
- Supplies keyword arguments for a callable xfer_func
362
+ `activation_args ` : dictionary, optional (default=None)
363
+ Supplies keyword arguments for a callable activation_func
356
364
357
365
`random_state` : int, RandomState instance or None (default=None)
358
366
Control the pseudo random number generator used to generate the
@@ -376,12 +384,13 @@ class SimpleELMRegressor(BaseEstimator, RegressorMixin):
376
384
2006.
377
385
"""
378
386
379
- def __init__ (self , n_hidden = 20 , xfer_func = 'tanh' , xfer_args = None ,
387
+ def __init__ (self , n_hidden = 20 ,
388
+ activation_func = 'tanh' , activation_args = None ,
380
389
random_state = None ):
381
390
382
391
self .n_hidden = n_hidden
383
- self .xfer_func = xfer_func
384
- self .xfer_args = xfer_args
392
+ self .activation_func = activation_func
393
+ self .activation_args = activation_args
385
394
self .random_state = random_state
386
395
387
396
self .elm_regressor_ = None
@@ -407,8 +416,8 @@ def fit(self, X, y):
407
416
Returns an instance of self.
408
417
"""
409
418
rhl = SimpleRandomHiddenLayer (n_hidden = self .n_hidden ,
410
- xfer_func = self .xfer_func ,
411
- xfer_args = self .xfer_args ,
419
+ activation_func = self .activation_func ,
420
+ activation_args = self .activation_args ,
412
421
random_state = self .random_state )
413
422
414
423
self .elm_regressor_ = ELMRegressor (hidden_layer = rhl )
@@ -440,8 +449,9 @@ class SimpleELMClassifier(BaseEstimator, ClassifierMixin):
440
449
SimpleELMClassifier is a classifier based on the Extreme Learning Machine.
441
450
442
451
An Extreme Learning Machine (ELM) is a single layer feedforward
443
- network with a random hidden layer components and least-squares fitting
444
- of the hidden->output weights by default. [1][2]
452
+ network with a random hidden layer components and ordinary linear
453
+ least squares fitting of the hidden->output weights by default.
454
+ [1][2]
445
455
446
456
SimpleELMClassifier is a wrapper for an ELMClassifier that uses a
447
457
SimpleRandomHiddenLayer and passes the __init__ parameters through
@@ -452,14 +462,14 @@ class SimpleELMClassifier(BaseEstimator, ClassifierMixin):
452
462
`n_hidden` : int, optional (default=20)
453
463
Number of units to generate in the SimpleRandomHiddenLayer
454
464
455
- `xfer_func ` : {callable, string} optional (default='tanh')
465
+ `activation_func ` : {callable, string} optional (default='tanh')
456
466
Function used to transform input activation
457
467
It must be one of 'tanh', 'sine', 'tribas', 'sigmoid', 'hardlim' or
458
468
a callable. If none is given, 'tanh' will be used. If a callable
459
469
is given, it will be used to compute the hidden unit activations.
460
470
461
- `xfer_args ` : dictionary, optional (default=None)
462
- Supplies keyword arguments for a callable xfer_func
471
+ `activation_args ` : dictionary, optional (default=None)
472
+ Supplies keyword arguments for a callable activation_func
463
473
464
474
`random_state` : int, RandomState instance or None (default=None)
465
475
Control the pseudo random number generator used to generate the
@@ -486,12 +496,13 @@ class SimpleELMClassifier(BaseEstimator, ClassifierMixin):
486
496
2006.
487
497
"""
488
498
489
- def __init__ (self , n_hidden = 20 , xfer_func = 'tanh' , xfer_args = None ,
499
+ def __init__ (self , n_hidden = 20 ,
500
+ activation_func = 'tanh' , activation_args = None ,
490
501
random_state = None ):
491
502
492
503
self .n_hidden = n_hidden
493
- self .xfer_func = xfer_func
494
- self .xfer_args = xfer_args
504
+ self .activation_func = activation_func
505
+ self .activation_args = activation_args
495
506
self .random_state = random_state
496
507
497
508
self .elm_classifier_ = None
@@ -538,8 +549,8 @@ def fit(self, X, y):
538
549
Returns an instance of self.
539
550
"""
540
551
rhl = SimpleRandomHiddenLayer (n_hidden = self .n_hidden ,
541
- xfer_func = self .xfer_func ,
542
- xfer_args = self .xfer_args ,
552
+ activation_func = self .activation_func ,
553
+ activation_args = self .activation_args ,
543
554
random_state = self .random_state )
544
555
545
556
self .elm_classifier_ = ELMClassifier (hidden_layer = rhl )
0 commit comments