QuizGenerator 0.8.0__py3-none-any.whl → 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -352,7 +352,6 @@ class MatrixMultiplication(MatrixMathQuestion):
352
352
  answers.extend(table_answers)
353
353
  body.add_element(
354
354
  ca.OnlyHtml([
355
- ca.Paragraph(["Result matrix (use '-' if cell doesn't exist):"]),
356
355
  table
357
356
  ])
358
357
  )
@@ -73,23 +73,19 @@ class SimpleNeuralNetworkBase(MatrixQuestion, abc.ABC):
73
73
  self.da2_dz2 = None # Gradient of activation w.r.t. pre-activation
74
74
  self.dL_dz2 = None # Gradient of loss w.r.t. output pre-activation
75
75
 
76
- def _build_context(self, *, rng_seed=None, **kwargs):
77
- if "num_inputs" in kwargs:
78
- self.num_inputs = kwargs.get("num_inputs", self.num_inputs)
79
- if "num_hidden" in kwargs:
80
- self.num_hidden = kwargs.get("num_hidden", self.num_hidden)
81
- if "num_outputs" in kwargs:
82
- self.num_outputs = kwargs.get("num_outputs", self.num_outputs)
83
- if "use_bias" in kwargs:
84
- self.use_bias = kwargs.get("use_bias", self.use_bias)
85
- if "param_digits" in kwargs:
86
- self.param_digits = kwargs.get("param_digits", self.param_digits)
76
+ @classmethod
77
+ def _build_context(cls, *, rng_seed=None, **kwargs):
78
+ context = super()._build_context(rng_seed=rng_seed, **kwargs)
79
+ self = context
80
+
81
+ self.num_inputs = kwargs.get("num_inputs", getattr(self, "num_inputs", 2))
82
+ self.num_hidden = kwargs.get("num_hidden", getattr(self, "num_hidden", 2))
83
+ self.num_outputs = kwargs.get("num_outputs", getattr(self, "num_outputs", 1))
84
+ self.use_bias = kwargs.get("use_bias", getattr(self, "use_bias", True))
85
+ self.param_digits = kwargs.get("param_digits", getattr(self, "param_digits", 1))
87
86
 
88
87
  self.rng.seed(rng_seed)
89
88
  self._np_rng = np.random.RandomState(rng_seed)
90
-
91
- context = dict(kwargs)
92
- context["rng_seed"] = rng_seed
93
89
  return context
94
90
 
95
91
  def _generate_network(self, weight_range=(-2, 2), input_range=(-3, 3)):
@@ -570,8 +566,10 @@ class ForwardPassQuestion(SimpleNeuralNetworkBase):
570
566
  - Final output (ŷ)
571
567
  """
572
568
 
573
- def _build_context(self, *, rng_seed=None, **kwargs):
574
- super()._build_context(rng_seed=rng_seed, **kwargs)
569
+ @classmethod
570
+ def _build_context(cls, *, rng_seed=None, **kwargs):
571
+ context = super()._build_context(rng_seed=rng_seed, **kwargs)
572
+ self = context
575
573
 
576
574
  # Generate network
577
575
  self._generate_network()
@@ -579,13 +577,12 @@ class ForwardPassQuestion(SimpleNeuralNetworkBase):
579
577
 
580
578
  # Run forward pass to get correct answers
581
579
  self._forward_pass()
582
-
583
- context = dict(kwargs)
584
- context["rng_seed"] = rng_seed
585
580
  return context
586
581
 
587
- def _build_body(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
582
+ @classmethod
583
+ def _build_body(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
588
584
  """Build question body and collect answers."""
585
+ self = context
589
586
  body = ca.Section()
590
587
  answers = []
591
588
 
@@ -621,8 +618,10 @@ class ForwardPassQuestion(SimpleNeuralNetworkBase):
621
618
 
622
619
  return body, answers
623
620
 
624
- def _build_explanation(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
621
+ @classmethod
622
+ def _build_explanation(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
625
623
  """Build question explanation."""
624
+ self = context
626
625
  explanation = ca.Section()
627
626
 
628
627
  explanation.add_element(ca.Paragraph([
@@ -711,8 +710,10 @@ class BackpropGradientQuestion(SimpleNeuralNetworkBase):
711
710
  - Gradients for multiple specific weights (∂L/∂w)
712
711
  """
713
712
 
714
- def _build_context(self, *, rng_seed=None, **kwargs):
715
- super()._build_context(rng_seed=rng_seed, **kwargs)
713
+ @classmethod
714
+ def _build_context(cls, *, rng_seed=None, **kwargs):
715
+ context = super()._build_context(rng_seed=rng_seed, **kwargs)
716
+ self = context
716
717
 
717
718
  # Generate network
718
719
  self._generate_network()
@@ -731,13 +732,12 @@ class BackpropGradientQuestion(SimpleNeuralNetworkBase):
731
732
  # Round loss to display precision (4 decimal places)
732
733
  self.loss = round(self.loss, 4)
733
734
  self._compute_output_gradient()
734
-
735
- context = dict(kwargs)
736
- context["rng_seed"] = rng_seed
737
735
  return context
738
736
 
739
- def _build_body(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
737
+ @classmethod
738
+ def _build_body(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
740
739
  """Build question body and collect answers."""
740
+ self = context
741
741
  body = ca.Section()
742
742
  answers = []
743
743
 
@@ -785,8 +785,10 @@ class BackpropGradientQuestion(SimpleNeuralNetworkBase):
785
785
 
786
786
  return body, answers
787
787
 
788
- def _build_explanation(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
788
+ @classmethod
789
+ def _build_explanation(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
789
790
  """Build question explanation."""
791
+ self = context
790
792
  explanation = ca.Section()
791
793
 
792
794
  explanation.add_element(ca.Paragraph([
@@ -877,11 +879,11 @@ class EnsembleAveragingQuestion(Question):
877
879
  self.num_models = kwargs.get("num_models", 5)
878
880
  self.predictions = None
879
881
 
880
- def _build_context(self, *, rng_seed=None, **kwargs):
881
- if "num_models" in kwargs:
882
- self.num_models = kwargs.get("num_models", self.num_models)
883
-
884
- self.rng.seed(rng_seed)
882
+ @classmethod
883
+ def _build_context(cls, *, rng_seed=None, **kwargs):
884
+ context = super()._build_context(rng_seed=rng_seed, **kwargs)
885
+ self = context
886
+ self.num_models = kwargs.get("num_models", getattr(self, "num_models", 5))
885
887
 
886
888
  # Generate predictions from multiple models
887
889
  # Use a range that makes sense for typical regression problems
@@ -893,13 +895,12 @@ class EnsembleAveragingQuestion(Question):
893
895
 
894
896
  # Round to make calculations easier
895
897
  self.predictions = [round(p, 1) for p in self.predictions]
896
-
897
- context = dict(kwargs)
898
- context["rng_seed"] = rng_seed
899
898
  return context
900
899
 
901
- def _build_body(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
900
+ @classmethod
901
+ def _build_body(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
902
902
  """Build question body and collect answers."""
903
+ self = context
903
904
  body = ca.Section()
904
905
  answers = []
905
906
 
@@ -929,8 +930,10 @@ class EnsembleAveragingQuestion(Question):
929
930
 
930
931
  return body, answers
931
932
 
932
- def _build_explanation(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
933
+ @classmethod
934
+ def _build_explanation(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
933
935
  """Build question explanation."""
936
+ self = context
934
937
  explanation = ca.Section()
935
938
 
936
939
  explanation.add_element(ca.Paragraph([
@@ -997,8 +1000,10 @@ class EndToEndTrainingQuestion(SimpleNeuralNetworkBase):
997
1000
  self.new_W1 = None
998
1001
  self.new_W2 = None
999
1002
 
1000
- def _build_context(self, *, rng_seed=None, **kwargs):
1001
- super()._build_context(rng_seed=rng_seed, **kwargs)
1003
+ @classmethod
1004
+ def _build_context(cls, *, rng_seed=None, **kwargs):
1005
+ context = super()._build_context(rng_seed=rng_seed, **kwargs)
1006
+ self = context
1002
1007
 
1003
1008
  # Generate network
1004
1009
  self._generate_network()
@@ -1023,9 +1028,6 @@ class EndToEndTrainingQuestion(SimpleNeuralNetworkBase):
1023
1028
 
1024
1029
  # Compute updated weights
1025
1030
  self._compute_weight_updates()
1026
-
1027
- context = dict(kwargs)
1028
- context["rng_seed"] = rng_seed
1029
1031
  return context
1030
1032
 
1031
1033
  def _compute_weight_updates(self):
@@ -1042,8 +1044,10 @@ class EndToEndTrainingQuestion(SimpleNeuralNetworkBase):
1042
1044
  grad = self._compute_gradient_W1(0, j)
1043
1045
  self.new_W1[0, j] = self.W1[0, j] - self.learning_rate * grad
1044
1046
 
1045
- def _build_body(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
1047
+ @classmethod
1048
+ def _build_body(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
1046
1049
  """Build question body and collect answers."""
1050
+ self = context
1047
1051
  body = ca.Section()
1048
1052
  answers = []
1049
1053
 
@@ -1111,8 +1115,10 @@ class EndToEndTrainingQuestion(SimpleNeuralNetworkBase):
1111
1115
 
1112
1116
  return body, answers
1113
1117
 
1114
- def _build_explanation(self, context) -> Tuple[ca.Section, List[ca.Answer]]:
1118
+ @classmethod
1119
+ def _build_explanation(cls, context) -> Tuple[ca.Section, List[ca.Answer]]:
1115
1120
  """Build question explanation."""
1121
+ self = context
1116
1122
  explanation = ca.Section()
1117
1123
 
1118
1124
  explanation.add_element(ca.Paragraph([