Changeset 32734

Show
Ignore:
Timestamp:
04/22/09 18:26:14 (4 years ago)
Author:
rezoo
Message:

アルゴリズムを変更できるオプションの追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/python/tremolo/tremolo/indications/neuralnet.py

    r32724 r32734  
    99        from pybrain.datasets import SupervisedDataSet 
    1010        from pybrain.structure  import RecurrentNetwork 
    11         from pybrain.supervised import RPropMinusTrainer 
    1211except:  
    1312        raise ImportError("this module needs pybrain.")  
     
    2524         
    2625        def __init__(self, indications, target, network=None, 
    27                      hiddenLayers=10, dim=1, verbose=True, parent=None): 
     26                     hiddenLayers=10, dim=1, 
     27                     trainer="Rprop", trainerOption={}, 
     28                     verbose=True, parent=None): 
    2829                """ 
    2930                オブジェクトのコンストラクタです. 
    3031                 
    31                 indications  : 対象となるIndicationsインスタンス 
    32                 target       : 学習先となる指標 
    33                 network      : 使用するネットワーク.指定されない場合は新規に作成される 
    34                 hiddenLayers : 隠れレイヤに用いるシグモイドユニットの数 
    35                 dim          : 隠れレイヤの数 
    36                 verbose      : 詳細なログを出力するか.デフォルトはTrue 
    37                 parent       : 親となるオブジェクト 
     32                indications   : 対象となるIndicationsインスタンス 
     33                target        : 学習先となる指標 
     34                network       : 使用するネットワーク.指定されない場合は新規に作成される 
     35                hiddenLayers  : 隠れレイヤに用いるシグモイドユニットの数 
     36                dim           : 隠れレイヤの数 
     37                trainer       : 学習に用いるアルゴリズム.'Rprop'か'Backprop'で指定. 
     38                                デフォルトはRprop 
     39                trainerOption : 学習アルゴリズムのインスタンス作成時に用いる引数の辞書 
     40                verbose       : 詳細なログを出力するか.デフォルトはTrue 
     41                parent        : 親となるオブジェクト 
    3842                """ 
    3943                Indication.__init__(self, None, parent) 
     
    6165                 
    6266                self.__dataset = SupervisedDataSet(len(self.indications), 1) 
    63                 self.__trainer = RPropMinusTrainer(self.__network, verbose=verbose) 
     67                 
     68                if trainer == "Rprop": 
     69                        from pybrain.supervised import RPropMinusTrainer 
     70                        self.__trainer = RPropMinusTrainer(self.__network, verbose=verbose, 
     71                                                           **trainerOption) 
     72                elif trainer == "Backprop": 
     73                        from pybrain.supervised import BackpropTrainer 
     74                        self.__trainer = BackpropTrainer(self.__network, verbose=verbose, 
     75                                                         **trainerOption) 
     76                else: raise TypeError("the attribute 'trainer' is not valid.") 
    6477         
    6578        def getVerbose(self): return self.__verbose 
     
    151164         
    152165        def __init__(self, indications, target, network=None, 
    153                      hiddenLayers=10, dim=1, verbose=True, parent=None): 
     166                     hiddenLayers=10, dim=1, 
     167                     trainer="Rprop", trainerOption={}, 
     168                     verbose=True, parent=None): 
    154169                """ 
    155170                オブジェクトのコンストラクタです. 
    156171                 
    157                 indications  : 対象となるIndicationsインスタンス 
    158                 target       : 学習先となる指標 
    159                 network      : 使用するネットワーク.指定されない場合は新規に作成される 
    160                 hiddenLayers : 隠れレイヤに用いるシグモイドユニットの数 
    161                 dim          : 隠れレイヤの数 
    162                 verbose      : 詳細なログを出力するか.デフォルトはTrue 
    163                 parent       : 親となるオブジェクト 
     172                indications   : 対象となるIndicationsインスタンス 
     173                target        : 学習先となる指標 
     174                network       : 使用するネットワーク.指定されない場合は新規に作成される 
     175                hiddenLayers  : 隠れレイヤに用いるシグモイドユニットの数 
     176                dim           : 隠れレイヤの数 
     177                trainer       : 学習に用いるアルゴリズム.'Rprop'か'Backprop'で指定. 
     178                                デフォルトはRprop 
     179                trainerOption : 学習アルゴリズムのインスタンス作成時に用いる引数の辞書 
     180                verbose       : 詳細なログを出力するか.デフォルトはTrue 
     181                parent        : 親となるオブジェクト 
    164182                """ 
    165183                Indication.__init__(self, None, parent) 
     
    187205                 
    188206                self.__dataset = SupervisedDataSet(len(self.indications), 1) 
    189                 self.__trainer = RPropMinusTrainer(self.__network, 
    190                                                    self.__dataset, verbose=verbose) 
     207                 
     208                if trainer == "Rprop": 
     209                        from pybrain.supervised import RPropMinusTrainer 
     210                        self.__trainer = RPropMinusTrainer(self.__network, verbose=verbose, 
     211                                                           **trainerOption) 
     212                elif trainer == "Backprop": 
     213                        from pybrain.supervised import BackpropTrainer 
     214                        self.__trainer = BackpropTrainer(self.__network, verbose=verbose, 
     215                                                         **trainerOption) 
     216                else: raise TypeError("the attribute 'trainer' is not valid.") 
    191217         
    192218        def getVerbose(self): return self.__verbose 
     
    266292                return self.network.activate(args)[0] 
    267293 
     294# TODO: LSTMネットワークを使用したクラスの追加. 
     295# この手の新しいアルゴリズムは日本語の文献が全くないので苦労する.