This article provides an example of how Microsoft Excel can be used as an interface to communicate with reinforcement learning policies. In this example, you can integrate predictions from a reinforcement learning policy, trained in Pathmind, directly into any Excel worksheet.


A special thank you to MOSIMTEC for helping to develop this example.


Step 1

Start your Pathmind policy server.

Initializing the policy server takes a couple of minutes. The pop up below will appear once that is done.

Take note of your policy serving URL and access token.

Step 2

Download and install the VBA-Web add-on: https://github.com/VBA-tools/VBA-Web.

Step 3

Once you install VBA-Web in your Excel sheet, you may use the example code below to integrate reinforcement learning predictions directly in any spreadsheet.

To see the example, navigate to Developer and then Visual Basic.

From there, run the code and inspect the output. This output can be used to populate cells in other sheets.

Sub test()

' Initialize Client
Dim Client As New WebClient
Dim Url As String
' Set Policy Serving Endpoint and Access Token
Url = "https://api.test.devpathmind.com/policy/id4165/predict/?access-token=b19e0116-9f8d-4449-a996-2074f76ffb36"

' Set Up Request
Dim Request As New WebRequest
Request.Method = WebMethod.HttpPost
Request.RequestFormat = WebFormat.json
Request.ResponseFormat = WebFormat.json

' Populate Request Body With Observations
Dim Body As New Dictionary
Body.Add "actionMask", Array(True, True, True, True)
Body.Add "stateChartState", Array(0, 0, 0)
Set Request.Body = Body

' Enable logging before the request is executed
WebHelpers.EnableLogging = True

' Execute Request
Dim Response As WebResponse
Set Response = Client.PostJson(Url, Body)

End Sub
Did this answer your question?