QuantEcon.jl icon indicating copy to clipboard operation
QuantEcon.jl copied to clipboard

DiscreteDP: Should not modify s_indices and a_indices when sorting

Open oyamad opened this issue 8 years ago • 2 comments

julia> using QuantEcon

julia> s_indices = [2, 1, 1];  # Not sorted;

julia> a_indices = [1, 1, 2];

julia> R = [-1., 5, 10];

julia> Q = [0 1; 0.5 0.5; 0 1];

julia> beta = 0.95;

julia> ddp = DiscreteDP(R, Q, beta, s_indices, a_indices);

julia> s_indices
3-element Array{Int64,1}:
 1
 1
 2

julia> a_indices
3-element Array{Int64,1}:
 1
 1
 2

One cannot reuse s_indices and a_indices:

julia> ddp = DiscreteDP(R, Q, beta, s_indices, a_indices);
ERROR: ArgumentError: Duplicate s-a pair found
 in anonymous at /Users/oyama/.julia/v0.4/QuantEcon/src/markov/ddp.jl:131
 in sparse at sparse/csparse.jl:93
 in call at /Users/oyama/.julia/v0.4/QuantEcon/src/markov/ddp.jl:130
 in call at /Users/oyama/.julia/v0.4/QuantEcon/src/markov/ddp.jl:205

oyamad avatar Jul 09 '16 12:07 oyamad

cc @albep

sglyon avatar Jul 09 '16 20:07 sglyon

@oyamad thanks for pointing that out. PR #122 fixes that, I tried it with your example

albep avatar Jul 11 '16 16:07 albep