# Print the MDP q-matrix

**URL:** <https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425>\
**Category:** New to Julia\
**Created:** [September 18, 2022, 5:57am UTC](https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425 "2022-09-18T05:57:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Wright](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@Richard\_Wright](https://discourse.julialang.org/u/Richard_Wright)\
**Post date:** [September 18, 2022, 5:57am UTC](https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425/1 "2022-09-18T05:57:36Z")

</div>

Hello,

Need some help please, with printing out the Q-matrix when using MDP and Tabular TD learning.

I have been able to formulate the MDP and the solver and solve the policy. The code is

```julia
mdp = TabularMDP(T, R, Discount_factor);
print("\nStep-1: MDP object created")
# use Q-Learning
exppolicy = EpsGreedyPolicy(mdp, 0.02)
q_learning_solver = QLearningSolver(exploration_policy=exppolicy, 
                                n_episodes=1000, 
                                max_episode_length=100,
                                learning_rate=0.5,
                                eval_every=10000, 
                                n_eval_traj=20, 
                                verbose=true);
print("\nStep-2: Solver working")
policy = solve(q_learning_solver, mdp)
print("\nStep-3: Policy solved \n")

```

When I run this in debug mode, I am able to see the value table

![image](https://global.discourse-cdn.com/julialang/original/3X/0/f/0f271d9148ffa61b024054467f790ce570b2182a.png)

How do I print this to console? I tried using

`showpolicy(stdout,"text/plain", mdp, policy)`

But this shows the following error.

Exception has occurred: MethodError  
MethodError: no method matching showpolicy(::Base.TTY, ::String, ::TabularMDP, ::ValuePolicy{TabularMDP, Matrix{Float64}, Int64})  
Closest candidates are:  
showpolicy(::IO, !Matched::MIME{Symbol(“text/plain”)}, ::MDP, ::Policy; pre, kwargs…)

What would be the correct way to print the q-matrix to console? Thank you

---

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [September 18, 2022, 6:07am UTC](https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425/2 "2022-09-18T06:07:41Z")

</div>

You can check the fields of the policy object yourself. In the REPL, you can write `policy.` and press tab twice to show the field names, one of which is likely the value table. Then you can print that directly to the console.

Also, could you say which package you are using to do this, to be more familiar with the functions?

---

<div class="post-metadata">

**Author:** ![Richard\_Wright](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@Richard\_Wright](https://discourse.julialang.org/u/Richard_Wright)\
**Post date:** [September 18, 2022, 7:33am UTC](https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425/3 "2022-09-18T07:33:17Z")

</div>

@jmair Thank you.

I was able to print the value table in REPL by using` policy.value_table`.

How would I do the same when coding in a file (using VS Code)?

The packages I am using are

```julia
using POMDPs, QMDP, POMDPModels, POMDPTools, QuickPOMDPs
using TabularTDLearning
using POMDPModels: TabularPOMDP

```

---

<div class="post-metadata">

**Author:** ![Richard\_Wright](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@Richard\_Wright](https://discourse.julialang.org/u/Richard_Wright)\
**Post date:** [September 18, 2022, 7:44am UTC](https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425/4 "2022-09-18T07:44:47Z")

</div>

@jmair

Used the same in VS Code and it’s working. Thanks

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 18, 2022, 3:26pm UTC](https://discourse.julialang.org/t/print-the-mdp-q-matrix/87425/5 "2022-09-18T15:26:06Z")

</div>

> [@Richard\_Wright](#):
>
> I tried using
> 
> `showpolicy(stdout,"text/plain", mdp, policy)`
> 
> But this shows the following error.

The first two arguments are optional, so you only need `showpolicy(mdp, policy)` here. (The specific error was because `"text/plain"` should be passed in as `MIME"text/plain"()`, but you can just skip the argument instead since that’s the default anyway.)
