2021年1月3日星期日

Function as class atribute

I am writing a class where I would like to pass function as a class attribute and later use it, like that:

class Nevronska_mreza:      def __init__(self, st_vhodni, st_skriti, st_izhod, prenosna_funkcija=pf.sigmoid):          self.mreza = []          self.st_vhodni = st_vhodni          self.st_skriti = st_skriti          self.st_izhodni = st_izhod          self.prenosna_funckija = prenosna_funkcija          self.mreza.append([{'utezi': [random() for i in range(st_vhodni + 1)]} for j in range(st_skriti)])          self.mreza.append([{'utezi': [random() for i in range(st_skriti + 1)]} for j in range(st_izhod)])        def razsirjanje_naprej(self, vhod):          for sloj in self.mreza:              nov_vhod = []              for nevron in sloj:                  nevron['izhod'] = self.prenosna_funkcija(self.aktivacijska_funkcija(nevron['utezi'], vhod))                  nov_vhod.append(nevron['izhod'])              vhod = nov_vhod          return vhod  

but it seems like this isn't the right way, I am getting the following error: AttributeError: 'Nevronska_mreza' object has no attribute 'prenosna_funkcija'. Is it possible to do something like that?

https://stackoverflow.com/questions/65556729/function-as-class-atribute January 04, 2021 at 09:40AM

没有评论:

发表评论