summerschool_simtech_2023/material/1_mon/firststeps/tasks.qmd
2023-09-28 14:18:35 +00:00

46 lines
2.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Task 1 {#1}
## Wait - how do I even run things in Julia/VScode?
Typically, you work in a Julia script ending in `scriptname.jl`
You concurrently have a REPL open, to not reload all packages etc. everytime. Further you typically have `Revise.jl` running in the background to automatically update your custom Packages / Modules (more to that later).
You can mark some code and execute it using `ctrl` + `enter` - you can also generate code-blocks using `#---` and run a whole code-block using `alt`+`enter`
## The exercise
1. Open a new script `statistic_functions.jl` in VSCode in a folder of your choice.
2. implement a function called `rse_sum`^[rse = research software engineering, we could use `sum` in a principled way, but it requires some knowledge you likely don't have right now]. This function should return `true` if provided with the following test: `res_sum(1:36) == 666`. You should further make use of a for-loop.
3. implement a second function called `rse_mean`, which calculates the mean of the provided vector. Make sure to use the `rse_sum` function! Test it using `res_mean(-15:17) == 1`
4. Next implement a standard deviation function `rse_std`: $\sqrt{\frac{\sum(x-mean(x))}{n-1}}$, this time you should use elementwise/broadcasting operators. Test it with `rse_std(1:3) == 1`
5. Finally, we will implement `rse_tstat`, returning the t-value with `length(x)-1` DF, that the provided Array actually has a mean of 0. Test it with `rse_tstat(2:3) == 5`. Add the keyword argument `σ` that allows the user to optionally provide a pre-calculated standard deviation.
Well done! You now have all functions defined with which we will continue our journey.
::: callout
## Bonus Task ProgressMeter
for very large sums we might want to add a progressmeter. To do so:
```julia
]add ProgressMeter
using ProgressMeter
...
@showprogress for ...
```
:::
And that's it! You should have a nice progress bar now
# Task 2 {#2}
1. Implement a type `StatResult` with fields for `x`, `n`, `std` and `tvalue`
2. Implement an outer constructor that can run `StatResult(2:10)` and return the full type including the calculated t-values.
3. Implement a function `length` for `StatResult` to multiple-dispatch on
4. **Optional:** If you have time, optimize the functions, so that mean, sum, length, std etc. is not calculated multiple times - you might want to rewrite your type. Note: This is a bit tricky :)