Skip to content

Commit

Permalink
Write readme module fit and simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianherreramonterrosa committed Oct 29, 2024
1 parent b3ab8d5 commit 667bd1f
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 218 deletions.
258 changes: 255 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

<p>
Phitter analyzes datasets and determines the best analytical probability distributions that represent them. Phitter studies over 80 probability distributions, both continuous and discrete, 3 goodness-of-fit tests, and interactive visualizations. For each selected probability distribution, a standard modeling guide is provided along with spreadsheets that detail the methodology for using the chosen distribution in data science, operations research, and artificial intelligence.
</p>

<p>
In addition, Phitter offers the capability to perform process simulations, allowing users to graph and observe minimum times for specific observations. It also supports queue simulations with flexibility to configure various parameters, such as the number of servers, maximum population size, system capacity, and different queue disciplines, including First-In-First-Out (FIFO), Last-In-First-Out (LIFO), and priority-based service (PBS).

</p>

<p>
This repository contains the implementation of the python library and the kernel of <a href="https://phitter.io">Phitter Web</a>
</p>
Expand All @@ -45,9 +47,11 @@ python: >=3.9
pip install phitter
```



## Usage

### Notebook's Tutorials
### ***1. Fit Notebook's Tutorials***

| Tutorial | Notebooks |
| :------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
Expand All @@ -57,7 +61,28 @@ pip install phitter
| **Fit Specific Disribution** | <a target="_blank" href="https://colab.research.google.com/github/phitterio/phitter-kernel/blob/main/examples/fit_specefic_distribution.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> |
| **Working Distribution** | <a target="_blank" href="https://colab.research.google.com/github/phitterio/phitter-kernel/blob/main/examples/working_distribution.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> |

### General
### ***2. Simulation Notebook's Tutorials***
pending

## Documentation











<details>

<summary style="font-size: 16px; font-weight: bold;">Documentation Fit Module</summary>



### General Fit

```python
import phitter
Expand Down Expand Up @@ -466,6 +491,233 @@ distribution.mode # -> 733.3333333333333
| poisson | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| uniform | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |

</details>









<details>
<summary style="font-size: 16px; font-weight: bold;">Documentation Simulation Module</summary>



## Process Simulation

This will help you to understand your processes. To use it, run the following line

```python
from phitter import simulation

# Create a simulation process instance
simulation = simulation.ProcessSimulation()

```

### Add processes to your simulation instance

There are two ways to add processes to your simulation instance:

- Adding a **process _without_ preceding process (new branch)**
- Adding a **process _with_ preceding process (with previous ids)**

#### Process _without_ preceding process (new branch)

```python
# Add a new process without preceding process
simulation.add_process(
prob_distribution="normal",
parameters={"mu": 5, "sigma": 2},
process_id="first_process",
number_of_products=10,
number_of_servers=3,
new_branch=True,
)

```

#### Process _with_ preceding process (with previous ids)

```python
# Add a new process with preceding process
simulation.add_process(
prob_distribution="exponential",
parameters={"lambda": 4},
process_id="second_process",
previous_ids=["first_process"],
)

```

#### All together and adding some new process

The order in which you add each process **_matters_**. You can add as many processes as you need.

```python
# Add a new process without preceding process
simulation.add_process(
prob_distribution="normal",
parameters={"mu": 5, "sigma": 2},
process_id="first_process",
number_of_products=10,
number_of_servers=3,
new_branch=True,
)

# Add a new process with preceding process
simulation.add_process(
prob_distribution="exponential",
parameters={"lambda": 4},
process_id="second_process",
previous_ids=["first_process"],
)

# Add a new process with preceding process
simulation.add_process(
prob_distribution="gamma",
parameters={"alpha": 15, "beta": 3},
process_id="third_process",
previous_ids=["first_process"],
)

# Add a new process without preceding process
simulation.add_process(
prob_distribution="exponential",
parameters={"lambda": 4.3},
process_id="fourth_process",
new_branch=True,
)


# Add a new process with preceding process
simulation.add_process(
prob_distribution="beta",
parameters={"alpha": 1, "beta": 1, "A": 2, "B": 3},
process_id="fifth_process",
previous_ids=["second_process", "fourth_process"],
)

# Add a new process with preceding process
simulation.add_process(
prob_distribution="normal",
parameters={"mu": 15, "sigma": 2},
process_id="sixth_process",
previous_ids=["third_process", "fifth_process"],
)
```

### Visualize your processes

You can visualize your processes to see if what you're trying to simulate is your actual process.

```python
# Graph your process
simulation.process_graph()
```

![Simulation](./multimedia/simulation_process_graph.png)

### Start Simulation

You can simulate and have different simulation time values or you can create a confidence interval for your process

#### Run Simulation

Simulate several scenarios of your complete process

```python
# Run Simulation
simulation.run(number_of_simulations=100)

# After run
simulation: pandas.Dataframe
```

### Review Simulation Metrics by Stage

If you want to review average time and standard deviation by stage run this line of code

```python
# Review simulation metrics
simulation.simulation_metrics() -> pandas.Dataframe
```

#### Run confidence interval

If you want to have a confidence interval for the simulation metrics, run the following line of code

```python
# Confidence interval for Simulation metrics
simulation.run_confidence_interval(
confidence_level=0.99,
number_of_simulations=100,
replications=10,
) -> pandas.Dataframe
```

## Queue Simulation

If you need to simulate queues run the following code:

```python
from phitter import simulation

# Create a simulation process instance
simulation = simulation.QueueingSimulation(
a="exponential",
a_paramters={"lambda": 5},
s="exponential",
s_parameters={"lambda": 20},
c=3,
)
```

In this case we are going to simulate **a** (arrivals) with _exponential distribution_ and **s** (service) as _exponential distribution_ with **c** equals to 3 different servers.

By default Maximum Capacity **k** is _infinity_, total population **n** is _infinity_ and the queue discipline **d** is _FIFO_. As we are not selecting **d** equals to "PBS" we don't have any information to add for **pbs_distribution** nor **pbs_parameters**

### Run the simulation

If you want to have the simulation results

```python
# Run simulation
simulation = simulation.run(simulation_time = 2000)
simulation: pandas.Dataframe
```

If you want to see some metrics and probabilities from this simulation you should use::

```python
# Calculate metrics
simulation.metrics_summary() -> pandas.Dataframe

# Calculate probabilities
number_probability_summary() -> pandas.Dataframe
```

### Run Confidence Interval for metrics and probabilities

If you want to have a confidence interval for your metrics and probabilities you should run the following line

```python
# Calculate confidence interval for metrics and probabilities
probabilities, metrics = simulation.confidence_interval_metrics(
simulation_time=2000,
confidence_level=0.99,
replications=10,
)

probabilities -> pandas.Dataframe
metrics -> pandas.Dataframe
```

</details>

## Contribution

If you would like to contribute to the Phitter project, please create a pull request with your proposed changes or enhancements. All contributions are welcome!
Loading

0 comments on commit 667bd1f

Please sign in to comment.