proso.models package¶
Submodules¶
proso.models.environment module¶
-
class
proso.models.environment.
Environment
[source]¶ Bases:
object
This class encapsulates environment for the purpose of modelling.
-
flush
()[source]¶ This method is called to enforce persistence of the data. This is useful mainly for interaction with database where it is not efficient to touch database for each answer. When your environment is only an in memery implementation, you can leave this method as it is.
-
process_answer
(user, item, asked, answered, time, answer, response_time, guess, **kwargs)[source]¶ This method is used during the answer streaming and is called after the predictive model for each answer.
Parameters: - user (int) – identifier of ther user answering the question
- asked (int) – identifier of the asked item
- answered (int) – identifier of the answered item or None if the user answered “I don’t know”
- response_time (int) – time the answer took in milliseconds
- time (datetime.datetime) – time when the user answered the question
- guess (float) – probability of correct response in case of random answer
-
read_more_keys
(keys, user=None, item=None, item_secondary=None, default=None, symmetric=True)[source]¶
-
-
class
proso.models.environment.
InMemoryEnvironment
(audit_enabled=True)[source]¶ Bases:
proso.models.environment.CommonEnvironment
-
CONFUSING_FACTOR
= 'confusing_factor'¶
-
LAST_CORRECTNESS
= 'last_correctness'¶
-
NUMBER_OF_ANSWERS
= 'number_of_answers'¶
-
NUMBER_OF_CORRECT_ANSWERS
= 'number_of_correct_answers'¶
-
NUMBER_OF_FIRST_ANSWERS
= 'number_of_first_answers'¶
-
proso.models.item_selection module¶
-
class
proso.models.item_selection.
ItemSelection
(predictive_model, target_probability=0.65, history_adjustment=True)[source]¶ Bases:
object
-
class
proso.models.item_selection.
RandomItemSelection
(predictive_model, target_probability=0.65, history_adjustment=True)[source]¶
-
class
proso.models.item_selection.
ScoreItemSelection
(predictive_model, weight_probability=10.0, weight_number_of_answers=5.0, weight_time_ago=5, weight_parent_time_ago=5.0, weight_parent_number_of_answers=2.5, target_probability=0.65, time_ago_max=120, recompute_parent_score=True, history_adjustment=True, estimate_parent_factors=True)[source]¶
proso.models.option_selection module¶
-
class
proso.models.option_selection.
AdjustedOptionSelection
(item_selector, options_number, **kwargs)[source]¶
-
class
proso.models.option_selection.
AdjustedOptionsNumber
(max_options=6, allow_zero_options_restriction=True)[source]¶
-
class
proso.models.option_selection.
CompetitiveOptionSelection
(item_selector, options_number, **kwargs)[source]¶
-
class
proso.models.option_selection.
ConstantOptionsNumber
(number_of_options, max_options=6, allow_zero_options_restriction=True)[source]¶
-
class
proso.models.option_selection.
FullyRandomOptionsNumber
(max_options=6, allow_zero_options_restriction=True)[source]¶
-
class
proso.models.option_selection.
OptionSelection
(item_selector, options_number, **kwargs)[source]¶ Bases:
object
-
class
proso.models.option_selection.
OptionsNumber
(max_options=6, allow_zero_options_restriction=True)[source]¶ Bases:
object
-
class
proso.models.option_selection.
PartiallyConstantOptionsNumber
(number_of_options, max_options=6, allow_zero_options_restriction=True)[source]¶
-
class
proso.models.option_selection.
PartiallyRandomOptionsNumber
(max_options=6, allow_zero_options_restriction=True)[source]¶
-
class
proso.models.option_selection.
RandomOptionSelection
(item_selector, options_number, **kwargs)[source]¶
-
class
proso.models.option_selection.
TestOptionSelection
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
class
proso.models.option_selection.
TestOptionsNumber
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
class
proso.models.option_selection.
UniformlyAdjustedOptionsNumber
(max_options=6, allow_zero_options_restriction=True)[source]¶
proso.models.prediction module¶
-
class
proso.models.prediction.
AlwaysLearningPredictiveModel
(pfae_good=1.0, pfae_bad=0.5, elo_alpha=0.8, elo_dynamic_alpha=0.05)[source]¶
-
class
proso.models.prediction.
PFAEStaircase
(pfae_good=1.8, pfae_bad=0.8, elo_alpha=0.8, elo_dynamic_alpha=0.05, staircase_size=20, staircase_base=60)[source]¶
-
class
proso.models.prediction.
PredictiveModel
[source]¶ Bases:
object
This class handles the logic behind the predictive models, which is divided into 3 phases:
- prepare: the model loads the necessary data from the environment
- predict: the model uses the loaded data to predict the correctness of the answer
- update: the model updates environment to persist it for the future prediction
-
predict_phase
(data, user, item, time, **kwargs)[source]¶ Uses the data from prepare phase and tries to predict the probability of the correct answer. That means the prediction for the user and the asked item before the given answer is processed.
Parameters: - data (object) – data from the prepare phase
- user (int) – identifier of the user answering the question
- item (int) – identifier of the question item
- time (datetime.datetime) – datetime when the question is asked
- kwargs – used for other information about the question
Returns: the number from [0, 1] representing the probability of the correct answer
Return type: float
-
prepare_phase
(environment, user, item, time, **kwargs)[source]¶ In this phase, the predictive model touches the environment, loads all necessary data and returns it.
Parameters: - environment (proso.models.environment.Environment) – environment where all the important data are persist
- user (int) – identifier of the user answering the question
- item (int) – identifier of the question item
- time (datetime.datetime) – datetime when the question is asked
- kwargs – used for other information about the question
Returns: object
-
update_phase
(environment, data, prediction, user, item, correct, time, answer_id, **kwargs)[source]¶ After the prediction update the environment and persist some information for the predictive model.
Parameters: - environment (proso.models.environment.Environment) – environment where all the important data are persist
- data (object) – data from the prepare phase
- user (int) – identifier of the user answering the question
- item (int) – identifier of the question item
- correct (bool) – corretness of the answer
-
class
proso.models.prediction.
PriorCurrentPredictiveModel
(time_shift=80.0, pfae_good=3.4, pfae_bad=0.3, elo_alpha=0.8, elo_dynamic_alpha=0.05)[source]¶
-
class
proso.models.prediction.
SimplePredictiveModel
[source]¶ Bases:
proso.models.prediction.PredictiveModel
Predictive model which doesn’t force you to use environment.
-
proso.models.prediction.
predict
(skill_asked, option_skills)[source]¶ Returns the probability of correct answer.
Parameters: - skill_asked (float) – number representing a knowledge of the given user for the asked item
- option_skills ([float]) – list of numbers representing a knowledge for the options
Returns: probability of the correct answer for the asked item and the probabilities for the options they will be answered instead of the asked item
Return type: (float, [float])