Skip to content

Commit

Permalink
docstring for UnivariateIIDProcess, see EconForge#183
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Apr 6, 2020
1 parent 2296a08 commit 2beae84
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions dolo/numeric/processes_iid.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,36 @@


class UnivariateIIDProcess(IIDProcess):
'''
A univariate, IID, continuous process.
'''

d = 1

def discretize(self, N=5, method='equiprobable', mass_point = "median" ,to='iid'):
'''
Returns a discretized version of this process.
Parameters
----------
N : int
Number of point masses in the discretized distribution.
method : str
'equiprobable' or 'gauss-hermite'
mass_point : str
'median', 'left', 'middle', or 'right'
to: str
e.g. 'iid'
Returns:
------------
process : DiscretizedIIDProcess
A discretized IID process derived from this continuous
process.
'''
if to !='iid':
raise Exception("Not implemented")

Expand Down Expand Up @@ -92,6 +119,33 @@ def __discretize_ep__(self, N=5, mass_point="median"): #Equiprobable

return DiscretizedIIDProcess(q[:,None], w)

def simulate(self, N, T, stochastic=True):
'''
Draw an array of values from process.
Parameters
----------
N : int
Number of draws in each row.
T: int
Number of rows.
stochastic: bool
Returns:
------------
draws : np.array
An N by T array fo draws from the process.
'''
# This is a dummy version of this method
from numpy.random import choice
ch = np.array([0])
p = np.array([1])
sim = choice(ch, size=T*N, p=p)
return sim.reshape((T,N,1))

@language_element
@dataclass
class Bernouilli(UnivariateIIDProcess):
Expand Down

1 comment on commit 2beae84

@albop
Copy link

@albop albop commented on 2beae84 Apr 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @sbenthall
I just realized that my answer in the related issue is wrong. I thought simulate was returning an xarray. This is the output when you simulate a model. I wonder whether simulated processes should be xarray too. It would make sense if we attach variable names to these objects, which is probably a good idea. I'll open an issue for that and merge your PR as is.

Please sign in to comment.