# DagSim
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/uio-bmi/dagsim/main?labpath=tutorials%2Fhello_world.ipynb)
DagSim is a Python-based framework and specification language for simulating data based on a Directed Acyclic Graph (
DAG)
structure, without any constraints on variable types or functional relations. A succinct YAML format for
defining the structure of the simulation model promotes transparency, while separate user-provided functions for
generating each variable based on its parents ensure the modularization of the simulation code.
## Installation
DagSim can be easily installed using pip.
### Installing DagSim using [pip](https://pypi.org/project/dagsim/)
To install the DagSim package using `pip`, run:
```bash
pip install dagsim
```
#### Quickstart
To check that DagSim is installed properly, run the following command in the console/terminal:
```bash
dagsim-quickstart
```
#### Installing graphviz
If you use `pip`, you need to install graphviz on the system level in order to use the drawing functionality in DagSim.
Please follow the instrcutions [here](https://graphviz.org/download/) on how to install graphviz depending on the
operating system.
[//]: # (### Installing DagSim using conda)
[//]: # (To install the DagSim package using `conda`, run:)
[//]: # (```bash)
[//]: # (conda install dagsim)
[//]: # (```)
[//]: # (With `conda`, graphviz is automatically installed, both, as a python package and at the system level.)
## Simple example
### Python code
Suppose we are interested in simulating two variables, X and Y, where X follows a standard Gaussian distribution, and Y
is the square of X.
For each node we need a function to simulate the node's values:
- For X, we can use the `numpy.random.normal` function
- For Y, we can use either `numpy.power` or define our own function. We will use the second to illustrate how one can
use
user-define functions.
```python
# needed imports
import dagsim.base as ds
import numpy as np
```
Here, we define our own `square` function:
```python
def square(arg):
return arg * arg
```
Then, we define the nodes in our graph/model by giving each node a name, the function to use in order to evaluate its
value, and the arguments of the function, if any:
```python
X = ds.Node(name="X", function=np.random.normal)
Y = ds.Node(name="Y", function=square, kwargs={"arg": X})
```
After that, we define the graph itself by giving it a name (optional) and a list of all the nodes to be included:
```python
graph = ds.Graph(name="demo_graph", list_nodes=[X, Y])
```
If you wish, you can draw the graph by calling the `draw` method, as follows:
```python
graph.draw()
```
Finally, we simulate data from this graph by calling the `simulate` method, and giving it the number of samples you
want to simulate, and a name for the csv_file (optional) where the data should be saved.
```python
data = graph.simulate(num_samples=10, csv_name="demo_data")
```
Here, `data` would be a dictionary with keys being the names of the nodes in the graph, and the corresponding values
being the simulated values for each node returned as a Python `list`.
For more detailed instructions, check
this [page](https://uio-bmi.github.io/dagsim/specify_with_code.html#how-to-specify-a-simulation-using-python-code), and
for other simple examples, please refer to the `tutorials` folder.
### YAML Specification
dagsim also allows the specification of a simulation using a YAML file. You can run dagsim on a YAML file by running:
```shell
dagsim path/to/yaml/file [-v|--verbose] [-d|--draw] [-o output/path|--output_path=output/path]
```
For a tutorial on using a YAMl file for simulation, check
this [page](https://uio-bmi.github.io/dagsim/specify_with_code.html#how-to-specify-a-simulation-using-yaml).
Raw data
{
"_id": null,
"home_page": "https://github.com/uio-bmi/dagsim",
"name": "dagsim",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Ghadi S. Al Hajj",
"author_email": "ghadia@uio.no",
"download_url": "https://files.pythonhosted.org/packages/7e/72/d656f862fb51fb5e427488bbac44fa1c00505b6d0b321083d695e355a9a8/dagsim-1.0.9.tar.gz",
"platform": null,
"description": "# DagSim\n\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/uio-bmi/dagsim/main?labpath=tutorials%2Fhello_world.ipynb)\n\nDagSim is a Python-based framework and specification language for simulating data based on a Directed Acyclic Graph (\nDAG)\nstructure, without any constraints on variable types or functional relations. A succinct YAML format for\ndefining the structure of the simulation model promotes transparency, while separate user-provided functions for\ngenerating each variable based on its parents ensure the modularization of the simulation code.\n\n## Installation\n\nDagSim can be easily installed using pip.\n\n### Installing DagSim using [pip](https://pypi.org/project/dagsim/)\n\nTo install the DagSim package using `pip`, run:\n\n```bash\npip install dagsim\n```\n\n#### Quickstart\n\nTo check that DagSim is installed properly, run the following command in the console/terminal:\n\n```bash\ndagsim-quickstart\n```\n\n#### Installing graphviz\n\nIf you use `pip`, you need to install graphviz on the system level in order to use the drawing functionality in DagSim.\nPlease follow the instrcutions [here](https://graphviz.org/download/) on how to install graphviz depending on the\noperating system.\n\n\n[//]: # (### Installing DagSim using conda)\n\n[//]: # (To install the DagSim package using `conda`, run:)\n\n[//]: # (```bash)\n\n[//]: # (conda install dagsim)\n\n[//]: # (```)\n\n[//]: # (With `conda`, graphviz is automatically installed, both, as a python package and at the system level.)\n\n## Simple example\n\n### Python code\n\nSuppose we are interested in simulating two variables, X and Y, where X follows a standard Gaussian distribution, and Y\nis the square of X.\n\nFor each node we need a function to simulate the node's values:\n\n- For X, we can use the `numpy.random.normal` function\n- For Y, we can use either `numpy.power` or define our own function. We will use the second to illustrate how one can\n use\n user-define functions.\n\n```python\n# needed imports\nimport dagsim.base as ds\nimport numpy as np\n```\n\nHere, we define our own `square` function:\n\n```python\ndef square(arg):\n return arg * arg\n```\n\nThen, we define the nodes in our graph/model by giving each node a name, the function to use in order to evaluate its\nvalue, and the arguments of the function, if any:\n\n```python\nX = ds.Node(name=\"X\", function=np.random.normal)\nY = ds.Node(name=\"Y\", function=square, kwargs={\"arg\": X})\n```\n\nAfter that, we define the graph itself by giving it a name (optional) and a list of all the nodes to be included:\n\n```python\ngraph = ds.Graph(name=\"demo_graph\", list_nodes=[X, Y])\n```\n\nIf you wish, you can draw the graph by calling the `draw` method, as follows:\n\n```python\ngraph.draw()\n```\n\nFinally, we simulate data from this graph by calling the `simulate` method, and giving it the number of samples you\nwant to simulate, and a name for the csv_file (optional) where the data should be saved.\n\n```python\ndata = graph.simulate(num_samples=10, csv_name=\"demo_data\")\n```\n\nHere, `data` would be a dictionary with keys being the names of the nodes in the graph, and the corresponding values\nbeing the simulated values for each node returned as a Python `list`.\n\nFor more detailed instructions, check\nthis [page](https://uio-bmi.github.io/dagsim/specify_with_code.html#how-to-specify-a-simulation-using-python-code), and\nfor other simple examples, please refer to the `tutorials` folder.\n\n### YAML Specification\n\ndagsim also allows the specification of a simulation using a YAML file. You can run dagsim on a YAML file by running:\n\n```shell\ndagsim path/to/yaml/file [-v|--verbose] [-d|--draw] [-o output/path|--output_path=output/path]\n```\n\nFor a tutorial on using a YAMl file for simulation, check\nthis [page](https://uio-bmi.github.io/dagsim/specify_with_code.html#how-to-specify-a-simulation-using-yaml).\n",
"bugtrack_url": null,
"license": "AGPL-3.0 License",
"summary": "A framework and specification language for simulating data based on user-defined graphical models",
"version": "1.0.9",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a8ba246964c426e8a5a5ce8f9cc5ecfe93d9d4782a1f31fbbab13df104ef035e",
"md5": "38672e4e8b38d6206706677b1e5200e4",
"sha256": "a63b3ab641e697c8ce21fe44b2416ac2a7439812cbc7ef1a414dcebcd464b7fa"
},
"downloads": -1,
"filename": "dagsim-1.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "38672e4e8b38d6206706677b1e5200e4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 32664,
"upload_time": "2023-02-01T09:46:11",
"upload_time_iso_8601": "2023-02-01T09:46:11.033923Z",
"url": "https://files.pythonhosted.org/packages/a8/ba/246964c426e8a5a5ce8f9cc5ecfe93d9d4782a1f31fbbab13df104ef035e/dagsim-1.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7e72d656f862fb51fb5e427488bbac44fa1c00505b6d0b321083d695e355a9a8",
"md5": "1e55426a3b26e938891f8aab2b06c4c9",
"sha256": "c8b7887ee1d176858a52ce7b74af58a382debfcb2e960c4cb319371b70c1802d"
},
"downloads": -1,
"filename": "dagsim-1.0.9.tar.gz",
"has_sig": false,
"md5_digest": "1e55426a3b26e938891f8aab2b06c4c9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 30753,
"upload_time": "2023-02-01T09:46:13",
"upload_time_iso_8601": "2023-02-01T09:46:13.212997Z",
"url": "https://files.pythonhosted.org/packages/7e/72/d656f862fb51fb5e427488bbac44fa1c00505b6d0b321083d695e355a9a8/dagsim-1.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-01 09:46:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "uio-bmi",
"github_project": "dagsim",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "dagsim"
}