I have a very simple composite type:
type DiscreteRv{T <: Real}
q::Vector{T}
Q::Vector{T}
end
DiscreteRv{T <: Real}(x::Vector{T}) = DiscreteRv(x, cumsum(x))
Here q represents a probability vector for a discrete random variable. Q is
the associated cdf.
I want to make sure that the relationship Q = cumsum(q) is preserved
whenver q is updated.
I presume I need to overload Base.setindex!, but I haven’t been able to
figure it out. Any suggestions?
------------------------------
In the end I would like this example to work:
julia> d = DiscreteRv([.1, .9])
DiscreteRv{Float64}([0.1,0.9],[0.1,1.0])
julia> d.q = [.3, .7]; d
DiscreteRv{Float64}([0.3,0.7],[0.3,1.0])