Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
06c8e94
Created Diagram stuct
Aug 10, 2021
dc7979f
Node adding functions.
Aug 10, 2021
9342c46
First draft of influence_diagram.jl
Aug 13, 2021
6d194c5
Used car buyer example with new interface.
Aug 13, 2021
6201db1
Added new functions and types to DecisionProgramming.jl
Aug 13, 2021
01ea402
Updated printing call.
Aug 13, 2021
598be0a
First round of edits on decision_model.jl
Aug 13, 2021
8484a9a
Edited the decision strategy printing function to use InfluenceDiagram
Aug 13, 2021
3e44b1a
Updated pig_breeding example.
Aug 13, 2021
199b0d8
Fixed hard coded N=4
Aug 13, 2021
8e8e2ab
Fixed hard coded N=4
Aug 13, 2021
30f9796
Improved influence diagram validation criteria.
Aug 17, 2021
0363b50
Fixed error messages that catch erroneous probability and consequence…
Aug 17, 2021
431d632
Deleted the old node validation from the Generate Diagram function.
Aug 17, 2021
cefc177
Implemented postive and negative utility translations in influence di…
Aug 17, 2021
8f3e299
Pig breeding example now using positive path utility.
Aug 17, 2021
b27b45d
some to-do comments.
Aug 18, 2021
4c62087
New implementation of deduce indices.
Aug 18, 2021
0eafb7b
Merge branch 'interface-influence-diagram' of github.com:helmihankima…
Aug 18, 2021
5fba91f
Moved primitive type Name definition to top, deleted type NodeData an…
Aug 19, 2021
1af4cb8
Redefined ValueNode, DecisionNode and ChanceNode structs. Added funct…
Aug 19, 2021
3edfa7e
Adjusted DefaultPathProbability to new definition of C in InfluenceDi…
Aug 19, 2021
8baf1b7
Updated the DefaultPathUtility.
Aug 19, 2021
dfce6e0
Fixed small typos and mistakes here and there.
Aug 19, 2021
4d45df1
Changed deduce_node_indices to GenerateArcs! and updated GenerateDiag…
Aug 20, 2021
3ced1d3
Added temporary AddProbabilities! and AddConsequences! functions unti…
Aug 20, 2021
ecf3ff1
Updated DecisionProgramming.jl to include new functions and reorganiz…
Aug 20, 2021
362852a
Updated DecisionVariables function to use new data types.
Aug 20, 2021
98b7c84
Updated PathCompatibilityVariables function to use new data types.
Aug 20, 2021
79abb6f
Deleted unnecessary variables from CVaR function
Aug 20, 2021
6d4741d
Updated the DecisionStrategy and LocalDecisionStrategy structs to usi…
Aug 20, 2021
3d614d0
Added I_d to DecisionStrategy and DecisionVariables structs because i…
Aug 20, 2021
d2df6a7
Updated CompatiblePaths to new data types
Aug 20, 2021
0564a16
Updated UtilityDistribution to new data types.
Aug 20, 2021
a25dc00
Fixed parameters in CompatiblePaths inner construction function to ne…
Aug 23, 2021
7da5222
Updated state probabilities functions to use new data types
Aug 23, 2021
53503c6
Redefined the parameters of value at risk and conditional value at ri…
Aug 23, 2021
3d74cb9
Rephrased comment.
Aug 23, 2021
a80fb34
Fixed mistake in parameters of CompatiblePaths.
Aug 24, 2021
646f05f
Added States to InfluenceDiagram for printing purposes.
Aug 24, 2021
6dbae19
Revamped printing decision strategy.
Aug 24, 2021
4459693
Updated n monitoring to new interface but this one is NOT working at …
Aug 24, 2021
de8ea83
Updated pig breeding.
Aug 24, 2021
aa415b9
Updated used car buyer.
Aug 24, 2021
e718511
Fixed N-monitoring example.
Aug 24, 2021
0423c3b
Deleted commented out code including old data types and node and infl…
Aug 25, 2021
1341082
Chanced all references to chance node use letter c instead of j.
Aug 25, 2021
bd0bb01
Chanced all references to value nodes use letter v instead of j.
Aug 25, 2021
3e66dd7
Removed duplicate code.
Aug 25, 2021
6fb622a
Renamed functions to abide Julia style guide.
Aug 26, 2021
b3f3a30
Added the ProbabilityMatrix struct and set_probability function. Edit…
Aug 26, 2021
736e5d7
Added UtilityMatrix, set_utilities and edited add_utilities. Also lau…
Aug 26, 2021
17712ca
Fixed data type in setindex. Data type in set_utility and add_utiliti…
Aug 26, 2021
d05b4df
Code oranising using section headings.
Aug 26, 2021
b5208bf
Added UtilityMatrix functionalities to DecisionProgramming.jl
Aug 26, 2021
2e63449
Implemented the check that all elements of a utility matrix have a va…
Aug 26, 2021
c757a8a
Fixed probability matrix to be declared as matrix of zeros.
Aug 27, 2021
c97348a
Moved validation that only one probability/utility matrix is added pe…
Aug 27, 2021
c239a44
Changed used car buyer to use new function names.
Aug 27, 2021
fc5c98c
Changed pig breeding to use new function names.
Aug 27, 2021
5fce654
Changed n_monitoring to use new function names.
Aug 27, 2021
bb8272e
Chaged utility matrix setindex! function to accetp y::T<:Real because…
Aug 27, 2021
7798bf4
Change StateProbabilities to allow fixed nodes and states to be given…
Aug 27, 2021
27185b7
Updated print_state_probabilities to use node names instead of indice…
Aug 27, 2021
e1ec518
Deleted unnecessary Utility() conversions.
Aug 27, 2021
89d2110
Specified ambigous Int types.
Aug 27, 2021
f96f30f
Improved readability in generate arcs function.
Aug 27, 2021
f1b0ef5
Deleted outer construction function State since it's not needed with …
Aug 27, 2021
b128fc3
Added some explicit conversions to allow for changing Node primitive …
Aug 27, 2021
ddfb836
Changed node primitive type to Int16.
Aug 27, 2021
28cb5c4
Created FixedPath struct and outer construction functions for FixedPa…
Aug 27, 2021
903da80
Fixed CompatiblePaths inner construction function.
Aug 27, 2021
510f1b6
Included new types and reorganised according to placement in code.
Aug 27, 2021
1271814
Fixed docstring in analysis.jl
Aug 27, 2021
9204c58
Fixed docstrings in decision_model.jl
Aug 30, 2021
bc14087
Fixed docstrings in printing.jl
Aug 30, 2021
6170857
Fixed docstrings in influence_diagram.jl
Aug 30, 2021
e151188
Updated API reference.
Aug 30, 2021
01afc38
Added some printing to pig breeding.
Aug 30, 2021
073c642
Updated used car buyer example and documentation.
Aug 30, 2021
9fc896d
Made set_probability! accept Real numbers, the conversion happens in …
Aug 30, 2021
91cc338
Updated example pig breeding documentation.
Aug 30, 2021
06faa15
Corrections to used car buyer example documentation.
Aug 30, 2021
a2b3cb4
Fixed two bugs in analysis.jl. One in compatible paths enumeration an…
Aug 30, 2021
52a7aa4
Fixed couple mistakes in docstrings.
Aug 31, 2021
7d694ff
Updated CHD example and its dokumentation to new interface.
Aug 31, 2021
f335160
State to Int16 and edits in docstrings.
Aug 31, 2021
77c7c9f
Fixed bug by specifying types of X and Y in setindex functions. The u…
Aug 31, 2021
485a064
Updated usage page of documentation.
Aug 31, 2021
8eec097
Updated code and documentation of n-monitoring example.
Aug 31, 2021
b5e0ee7
Deleted images used in the old usage page.
Aug 31, 2021
85ca4e3
Minor changes to examples' documentations.
Aug 31, 2021
5ebc9aa
Proof read fixes to Usage.md.
Sep 3, 2021
2c32487
Proof reading edits.
Sep 6, 2021
4398583
Edited docstring of printing function.
Sep 6, 2021
8ca9adb
Updated the read me file.
Sep 6, 2021
b2c27c0
Added check that all utility values are filled in utility matrix.
Sep 7, 2021
1b56008
Updated testing of influence diagram.
Sep 7, 2021
ad01e56
Added a few broken influence diagrams to generate_arcs! testing.
Sep 7, 2021
4a70153
Corrected from subsetneq to subseteq. Instances were this has effect …
Sep 7, 2021
7dd7141
Added length function
solliolli Sep 10, 2021
c01346c
Updated random.jl and added the necessary functions to DecisionProgra…
Sep 13, 2021
b8774b5
Updated cpp example.
Sep 16, 2021
d318cfb
Created wrapper function for StateProbabilities so that it can be als…
Sep 16, 2021
58d8d15
Added test for positive and negative path utility.
Sep 16, 2021
964c59f
Fixed parametrs VaR and CVaR function calls.
Sep 16, 2021
154d703
Fixed tests for decision model, analysis and printing.
Sep 16, 2021
0c7a702
Improved docstring and added checks for probabilities only being adde…
Sep 16, 2021
bcf487e
Fixed tests for random.jl.
Sep 16, 2021
c0d047e
Added logging info.
Sep 16, 2021
977bacf
Merge branch 'interface-influence-diagram' of github.com:helmihankima…
Sep 16, 2021
b365cb1
Merge pull request #27 from helmihankimaa/interface-influence-diagram
solliolli Sep 28, 2021
d760c7b
Added two helper functions
solliolli Sep 28, 2021
015f3dd
Finished updating the CPP example
solliolli Sep 28, 2021
2b2c0c1
fixing broken docstrings
solliolli Sep 29, 2021
e62eb46
Finished fixing documentation
solliolli Oct 1, 2021
fc6f7ba
Fixed deprecated syntax
solliolli Oct 1, 2021
6dc9964
Cleaner syntax for setting values of probability and utility matrices
solliolli Oct 1, 2021
8bd145c
Fixed tests
solliolli Oct 1, 2021
3cf533c
Updates to random diagram generation and documentation
solliolli Oct 7, 2021
3f6953f
Added documentation preview
solliolli Oct 8, 2021
9e35766
Updated docstrings for influence_diagram.jl
solliolli Oct 8, 2021
9e0f7d2
Changes to probability scaling factor and documentation improvements
solliolli Oct 8, 2021
2d2933e
Documentation fixes
solliolli Oct 8, 2021
ab82e5d
Fixed tests
solliolli Oct 8, 2021
f35907b
Fixing tests
solliolli Oct 8, 2021
e1eb3a8
Small improvements to docs
solliolli Oct 11, 2021
2a0f2e7
Readability improvements
solliolli Oct 11, 2021
cf53a0c
Apply suggestions from code review
solliolli Oct 12, 2021
03d2908
More readability improvements
solliolli Oct 12, 2021
a6d1fb6
Prettier printing for state probabilities
solliolli Oct 13, 2021
6b18576
Update docs/src/examples/used-car-buyer.md
FabsOliveira Oct 14, 2021
0cb6d49
Apply suggestions from code review
solliolli Oct 21, 2021
a6b878a
Small documentation improvements
solliolli Oct 21, 2021
ec941c2
Small fix to CVaR calculation when all utilities are the same.
solliolli Oct 21, 2021
ead5718
Added contribution guidelines
solliolli Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Contribution guidelines

First of all, thank you for your interest in this project! Most of us working on this are researchers, not software engineers, so we expect there to be room for improvement in this package. If you find something that is unclear or doesn't work or should be done more efficiently etc., please let us know, but remember to be respectful.

If you are new to Julia package development, we strongly recommend reading the rather well-written guide in [the JuMP documentation](https://jump.dev/JuMP.jl/dev/developers/contributing/#Contribute-code-to-JuMP).

How to proceed when you have:
- A question about how something works
- Ask a question on our [discussion forum](https://github.com/gamma-opt/DecisionProgramming.jl/discussions)
- If the reason for your confusion was that something was not properly explained in the documentation, create an issue and/or a pull request.
- A bug report 🐛
- Create an issue with a minimal working example that shows how you encountered the bug.
- If you know how to fix the bug, you can create a pull request as well, otherwise we'll see your issue and start working on fixing whatever you found.
- An improvement suggestion
- It might be a good idea to first discuss your idea with us, you can start by posting on the [discussion forum](https://github.com/gamma-opt/DecisionProgramming.jl/discussions).
- Create an issue and start working on a pull request.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,36 @@ We can create an influence diagram as follows:

```julia
using DecisionProgramming
S = States([2, 2, 2, 2])
C = [ChanceNode(2, [1]), ChanceNode(3, [1])]
D = [DecisionNode(1, Node[]), DecisionNode(4, [2, 3])]
V = [ValueNode(5, [4])]
X = [Probabilities(2, [0.4 0.6; 0.6 0.4]), Probabilities(3, [0.7 0.3; 0.3 0.7])]
Y = [Consequences(5, [1.5, 1.7])]
validate_influence_diagram(S, C, D, V)
sort!.((C, D, V, X, Y), by = x -> x.j)
P = DefaultPathProbability(C, X)
U = DefaultPathUtility(V, Y)

diagram = InfluenceDiagram()

add_node!(diagram, DecisionNode("A", [], ["a", "b"]))
add_node!(diagram, DecisionNode("D", ["B", "C"], ["k", "l"]))
add_node!(diagram, ChanceNode("B", ["A"], ["x", "y"]))
add_node!(diagram, ChanceNode("C", ["A"], ["v", "w"]))
add_node!(diagram, ValueNode("V", ["D"]))

generate_arcs!(diagram)

add_probabilities!(diagram, "B", [0.4 0.6; 0.6 0.4])
add_probabilities!(diagram, "C", [0.7 0.3; 0.3 0.7])
add_utilities!(diagram, "V", [1.5, 1.7])

generate_diagram!(diagram)
```

Using the influence diagram, we create the decision model as follow:

```julia
using JuMP
model = Model()
z = DecisionVariables(model, S, D)
x_s = PathCompatibilityVariables(model, z, S, P)
EV = expected_value(model, x_s, U, P)
z = DecisionVariables(model, diagram)
x_s = PathCompatibilityVariables(model, diagram, z)
EV = expected_value(model, diagram, x_s)
@objective(model, Max, EV)
```

Finally, we can optimize the model using MILP solver.
We can optimize the model using MILP solver.

```julia
using Gurobi
Expand Down
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ makedocs(
# See "Hosting Documentation" and deploydocs() in the Documenter manual
# for more information.
deploydocs(
repo = "github.com/gamma-opt/DecisionProgramming.jl.git"
repo = "github.com/gamma-opt/DecisionProgramming.jl.git",
push_preview = true
)
58 changes: 37 additions & 21 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
### Nodes
```@docs
Node
Name
AbstractNode
ChanceNode
DecisionNode
ValueNode
State
States
States(::Vector{Tuple{State, Vector{Node}}})
validate_influence_diagram
```

### Paths
```@docs
Path
paths(::AbstractVector{State})
paths(::AbstractVector{State}, ::Dict{Node, State})
ForbiddenPath
FixedPath
paths(::AbstractVector{State})
paths(::AbstractVector{State}, ::FixedPath)
```

### Probabilities
Expand All @@ -33,9 +34,10 @@ AbstractPathProbability
DefaultPathProbability
```

### Consequences
### Utilities
```@docs
Consequences
Utility
Utilities
```

### Path Utility
Expand All @@ -44,6 +46,20 @@ AbstractPathUtility
DefaultPathUtility
```

### InfluenceDiagram
```@docs
InfluenceDiagram
generate_arcs!
generate_diagram!
add_node!
ProbabilityMatrix
add_probabilities!
UtilityMatrix
add_utilities!
index_of
num_states
```

### Decision Strategy
```@docs
LocalDecisionStrategy
Expand All @@ -56,15 +72,13 @@ DecisionStrategy
```@docs
DecisionVariables
PathCompatibilityVariables
lazy_probability_cut(::Model, ::PathCompatibilityVariables, ::AbstractPathProbability)
lazy_probability_cut
```

### Objective Functions
```@docs
PositivePathUtility
NegativePathUtility
expected_value(::Model, ::PathCompatibilityVariables, ::AbstractPathUtility, ::AbstractPathProbability; ::Float64)
conditional_value_at_risk(::Model, ::PathCompatibilityVariables{N}, ::AbstractPathUtility, ::AbstractPathProbability, ::Float64; ::Float64) where N
expected_value(::Model, ::InfluenceDiagram, ::PathCompatibilityVariables; ::Float64)
conditional_value_at_risk(::Model, ::InfluenceDiagram, ::PathCompatibilityVariables{N}, ::Float64; ::Float64) where N
```

### Decision Strategy from Variables
Expand All @@ -76,13 +90,14 @@ DecisionStrategy(::DecisionVariables)
## `analysis.jl`
```@docs
CompatiblePaths
CompatiblePaths(::InfluenceDiagram, ::DecisionStrategy, ::FixedPath)
UtilityDistribution
UtilityDistribution(::States, ::AbstractPathProbability, ::AbstractPathUtility, ::DecisionStrategy)
UtilityDistribution(::InfluenceDiagram, ::DecisionStrategy)
StateProbabilities
StateProbabilities(::States, ::AbstractPathProbability, ::DecisionStrategy)
StateProbabilities(::States, ::AbstractPathProbability, ::DecisionStrategy, ::Node, ::State, ::StateProbabilities)
value_at_risk(::Vector{Float64}, ::Vector{Float64}, ::Float64)
conditional_value_at_risk(::Vector{Float64}, ::Vector{Float64}, ::Float64)
StateProbabilities(::InfluenceDiagram, ::DecisionStrategy)
StateProbabilities(::InfluenceDiagram, ::DecisionStrategy, ::Name, ::Name, ::StateProbabilities)
value_at_risk(::UtilityDistribution, ::Float64)
conditional_value_at_risk(::UtilityDistribution, ::Float64)
```

## `printing.jl`
Expand All @@ -96,9 +111,10 @@ print_risk_measures

## `random.jl`
```@docs
random_diagram(::AbstractRNG, ::Int, ::Int, ::Int, ::Int, ::Int)
States(::AbstractRNG, ::Vector{State}, ::Int)
Probabilities(::AbstractRNG, ::ChanceNode, ::States; ::Int)
Consequences(::AbstractRNG, ::ValueNode, ::States; ::Float64, ::Float64)
LocalDecisionStrategy(::AbstractRNG, ::DecisionNode, ::States)
random_diagram!
random_probabilities!
random_utilities!
LocalDecisionStrategy(::AbstractRNG, ::InfluenceDiagram, ::Node)
DecisionProgramming.information_set(::AbstractRNG, ::Node, ::Int64)
DecisionProgramming.information_set(::AbstractRNG, ::Vector{Node}, ::Int64)
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Analyzing Decision Strategies](@id analyzing-decision-strategies)
## Introduction
This section focuses on how we can analyze fixed decision strategies $Z$ on an influence diagram $G$, such as ones resulting from the optimization. We can rule out all incompatible and inactive paths from the analysis because they do not influence the outcomes of the strategy. This means that we only consider paths $𝐬$ that are compatible and active $𝐬 \in 𝐒(X) \cap 𝐒(Z)$.
This section focuses on how we can analyze fixed decision strategies $Z$ on an influence diagram $G$, such as ones obtained by solving the Decision Programming model described in [the previous section](@ref decision-model). We can rule out all incompatible and inactive paths from the analysis because they do not influence the outcomes of the strategy. This means that we only consider paths $𝐬$ that are compatible and active $𝐬 \in 𝐒(X) \cap 𝐒(Z)$.


## Generating Compatible Paths
Expand All @@ -20,7 +20,7 @@ The probability mass function of the **utility distribution** associates each un

$$ℙ(X=u)=∑_{𝐬∈𝐒(Z)∣\mathcal{U}(𝐬)=u} p(𝐬),\quad ∀u∈\mathcal{U}^∗.$$

From the utility distribution, we can calculate the cumulative distribution, statistics, and risk measures. The relevant statistics are expected value, standard deviation, skewness and kurtosis. Risk measures focus on the conditional value-at-risk (CVaR), also known as, expected shortfall.
From the utility distribution, we can calculate the cumulative distribution, statistics, and risk measures. The relevant statistics are expected value, standard deviation, skewness and kurtosis. Risk measures focus on the conditional value-at-risk (CVaR), also known as expected shortfall.


## Measuring Risk
Expand Down Expand Up @@ -56,7 +56,7 @@ The above figure demonstrates these values on a discrete probability distributio


## State Probabilities
We denote **paths with fixed states** where $ϵ$ denotes an empty state using a recursive definition.
We use a recursive definition where $ϵ$ denotes an empty state to denote **paths with fixed states**.

$$\begin{aligned}
𝐒_{ϵ} &= 𝐒(Z) \\
Expand Down
12 changes: 6 additions & 6 deletions docs/src/decision-programming/computational-complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ $$0 ≤ ∑_{i∈D}|𝐒_{I(i)∪\{i\}}| ≤ |D| \left(\max_{i∈C∪D} |S_j|\ri

In the worst case, $m=n$, a decision node is influenced by every other chance and decision node. However, in most practical cases, we have $m < n,$ where decision nodes are influenced only by a limited number of other chance and decision nodes, making models easier to solve.

## Numerical challenges
## Numerical challenges

As has become evident above, in Decision Programming the size of the [Decision Model](@ref decision-model) may become large if the influence diagram has a large number of nodes or nodes with a large number of states. In practice, this results in having a large number of path compatibility and decision variables. This may results in numerical challenges.
As has become evident above, in Decision Programming the size of the [Decision Model](@ref decision-model) may become large if the influence diagram has a large number of nodes or nodes with a large number of states. In practice, this results in having a large number of path compatibility and decision variables. This may result in numerical challenges.

### Probability Scaling Factor
In an influence diagram a large number of nodes or some nodes having a large set of states, causes the path probabilities $p(𝐬)$ to become increasingly small. This may cause numerical issues with the solver or inable it from finding a solution. This issue is showcased in the [CHD preventative care example](../examples/CHD_preventative_care.md).
If an influence diagram has a large number of nodes or some nodes have a large set of states, the path probabilities $p(𝐬)$ become increasingly small. This may cause numerical issues with the solver, even prevent it from finding a solution. This issue is showcased in the [CHD preventative care example](../examples/CHD_preventative_care.md).

The issue may be helped by multiplying the path probabilities with a scaling factor $\gamma > 0$ in the objective function.
The issue may be helped by multiplying the path probabilities with a scaling factor $\gamma > 0$. For example, the objective function becomes

$$\operatorname{E}(Z) = ∑_{𝐬∈𝐒} x(𝐬) \ p(𝐬) \ \gamma \ \mathcal{U}(𝐬)$$
$$\operatorname{E}(Z) = ∑_{𝐬∈𝐒} x(𝐬) \ p(𝐬) \ \gamma \ \mathcal{U}(𝐬).$$

The conditional value-at-risk function can also be scaled so that it is compatible with an expected value objective function that has been scaled.
The path probabilities should also be scaled in other objective functions or constraints, including the conditional value-at-risk function and the probability cut constraint $∑_{𝐬∈𝐒}x(𝐬) p(𝐬) = 1$.
Loading