pycmtensor


Namepycmtensor JSON
Version 1.12.0 PyPI version JSON
download
home_pagehttps://github.com/mwong009/pycmtensor
SummaryA robust and efficient Python package leveraging tensor computations for advanced discrete choice modelling.
upload_time2024-03-06 15:40:26
maintainer
docs_urlNone
authorMelvin Wong
requires_python>=3.9,<3.13
licenseMIT
keywords tensor discrete choice modelling transportation economics python data analysis machine learning artificial intelligence scientific computing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyCMTensor

![PyCMTensor](docs/assets/img/logo.jpg)

[![Licence](https://img.shields.io/badge/Licence-MIT-blue)](about/licence.md)
![](https://img.shields.io/pypi/pyversions/pycmtensor) 
[![PyPI version](https://badge.fury.io/py/pycmtensor.svg)](https://badge.fury.io/py/pycmtensor) 
![Conda-Forge|downloads](https://img.shields.io/conda/d/conda-forge/pycmtensor)

[![codecov](https://codecov.io/gh/mwong009/pycmtensor/branch/master/graph/badge.svg?token=LFwgggDyjS)](https://codecov.io/gh/mwong009/pycmtensor) 
[![Downloads](https://static.pepy.tech/personalized-badge/pycmtensor?period=month&units=international_system&left_color=grey&right_color=orange&left_text=downloads/month)](https://pepy.tech/project/pycmtensor) 
[![DOI](https://zenodo.org/badge/460802394.svg)](https://zenodo.org/badge/latestdoi/460802394)

*Advanced Tensor-based Choice Modelling Python package*

[Introduction](#introduction) | [Install](#installation) | [Key Features](#key-features)

---

## Introduction

PyCMTensor is a Python library that use tensor-based computations for discrete choice modelling and estimation. It specializes in the estimation of hybrid neural networks, Logit models, and Mixed Logit models. The models in PyCMTensor are built on computational graphs and are estimated using generalized backpropagation algorithms.

This library provides the tools to fully specify and estimate Multinomial Logit and Mixed Logit models. It also enables the generation of statistical test results for comprehensive econometric analysis. With PyCMTensor, you can perform model estimation using computational graphs, making it a powerful tool for advanced statistical modelling.

## Installation

**PyCMTensor** is available on Conda-forge:

```bash
conda install -c conda-forge pycmtensor
```

## Quick start

A simple Multinomial logit model. Dataset: [Swissmetro](http://transp-or.epfl.ch/data/swissmetro.dat)

```python
import pandas as pd
from pycmtensor import train
from pycmtensor.dataset import Dataset
from pycmtensor.expressions import Beta
from pycmtensor.models import MNL
import pycmtensor.optimizers as optim

def mnl_model(filename='http://transp-or.epfl.ch/data/swissmetro.dat'):
    # Load the CSV file into a DataFrame
    df = pd.read_csv(filename, sep='\t')

    # Load the DataFrame into a Dataset object
    ds = Dataset(df, choice="CHOICE")
    ds.scale_variable("TRAIN_TT", 100)
    ds.scale_variable("SM_TT", 100)
    ds.scale_variable("CAR_TT", 100)
    ds.scale_variable("TRAIN_CO", 100)
    ds.scale_variable("SM_CO", 100)
    ds.scale_variable("CAR_CO", 100)
    ds.split(0.8)

    # Define the alternative specific constants (ASCs) for each mode of transport
    ASC_TRAIN = Beta("ASC_TRAIN", 0., None, None, 0)
    ASC_SM = Beta("ASC_SM", 0., None, None, 0)
    ASC_CAR = Beta("ASC_CAR", 0., None, None, 1)
    B_COST = Beta("B_COST", -1., None, None, 1)
    B_TIME_TRAIN = Beta("B_TIME_TRAIN", 0., None, None, 0)
    B_TIME_SM = Beta("B_TIME_SM", 0., None, None, 0)
    B_TIME_CAR = Beta("B_TIME_CAR", 0., None, None, 0)
    B_SEAT = Beta("B_SEAT", 0., None, None, 0)

    # Define the utility functions for each mode of transport
    V_TRAIN = ASC_TRAIN + B_TIME_TRAIN * ds["TRAIN_TT"] + B_COST * ds["TRAIN_CO"]
    V_SM = ASC_SM + B_TIME_SM * ds["SM_TT"] + B_COST * ds["SM_CO"] + B_SEAT * ds["SM_SEATS"]
    V_CAR = ASC_CAR + B_TIME_CAR * ds["CAR_TT"] + B_COST * ds["CAR_CO"]

    # Define the model
    U = [V_TRAIN, V_SM, V_CAR]
    AV = [ds["TRAIN_AV"], ds["SM_AV"], ds["CAR_AV"]]
    model = MNL(ds, locals(), utility=U, av=AV)
    
    return model, ds

# Train model
model, ds = mnl_model()
train(model, ds, optimizer=optim.Adam, max_epochs=2000, base_learning_rate=0.1, convergence_threshold=1e-3)

# Print model results
print(model.results.beta_statistics())
print(model.results.model_statistics())
print(model.results.benchmark())
```

## Key Features

- **Interpretable and customizable utility specification syntaxes**: Easily define your models with an intuitive syntax.
- **Neural network specification**: Specify neural networks with weight and bias parameters inside utility functions (e.g., TasteNet).
- **Comprehensive analysis tools**: Perform specification testing, analyze covariances, and compute standard errors for taste parameters.
- **Fast model estimation**: Quickly estimate models, including simulation-based methods like Mixed Logit models, using a computational graph approach.
- **Flexible optimization methods**: Tune the model estimation with 1st order methods (e.g., Adam, Stochastic Gradient Descent) or 1.5th order methods (e.g., Stochastic BFGS).

While other choice modelling estimation software in Python are available, such as Biogeme, xlogit, and PyLogit, PyCMTensor sets itself apart by fully implementing deep learning-based methods with a simplified syntax for utility equation specification.

## Documentation

For more information on how to use PyCMTensor, please refer to our [documentation](link-to-documentation).
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mwong009/pycmtensor",
    "name": "pycmtensor",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<3.13",
    "maintainer_email": "",
    "keywords": "tensor,discrete choice modelling,transportation,economics,python,data analysis,machine learning,artificial intelligence,scientific computing",
    "author": "Melvin Wong",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/fc/3f/da5a0f36530e1388224d6e4f1bc84e2f566c6a776e4bbed8261a0be0c4d3/pycmtensor-1.12.0.tar.gz",
    "platform": null,
    "description": "# PyCMTensor\n\n![PyCMTensor](docs/assets/img/logo.jpg)\n\n[![Licence](https://img.shields.io/badge/Licence-MIT-blue)](about/licence.md)\n![](https://img.shields.io/pypi/pyversions/pycmtensor) \n[![PyPI version](https://badge.fury.io/py/pycmtensor.svg)](https://badge.fury.io/py/pycmtensor) \n![Conda-Forge|downloads](https://img.shields.io/conda/d/conda-forge/pycmtensor)\n\n[![codecov](https://codecov.io/gh/mwong009/pycmtensor/branch/master/graph/badge.svg?token=LFwgggDyjS)](https://codecov.io/gh/mwong009/pycmtensor) \n[![Downloads](https://static.pepy.tech/personalized-badge/pycmtensor?period=month&units=international_system&left_color=grey&right_color=orange&left_text=downloads/month)](https://pepy.tech/project/pycmtensor) \n[![DOI](https://zenodo.org/badge/460802394.svg)](https://zenodo.org/badge/latestdoi/460802394)\n\n*Advanced Tensor-based Choice Modelling Python package*\n\n[Introduction](#introduction) | [Install](#installation) | [Key Features](#key-features)\n\n---\n\n## Introduction\n\nPyCMTensor is a Python library that use tensor-based computations for discrete choice modelling and estimation. It specializes in the estimation of hybrid neural networks, Logit models, and Mixed Logit models. The models in PyCMTensor are built on computational graphs and are estimated using generalized backpropagation algorithms.\n\nThis library provides the tools to fully specify and estimate Multinomial Logit and Mixed Logit models. It also enables the generation of statistical test results for comprehensive econometric analysis. With PyCMTensor, you can perform model estimation using computational graphs, making it a powerful tool for advanced statistical modelling.\n\n## Installation\n\n**PyCMTensor** is available on Conda-forge:\n\n```bash\nconda install -c conda-forge pycmtensor\n```\n\n## Quick start\n\nA simple Multinomial logit model. Dataset: [Swissmetro](http://transp-or.epfl.ch/data/swissmetro.dat)\n\n```python\nimport pandas as pd\nfrom pycmtensor import train\nfrom pycmtensor.dataset import Dataset\nfrom pycmtensor.expressions import Beta\nfrom pycmtensor.models import MNL\nimport pycmtensor.optimizers as optim\n\ndef mnl_model(filename='http://transp-or.epfl.ch/data/swissmetro.dat'):\n    # Load the CSV file into a DataFrame\n    df = pd.read_csv(filename, sep='\\t')\n\n    # Load the DataFrame into a Dataset object\n    ds = Dataset(df, choice=\"CHOICE\")\n    ds.scale_variable(\"TRAIN_TT\", 100)\n    ds.scale_variable(\"SM_TT\", 100)\n    ds.scale_variable(\"CAR_TT\", 100)\n    ds.scale_variable(\"TRAIN_CO\", 100)\n    ds.scale_variable(\"SM_CO\", 100)\n    ds.scale_variable(\"CAR_CO\", 100)\n    ds.split(0.8)\n\n    # Define the alternative specific constants (ASCs) for each mode of transport\n    ASC_TRAIN = Beta(\"ASC_TRAIN\", 0., None, None, 0)\n    ASC_SM = Beta(\"ASC_SM\", 0., None, None, 0)\n    ASC_CAR = Beta(\"ASC_CAR\", 0., None, None, 1)\n    B_COST = Beta(\"B_COST\", -1., None, None, 1)\n    B_TIME_TRAIN = Beta(\"B_TIME_TRAIN\", 0., None, None, 0)\n    B_TIME_SM = Beta(\"B_TIME_SM\", 0., None, None, 0)\n    B_TIME_CAR = Beta(\"B_TIME_CAR\", 0., None, None, 0)\n    B_SEAT = Beta(\"B_SEAT\", 0., None, None, 0)\n\n    # Define the utility functions for each mode of transport\n    V_TRAIN = ASC_TRAIN + B_TIME_TRAIN * ds[\"TRAIN_TT\"] + B_COST * ds[\"TRAIN_CO\"]\n    V_SM = ASC_SM + B_TIME_SM * ds[\"SM_TT\"] + B_COST * ds[\"SM_CO\"] + B_SEAT * ds[\"SM_SEATS\"]\n    V_CAR = ASC_CAR + B_TIME_CAR * ds[\"CAR_TT\"] + B_COST * ds[\"CAR_CO\"]\n\n    # Define the model\n    U = [V_TRAIN, V_SM, V_CAR]\n    AV = [ds[\"TRAIN_AV\"], ds[\"SM_AV\"], ds[\"CAR_AV\"]]\n    model = MNL(ds, locals(), utility=U, av=AV)\n    \n    return model, ds\n\n# Train model\nmodel, ds = mnl_model()\ntrain(model, ds, optimizer=optim.Adam, max_epochs=2000, base_learning_rate=0.1, convergence_threshold=1e-3)\n\n# Print model results\nprint(model.results.beta_statistics())\nprint(model.results.model_statistics())\nprint(model.results.benchmark())\n```\n\n## Key Features\n\n- **Interpretable and customizable utility specification syntaxes**: Easily define your models with an intuitive syntax.\n- **Neural network specification**: Specify neural networks with weight and bias parameters inside utility functions (e.g., TasteNet).\n- **Comprehensive analysis tools**: Perform specification testing, analyze covariances, and compute standard errors for taste parameters.\n- **Fast model estimation**: Quickly estimate models, including simulation-based methods like Mixed Logit models, using a computational graph approach.\n- **Flexible optimization methods**: Tune the model estimation with 1st order methods (e.g., Adam, Stochastic Gradient Descent) or 1.5th order methods (e.g., Stochastic BFGS).\n\nWhile other choice modelling estimation software in Python are available, such as Biogeme, xlogit, and PyLogit, PyCMTensor sets itself apart by fully implementing deep learning-based methods with a simplified syntax for utility equation specification.\n\n## Documentation\n\nFor more information on how to use PyCMTensor, please refer to our [documentation](link-to-documentation).",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A robust and efficient Python package leveraging tensor computations for advanced discrete choice modelling.",
    "version": "1.12.0",
    "project_urls": {
        "Homepage": "https://github.com/mwong009/pycmtensor",
        "Repository": "https://github.com/mwong009/pycmtensor"
    },
    "split_keywords": [
        "tensor",
        "discrete choice modelling",
        "transportation",
        "economics",
        "python",
        "data analysis",
        "machine learning",
        "artificial intelligence",
        "scientific computing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90d5d45e52c876a54753f37e625ccfa79267ebc3b322a0dd278ed980f1a3620b",
                "md5": "6d8bb18ca5da3b51d74304e3b18216a3",
                "sha256": "e53f3ecf23b5a8305c6d98151c0b429ca88325605c01dd07355cc5dc56f2cb2a"
            },
            "downloads": -1,
            "filename": "pycmtensor-1.12.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6d8bb18ca5da3b51d74304e3b18216a3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<3.13",
            "size": 48943,
            "upload_time": "2024-03-06T15:40:24",
            "upload_time_iso_8601": "2024-03-06T15:40:24.380415Z",
            "url": "https://files.pythonhosted.org/packages/90/d5/d45e52c876a54753f37e625ccfa79267ebc3b322a0dd278ed980f1a3620b/pycmtensor-1.12.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc3fda5a0f36530e1388224d6e4f1bc84e2f566c6a776e4bbed8261a0be0c4d3",
                "md5": "f7f7a23e00f7a4d9f6f33f1afd70596e",
                "sha256": "a1ec73076383f558cda88e91e736d2cb73dfa547e69a0db8ae6c2eb054eda794"
            },
            "downloads": -1,
            "filename": "pycmtensor-1.12.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f7f7a23e00f7a4d9f6f33f1afd70596e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<3.13",
            "size": 40597,
            "upload_time": "2024-03-06T15:40:26",
            "upload_time_iso_8601": "2024-03-06T15:40:26.174348Z",
            "url": "https://files.pythonhosted.org/packages/fc/3f/da5a0f36530e1388224d6e4f1bc84e2f566c6a776e4bbed8261a0be0c4d3/pycmtensor-1.12.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-06 15:40:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mwong009",
    "github_project": "pycmtensor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pycmtensor"
}
        
Elapsed time: 0.20451s