사용자 도구

사이트 도구


maine_learning:extream_learning_machine

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
maine_learning:extream_learning_machine [2020/10/26 16:31] rex8312maine_learning:extream_learning_machine [2024/03/23 02:42] (현재) – 바깥 편집 127.0.0.1
줄 15: 줄 15:
  
   * https://github.com/rex8312/pyELM   * https://github.com/rex8312/pyELM
- 
  
 <code python ELM.py> <code python ELM.py>
줄 27: 줄 26:
  
 class ELM: class ELM:
-    def __init__(self, input_dimoutput_dim, hidden_dim=1024): +    def __init__(self, xy, hidden_dim=None): 
-        self.input_size = input_dim +        self.input_size = x.shape[-1] 
-        self.hidden_size = hidden_dim+        if hidden_dim is None: 
 +            self.hidden_size = int(x.shape[0] / 7)  
 +        else: 
 +            self.hidden_size = hidden_dim
         self.input_weights = np.random.normal(size=[self.input_size, self.hidden_size])         self.input_weights = np.random.normal(size=[self.input_size, self.hidden_size])
         self.biases = np.random.normal(size=[self.hidden_size])         self.biases = np.random.normal(size=[self.hidden_size])
- +        self.output_weights = np.dot(pinv2(self.hidden_nodes(x))y)
-    def relu(self, x): +
-        return np.maximum(x, 0, x)+
  
     def hidden_nodes(self, X):     def hidden_nodes(self, X):
         G = np.dot(X, self.input_weights) + self.biases         G = np.dot(X, self.input_weights) + self.biases
-        self.relu(G)+        relu lambda x_: np.maximum(x_, 0, x_) 
 +        H = relu(G)
         return H         return H
- 
-    def fit(self, x, y): 
-        self.output_weights = np.dot(pinv2(self.hidden_nodes(x)), y) 
  
     def __call__(self, x):     def __call__(self, x):
줄 55: 줄 53:
     X = (X - X.min(0) + 1e-6) / (X.max(0) - X.min(0) + 1e-6)     X = (X - X.min(0) + 1e-6) / (X.max(0) - X.min(0) + 1e-6)
  
-    n_hiddens = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]+    n_hiddens = list(range(2, 32))
     losses = list()     losses = list()
     for n_hidden in tqdm.tqdm(n_hiddens):     for n_hidden in tqdm.tqdm(n_hiddens):
줄 61: 줄 59:
         train_x, train_y = X[mask], y[mask]         train_x, train_y = X[mask], y[mask]
         test_x, test_y = X[~mask], y[~mask]         test_x, test_y = X[~mask], y[~mask]
-        model = ELM(X.shape[-1]y.shape[-1], n_hidden+        model = ELM(train_xtrain_y, n_hidden)
-        model.fit(train_x, train_y)+
         loss = (0.5 * (test_y - model(test_x)) ** 2).mean()         loss = (0.5 * (test_y - model(test_x)) ** 2).mean()
         losses.append(loss)         losses.append(loss)
  
     print(plotille.plot(n_hiddens, losses))     print(plotille.plot(n_hiddens, losses))
 +
 +    model = ELM(train_x, train_y)
 +    loss = (0.5 * (test_y - model(test_x)) ** 2).mean()
 +    embed(); exit()
 </code> </code>
  
maine_learning/extream_learning_machine.1603729867.txt.gz · 마지막으로 수정됨: (바깥 편집)