QuizGenerator 0.8.1__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.
- QuizGenerator/contentast.py +1 -1
- QuizGenerator/generate.py +1 -1
- QuizGenerator/mixins.py +6 -2
- QuizGenerator/premade_questions/basic.py +49 -7
- QuizGenerator/premade_questions/cst463/gradient_descent/gradient_calculation.py +92 -82
- QuizGenerator/premade_questions/cst463/gradient_descent/gradient_descent_questions.py +68 -45
- QuizGenerator/premade_questions/cst463/gradient_descent/loss_calculations.py +235 -162
- QuizGenerator/premade_questions/cst463/neural-network-basics/neural_network_questions.py +51 -45
- QuizGenerator/premade_questions/cst463/tensorflow-intro/tensorflow_questions.py +212 -215
- QuizGenerator/question.py +139 -18
- {quizgenerator-0.8.1.dist-info → quizgenerator-0.9.0.dist-info}/METADATA +9 -6
- {quizgenerator-0.8.1.dist-info → quizgenerator-0.9.0.dist-info}/RECORD +15 -15
- {quizgenerator-0.8.1.dist-info → quizgenerator-0.9.0.dist-info}/WHEEL +0 -0
- {quizgenerator-0.8.1.dist-info → quizgenerator-0.9.0.dist-info}/entry_points.txt +0 -0
- {quizgenerator-0.8.1.dist-info → quizgenerator-0.9.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
574
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
715
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
self.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1001
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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([
|