Giter VIP home page Giter VIP logo

girth_mcmc's Introduction

CodeFactor PyPI version License: MIT PyPI - Downloads

GIRTH MCMC

Item Response Theory using Markov Chain Monte Carlo / Variational Inference

Dependencies

We recommend using Anaconda. Individual packages can be installed through pip otherwise.

  • Python โ‰ฅ 3.8
  • Numpy
  • Scipy
  • Girth
  • PyMC3

Installation

Via pip

pip install girth_mcmc --upgrade

From Source

pip install . -t $PYTHONPATH --upgrade

Supports

Unidimensional

  • Rasch Model
  • 1PL Model
  • 2PL Model
  • 3PL Model
  • Graded Response Model
  • Partial Credit Model

Multi-dimensional

  • 2PL Model
  • Graded Response Model
  • Partial Credit Model

Usage

Subject to change but for now:

import numpy as np
from girth.synthetic import create_synthetic_irt_dichotomous
from girth_mcmc import GirthMCMC
                        
discrimination = 0.89 * np.sqrt(-2 * np.log(np.random.rand(10)))
difficulty = np.random.randn(10)
theta = np.random.randn(100)

syn_data = create_synthetic_irt_dichotomous(difficulty, discrimination, 
                                            theta)

girth_model = GirthMCMC(model='2PL', 
                        options={'n_processors': 4})
results = girth_model(syn_data)
print(results)

for the graded response model, pass in the number of categories

import numpy as np
from girth.synthetic import create_synthetic_irt_polytomous
from girth_mcmc import GirthMCMC

n_categories = 3

difficulty = np.random.randn(10, n_categories-1)
difficulty = np.sort(difficulty, 1)        
discrimination = 0.96 * np.sqrt(-2 * np.log(np.random.rand(10)))
theta = np.random.randn(150)

syn_data = create_synthetic_irt_polytomous(difficulty, discrimination, 
                                            theta, model='grm')

girth_model = GirthMCMC(model='GRM', model_args=(n_categories,),
                        options={'n_processors': 4})
results = girth_model(syn_data)
print(results)

Is some data missing? Tag it with a convenience function and run it like normal

import numpy as np
from girth.synthetic import create_synthetic_irt_dichotomous
from girth_mcmc import GirthMCMC
from girth_mcmc.utils import tag_missing_data_mcmc
                        
discrimination = 0.89 * np.sqrt(-2 * np.log(np.random.rand(10)))
difficulty = np.random.randn(10)
theta = np.random.randn(100)

syn_data = create_synthetic_irt_dichotomous(difficulty, discrimination, 
                                            theta)
mask = np.random.rand(*syn_data.shape) < .1
syn_data[mask] = -9999
syn_data_missing = tag_missing_data_mcmc(syn_data, [0, 1])

girth_model = GirthMCMC(model='2PL', 
                        options={'n_processors': 4})
results = girth_model(syn_data_missing)
print(results)

Don't like waiting? me either. Run Variational Inference for faster but less accurate estimation.

import numpy as np
from girth.synthetic import create_synthetic_irt_polytomous
from girth_mcmc import GirthMCMC

n_categories = 3

difficulty = np.random.randn(10, n_categories-1)
difficulty = np.sort(difficulty, 1)        
discrimination = 1.76 * np.sqrt(-2 * np.log(np.random.rand(10)))
theta = np.random.randn(150)

syn_data = create_synthetic_irt_polytomous(difficulty, discrimination, 
                                            theta, model='grm')

girth_model = GirthMCMC(model='GRM', model_args=(n_categories,),
                        options={'variational_inference': True,
                                 'variational_samples': 10000,
                                 'n_samples': 10000})
results_variational = girth_model(syn_data, progressbar=False)
print(results_variational)

Unittests

pytest with coverage.py module

pytest --cov=girth_mcmc --cov-report term

Contact

Ryan Sanchez
[email protected]

Other Estimation Packages

If you are looking for Marginal Maximum Likelihood estimation routines, check out GIRTH, a graphical interface is also at GoFactr

License

MIT License

Copyright (c) 2021 Ryan C. Sanchez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

girth_mcmc's People

Contributors

eribean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sandy4321

girth_mcmc's Issues

Inverted results for difficulty compared to mirt

Just did a quick comparison for a 2PL model on a dichotomous dataset between the R package mirt and girth_mcmc. Are there any specific reasons that the scale for the difficulty values are inverted (for lack of a better term)?

girth_vs_mirt_1

Investigate GPU support

Future PYMC3 is going to incorporate JAX and will bring with it better GPU support, keep an eye on this.

Add Graded Unfolding Model

The graded unfolding model is an ideal point IRT model and an extension of the PCM #9. The framework for this model reuses a lot from the partial credit model and should be straightforward to implement. Not so straightforward is obtaining good initial estimates for item locations. The polarity ambiguity of item locations can cause posterior methods to diverge since to stable points will exist....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.