134 lines
4.1 KiB
Markdown
134 lines
4.1 KiB
Markdown
# Erlang Decision Tree and Baysian Networks
|
|
|
|

|
|
|
|
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.
|
|
|
|
* erlang - https://www.erlang.org;
|
|
|
|
|
|
### 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](https://hub.docker.com/search?q=erlang&type=image) and start the container.
|
|
|
|
I suggest [this container](https://hub.docker.com/r/bitwalker/alpine-erlang) 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:
|
|
|
|

|
|
|
|
** You can take medication 1 and medication 2 with a 97.6 per cent success rate to get well.
|
|
|
|
|
|
|
|
|
|
|
|
2. For the second exercise (Baysian Networks):
|
|
|
|
```
|
|
c(motor3).
|
|
motor3:getp({m2, ok}).
|
|
```
|
|
|
|
|
|

|
|
|
|
**There is a 16 per cent chance that the patient will be OK when administering drug M2.
|
|
|
|
## Created with
|
|
|
|
* erlang - https://www.erlang.org;
|
|
|
|
## Contributing
|
|
|
|
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on my code of conduct, and the process for submitting pull requests to me.
|
|
|
|
## Versioning
|
|
|
|
I use [SemVer](http://semver.org/) for versioning. For available versions, see [tags on this repository](https://gitlab.andrealmeida.net/public_projects/erlang-decision-tree/tags).
|
|
|
|
## Authors
|
|
|
|
[](https://andrealmeida.net)
|
|
|
|
## Licence
|
|
|
|
This project is licensed under the MIT licence - see the file [LICENSE.md](LICENSE.md) for more details.
|