zward / Amua

An open source modeling framework
GNU General Public License v3.0
33 stars 11 forks source link

Error with Dirichlet distribution #62

Open VictorvanRoey opened 1 year ago

VictorvanRoey commented 1 year ago

Using the dirichlet distribution in a three-arm node keeps giving the error that the sum of probabilities does not equal 1. I included the dirichlet distribution as Dir([7, 2,1], ~) as a parameter. Then I included the probabilities as a subset of the parameter for all three arms i.e. parameter[0], parameter[1], parameter[2].

Initially this works, however, when performing a PSA it keeps giving the abovementioned error. Can I fix this error or is this a problem with the software?

VictorvanRoey commented 1 year ago

The error log did not include any errors:

Version: 0.3.0

Errors (0):


System properties Java Runtime Environment version: 1.8.0_333 Java Runtime Environment vendor: Oracle Corporation Java vendor URL: http://java.oracle.com/ Java installation directory: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home Java Virtual Machine specification version: 1.8 Java Virtual Machine specification vendor: Oracle Corporation Java Virtual Machine specification name: Java Virtual Machine Specification Java Virtual Machine implementation version: 25.333-b02 Java Virtual Machine implementation vendor: Oracle Corporation Java Virtual Machine implementation name: Java HotSpot(TM) 64-Bit Server VM Java Runtime Environment specification version: 1.8 Java Runtime Environment specification vendor: Oracle Corporation Java Runtime Environment specification name: Java Platform API Specification Java class format version number: 52.0 Java class path: Amua-0.3.0.jar Default temp file path: /var/folders/y8/97rs5kgj3blcqbpwd0b8m5w40000gn/T/ Name of JIT compiler to use: null Operating system name: Mac OS X Operating system architecture: x86_64 Operating system version: 13.1 Heap - Used Memory: 12 MB Heap - Total Memory: 245 MB Heap - Max Memory: 3641 MB Available Processors: 8 Screen Resolution: 128 Screen Size: java.awt.Dimension[width=1440,height=900]

RiversPharmD commented 1 year ago

I think this is a challenge with drichlet distributions in PSAs. This error means youre getting three values either greater than 1 or less than 1. I'm not sure how it's being written here, I'll leave that to the other Zach. When I use them, I sample two of the three parameters, and then set the parameter[2] = MAX(0, 1-(parameter[0]+parameter[1])). I usually end up turning my three-branch nodes into a nested two-branch->two-branch node.

If the three node model has probabilities p0=0.75, p1=0.15, and p2=0.1, my first node ends up having probabilities 0.75(p0) and 0.25(1-p0). the p0 arm gets extended by one length, and then the 1-p0 arm has a node with probabilities 0.6(p1/p1+p2) and 0.4(p2/p1+p2).

zward commented 1 year ago

This might be a finite-precision rounding issue, with the 3 sampled probabilities not summing close enough to 1.0 (slightly above or below). Have you tried using 'C' as one of the branch probabilities? ('C' stands for ‘complementary’ probability and will ensure that all branches sum to 1.0, as long as the other two sum to <=1.0)

zward commented 1 year ago

See this FAQ as well: https://github.com/zward/Amua/wiki/FAQ#Why-does-it-say-my-probabilities-do-not-sum-to-1

VictorvanRoey commented 1 year ago

Thank you for your responses! It is not a problem with precision rounding issues, since the sum of probabilities is sometimes quite different from 1 (e.g. >2 or <0.8). Using the C does not work.

I think that the problem is that the uncertainty around the three probabilities allow the sum of probabilities to exceed 1. However, in theory this should be prevented with the dirichlet distribution, but this does not work. It seems that the probabilities from the dirichlet distribution in the PSA are sampled independently instead of simultaneous, making it possible for the sum to be not equal to 1.

I have also tried the nested two-branch -> two-branch node as suggested by RiversPharmD, but this does only work if you have discrete values for the probabilities without uncertainty. I have also tried the nested two-branch node together with the Dirichlet distribution to see if that would work and solve rounding issues, but it does not too. It just seems to be a problem with sampling of the dirichlet distribution in PSA.

zward commented 1 year ago

I'm able to run a PSA sampling from a Dirichlet - see a simple example below. The parameter 'dir' is defined as "Dir([7, 2, 1], ~)". Are you able to replicate this example?

image

VictorvanRoey commented 1 year ago

Although I got the error message about the sum of probabilities that were related to the ditrichlet distribution, that was not the problem at all. The problem lies in the constraints. Even though it is weird that the constraints in question have nothing to do with the probabilities of the ditrichlet distribution. Perhaps a good thing to know for other people that face errors when using the ditrichlet distribution!