Giter VIP home page Giter VIP logo

Comments (3)

eribean avatar eribean commented on September 23, 2024

Added latent ability estimation, works well. The Blue line is the true latent ability distribution, the red is estimated from the data and the black is a standard normal distribution. Need to propagate it through the estimation functions and write unittests.
Plot

from girth.

eribean avatar eribean commented on September 23, 2024

Added the latent distribution estimation to most of the algorithms, need to fix unittests.

from girth.

eribean avatar eribean commented on September 23, 2024

Ability estimation is available in 2pl_mml (through grm_mml), grm_mml, pcm_mml and gum_mml methods. It is not turned on by default, and the estimated samples default to 9.

Below is an example to demonstrate it:

import numpy as np
from scipy import stats
from bokeh.plotting import figure, show, output_notebook

from girth import create_synthetic_irt_dichotomous, create_synthetic_irt_polytomous
from girth import grm_mml

output_notebook()

np.random.seed(1124)
x = np.linspace(-4, 4, 1001)

# Random parameters
loc1 = -np.random.rand(1) - .4
loc2 = np.random.rand(1) + .4
scale1 = 0.3 + np.random.rand(1) * 0.7
scale2 = 0.3 + np.random.rand(1) * 0.7
weight1 = np.random.rand(1)
weight2 = 1 - weight1

# Initial distiribution
n = (weight1 * stats.distributions.norm.pdf(x, loc=loc1, scale=scale1) + 
     weight2 * stats.distributions.norm.pdf(x, loc=loc2, scale=scale2))
n /= n.sum()

# Get the adjustment factors
mn = x.dot(n)
std = np.sqrt(n.dot((x - mn)**2))

# Scale to be zero mean and unit variance
n = (weight1 * stats.distributions.norm.pdf(x * std, loc=loc1-mn, scale=scale1) + 
     weight2 * stats.distributions.norm.pdf(x * std, loc=loc2-mn, scale=scale2))
n /= n.sum()

# Set the hypothetical study
n_participants = 1000
n_items = 20

# get a distribution of abilitites
theta = np.random.choice(x, size=n_participants, p=n/n.sum())
difficulty = np.random.randn(n_items, 4)
difficulty = np.sort(difficulty, axis=1)
discrimination = np.random.rand(n_items) + 0.75

# Create the synthetic data
syn_data_grm = create_synthetic_irt_polytomous(difficulty, discrimination, theta, model='grm')

# Estimate the parameters
output = grm_mml(syn_data_grm, options={"estimate_distribution": True,
                                        "number_of_samples": 11})

xx, yy = output['LatentPDf'].cubic_splines[-1].continuous_pdf()
scalar = (xx[2] - xx[1]) / (x[2] - x[1])

p = figure()
p.line(x, n, legend_label="Truth")
p.line(xx, yy / scalar / yy.sum(), color='red', legend_label="Estimated")
show(p)

The result should look like below:
example_result

from girth.

Related Issues (20)

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.