From a3e1b2a70ae84964b0ce32c4716f328cb06f54d1 Mon Sep 17 00:00:00 2001 From: nnnyt <793313994@qq.com> Date: Wed, 13 Jan 2021 22:27:23 +0800 Subject: [PATCH] add abstract strategy and random strategy --- CAT/strategy/__init__.py | 2 ++ CAT/strategy/abstract_strategy.py | 24 ++++++++++++++++++++++++ CAT/strategy/random_strategy.py | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 CAT/strategy/__init__.py create mode 100644 CAT/strategy/abstract_strategy.py create mode 100644 CAT/strategy/random_strategy.py diff --git a/CAT/strategy/__init__.py b/CAT/strategy/__init__.py new file mode 100644 index 0000000..a368902 --- /dev/null +++ b/CAT/strategy/__init__.py @@ -0,0 +1,2 @@ +from .abstract_strategy import AbstractStrategy +from .random_strategy import RandomStrategy \ No newline at end of file diff --git a/CAT/strategy/abstract_strategy.py b/CAT/strategy/abstract_strategy.py new file mode 100644 index 0000000..dca07a7 --- /dev/null +++ b/CAT/strategy/abstract_strategy.py @@ -0,0 +1,24 @@ +from abc import ABC, abstractmethod + + +class AbstractStrategy(ABC): + + @property + @abstractmethod + def name(self): + """ the name of the strategy + Returns: + name: str + """ + raise NotImplementedError + + @abstractmethod + def adaptest_select(self, model, adaptest_data): + """ + Args: + model: AbstractModel + adaptest_data: AdapTestDataset + Returns: + selected_questions: dict, {student_idx: question_idx} + """ + raise NotImplementedError \ No newline at end of file diff --git a/CAT/strategy/random_strategy.py b/CAT/strategy/random_strategy.py new file mode 100644 index 0000000..23eea37 --- /dev/null +++ b/CAT/strategy/random_strategy.py @@ -0,0 +1,21 @@ +import numpy as np +from .abstract_strategy import AbstractStrategy +from ..model import AbstractModel +from ..dataset import AdapTestDataset + + +class RandomStrategy(AbstractStrategy): + + def __init__(self): + super().__init__() + + @property + def name(self): + return 'Random Select Strategy' + + def adaptest_select(self, model: AbstractModel, adaptest_data: AdapTestDataset): + selection = {} + for sid in range(adaptest_data.num_students): + untested_questions = np.array(list(adaptest_data.untested[sid])) + selection[sid] = np.random.randint(len(untested_questions)) + return selection \ No newline at end of file