the big format

This commit is contained in:
Joshua Burman
2022-02-10 20:29:50 -05:00
parent 19a37ab33a
commit deb6b9014e
25 changed files with 682 additions and 466 deletions

View File

@ -1,2 +1,2 @@
class ItemGenerationError(Exception):
pass
pass

View File

@ -3,22 +3,28 @@ import logging
from lib.irt.models.three_parameter_logistic import ThreeParameterLogistic
from lib.errors.item_generation_error import ItemGenerationError
class ItemInformationFunction():
def __init__(self, irt_model):
self.model_data = irt_model
# determines the amount of information for a given question at a given theta (ability level)
# further detailed on page 161, equation 4 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def calculate(self, **kwargs):
try:
if self.model_data.model == '3PL':
p = ThreeParameterLogistic(self.model_data, kwargs).result()
q = 1 - p
return (self.model_data.a_param * q * (p - self.model_data.c_param)**2) / (p * ((1 - self.model_data.c_param)**2))
else:
# potentially error out
raise ItemGenerationError("irt model not supported or provided")
except ZeroDivisionError as error:
logging.error(error)
raise ItemGenerationError("params not well formatted", error.args[0])
class ItemInformationFunction():
def __init__(self, irt_model):
self.model_data = irt_model
# determines the amount of information for a given question at a given theta (ability level)
# further detailed on page 161, equation 4 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def calculate(self, **kwargs):
try:
if self.model_data.model == '3PL':
p = ThreeParameterLogistic(self.model_data, kwargs).result()
q = 1 - p
return (self.model_data.a_param * q *
(p - self.model_data.c_param)**2) / (p * (
(1 - self.model_data.c_param)**2))
else:
# potentially error out
raise ItemGenerationError(
"irt model not supported or provided")
except ZeroDivisionError as error:
logging.error(error)
raise ItemGenerationError("params not well formatted",
error.args[0])

View File

@ -1,12 +1,14 @@
from lib.irt.models.three_parameter_logistic import ThreeParameterLogistic
from lib.errors.item_generation_error import ItemGenerationError
class ItemResponseFunction():
def __init__(self, irt_model):
self.model_data = irt_model
def calculate(self, **kwargs):
if self.model_data.model == '3PL':
return ThreeParameterLogistic(self.model_data, kwargs).result()
else:
raise ItemGenerationError("irt model not supported or provided")
class ItemResponseFunction():
def __init__(self, irt_model):
self.model_data = irt_model
def calculate(self, **kwargs):
if self.model_data.model == '3PL':
return ThreeParameterLogistic(self.model_data, kwargs).result()
else:
raise ItemGenerationError("irt model not supported or provided")

View File

@ -1,16 +1,18 @@
class ThreeParameterLogistic:
def __init__(self, model_params, kwargs):
self.model_params = model_params
# check if exists, if not error out
self.b_param = kwargs['b_param']
self.e = 2.71828
self.theta = kwargs['theta']
# contains the primary 3pl function, determining the probably of an inidividual
# that an individual at a certain theta would get a particular question correct
# detailed further on page 161, equation 1 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def result(self):
a = self.model_params.a_param
c = self.model_params.c_param
return c + (1 - c) * (1 / (1 + self.e**(-a * (self.theta - self.b_param))))
def __init__(self, model_params, kwargs):
self.model_params = model_params
# check if exists, if not error out
self.b_param = kwargs['b_param']
self.e = 2.71828
self.theta = kwargs['theta']
# contains the primary 3pl function, determining the probably of an inidividual
# that an individual at a certain theta would get a particular question correct
# detailed further on page 161, equation 1 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def result(self):
a = self.model_params.a_param
c = self.model_params.c_param
return c + (1 - c) * (1 / (1 + self.e**(-a *
(self.theta - self.b_param))))

View File

@ -1,19 +1,22 @@
from lib.irt.item_information_function import ItemInformationFunction
class TestInformationFunction():
def __init__(self, irt_model):
self.irt_model = irt_model
self.iif = ItemInformationFunction(irt_model)
# determins the amount of information
# at a certain theta (ability level) of the sum of a question set correct
# detailed further on page 166, equation 4 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def calculate(self, items, **kwargs):
sum = 0
def __init__(self, irt_model):
self.irt_model = irt_model
self.iif = ItemInformationFunction(irt_model)
for item in items:
result = self.iif.calculate(b_param=item.b_param, theta=kwargs['theta'])
sum += result
# determins the amount of information
# at a certain theta (ability level) of the sum of a question set correct
# detailed further on page 166, equation 4 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def calculate(self, items, **kwargs):
sum = 0
return sum
for item in items:
result = self.iif.calculate(b_param=item.b_param,
theta=kwargs['theta'])
sum += result
return sum

View File

@ -1,20 +1,23 @@
from lib.irt.item_response_function import ItemResponseFunction
# otherwise known as the Test Characteristic Curve (TCC)
class TestResponseFunction():
def __init__(self, irt_model):
self.irt_model = irt_model
self.irf = ItemResponseFunction(irt_model)
# determins the probably of an inidividual
# at a certain theta (ability level) would get a sum of questions correct
# detailed further on page 166, equation 3 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def calculate(self, items, **kwargs):
sum = 0
def __init__(self, irt_model):
self.irt_model = irt_model
self.irf = ItemResponseFunction(irt_model)
for item in items:
result = self.irf.calculate(b_param=item.b_param, theta=kwargs['theta'])
sum += result
# determins the probably of an inidividual
# at a certain theta (ability level) would get a sum of questions correct
# detailed further on page 166, equation 3 here:
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
def calculate(self, items, **kwargs):
sum = 0
return sum
for item in items:
result = self.irf.calculate(b_param=item.b_param,
theta=kwargs['theta'])
sum += result
return sum