Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ITMO-NSS-team/BAMT
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman223 committed Oct 11, 2023
2 parents c3e64b5 + 1507472 commit 4381c55
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 7,993 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ tutorials/bamt
.DS_Store
/example_socio.ipynb
/temp.ipynb
/bamt_house_price_example_feature_analysis.ipynb
/bamt_house_price_example_data_sampling.ipynb
32 changes: 27 additions & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
# .readthedocs.yml
# Read the Docs configuration file
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py
fail_on_warning: true
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt

python:
version: "3.8"
install:
- requirements: other_requirements/readthedocs.txt
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ Then the necessary classes are imported from the library:

.. code-block:: python
import bamt.networks as Nets
from bamt.networks.hybrid_bn import HybridBN
Next, a network instance is created and training (structure and parameters) is performed:

.. code-block:: python
bn = Nets.HybridBN(has_logit=False, use_mixture=True)
bn.add_edges(discretized_data, scoring_function=('K2',K2Score))
bn = HybridBN(has_logit=False, use_mixture=True)
bn.add_edges(preprocessed_data)
bn.fit_parameters(data)
Examples & Tutorials
^^^^^^^^^^^^^^^^^^^^^^

More examples can be found in `tutorials <https://github.com/ITMO-NSS-team/BAMT/tree/master/tutorials>`__ and `Documentation <https://bamt.readthedocs.io/en/latest/examples/learn_save.html>`__.
More examples can be found in `Documentation <https://bamt.readthedocs.io/en/latest/examples/learn_save.html>`__.

Publications about BAMT
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
11 changes: 9 additions & 2 deletions bamt/utils/composite_utils/MLUtils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
from random import choice

import pkg_resources
from typing import Union

from catboost import CatBoostClassifier, CatBoostRegressor
Expand Down Expand Up @@ -33,6 +35,11 @@
LGBMRegressor = None
LGBMClassifier = None

lgbm_params = "lgbm_params.json"
models_repo = "models_repo.json"
lgbm_params_path = pkg_resources.resource_filename(__name__, lgbm_params)
models_repo_path = pkg_resources.resource_filename(__name__, models_repo)


class MlModels:
def __init__(self):
Expand Down Expand Up @@ -94,7 +101,7 @@ def __init__(self):
self.operations_by_types["lgbm"] = "LGBMClassifier"

if LGBMClassifier and LGBMRegressor is not None:
with open("bamt/utils/composite_utils/lgbm_params.json") as file:
with open(lgbm_params_path) as file:
self.lgbm_dict = json.load(file)

def get_model_by_children_type(self, node: Union[GraphNode, CompositeNode]):
Expand All @@ -104,7 +111,7 @@ def get_model_by_children_type(self, node: Union[GraphNode, CompositeNode]):
else:
type_model = "class"
forbidden_tags = ["non-default", "expensive"]
with open("bamt/utils/composite_utils/models_repo.json", "r") as f:
with open(models_repo_path, "r") as f:
models_json = json.load(f)
models = models_json["operations"]
if LGBMClassifier and LGBMRegressor is not None:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/add_ml_models_to_nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ First, lets import BAMT modules and required machine learning modules.

.. code-block:: python
from bamt.networks.hybrid_bn import HybridBN
import bamt.networks as networks
import bamt.Preprocessors as pp
import pandas as pd
Expand Down Expand Up @@ -66,7 +66,7 @@ Next, we initialize Bayesian Network object and add nodes to it.

.. code-block:: python
bn = HybridBN(has_logit=True, use_mixture=True)
bn = networks.HybridBN(has_logit=True, use_mixture=True)
bn.add_nodes(info)
After adding nodes we can perform structure learning.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/learn_params_vis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Used imports:

.. code-block:: python
from bamt.networks.hybrid_bn import HybridBN
import bamt.networks as networks
import bamt.Preprocessors as pp
import pandas as pd
Expand Down Expand Up @@ -44,7 +44,7 @@ Preprocessing data, encode categorical features and discretize numerical feature
p = pp.Preprocessor([('encoder', encoder), ('discretizer', discretizer)])
discretized_data, est = p.apply(data)
bn = HybridBN(has_logit=True, use_mixture=True) # init BN
bn = networks.HybridBN(has_logit=True, use_mixture=True) # init BN
info = p.info
info
bn.add_nodes(info)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/learn_sampling_predict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Used imports:

.. code-block:: python
from bamt.networks.hybrid_bn import HybridBN
import bamt.networks as networks
import bamt.Preprocessors as pp
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/learn_save.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Used imports:
from bamt.preprocessors import Preprocessor
import pandas as pd
from sklearn import preprocessing as pp
from bamt.networks.hybrid_bn import HybridBN
from bamt.networks import HybridBN
Let's start with data loading and preprocessing:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/read_structure_and_params.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Used imports:
from bamt.preprocessors import Preprocessor
import pandas as pd
from sklearn import preprocessing as pp
from bamt.networks.hybrid_bn import HybridBN
from bamt.networks import HybridBN
import json
You can read the pre-trained structure and distribution parameters from a file.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/read_structure_param_learning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Used imports:
from bamt.preprocessors import Preprocessor
import pandas as pd
from sklearn import preprocessing as pp
from bamt.networks.hybrid_bn import HybridBN
from bamt.networks import HybridBN
import json
There are two options for loading a BN structure. The first is to read it directly from a JSON file:
Expand Down
9 changes: 7 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ generating synthetic data, assessing edges strength e.t.c.
models/bayesiannetworks/hybrid_bn.rst
models/bayesiannetworks/sampling_predicting.rst
models/bayesiannetworks/large_bn_algs.rst
models/bayesiannetworks/models_storing.rst

.. toctree::
:maxdepth: 1
Expand All @@ -66,7 +65,6 @@ generating synthetic data, assessing edges strength e.t.c.

bnalgs/bn_learning.rst
bnalgs/big_bns.rst
bnalgs/applied_tasks.rst

.. toctree::
:maxdepth: 1
Expand All @@ -88,6 +86,13 @@ generating synthetic data, assessing edges strength e.t.c.
examples/add_ml_models_to_nodes.rst
examples/composite_network_example.rst

.. toctree::
:maxdepth: 1
:hidden:
:caption: Tutorials

tutorials/tutorials_gists.rst



Indices and tables
Expand Down
4 changes: 2 additions & 2 deletions docs/source/models/bayesiannetworks/base_network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ For Example:

.. code-block:: python
from bamt.networks.discrete_bn import DiscreteBN
import bamt.networks as networks
import bamt.preprocessors as pp
import pandas as pd
Expand All @@ -38,7 +38,7 @@ For Example:
p = pp.Preprocessor([('encoder', encoder), ('discretizer', discretizer)])
discretized_data, est = p.apply(asia)
bn = DiscreteBN()
bn = networks.DiscreteBN()
info = p.info
info
Expand Down
4 changes: 2 additions & 2 deletions docs/source/models/bayesiannetworks/composite_bn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ To initialize a ``CompositeBN`` object, you can use the following code:

.. code-block:: python
from bamt.networks.composite_bn import CompositeBN
import bamt.networks as networks
bn = CompositeBN()
bn = networks.CompositeBN()
Data Preprocessing
Expand Down
4 changes: 2 additions & 2 deletions docs/source/models/bayesiannetworks/continuous_bn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ To initialize a ``ContinuousBN`` object, you can use the following code:

.. code-block:: python
from bamt.networks.continuous_bn import ContinuousBN
import bamt.networks as networks
bn = ContinuousBN(use_mixture=True)
bn = networks.ContinuousBN(use_mixture=True)
ContinuousBN has an additional parameter ``use_mixture``.
It is used to determine whether to use mixuters of Gaussian distributions to represent the conditional distribution of continuous variables.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/models/bayesiannetworks/discrete_bn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ To initialize a ``DiscreteBN`` object, you can use the following code:

.. code-block:: python
from bamt.networks.discrete_bn import DiscreteBN
import bamt.networks as networks
bn = DiscreteBN()
bn = networks.DiscreteBN()
Data Preprocessing
~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions docs/source/models/bayesiannetworks/hybrid_bn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ To initialize a ``HybridBN`` object, you can use the following code:

.. code-block:: python
from bamt.networks.hybrid_bn import HybridBN
import bamt.networks as networks
bn = HybridBN(has_logit=True, use_mixture=True)
bn = networks.HybridBN(has_logit=True, use_mixture=True)
HybridBN has two additional parameters ``has_logit`` and ``use_mixture``.
``has_logit`` is used to determine whether to use logit nodes. Logit nodes use machine learning algorithms to represent variable.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/models/bayesiannetworks/large_bn_algs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Then perform structure learning as usual, but use ``ps`` as ``white_list``:

.. code-block:: python
bn = Nets.ContinuousBN()
bn = networks.ContinuousBN()
bn.add_nodes(descriptor=info)
Expand Down
8 changes: 8 additions & 0 deletions docs/source/tutorials/tutorials_gists.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Full-scale tutorial examples
============================

In this section full-scale GitHub Gist tutorials for BAMT use cases are listed,
feel free to leave your comments and questions at the following gists:

* `BAMT house price dataset prediction results improvement with sampling. <https://gist.github.com/jrzkaminski/ca4c9ef9292ef0e8df4da5b81effae1e>`__
* `BAMT house price dataset linear regression with BAMT. <https://gist.github.com/jrzkaminski/50805963ca02ca8a326e344ea39e592c>`__
1 change: 1 addition & 0 deletions tests/sendingRegressors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from catboost import CatBoostRegressor
from sklearn import preprocessing as pp
from sklearn.ensemble import RandomForestRegressor

# from sklearn.linear_model import ElasticNet
from sklearn.tree import DecisionTreeRegressor

Expand Down
Loading

0 comments on commit 4381c55

Please sign in to comment.