QuizGenerator 0.4.2__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.
Files changed (52) hide show
  1. QuizGenerator/README.md +5 -0
  2. QuizGenerator/__init__.py +27 -0
  3. QuizGenerator/__main__.py +7 -0
  4. QuizGenerator/canvas/__init__.py +13 -0
  5. QuizGenerator/canvas/canvas_interface.py +627 -0
  6. QuizGenerator/canvas/classes.py +235 -0
  7. QuizGenerator/constants.py +149 -0
  8. QuizGenerator/contentast.py +1955 -0
  9. QuizGenerator/generate.py +253 -0
  10. QuizGenerator/logging.yaml +55 -0
  11. QuizGenerator/misc.py +579 -0
  12. QuizGenerator/mixins.py +548 -0
  13. QuizGenerator/performance.py +202 -0
  14. QuizGenerator/premade_questions/__init__.py +0 -0
  15. QuizGenerator/premade_questions/basic.py +103 -0
  16. QuizGenerator/premade_questions/cst334/__init__.py +1 -0
  17. QuizGenerator/premade_questions/cst334/languages.py +391 -0
  18. QuizGenerator/premade_questions/cst334/math_questions.py +297 -0
  19. QuizGenerator/premade_questions/cst334/memory_questions.py +1400 -0
  20. QuizGenerator/premade_questions/cst334/ostep13_vsfs.py +572 -0
  21. QuizGenerator/premade_questions/cst334/persistence_questions.py +451 -0
  22. QuizGenerator/premade_questions/cst334/process.py +648 -0
  23. QuizGenerator/premade_questions/cst463/__init__.py +0 -0
  24. QuizGenerator/premade_questions/cst463/gradient_descent/__init__.py +3 -0
  25. QuizGenerator/premade_questions/cst463/gradient_descent/gradient_calculation.py +369 -0
  26. QuizGenerator/premade_questions/cst463/gradient_descent/gradient_descent_questions.py +305 -0
  27. QuizGenerator/premade_questions/cst463/gradient_descent/loss_calculations.py +650 -0
  28. QuizGenerator/premade_questions/cst463/gradient_descent/misc.py +73 -0
  29. QuizGenerator/premade_questions/cst463/math_and_data/__init__.py +2 -0
  30. QuizGenerator/premade_questions/cst463/math_and_data/matrix_questions.py +631 -0
  31. QuizGenerator/premade_questions/cst463/math_and_data/vector_questions.py +534 -0
  32. QuizGenerator/premade_questions/cst463/models/__init__.py +0 -0
  33. QuizGenerator/premade_questions/cst463/models/attention.py +192 -0
  34. QuizGenerator/premade_questions/cst463/models/cnns.py +186 -0
  35. QuizGenerator/premade_questions/cst463/models/matrices.py +24 -0
  36. QuizGenerator/premade_questions/cst463/models/rnns.py +202 -0
  37. QuizGenerator/premade_questions/cst463/models/text.py +203 -0
  38. QuizGenerator/premade_questions/cst463/models/weight_counting.py +227 -0
  39. QuizGenerator/premade_questions/cst463/neural-network-basics/__init__.py +6 -0
  40. QuizGenerator/premade_questions/cst463/neural-network-basics/neural_network_questions.py +1314 -0
  41. QuizGenerator/premade_questions/cst463/tensorflow-intro/__init__.py +6 -0
  42. QuizGenerator/premade_questions/cst463/tensorflow-intro/tensorflow_questions.py +936 -0
  43. QuizGenerator/qrcode_generator.py +293 -0
  44. QuizGenerator/question.py +715 -0
  45. QuizGenerator/quiz.py +467 -0
  46. QuizGenerator/regenerate.py +472 -0
  47. QuizGenerator/typst_utils.py +113 -0
  48. quizgenerator-0.4.2.dist-info/METADATA +265 -0
  49. quizgenerator-0.4.2.dist-info/RECORD +52 -0
  50. quizgenerator-0.4.2.dist-info/WHEEL +4 -0
  51. quizgenerator-0.4.2.dist-info/entry_points.txt +3 -0
  52. quizgenerator-0.4.2.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,73 @@
1
+
2
+ from typing import List, Tuple, Callable, Union, Any
3
+ import sympy as sp
4
+
5
+ from QuizGenerator.misc import Answer
6
+
7
+ def generate_function(rng, num_variables: int, max_degree: int, use_quadratic: bool = True) -> tuple[Any, sp.Expr, sp.MutableDenseMatrix, sp.Equality]:
8
+ """
9
+ Generate a function, its gradient, LaTeX representation, and optimal point using SymPy.
10
+ Returns: (variables, function, gradient_function, equation)
11
+
12
+ Args:
13
+ rng: Random number generator
14
+ num_variables: Number of variables in the function
15
+ max_degree: Maximum degree of polynomial terms (only used if use_quadratic=False)
16
+ use_quadratic: If True, generates well-conditioned quadratic functions that converge nicely.
17
+ If False, uses the original random polynomial generation.
18
+ """
19
+ # Create variable symbols
20
+ var_names = [f'x_{i}' for i in range(num_variables)]
21
+ variables = sp.symbols(var_names) # returns a tuple; robust when n==1
22
+
23
+ if use_quadratic:
24
+ # Generate well-conditioned quadratic function: f = sum of (x_i - center_i)^2 terms
25
+ # This creates a paraboloid with a clear minimum at (center_0, center_1, ...)
26
+
27
+ # Random center point (small integers for clean calculations)
28
+ centers = [rng.choice([-2, -1, 0, 1, 2]) for _ in range(num_variables)]
29
+
30
+ # Random positive coefficients for each squared term (keeps function convex)
31
+ # Use small values (0.5 to 2) to avoid huge gradients
32
+ coeffs = [rng.choice([0.5, 1, 1.5, 2]) for _ in range(num_variables)]
33
+
34
+ # Build quadratic: sum of coeff_i * (x_i - center_i)^2
35
+ poly = sp.Add(*[
36
+ coeffs[i] * (variables[i] - centers[i])**2
37
+ for i in range(num_variables)
38
+ ])
39
+
40
+ else:
41
+ # Original random polynomial generation (may not converge well)
42
+ # monomials up to max_degree; drop constant 1
43
+ terms = [m for m in sp.polys.itermonomials(variables, max_degree) if m != 1]
44
+
45
+ # random nonzero integer coefficients in [-10,-1] ∪ [1,9]
46
+ coeff_pool = [*range(-10, 0), *range(1, 10)]
47
+
48
+ # polynomial; if no terms (e.g., max_degree==0), fall back to 0
49
+ poly = sp.Add(*(rng.choice(coeff_pool) * t for t in terms)) if terms else sp.Integer(0)
50
+
51
+ # f(x_1, ..., x_n) = poly
52
+ f = sp.Function('f')
53
+ function = poly
54
+ gradient_function = sp.Matrix([poly.diff(v) for v in variables])
55
+ equation = sp.Eq(f(*variables), poly)
56
+
57
+ return variables, function, gradient_function, equation
58
+
59
+
60
+ def format_vector(vec: List[float]) -> str:
61
+
62
+ vector_string = ', '.join(
63
+ [
64
+ sorted(Answer.accepted_strings(v), key=lambda s: len(s))[0]
65
+ for v in vec
66
+ ]
67
+ )
68
+
69
+ if len(vec) == 1:
70
+ return vector_string
71
+ else:
72
+ return f"({vector_string})"
73
+
@@ -0,0 +1,2 @@
1
+ from .matrix_questions import MatrixAddition, MatrixScalarMultiplication, MatrixMultiplication
2
+ from .vector_questions import VectorAddition, VectorScalarMultiplication, VectorDotProduct, VectorMagnitude