DoneKwargTuplesList=map( lambda __KwargTuple: ( DoingStr+DoingPrefixStr.join( __KwargTuple[0].split(DoingPrefixStr)[1:]), __KwargTuple[1] ) if __KwargTuple[0].startswith(DoingPrefixStr) else __KwargTuple, _KwargVariablesDict.items() ) #Check if len(DoneKwargTuplesList)>0: #group by [DoClass.DoneAttributeTuplesList,DoClass.DoneNotAttributeTupleItemsList]=SYS.groupby( lambda __AttributeTuple: hasattr(_InstanceVariable,__AttributeTuple[0]), DoneKwargTuplesList ) #set in the instance the corresponding kwarged arguments map( lambda __AttributeTuple: #set direct explicit attributes _InstanceVariable.__setattr__(*__AttributeTuple), DoClass.DoneAttributeTuplesList ) #Define DoneKwargDict=dict(DoClass.DoneNotAttributeTupleItemsList)
def imitateDo(_InstanceVariable,*_LiargVariablesList,**_KwargVariablesDict): #Debug ''' print('Imitater l.93 inside of the function imitateDo') print('_InstanceVariable is ',_InstanceVariable) print('_LiargVariablesList is ',_LiargVariablesList) print('_KwargVariablesDict is ',_KwargVariablesDict) print('') ''' if len(_KwargVariablesDict)>0: #group by [ImitatedItemTuplesList,ImitatedNotItemTuplesList]=SYS.groupby( lambda __ItemTuple:hasattr(_InstanceVariable,__ItemTuple[0]), _KwargVariablesDict.items() ) #Debug ''' print('ImitatedItemTuplesList is ',ImitatedItemTuplesList) print('ImitatedNotItemTuplesList is ',ImitatedNotItemTuplesList) print('') ''' #set in the instance the corresponding kwarged arguments map( lambda __ItemTuple: #set direct explicit attributes _InstanceVariable.__setattr__(*__ItemTuple), ImitatedItemTuplesList ) #Define ImitatedKwargDict=dict(ImitatedNotItemTuplesList) else: #Define ImitatedKwargDict={} #Init ImitatedOutputVariable=None #Debug ''' print('l.141 Imitater') print('self.ImitatingFunction is ',self.ImitatingFunction) print('ImitatedKwargDict is ',ImitatedKwargDict) print('') ''' #call the imitated function if len(ImitatedKwargDict)>0: ImitatedOutputVariable=self.ImitatingFunction( _InstanceVariable, *_LiargVariablesList, **ImitatedKwargDict ) else: ImitatedOutputVariable=self.ImitatingFunction( _InstanceVariable, *_LiargVariablesList ) #Check if ImitatedClass.DoingGetBool==False: #Return return _InstanceVariable else: #Return the return ImitatedOutputVariable
DoingStr+DoingAttributePrefixStr.join( __KwargTuple[0].split(DoingAttributePrefixStr)[1:]), __KwargTuple[1] ) if __KwargTuple[0].startswith(DoingAttributePrefixStr) else __KwargTuple, _KwargVariablesDict.items() ) #Check if len(DoKwargTuplesList)>0: #group by [ DoClass.DoTempAttributeItemTuplesList, DoClass.DoTempNotAttributeItemTupleItemsList ]=SYS.groupby( lambda __DoKwargTuple: hasattr(_InstanceVariable,__DoKwargTuple[0]), DoKwargTuplesList ) #set in the instance the corresponding kwarged arguments map( lambda __DoTempAttributeItemTuple: #set direct explicit attributes _InstanceVariable.__setattr__(*__DoTempAttributeItemTuple), DoClass.DoTempAttributeItemTuplesList ) #Define DoneKwargDict=dict(DoClass.DoTempNotAttributeItemTupleItemsList)
def do_scriptbook(self): #debug self.debug( [ 'We scriptbook here', ('self.',self,[ 'FolderedDirKeyStrsList' ]) ] ) #Definition self.ScriptbookedFileKeyStrsList=SYS._filter( lambda __DirKeyStr: any( map( lambda __ExtensionStr: __DirKeyStr.endswith( self.GuidingBookStr+__ExtensionStr ), ['.py','.md','.tex'] )), self.FolderedDirKeyStrsList ) #debug ''' self.debug( [ ('self.',self,[ 'ScriptbookedFileKeyStrsList' ]) ] ) ''' #Definition ScriptbookedPageStrsList=map( lambda __ScriptbookerScriptbookFileKeyStr: Guider.GuidingSortStr.join( __ScriptbookerScriptbookFileKeyStr.split( Guider.GuidingSortStr)[1:] ), self.ScriptbookedFileKeyStrsList ) #set self.ScriptbookedSortDict=dict( zip( ScriptbookedPageStrsList, self.ScriptbookedFileKeyStrsList ) ) #debug ''' self.debug(('self.',self,['ScriptbookedSortDict'])) ''' #Check if len(self.ScriptbookingGuideTuplesList)>0: #map ScriptbookedGuideTuplesList=map( lambda __ScriptbookingGuideTuple: list(__ScriptbookingGuideTuple)+[ __ScriptbookingGuideTuple[1]+self.GuidingBookStr+dict( Guider.GuideFormatTuplesList )[ __ScriptbookingGuideTuple[2] ] ], self.ScriptbookingGuideTuplesList ) #groupby [ self.ScriptbookedNewGuideTuplesList, self.ScriptbookedOldGuideTuplesList ]=SYS.groupby( lambda __ScriptbookedGuideTuple: __ScriptbookedGuideTuple[3] not in self.ScriptbookedSortDict, ScriptbookedGuideTuplesList ) #debug ''' self.debug( [ ('self.',self,[ 'ScriptbookedNewGuideTuplesList' ]) ] ) ''' #map a guide for the news map( lambda __ScriptbookedNewGuideTuple: self.guide( __ScriptbookedNewGuideTuple[0], __ScriptbookedNewGuideTuple[1], self.GuidingBookStr, __ScriptbookedNewGuideTuple[2] ), self.ScriptbookedNewGuideTuplesList ) #debug ''' self.debug( [ ('self.',self,[ 'ScriptbookedOldGuideTuplesList', 'ScriptbookedSortDict' ]) ] ) ''' #check if we rewrite for the olds map( lambda __ScriptbookedOldGuideTuple: self.file( _ModeStr='c' ) if "#FrozenIsBool True" in self.file( self.ScriptbookedSortDict[ __ScriptbookedOldGuideTuple[3] ], _ModeStr='r', _FormatStr='txt' ).FiledReadVariable else self.file( _ModeStr='c' ).guide( __ScriptbookedOldGuideTuple[0], __ScriptbookedOldGuideTuple[1], self.GuidingBookStr, __ScriptbookedOldGuideTuple[2] ), self.ScriptbookedOldGuideTuplesList )
def shape(self,_DimensionsTupleList=None,**_KwargVariablesDict): #Init if self.ShapingDimensionsTupleList==None: self.ShapingDimensionsTupleList=[] #Init if self.ShapedGettingStrsList==None: self.ShapedGettingStrsList=[] if self.ShapedColClassAndGettingStrTuplesList==None: self.ShapedColClassAndGettingStrTuplesList=[] #set the ShapedOldModelingDescriptionTuplesList self.ShapedCopyModelingDescriptionTuplesList=copy.copy(self.ModelingDescriptionTuplesList) #debug ''' self.debug('We are going to filter the shaping tuples among the columning tuples') ''' #Unpack [ self.ShapedModelingDescriptionTuplesList, self.ShapedNotModelingDescriptionTuplesList ]=SYS.groupby( lambda __ColumnTuple: type(__ColumnTuple[1])==tuple, self.ModelingDescriptionTuplesList, ) #set the ShapedGettingStrsList and ShapedColClassAndGettingStrTuplesList FilteredList=map(list, SYS.unzip(self.ShapedModelingDescriptionTuplesList,[0,1]) ) if len(FilteredList)>0: [ self.ShapedGettingStrsList, self.ShapedColClassAndGettingStrTuplesList ]=FilteredList #debug ''' self.debug( ('self.',self,[ 'ShapedNotModelingDescriptionTuplesList', 'ShapedGettingStrsList', 'ShapedColClassAndGettingStrTuplesList' ] ) ) ''' #set the ShapedGettingStrsList self.ShapedDimensionKeyStrsList=list(set(SYS.unzip( self.ShapedColClassAndGettingStrTuplesList,[1] ))) #debug ''' self.debug(("self.",self,['ShapedGettingStrsList'])) ''' #set the ShapedVariablePointer to get inside the shaped variables if self.ShapedVariablePointer==None and hasattr(self,'NodedDatabaseParentPointer'): self.ShapedVariablePointer=self.NodedDatabaseParentPointer #set the ShapedVariablesList setting self.ShapedDimensionVariablesList=map( lambda __GettedVariable: (__GettedVariable) if type(__GettedVariable)==int else tuple(__GettedVariable), map( lambda __ShapedDimensionKeyStr: self.ShapedVariablePointer[__ShapedDimensionKeyStr], self.ShapedDimensionKeyStrsList ) ) #Bind with ModeledShapedStr setting self.ShapedStr=ShapingJoiningStr.join( map( lambda __ShapingGettingStr,__ShapedVariable: ShapingJoiningStr+str( __ShapingGettingStr )+ShapingTuplingStr+str( __ShapedVariable), self.ShapedDimensionKeyStrsList, self.ShapedDimensionVariablesList ) ) #debug ''' self.debug(('self.',self,['ShapedDimensionVariablesList','ShapedStr'])) ''' #<NotHook> #Return self return self
def do_represent(self): #alias RepresentedClass=self.DoClass #debug ''' print('Representer l.352 : RepresentedClass is ',RepresentedClass) print('') ''' #Check ''' if hasattr(RepresentedClass,'RepresentingKeyStrsList')==False or ( len(RepresentedClass.__bases__)>0 and hasattr(RepresentedClass.__bases__[0 ],'RepresentingKeyStrsList') and RepresentedClass.__bases__[0 ].RepresentingKeyStrsList==RepresentedClass.RepresentingKeyStrsList): #init RepresentedClass.RepresentingKeyStrsList=[] ''' RepresentedClass.RepresentingKeyStrsList=RepresentedClass.DefaultSetKeyStrsList #init #RepresentedClass.RepresentingSkipKeyStrsList=None #init #RepresentedClass.RepresentingForceKeyStrsList=None #set the BaseKeyStrsList KeyStrsSet=set( SYS.collect( RepresentedClass, '__bases__', 'RepresentingKeyStrsList' ) ) #KeyStrsSet.difference_update(set(RepresentedClass.RepresentingKeyStrsList)) RepresentedClass.RepresentedBaseKeyStrsList=list(KeyStrsSet) #Split between the one from the class or not [ RepresentedClass.RepresentedSpecificKeyStrsList, RepresentedClass.RepresentedNotSpecificKeyStrsList ]=SYS.groupby( lambda __KeyStr: __KeyStr not in RepresentedClass.RepresentedBaseKeyStrsList, RepresentedClass.RepresentingKeyStrsList ) #debug ''' print( RepresentedClass.__name__, #Class.__mro__, #Class.RepresentedNotGettingStrsList, list(RepresentedClass.RepresentedBasedKeyStrsList) ) ''' #Add to the KeyStrsList RepresentedClass.KeyStrsList+=[ 'RepresentingKeyStrsList', 'RepresentingSkipKeyStrsList', 'RepresentingForceKeyStrsList', 'RepresentedBaseKeyStrsList', 'RepresentedSpecificKeyStrsList', 'RepresentedNotSpecificKeyStrsList', ] """
def do_numscipy( self ): #debug ''' self.debug( [ 'We numscipy here', ('self.',self,[ 'NumscipyingValueVariable', 'NumscipiedValueFloatsArray' ]) ] ) ''' #/#################/# # Set the size of the matrix # #Check if type(self.NumscipyingValueVariable)==None.__class__: #debug ''' self.debug( [ 'This is an array that we have to build' ] ) ''' #set if self.NumscipyingSizeTuple==None or len(self.NumscipyingSizeTuple)==0 : #set self.NumscipyingSizeTuple=( self.NumscipyingRowsInt, self.NumscipyingColsInt ) else: #set self.NumscipyingRowsInt=self.NumscipyingSizeTuple[0] self.NumscipyingColsInt=self.NumscipyingSizeTuple[1] #init self.NumscipiedValueFloatsArray=None else: #debug ''' self.debug( [ 'This is an array already built' ] ) ''' #set self.NumscipyingSizeTuple=np.shape( self.NumscipyingValueVariable ) self.NumscipyingRowsInt=self.NumscipyingSizeTuple[0] self.NumscipyingColsInt=self.NumscipyingSizeTuple[1] #alias self.NumscipiedValueFloatsArray=self.NumscipyingValueVariable #debug ''' self.debug( [ 'We have setted the shape of the matrix', ('self.',self,['NumscipyingSizeTuple']) ] ) ''' #/#################/# # Build maybe # #Check if type(self.NumscipyingValueVariable)==None.__class__: #/#################/# # Set maybe the seed # #check if self.NumscipyingSeedVariable!=None: #seed np.random.seed(self.NumscipyingSeedVariable) #debug ''' self.debug( [ "We have fixed a seed", ('self.',self,[ 'NumscipyingSeedVariable' ]) ] ) ''' #/#################/# # Get the continuous stat # #Check if self.NumscipyingStdFloat>0.: #import import scipy.stats #get self.NumscipiedContinuousStatRigidFunction=getattr( scipy.stats, self.NumscipyingContinuousStatStr )( self.NumscipyingMeanFloat, self.NumscipyingStdFloat ).rvs #/#################/# # Get the discrete stat # #Check if self.NumscipyingSparseFloat>0. and self.NumscipyingSparseFloat<1.: #debug ''' self.debug( [ 'We numscipy here', 'We set a discrete skeleton', ('self.',self,[ 'NumscipyingDiscreteStatStr', 'NumscipyingSparseFloat' ]) ] ) ''' #/#################/# # Get a list of one or zero # #import import scipy.stats #get self.NumscipiedDiscreteStatRigidFunction=getattr( scipy.stats, self.NumscipyingDiscreteStatStr ).rvs #prod NumscipiedSizeInt=np.prod(self.NumscipyingSizeTuple) #set NumscipiedRandomIntsArray=self.NumscipiedDiscreteStatRigidFunction( self.NumscipyingSparseFloat, size=NumscipiedSizeInt ) #/#################/# # Maybe set a continuous stat for non zero values # #debug self.debug( [ ('self.',self,[ 'NumscipiedContinuousStatRigidFunction' ]) ] ) #map if self.NumscipiedContinuousStatRigidFunction!=None: #Check self.NumscipiedValueFloatsArray=np.array( map( lambda __IndexInt,__BoolInt: self.NumscipiedContinuousStatRigidFunction() if __BoolInt==1 else 0., xrange(NumscipiedSizeInt), NumscipiedRandomIntsArray, ) ) else: #just floatify self.NumscipiedValueFloatsArray=self.NumscipyingMeanFloat*np.array( map( float, NumscipiedRandomIntsArray ) ) #reshape self.NumscipiedValueFloatsArray=self.NumscipiedValueFloatsArray.reshape( self.NumscipyingSizeTuple ) #Check if self.NumscipyingSwitchFloat>0.: #/##################/# # Switch the sgn # #debug ''' self.debug( [ 'We switch the sign', ('self.',self,[ 'NumscipyingSwitchFloat' ]) ] ) ''' #import import itertools #filter the upper index tuples self.NumscipiedIndexIntsTuplesList=filter( lambda __Tuple: __Tuple[1]!=__Tuple[0], itertools.product( xrange(self.NumscipyingColsInt), xrange(self.NumscipyingColsInt) ) ) #/#################/# # group by the null and non null index tuples # #filter [ self.NumscipiedNonNullIndexIntsTuplesList, self.NumscipiedNullIndexIntsTuplesList ]=SYS.groupby( lambda __IndexIntsTuple: self.NumscipiedValueFloatsArray[ __IndexIntsTuple ]!=0., self.NumscipiedIndexIntsTuplesList ) #len NumscipiedSwitchsInt=int(self.NumscipyingSwitchFloat*len( self.NumscipiedNonNullIndexIntsTuplesList ) ) #copy self.NumscipiedToSwitchIndexIntsTuplesList=self.NumscipiedNonNullIndexIntsTuplesList[:] #debug ''' self.debug( [ 'Before shuffle to switch', ('self.',self,[ 'NumscipiedToSwitchIndexIntsTuplesList' ]), ] ) ''' #Shuffle and pick the NumscipiedToSwitchIndexIntsTuplesList np.random.shuffle( self.NumscipiedToSwitchIndexIntsTuplesList ) #cut self.NumscipiedToSwitchIndexIntsTuplesList=self.NumscipiedToSwitchIndexIntsTuplesList[ :NumscipiedSwitchsInt ] #debug ''' self.debug( [ 'We map switch here', ('self.',self,[ 'NumscipiedToSwitchIndexIntsTuplesList' ]), 'NumscipiedSwitchsInt is '+str(NumscipiedSwitchsInt) ] ) ''' #map switch map( lambda __NumscipiedToSwitchIndexIntsTuple: self.NumscipiedValueFloatsArray.__setitem__( __NumscipiedToSwitchIndexIntsTuple, -self.NumscipiedValueFloatsArray[ __NumscipiedToSwitchIndexIntsTuple ] ), self.NumscipiedToSwitchIndexIntsTuplesList ) #/#################/# # If it is a dense matrix then # set direct all the matrix #Check if type(self.NumscipiedValueFloatsArray)==None.__class__: #debug ''' self.debug( [ 'This is a random norm distribution', ('self.',self,[ 'NumscipyingMeanFloat', 'NumscipyingStdFloat', 'NumscipiedContinuousStatRigidFunction' ]) ] ) ''' #Check if self.NumscipiedContinuousStatRigidFunction!=None: #set self.NumscipiedValueFloatsArray=self.NumscipiedContinuousStatRigidFunction( size=self.NumscipyingSizeTuple ) else: #set self.NumscipiedValueFloatsArray=self.NumscipyingMeanFloat*np.ones( self.NumscipyingSizeTuple ) #debug ''' self.debug( [ 'at this step', ('self.',self,[ 'NumscipiedValueFloatsArray', 'NumscipyingMeanFloat' ]) ] ) ''' #/#################/# # Normalize maybe # #debug ''' self.debug( [ 'Do we have to normalize', ('self.',self,[ 'NumscipyingDivideVariable', 'NumscipyingNormalisationFunction' ]) ] ) ''' #Check if self.NumscipyingDivideVariable!=None: #divide self.NumscipiedValueFloatsArray=( self.NumscipiedValueFloatsArray.T/self.NumscipyingDivideVariable ).T #Check if self.NumscipyingNormalisationFunction!=None and len( self.NumscipyingSizeTuple) and self.NumscipyingSizeTuple[0]==self.NumscipyingSizeTuple[1]: #set self.NumscipiedNormVariable=self.NumscipyingNormalisationFunction( self.NumscipyingSizeTuple[0] ) #debug ''' self.debug( [ 'We normalize with', 'NumscipiedNormVariable is', str(NumscipiedNormVariable), ('self.',self,[ 'NumscipyingStdFloat' ]) ] ) ''' #normalize self.NumscipiedValueFloatsArray/=self.NumscipiedNormVariable #/#################/# # Symmetrize maybe # #set NumscipiedShiftSymmetryFloat=0.5*(self.NumscipyingSymmetryFloat+1.) #compute self.NumscipiedSymmetricsInt=( self.NumscipyingColsInt*(self.NumscipyingColsInt-1) ) #Check if self.NumscipyingSymmetryFloat!=0.: #debug ''' self.debug( [ 'We are going to symmetrize', ('self.',self,[ 'NumscipyingSymmetryFloat' ]) ] ) ''' #Check if self.NumscipyingSparseFloat==0. and self.NumscipyingStdFloat>0.: #/#################/# # This is a dense symmetrization # #debug ''' self.debug( [ 'We do a dense symmetrization' ] ) ''' #import import itertools #copy NumscipiedValueFloatsArray=self.NumscipiedValueFloatsArray[:] #build the scale factor """ #ERWAN version NumscipiedScaleFloat=( ( self.NumscipyingSymmetryFloat-1. )*0.5 )+1 #Build a more or less DisSymmetricRandomArray self.NumscipiedValueFloatsArray=2.*( (NumscipiedScaleFloat/2.)*(NumscipiedValueFloatsArray+NumscipiedValueFloatsArray.T) +(0.5-(NumscipiedScaleFloat/2.))*(NumscipiedValueFloatsArray-NumscipiedValueFloatsArray.T) ) """ #CELIAN version #compute NumscipiedScaleFloat = np.sqrt( NumscipiedShiftSymmetryFloat**2-NumscipiedShiftSymmetryFloat+0.5 ) #compute the anti-symm martix self.NumscipiedValueFloatsArray = ( NumscipiedShiftSymmetryFloat * ( NumscipiedValueFloatsArray + NumscipiedValueFloatsArray.T )/2. + (1.-NumscipiedShiftSymmetryFloat) * ( NumscipiedValueFloatsArray - NumscipiedValueFloatsArray.T )/2. ) / NumscipiedScaleFloat #fill diagonal np.fill_diagonal( NumscipiedValueFloatsArray, np.diagonal(self.NumscipiedValueFloatsArray) ) elif self.NumscipyingSparseFloat>0.: #/#################/# # This is a sparse symmetrization # #debug ''' self.debug( [ 'We do a targeted symmetrization', 'First we keep only the upper part and triangularize', ('self.',self,[ 'NumscipyingSymmetryFloat', 'NumscipiedSymmetricsInt' ]) ] ) ''' #triu self.NumscipiedValueFloatsArray=np.triu( self.NumscipiedValueFloatsArray ) self.NumscipiedValueFloatsArray=self.NumscipiedValueFloatsArray+( 1. if self.NumscipyingSymmetryFloat>=0. else -1. )*self.NumscipiedValueFloatsArray.T-np.diag( np.diagonal( self.NumscipiedValueFloatsArray ) ) #Check if self.NumscipiedIndexIntsTuplesList==None: #import import itertools #filter the upper index tuples self.NumscipiedIndexIntsTuplesList=filter( lambda __Tuple: __Tuple[1]!=__Tuple[0], itertools.product( xrange(self.NumscipyingColsInt), xrange(self.NumscipyingColsInt) ) ) #/#################/# # group by the null and non null index tuples # #filter [ self.NumscipiedNonNullIndexIntsTuplesList, self.NumscipiedNullIndexIntsTuplesList ]=SYS.groupby( lambda __IndexIntsTuple: self.NumscipiedValueFloatsArray[ __IndexIntsTuple ]!=0., self.NumscipiedIndexIntsTuplesList ) #debug ''' self.debug( [ 'Now', ('self.',self,[ 'NumscipiedNonNullIndexIntsTuplesList' ]) ] ) ''' #/#################/# # This is a sparse targeting symmetrization # #debug ''' self.debug( [ 'Ok we have built a sparse symmetric matrix', 'We are going to dissymetrize by picking index tuples', 'For now, we have just kept the upper values', ('self.',self,[ 'NumscipiedIndexIntsTuplesList' ]), 'We are just going to pick the non null values', ] ) ''' #/#################/# # determine a shuffle list of pair to dissymetrize # #int self.NumscipiedToDissymetricsInt=(int)( (1.-abs(self.NumscipyingSymmetryFloat))*len( self.NumscipiedNonNullIndexIntsTuplesList ) )/2 #copy self.NumscipiedToDissymetrizeIndexIntsTuplesList=self.NumscipiedNonNullIndexIntsTuplesList[:] #debug ''' self.debug( [ 'Before shuffle', ('self.',self,[ 'NumscipiedToDissymetrizeIndexIntsTuplesList' ]), 'We take the half of self.NumscipiedToDissymetricsInt for the targetting case' ] ) ''' #Shuffle and pick the self.NumscipiedToDissymetricsInt/2 np.random.shuffle(self.NumscipiedToDissymetrizeIndexIntsTuplesList) self.NumscipiedToDissymetrizeIndexIntsTuplesList=self.NumscipiedToDissymetrizeIndexIntsTuplesList[ :(self.NumscipiedToDissymetricsInt/2) ] if self.NumscipyingStdFloat==0 else self.NumscipiedToDissymetrizeIndexIntsTuplesList[ :self.NumscipiedToDissymetricsInt ] #debug ''' self.debug( [ 'in the end', ('self.',self,[ #'NumscipiedNonNullIndexIntsTuplesList', 'NumscipiedToDissymetrizeIndexIntsTuplesList', #'NumscipiedNullIndexIntsTuplesList', 'NumscipiedToDissymetricsInt' ]), 'len(self.NumscipiedNonNullIndexIntsTuplesList) is ', str(len(self.NumscipiedNonNullIndexIntsTuplesList)), ] ) ''' #/#################/# # prepare the other list of null tuples # in which we are going to transform #map self.NumscipiedNullIndexIntsListsList=map( lambda __IndexInt: [], xrange(self.NumscipyingColsInt) ) #map map( lambda __NumscipiedNullIndexIntsTuple: self.NumscipiedNullIndexIntsListsList[ __NumscipiedNullIndexIntsTuple[0] ].append( __NumscipiedNullIndexIntsTuple[1] ), self.NumscipiedNullIndexIntsTuplesList ) #debug ''' self.debug( [ ('self.',self,[ 'NumscipiedNullIndexIntsListsList' ]) ] ) ''' #/#################/# # Now setSymmmetrize for each ToDissymetrize # #map self.NumscipiedIsDisymmetrizeIndexIntsListsList=map( lambda __IndexInt: [], xrange(self.NumscipyingColsInt) ) #init self.NumscipiedIsDissymetricsInt=0 #set self.NumscipiedDissymetryFunction=(lambda : 0.) if self.NumscipyingStdFloat==0. else ( (lambda : self.NumscipiedContinuousStatRigidFunction()/self.NumscipiedNormVariable) if self.NumscipiedNormVariable!=None else self.NumscipiedContinuousStatRigidFunction ) #debug ''' self.debug( [ 'before setDisymmetrize', ('self.',self,[ 'NumscipiedDissymetryFunction' ]) ] ) ''' #map map( lambda __NumscipiedToDissymetrizeIndexIntsTuple: self.setDisymmetrize( __NumscipiedToDissymetrizeIndexIntsTuple ), self.NumscipiedToDissymetrizeIndexIntsTuplesList ) #debug ''' self.debug( [ 'In the end', ('self.',self, [ 'NumscipiedToDissymetricsInt', 'NumscipiedToDissymetrizeIndexIntsTuplesList', 'NumscipiedIsDisymmetrizeIndexIntsListsList', 'NumscipiedIsDissymetricsInt', ] ) ] ) ''' #/#################/# # Maybe set a specific diagonal # #Check if type(self.NumscipyingDiagFloatsArray)!=None.__class__ and len( self.NumscipyingDiagFloatsArray)==np.shape( self.NumscipiedValueFloatsArray )[0]: #debug ''' self.debug(('self.',self,['NumscipyingDiagFloatsArray'])) ''' #map ''' map( lambda __RowInt,__NumscipyingDiagFloat: self.NumscipiedValueFloatsArray.__setitem__( (__RowInt,__RowInt), __NumscipyingDiagFloat ), xrange(len(self.NumscipiedValueFloatsArray)), self.NumscipyingDiagFloatsArray ) ''' #fill diagonal np.fill_diagonal( self.NumscipiedValueFloatsArray, np.diagonal(self.NumscipyingDiagFloatsArray) ) #/#################/# # Force maybe the sum of the rows or the cols to be the same # #Check if self.NumscipyingMeanForceStr!="None": #debug """ self.debug( [ ('We force the ' + self.NumscipyingMeanForceStr + ' to be the same'), ('self.',self,[ 'NumscipyingMeanFloat', 'NumscipiedValueFloatsArray' ]) ] ) """ #Check if self.NumscipyingMeanForceStr=="rows": SumAxisInt=1 SetAxisInt=0 elif self.NumscipyingMeanForceStr=="cols": SumAxisInt=0 SetAxisInt=1 #compute NumscipiedResiduFloatsArray = np.sum( self.NumscipiedValueFloatsArray, axis = SumAxisInt, ) - self.NumscipyingMeanFloat #debug """ self.debug( [ "NumscipiedResiduFloatsArray is "+str(NumscipiedResiduFloatsArray) ] ) """ #set SYS.setMatrixArray( self.NumscipiedValueFloatsArray, - NumscipiedResiduFloatsArray/float(self.NumscipyingColsInt), _SetMethod=np.ndarray.__add__, _AxisInt=SetAxisInt ) #/#################/# # Compute statistic # #debug ''' self.debug( [ 'Do we compute statistics on the matrix ?', ('self.',self,[ 'NumscipyingStatBool', 'NumscipyingRowsInt', 'NumscipyingColsInt' ]), 'self.NumscipyingRowsInt==self.NumscipyingColsInt is '+str( self.NumscipyingRowsInt==self.NumscipyingColsInt ) ] ) ''' #Check if self.NumscipyingStatBool and self.NumscipyingRowsInt==self.NumscipyingColsInt: #import import itertools #debug ''' self.debug( [ 'We compute the variance', ('self.',self,[ 'NumscipiedSymmetricsInt' ]) ] ) ''' #list NumscipiedLateralIndexIntsList=list( itertools.product( xrange(self.NumscipyingRowsInt), xrange(self.NumscipyingColsInt) ) ) #variance self.NumscipiedMeanFloat=np.sum( np.array( filter( lambda __Float: __Float!=None, map( lambda __Tuple: self.NumscipiedValueFloatsArray[__Tuple] if __Tuple[0]!=__Tuple[1] else None , NumscipiedLateralIndexIntsList ) ) ) )/(float(self.NumscipiedSymmetricsInt)) #debug ''' self.debug( [ ('self.',self,[ 'NumscipiedMeanFloat' ]) ] ) ''' #variance self.NumscipiedVarianceFloat=np.sum( np.array( filter( lambda __Float: __Float!=None, map( lambda __Tuple: ( self.NumscipiedValueFloatsArray[__Tuple]-self.NumscipiedMeanFloat )**2 if __Tuple[0]!=__Tuple[1] else None ,NumscipiedLateralIndexIntsList ) ) ) )/(float(self.NumscipiedSymmetricsInt-1)) #set self.NumscipiedSommersFloat = ( 2.*NumscipiedShiftSymmetryFloat-1. )/( 2.*NumscipiedShiftSymmetryFloat*( NumscipiedShiftSymmetryFloat-1. )+1. ) #Check if self.NumscipyingStdFloat==0.: #mul self.NumscipiedSommersFloat*=self.NumscipyingSparseFloat*( 1.-self.NumscipyingSparseFloat ) #debug ''' self.debug( [ 'NumscipiedShiftSymmetryFloat is '+str(NumscipiedShiftSymmetryFloat), ('self.',self, [ 'NumscipyingSparseFloat', 'NumscipiedVarianceFloat', 'NumscipiedSommersFloat', 'NumscipiedSymmetricsInt' ] ) ] ) ''' #deviation self.NumscipiedStdFloat=np.sqrt(self.NumscipiedVarianceFloat) #covariance self.NumscipiedCovarianceFloat=self.NumscipyingColsInt*np.sum( np.array( filter( lambda __Float: __Float!=None, map( lambda __Tuple: ( self.NumscipiedValueFloatsArray[__Tuple]-self.NumscipiedMeanFloat )*( self.NumscipiedValueFloatsArray[(__Tuple[1],__Tuple[0])]-self.NumscipiedMeanFloat ) if __Tuple[0]!=__Tuple[1] else None ,NumscipiedLateralIndexIntsList ) ) ) )/( float( self.NumscipiedSymmetricsInt-1 ) ) #debug ''' self.debug( [ 'We compute the center', ('self.',self,[ 'NumscipyingSwitchFloat', 'NumscipyingMeanFloat' ]) ] ) ''' #compute the center self.NumscipiedCenterFloat=( self.NumscipyingSwitchFloat*self.NumscipyingMeanFloat-( 1.-self.NumscipyingSwitchFloat )*self.NumscipyingMeanFloat)/2. #set self.NumscipiedWidthFloat=2.*(1.+self.NumscipiedSommersFloat) self.NumscipiedHeightFloat=2.*(1.-self.NumscipiedSommersFloat) #Check if self.NumscipyingStdFloat>0.: #mul self.NumscipiedWidthFloat*=self.NumscipyingStdFloat self.NumscipiedHeightFloat*=self.NumscipyingStdFloat else: #sqrt self.NumscipiedStdSparseFloat=np.sqrt( self.NumscipyingSparseFloat*( 1.-self.NumscipyingSparseFloat) ) #mul self.NumscipiedWidthFloat*=self.NumscipiedStdSparseFloat self.NumscipiedHeightFloat*=self.NumscipiedStdSparseFloat #/#################/# # Get the eigenvalues # #Check if self.NumscipyingEigenvectorBool: pass #Check if self.NumscipyingEigenvalueBool: #debug ''' self.debug( [ 'We compute the eigenvalues', ('self.',self,[ 'NumscipiedValueFloatsArray' ]) ] ) ''' #Check if self.NumscipyingSymmetryFloat==1.: #compute self.NumscipiedEigenvalueComplexesArray=np.linalg.eigvalsh( self.NumscipiedValueFloatsArray ) else: #compute self.NumscipiedEigenvalueComplexesArray=np.linalg.eigvals( self.NumscipiedValueFloatsArray ) #project self.NumscipiedRealEigenvalueFloatsArray=np.real( self.NumscipiedEigenvalueComplexesArray ) self.NumscipiedImagEigenvalueFloatsArray=np.imag( self.NumscipiedEigenvalueComplexesArray ) #debug ''' self.debug( [ 'We have computed the eigenvalues', ('self.',self,[ 'NumscipiedEigenvalueComplexesArray' ]) ] ) ''' #/#################/# # Compute Global # #Check if self.NumscipyingGlobalBool: #debug ''' self.debug( [ 'We compute some global properties' ] ) ''' #/###############/# # Compute basic statistics # #mean self.NumscipiedMeanGlobalFloatsArray=self.NumscipiedValueFloatsArray.mean( axis=0 ) #std self.NumscipiedStdGlobalFloatsArray=self.NumscipiedValueFloatsArray.std( axis=0 ) #/###############/# # Compute fourier amp and phase # #import from scipy.fftpack import fft #set self.NumscipiedSampleStepFloat=self.NumscipyingSampleFloatsArray[ 1 ]-self.NumscipyingSampleFloatsArray[ 0 ] #linspace self.NumscipiedFourierFrequencyFloatsArray=np.linspace( 0.0, 1.0/(2.0*self.NumscipiedSampleStepFloat), self.NumscipyingColsInt/2 ) #fft self.NumscipiedFourierGlobalComplexesArray=fft( self.NumscipiedMeanGlobalFloatsArray ) #amplitude self.NumscipiedFourierAmplitudeGlobalFloatsArray=( 2.0/self.NumscipyingColsInt )* np.abs( self.NumscipiedFourierGlobalComplexesArray[ 0:self.NumscipyingColsInt/2 ] ) #fourier self.NumscipiedFourierComplexesArray=np.array( map( lambda __NumscipiedValueFloatsArray: fft( __NumscipiedValueFloatsArray ), self.NumscipiedValueFloatsArray ) ) #get NumscipiedHalfFourierComplexesArray=self.NumscipiedFourierComplexesArray[ :, 0:self.NumscipyingColsInt/2 ] #ampitude self.NumscipiedFourierAmplitudeFloatsArray=( 2.0/float(self.NumscipyingColsInt) )* np.abs( NumscipiedHalfFourierComplexesArray ) #phase self.NumscipiedFourierPhaseFloatsArray=np.array( map( lambda __NumscipiedHalfFourierComplexesArray: getArgumentVariable( __NumscipiedHalfFourierComplexesArray ), NumscipiedHalfFourierComplexesArray ) ) #setCrossPhase self.setCrossPhase() #setExtremum self.setExtremum() #debug ''' self.debug( [ ('self.',self,[ 'NumscipiedFourierMaxCrossPhaseFloatsArray' ]) ] ) ''' # ( # xrange(self.NumscipyingColsInt), # [0]* # ) """ NumscipiedFourierCrossPhaseDict=map( lambda __NumscipiedFourierCrossPhaseTuple: ( __NumscipiedFourierCrossPhaseTuple[0][0], __NumscipiedFourierCrossPhaseTuple[1] ), self.NumscipiedFourierCrossPhaseTuplesList ) """ """ self.NumscipiedFourierMaxCrossPhaseFloatsArray=np.array( map( lambda __NumscipiedFourierMaxAmplitudeIndexIntsArray,__IndexInt: self.NumscipiedFourierCrossPhaseTuplesList[ __IndexInt, : ], self.NumscipiedFourierMaxAmplitudeIndexIntsArray, xrange(len(self.NumscipiedFourierMaxAmplitudeIndexIntsArray)) ) ) """ #/###############/# # Compute correlations # #import from scipy import signal #acf self.NumscipiedAutocorrelationGlobalFloatsArray=signal.correlate( self.NumscipiedMeanGlobalFloatsArray, self.NumscipiedMeanGlobalFloatsArray, mode="same" ) #cut #self.NumscipiedAutocorrelationGlobalFloatsArray=self.NumscipiedAutocorrelationGlobalFloatsArray[ # self.NumscipiedAutocorrelationGlobalFloatsArray.size/2: #] #debug ''' self.debug( [ 'We computed the correlations', ('self.',self,[ 'NumscipiedAutocorrelationGlobalFloatsArray' ]) ] ) ''' #/###############/# # Compute local maxima # """ #Maxima self.NumscipiedMaxGlobalIndexIntsArray=SYS.argmax( self.NumscipiedMeanGlobalFloatsArray ) #debug self.debug( [ 'We found the local extrema', ('self.',self,[ 'NumscipiedMaxGlobalIndexIntsArray' ]) ] ) #map NumscipiedMaxIndexIntsArray=map( lambda __SimulatedFloatsArray: SYS.argmax(__SimulatedFloatsArray), SimulatedFloatsArray ) """ #/#################/# # Reset to None # #set self.NumscipiedDiscreteStatRigidFunction=None self.NumscipiedContinuousStatRigidFunction=None
def do( _InstanceVariable, *_LiargVariablesList, **_KwargVariablesDict ): #/################/# # Prepare the call of the do method # #Define DoDecorationMethodStr=_KwargVariablesDict['DoDecorationMethodStr'] DoMethodStr=DoDecorationMethodStr.split( DoingDecorationPrefixStr+DoingDecorationTagStr+DoingDecorationSuffixStr )[-1] if DoingDecorationSuffixStr in DoDecorationMethodStr else DoDecorationMethodStr DoStr=DoMethodStr[0].upper()+DoMethodStr[1:] if DoMethodStr[0]!="_" else DoMethodStr[0]+DoMethodStr[1].upper()+DoMethodStr[2:] DoingStr=DoStrToDoingStrOrderedDict[DoStr] DoClassStr=_KwargVariablesDict['DoClassStr'] DoClass=getattr(SYS,DoClassStr) DoWrapMethodStr=DoingWrapPrefixStr+DoMethodStr DoWrapUnboundMethod=getattr( DoClass, DoWrapMethodStr ) del _KwargVariablesDict['DoDecorationMethodStr'] del _KwargVariablesDict['DoClassStr'] #/################/# # Look in the Kwarg if there were specifications of doing attributes # #debug ''' print('Doer l.219 inside of the function DoFunction') #print('InstanceVariable is ',_InstanceVariable) print('_LiargVariablesList is ',_LiargVariablesList) print('_KwargVariablesDict is ',_KwargVariablesDict) print('') ''' #Definition of the DoKwargTuplesList DoKwargTuplesList=map( lambda __KwargTuple: ( DoingStr+DoingAttributePrefixStr.join( __KwargTuple[0].split(DoingAttributePrefixStr)[1:]), __KwargTuple[1] ) if __KwargTuple[0].startswith(DoingAttributePrefixStr) else __KwargTuple, _KwargVariablesDict.items() ) #Debug ''' print('Doer l 239 ') print('DoKwargTuplesList is') print(DoKwargTuplesList) print('') ''' #Check if len(DoKwargTuplesList)>0: #group by [ DoClass.DoTempAttributeItemTuplesList, DoClass.DoTempNotAttributeItemTupleItemsList ]=SYS.groupby( lambda __DoKwargTuple: hasattr(_InstanceVariable,__DoKwargTuple[0]), DoKwargTuplesList ) #set in the instance the corresponding kwarged arguments map( lambda __DoTempAttributeItemTuple: #set direct explicit attributes _InstanceVariable.__setattr__(*__DoTempAttributeItemTuple), DoClass.DoTempAttributeItemTuplesList ) #Define DoneKwargDict=dict(DoClass.DoTempNotAttributeItemTupleItemsList) else: #Define DoneKwargDict={} #/################/# # Set to default values the doing and done mutables # #set _InstanceVariable.setDefaultMutable( DoClass, _AttributeKeyVariable=DoClass.DoingAttributeVariablesOrderedDict.keys( )+DoClass.DoneAttributeVariablesOrderedDict.keys() ) #debug ''' print('Doer l.274 we are going to call the DoWrapUnboundMethod') print('DoWrapUnboundMethod is ',DoWrapUnboundMethod) print('_LiargVariablesList is ',_LiargVariablesList) print('') ''' #Return the call of the defined do method if len(DoneKwargDict)>0: return DoWrapUnboundMethod( _InstanceVariable, *_LiargVariablesList, **DoneKwargDict ) else: return DoWrapUnboundMethod( _InstanceVariable, *_LiargVariablesList )
def mimic(_InstanceVariable,*_LiargVariablesList,**_KwargVariablesDict): #Set MimicMethodStr=_KwargVariablesDict['MimicMethodStr'] MimicClassStr=_KwargVariablesDict['MimicClassStr'] MimicClass=getattr(SYS,MimicClassStr) MimicUnBoundMethod=getattr( MimicClass, MimicMethodStr ) BaseClassStr=_KwargVariablesDict['BaseClassStr'] BaseClass=getattr(SYS,BaseClassStr) del _KwargVariablesDict['MimicMethodStr'] del _KwargVariablesDict['MimicClassStr'] del _KwargVariablesDict['BaseClassStr'] #Debug ''' print('Mimicker l.48 inside of the function mimic') #print('_InstanceVariable is ',_InstanceVariable) print('_LiargVariablesList is ',_LiargVariablesList) print('_KwargVariablesDict is ',_KwargVariablesDict) print('') ''' if len(_KwargVariablesDict)>0: #group by [ MimicTempAttributeItemTuplesList, MimicTempNotAttributeItemTuplesList ]=SYS.groupby( lambda __KwargItemTuple: hasattr(_InstanceVariable,__KwargItemTuple[0]), _KwargVariablesDict.items() ) #Debug ''' print('MimicTempAttributeItemTuplesList is ',MimicTempAttributeItemTuplesList) print('MimicTempNotItemTuplesList is ',MimicTempNotItemTuplesList) print('') ''' #set in the instance the corresponding kwarged arguments map( lambda __MimicTempAttributeItemTuple: #set direct explicit attributes _InstanceVariable.__setattr__(*__MimicTempAttributeItemTuple), MimicTempAttributeItemTuplesList ) #Define MimicKwargDict=dict(MimicTempNotAttributeItemTuplesList) else: #Define MimicKwargDict={} #Init MimicOutputVariable=None #Debug ''' print('Mimicker l.96 inside of the function mimic') print('MimicClass is ',MimicClass) print('MimicMethodStr is ',MimicMethodStr) print('MimicUnBoundMethod is ',MimicUnBoundMethod) print('') ''' #call the Mimicked function if len(MimicKwargDict)>0: MimicOutputVariable=MimicUnBoundMethod( _InstanceVariable, *_LiargVariablesList, **MimicKwargDict ) else: MimicOutputVariable=MimicUnBoundMethod( _InstanceVariable, *_LiargVariablesList ) #Debug ''' print('Mimicker l.117 inside of the function mimic') print('MimicOutputVariable is ',MimicOutputVariable) print('') ''' #Check if BaseClass.DoingGetBool==False: #Return return _InstanceVariable else: #Return the return MimicOutputVariable
def MimickedNewFunction(_InstanceVariable,*_LiargVariablesList,**_KwargVariablesDict): #Set MimicMethodStr=_KwargVariablesDict['MimicMethodStr'] del _KwargVariablesDict['MimicMethodStr'] MimicDoStr=MimickingPrefixStr.join(MimicMethodStr.split(MimickingPrefixStr)[1:]) MimicDoStr=MimicDoStr[0].upper()+MimicDoStr[1:] if MimicDoStr[0]!='_' else MimicDoStr[1].upper()+MimicDoStr[2:] MimicNameStr=Doer.DoStrToDoerStrOrderedDict[MimicDoStr] MimicClass=getattr(SYS,SYS.getClassStrWithNameStr(MimicNameStr)) DoClassStr=_KwargVariablesDict['DoClassStr'] del _KwargVariablesDict['DoClassStr'] DoClass=getattr(SYS,DoClassStr) #Debug ''' print('Mimicker l.119 inside of the function MimickedNewFunction') #print('_InstanceVariable is ',_InstanceVariable) print('_LiargVariablesList is ',_LiargVariablesList) print('_KwargVariablesDict is ',_KwargVariablesDict) print('MimicMethodStr is ',MimicMethodStr) print('') ''' if len(_KwargVariablesDict)>0: #group by [ MimicItemTuplesList, MimicNotItemTuplesList ]=SYS.groupby( lambda __ItemTuple: hasattr(_InstanceVariable,__ItemTuple[0]), _KwargVariablesDict.items() ) #Debug ''' print('MimicItemTuplesList is ',MimicItemTuplesList) print('MimicNotItemTuplesList is ',MimicNotItemTuplesList) print('') ''' #set in the instance the corresponding kwarged arguments map( lambda __ItemTuple: #set direct explicit attributes _InstanceVariable.__setattr__(*__ItemTuple), MimicItemTuplesList ) #Define MimicKwargDict=dict(MimicNotItemTuplesList) else: #Define MimicKwargDict={} #Init MimicOutputVariable=None #Debug ''' print('Mimicker l.167 inside of the function MimickedNewFunction') print('DoClass is ',DoClass) print('MimicMethodStr is ',MimicMethodStr) print('') ''' #Get the method MimicUnBoundMethod=getattr( DoClass, MimicMethodStr ) #Debug ''' print('Mimicker l.181 inside of the function MimickedNewFunction') print('MimicUnBoundMethod is ',MimicUnBoundMethod) print('MimicKwargDict is ',MimicKwargDict) print('') ''' #call the Mimicked function if len(MimicKwargDict)>0: MimicOutputVariable=MimicUnBoundMethod( _InstanceVariable, *_LiargVariablesList, **MimicKwargDict ) else: MimicOutputVariable=MimicUnBoundMethod( _InstanceVariable, *_LiargVariablesList ) #Debug ''' print('Mimicker l.178 inside of the function MimickedNewFunction') print('MimicClass is ',MimicClass) print('MimicClass.DoingGetBool is ',MimicClass.DoingGetBool) print('MimicOutputVariable is ',MimicOutputVariable) print('') ''' #Check if MimicClass.DoingGetBool==False: #Return return _InstanceVariable else: #Return the return MimicOutputVariable