add basic error handling
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
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):
|
||||
@ -8,10 +11,14 @@ class ItemInformationFunction():
|
||||
# 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):
|
||||
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
|
||||
return None
|
||||
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])
|
||||
|
Reference in New Issue
Block a user