Skip to content

Commit

Permalink
added random and invert methods to Ensemble
Browse files Browse the repository at this point in the history
  • Loading branch information
apetri committed Apr 20, 2016
1 parent 0c69757 commit de08ab6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lenstools/statistics/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,28 @@ def save(self,filename,format=None,**kwargs):
else:
format(self,filename,**kwargs)

#############################################################
######Construct a random ensemble for testing purposes#######
#############################################################

@classmethod
def random(cls,nobs=10,columns=list("abc")):

"""
Construct a random ensemble for testing purposes, sampling from a univariate normal distribution in each column
:param nobs: number of observations (rows)
:type nobs: int.
:param columns: columns of the ensemble
:type columns: list.
:rtype: :py:class:`Ensemble`
"""

return cls(np.random.randn(nobs,len(columns)),columns=columns)


#################################################
#############Construct from meshgrid#############
Expand Down Expand Up @@ -827,6 +849,20 @@ def shuffle(self,seed=None):

#####################################################################################################################

def invert(self):

"""
If the Ensemble is a square matrix, compute its inverse
:rtype: :py:class:`Ensemble`
"""

if self.shape[0]!=self.shape[1]:
raise ValueError("This is not a square matrix!")

return self.__class__(np.linalg.inv(self.values),index=self.index,columns=self.columns)

####################################
#############Visualization##########
####################################
Expand Down

0 comments on commit de08ab6

Please sign in to comment.