사용자 도구

사이트 도구


maine_learning:extream_learning_machine

차이

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

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
maine_learning:extream_learning_machine [2015/02/14 10:38] rex8312maine_learning:extream_learning_machine [2024/03/23 02:42] (현재) – 바깥 편집 127.0.0.1
줄 16: 줄 16:
   * https://github.com/rex8312/pyELM   * https://github.com/rex8312/pyELM
  
 +<code python ELM.py>
 +import numpy as np
 +import plotille
 +import tqdm
 +from IPython import embed
 +from scipy.linalg import pinv2
 +from sklearn.datasets import make_circles, make_classification, make_moons
  
-===== 참고문헌 ===== 
  
-  * HuangGuang-BinDian Hui Wangand Yuan Lan. "Extreme learning machinesa survey." International Journal of Machine Learning and Cybernetics 2.(2011): 107-122.+class ELM: 
 +    def __init__(selfxyhidden_dim=None): 
 +        self.input_size = x.shape[-1] 
 +        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.biases = np.random.normal(size=[self.hidden_size]) 
 +        self.output_weights = np.dot(pinv2(self.hidden_nodes(x)), y)
  
-{{tag>machine_laerning artificial_neural_network ann}}+    def hidden_nodes(self, X): 
 +        G = np.dot(X, self.input_weights) + self.biases 
 +        relu = lambda x_: np.maximum(x_, 0, x_) 
 +        H = relu(G) 
 +        return H 
 + 
 +    def __call__(self, x): 
 +        H = self.hidden_nodes(x) 
 +        y = np.dot(H, self.output_weights) 
 +        return y 
 + 
 + 
 +if __name__ == '__main__': 
 + 
 +    X, y = make_moons(n_samples=500, noise=0.3, random_state=0) 
 +    X = (X - X.min(0) + 1e-6) / (X.max(0) - X.min(0) + 1e-6) 
 + 
 +    n_hiddens = list(range(2, 32)) 
 +    losses = list() 
 +    for n_hidden in tqdm.tqdm(n_hiddens): 
 +        mask = np.random.random(X.shape[0]) < 0.1  
 +        train_x, train_y = X[mask], y[mask] 
 +        test_x, test_y = X[~mask], y[~mask] 
 +        model = ELM(train_x, train_y, n_hidden) 
 +        loss = (0.5 * (test_y - model(test_x)) ** 2).mean() 
 +        losses.append(loss) 
 + 
 +    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> 
 + 
 +===== 참고자료 ===== 
 + 
 +  * Huang, Guang-Bin, Dian Hui Wang, and Yuan Lan. "Extreme learning machines: a survey." International Journal of Machine Learning and Cybernetics 2.2 (2011): 107-122. 
 +  * https://towardsdatascience.com/build-an-extreme-learning-machine-in-python-91d1e8958599 
 +  * http://lepisma.svbtle.com/extreme-learning-machines-with-julia
maine_learning/extream_learning_machine.1423910282.txt.gz · 마지막으로 수정됨: (바깥 편집)