Go to file
2024-11-28 09:30:39 +00:00
app MAJOR: first commit 2019-05-09 15:58:45 +01:00
CHANGELOG.md Update CHANGELOG 2019-05-09 07:52:36 -07:00
CONTRIBUTING.md Add CONTRIBUTING 2019-05-09 07:53:02 -07:00
LICENSE.md Add LICENSE 2019-05-09 07:53:59 -07:00
README.md Update README.md 2024-11-28 09:30:39 +00:00

Erlang Decision Tree and Baysian Networks

alt text

This repository have two different exercises in erlang:

1.Decision tree that maximizes the optimal point and consequently provides decision support based on the given assumptions.

  • The probability of taking medication/treatment 1 and the user being OK is 42%;
  • The probability of taking medication/treatment 1 and the user becoming KO is 22.5%;
  • The probability of taking medication/treatment 1 and it not being conclusive is 35.6%;
  • The probability of taking medication/treatment 2 and being OK is 62%;
  • The probability of taking a medication/treatment 2 and getting KO is 38%.

-module(engine).
-compile([export_all]).

% Decision Tree
%
%                           +----+
%                       +---> OK |
%                       |   +----+
%                       |
%            +----------|   +----+
%            | DO MED 1 +---> KO |
%            +----------+   +----+              +----+
%                       |                   +---> OK |
%                       |   +---------------|   +----+
%                       +--->   DO MED 2    +
%                           +---------------|   +----+
%                                           +---> KO |
%                                               +----+
%	Each edge can be calculated from the table


doAll() ->
		T = dec_tree:start(),
		T ! {create_node, 'DO MED1', 0, none},
		T ! {create_node, 'MED1 OK', 0.980, 'DO MED1'},
		T ! {create_node, 'MED1 KO', 0.225, 'DO MED1'},
		T ! {create_node, 'DO MED2', 0.356, 'DO MED1'},
		T ! {create_node, 'MED 2 OK', 0.62, 'DO MED2'},
		T ! {create_node, 'MED 2 KO', 0.38, 'DO MED2'},
		T ! {solve}.


2. There are ways of obtaining probabilities knowing certain parameters (they don't indicate the optimum point, but calculate a probability of success depending on the existing resources) - using Baysian networks.

What is the probability of giving the patient M2 and the patient being well, knowing that:

  • The probability of administering M1 and the patient being well is 20 per cent;
  • The probability of administering M2 knowing that I have administered M1 and the patient is well is 70%;
  • The probability of administering M2 knowing that I have not administered M1 and the patient is OK is 20 per cent.

Prerequisites

Basic knowledge of erlang, algorithm and statistics.

Install or use Docker

If you prefer to install the erlang compiler, please find the appropriate installation for your operating system.

If you prefer, you can use Docker to test this solution. Get a docker container and start the container.

I suggest this container and run it:

docker pull bitwalker/alpine-erlang
docker run --rm -it --user=root bitwalker/alpine-erlang

Run the solution

  1. For the first exercise (Decision Tree):
c(motor).
motor:doAll().

and the best solution is:

alt text

** You can take medication 1 and medication 2 with a 97.6 per cent success rate to get well.

  1. For the second exercise (Baysian Networks):
c(motor3).
motor3:getp({m2, ok}).

alt text

**There is a 16 per cent chance that the patient will be OK when administering drug M2.

Created with

Contributing

Please read CONTRIBUTING.md for details on my code of conduct, and the process for submitting pull requests to me.

Versioning

I use SemVer for versioning. For available versions, see tags on this repository.

Authors

Author

Licence

This project is licensed under the MIT licence - see the file LICENSE.md for more details.