exercise_template.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. """
  3. Day {{DAY_N}}: {{TOPIC_NAME}}
  4. The Math Skeleton - Pure numpy/torch operations, no high-level APIs
  5. Expected functions:
  6. - def {{function_name}}(): # Your implementation here
  7. """
  8. import numpy as np
  9. import torch
  10. import matplotlib.pyplot as plt
  11. from typing import Tuple
  12. # Configure visualization
  13. plt.style.use('seaborn-v0_8-darkgrid')
  14. def {{function_name}}({{parameters}}):
  15. """
  16. {{brief_description}}
  17. Parameters:
  18. {{param1}}: {{param1_type}} - {{param1_desc}}
  19. {{param2}}: {{param2_type}} - {{param2_desc}}
  20. Returns:
  21. {{return_type}}: {{return_desc}}
  22. """
  23. # TODO: Implement the mathematical operation
  24. # Your math translation here...
  25. # Example: numpy implementation
  26. return result
  27. def plot_concept():
  28. """
  29. Visualize the concept with matplotlib.
  30. Include this in your solution.
  31. Typical visualizations:
  32. - Loss contours
  33. - Activation functions
  34. - Geometric interpretations
  35. """
  36. fig, ax = plt.subplots(figsize=(10, 6))
  37. # TODO: Add your visualization logic here
  38. ax.set_xlabel('{{x_label}}')
  39. ax.set_ylabel('{{y_label}}')
  40. ax.set_title('{{visualization_title}}')
  41. ax.legend()
  42. plt.tight_layout()
  43. plt.show()
  44. if __name__ == "__main__":
  45. # Manual testing
  46. print(f"Testing Day {{DAY_N}}: {{TOPIC_NAME}}")
  47. # Test the core function
  48. result = {{function_name}}()
  49. print(f"Result: {result}")
  50. # Run the visualizer
  51. plot_concept()