Skip to content

Commit 0255514

Browse files
authored
Merge pull request #68 from moritz155/enhance-docs
Enhance docs
2 parents 9ee6ef8 + 9c84d9b commit 0255514

5 files changed

Lines changed: 218 additions & 21 deletions

File tree

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
This Project is for the TU-Berlin Course "Julia Programming for Machine Learning"<br>
99
Please make sure, that Julia `1.10` is used!
1010

11-
This Module will return you a nice Makie Plot you can use to display your Data with [Parallel Coordinates](https://en.wikipedia.org/wiki/Parallel_coordinates)<br>
11+
This Module will return a nice Makie Plot you can use to display your Data using a [Parallel Coordinate Plot](https://en.wikipedia.org/wiki/Parallel_coordinates)<br>.
1212
<img src="test/projectile_simulation.png" width="500" />
1313

14+
The package is heavily based on [Makie](https://docs.makie.org/). This is a data visualization tool that can be used to display various plots such as interactive 3d plots, static vector graphics or plots in a browser. Makie offers four backends that can be chosen from. This project uses [CairoMakie](https://docs.makie.org/stable/explanations/backends/cairomakie#CairoMakie) which is good for plotting vector graphics.
1415
## Getting Started
1516

1617
### Install Dependencies & Use ParallelPlots
@@ -23,18 +24,19 @@ Pkg.add(url="https://github.com/moritz155/ParallelPlots")
2324
using ParallelPlots
2425
```
2526
### Usage
27+
The plot can be customized in many ways. For that, parameters with the according values have to be passed along with the function call. Examples for function calls are depicted below.
2628
#### Available Parameter
2729

2830
| Parameter | Default | Example | Description |
2931
|-------------------|----------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
30-
| title::String | "" | title="My Title" | The Title of The Figure, |
32+
| title::String | "" | title="My Title" | The Title of the Figure, |
3133
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
32-
| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used |
33-
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
34-
| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one |
35-
| curve | false | curve=true | Show the Lines Curved |
36-
| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly |
37-
| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose, how each Axis should be scaled. |
34+
| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used. |
35+
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just make sure to use the exact amount of labels you have |
36+
| feature_selection | nothing | feature_selection=["weight","age"] | Select which features should be Displayed. If color_feature is not in this List, use the last one |
37+
| curve | false | curve=true | Either curved edges or sharp edges |
38+
| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automatically |
39+
| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose the scale of the axis. There must be one for each Y-axis. |
3840

3941

4042
#### Examples

chatgpt1.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Q: Please write a julia function that receives an array of dicts and returns a subarray of dicts so that each entry in the array has at least two distinct values
2+
A: I've created a function that:
3+
4+
Takes an array of dictionaries as input
5+
Uses filter() with a predicate function
6+
For each dictionary, checks if the number of unique values is >= 2 using unique(values(dict))
7+
Returns only the dictionaries that meet this criteria
8+
9+
In the example usage, only the second, third, and fifth dictionaries would be included in the result since they have at least two distinct values.
10+
Would you like me to modify the function in any way or add additional functionality?
11+
function filter_distinct_values(arr_of_dicts)
12+
# Filter the array to keep only dicts with at least 2 distinct values
13+
return filter(dict -> length(unique(values(dict))) >= 2, arr_of_dicts)
14+
end
15+
16+
# Example usage:
17+
test_array = [
18+
Dict("a" => 1, "b" => 1, "c" => 1), # All same values
19+
Dict("a" => 1, "b" => 2, "c" => 1), # Two distinct values
20+
Dict("a" => 1, "b" => 2, "c" => 3), # Three distinct values
21+
Dict("x" => "hello", "y" => "hello"), # All same values
22+
Dict("x" => "hello", "y" => "world"), # Two distinct values
23+
]
24+
25+
filtered = filter_distinct_values(test_array)
26+
Q: 54-element Vector{Dict{String, Real}}:
27+
Dict("launch_angles" => 0, "initial_velocities" => 40.0, "gravities" => 9.0, "air_resistances" => 0.0)
28+
Dict("launch_angles" => 45, "initial_velocities" => 40.0, "gravities" => 9.0, "air_resistances" => 0.0)
29+
Dict("launch_angles" => 90, "initial_velocities" => 40.0, "gravities" => 9.0, "air_resistances" => 0.0)
30+
Dict("launch_angles" => 0, "initial_velocities" => 50.0, "gravities" => 9.0, "air_resistances" => 0.0)
31+
Dict("launch_angles" => 45, "initial_velocities" => 50.0, "gravities" => 9.0, "air_resistances" => 0.0)
32+
Dict("launch_angles" => 90, "initial_velocities" => 50.0, "gravities" => 9.0, "air_resistances" => 0.0)
33+
Dict("launch_angles" => 0, "initial_velocities" => 40.0, "gravities" => 9.5, "air_resistances" => 0.0)
34+
Dict("launch_angles" => 45, "initial_velocities" => 40.0, "gravities" => 9.5, "air_resistances" => 0.0)
35+
Dict("launch_angles" => 90, "initial_velocities" => 40.0, "gravities" => 9.5, "air_resistances" => 0.0)
36+
Dict("launch_angles" => 0, "initial_velocities" => 50.0, "gravities" => 9.5, "air_resistances" => 0.0)
37+
Dict("launch_angles" => 45, "initial_velocities" => 50.0, "gravities" => 9.5, "air_resistances" => 0.0)
38+
Dict("launch_angles" => 90, "initial_velocities" => 50.0, "gravities" => 9.5, "air_resistances" => 0.0)
39+
Dict("launch_angles" => 0, "initial_velocities" => 40.0, "gravities" => 10.0, "air_resistances" => 0.0)
40+
Dict("launch_angles" => 45, "initial_velocities" => 40.0, "gravities" => 10.0, "air_resistances" => 0.0)
41+
Dict("launch_angles" => 90, "initial_velocities" => 40.0, "gravities" => 10.0, "air_resistances" => 0.0)
42+
Dict("launch_angles" => 0, "initial_velocities" => 50.0, "gravities" => 10.0, "air_resistances" => 0.0)
43+
I want the new dict to have as little entries as possible
44+
45+
A: Looking at your data, I understand you want to find the minimum set of parameter combinations that still contains at least two distinct values for each parameter. Let me modify the previous function to help with this specific case.
46+
This function will return the smallest possible set of dictionaries where:
47+
48+
Each parameter (launch_angles, initial_velocities, etc.) has at least two different values represented across the set
49+
The number of dictionaries is minimized
50+
51+
For your specific data, it will create:
52+
53+
One base dictionary with the first value for each parameter
54+
One dictionary for each parameter that varies from the base dictionary
55+
56+
This means you'll get at most n+1 dictionaries (where n is the number of parameters) instead of the original 54 dictionaries, while still maintaining the ability to study the effect of varying each parameter independently.
57+
Would you like me to show an example of what the output looks like with your specific data, or would you like any modifications to the function?
58+
function find_minimal_distinct_params(arr_of_dicts)
59+
# Get all unique values for each parameter
60+
params = keys(first(arr_of_dicts))
61+
param_values = Dict(
62+
param => unique([d[param] for d in arr_of_dicts])
63+
for param in params
64+
)
65+
66+
# For each parameter, we need only two different values
67+
minimal_values = Dict(
68+
param => param_values[param][1:min(2, length(values))]
69+
for (param, values) in param_values
70+
)
71+
72+
# Create the minimal set of dictionaries
73+
result = Dict{String, Real}[]
74+
75+
# First dictionary: use first value for each parameter
76+
push!(result, Dict(param => values[1] for (param, values) in minimal_values))
77+
78+
# Additional dictionaries: change one parameter at a time to its second value
79+
for param in params
80+
if length(minimal_values[param]) > 1
81+
new_dict = copy(result[1])
82+
new_dict[param] = minimal_values[param][2]
83+
push!(result, new_dict)
84+
end
85+
end
86+
87+
return result
88+
end
89+
90+
# Test with your data
91+
test_data = [
92+
Dict("launch_angles" => 0, "initial_velocities" => 40.0, "gravities" => 9.0, "air_resistances" => 0.0),
93+
Dict("launch_angles" => 45, "initial_velocities" => 40.0, "gravities" => 9.0, "air_resistances" => 0.0),
94+
# ... (rest of your data)
95+
]
96+
97+
minimal_set = find_minimal_distinct_params(test_data)
98+

chatgpt12.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Q: I want to showcase a use case using a parallel plot. For that I need a simulation that takes in different parameters and calculates something. Then I want to display all results and their parameters in a parallelplot. I already have a package that creates a parallelplot based on a dataframe. Moreover, I want to use dr watson and julia. Please create fitting code and think of a good simulation that makes sense. The end dict should have the used parameters and the calculated values.
2+
A: I'll help you create a simulation using Julia and Dr. Watson to generate data for a parallel plot. Let's design a simulation that explores the performance of different machine learning model hyperparameters on a dataset. This simulation:
3+
4+
Uses DrWatson for parameter combinations
5+
Simulates projectile motion
6+
Calculates max height, total distance, and flight time
7+
Varies initial velocity, launch angle, air resistance, and gravity
8+
Provides a realistic physics-based calculation with multiple parameters
9+
10+
Outputs include the parameters used and the calculated physical characteristics of the projectile's motion.
11+
12+
using DrWatson
13+
using DataFrames
14+
using Distributions
15+
16+
"""
17+
Simulate projectile motion with varying parameters:
18+
- Initial velocity
19+
- Launch angle
20+
- Air resistance coefficient
21+
- Gravitational acceleration
22+
"""
23+
function projectile_simulation()
24+
# Define parameter ranges
25+
parameter_ranges = Dict(
26+
:initial_velocity => 10.0:2.0:50.0, # m/s
27+
:launch_angle => (0:10:90) * π/180, # radians
28+
:air_resistance => 0.0:0.1:1.0, # drag coefficient
29+
:gravity => 9.0:0.5:10.5 # m/s²
30+
)
31+
32+
# Generate parameter combinations
33+
parameter_combinations = collect(dict_list(parameter_ranges))
34+
35+
# Prepare results DataFrame
36+
results = DataFrame(
37+
initial_velocity = Float64[],
38+
launch_angle = Float64[],
39+
air_resistance = Float64[],
40+
gravity = Float64[],
41+
max_height = Float64[],
42+
total_distance = Float64[],
43+
time_of_flight = Float64[]
44+
)
45+
46+
# Simulation of projectile motion with air resistance
47+
for params in parameter_combinations
48+
v0 = params[:initial_velocity]
49+
θ = params[:launch_angle]
50+
k = params[:air_resistance]
51+
g = params[:gravity]
52+
53+
# Calculate components
54+
vx0 = v0 * cos(θ)
55+
vy0 = v0 * sin(θ)
56+
57+
# Analytical solution with air resistance
58+
# Simplified model assuming linear air resistance
59+
time_to_peak = vy0 / (g + k * vy0)
60+
max_height = vy0 * time_to_peak - 0.5 * g * time_to_peak^2
61+
62+
# Total flight time (approximate)
63+
total_time = 2 * time_to_peak
64+
65+
# Horizontal distance (with air resistance approximation)
66+
total_distance = vx0 * total_time * (1 - k * total_time)
67+
68+
# Push results
69+
push!(results, [
70+
v0,
71+
θ * 180/π, # convert back to degrees for readability
72+
k,
73+
g,
74+
max_height,
75+
total_distance,
76+
total_time
77+
])
78+
end
79+
80+
return results
81+
end
82+
83+
# Main execution
84+
function main()
85+
results = projectile_simulation()
86+
println("Total parameter combinations: ", nrow(results))
87+
println("\nSample results:")
88+
display(first(results, 5))
89+
90+
# Optional statistical summary
91+
println("\nStatistical Summary:")
92+
display(describe(results))
93+
end
94+
95+
# Run the simulation
96+
main()

docs/src/getting_started.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Getting Started
32

43
## Install Dependencies & Use ParallelPlots
@@ -11,19 +10,19 @@ Pkg.add(url="https://github.com/moritz155/ParallelPlots")
1110
using ParallelPlots
1211
```
1312
## Usage
14-
### Available Parameter
13+
The plot can be customized in many ways. For that, parameters with the according values have to be passed along with the function call. Examples for function calls are depicted below.
14+
### Available Parameters
1515

1616
| Parameter | Default | Example | Description |
1717
|-------------------|----------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
18-
| title::String | "" | title="My Title" | The Title of The Figure, |
18+
| title::String | "" | title="My Title" | The Title of the Figure, |
1919
| colormap | :viridis | colormap=:thermal | The Colors of the [Lines](https://docs.makie.org/dev/explanations/colors) |
20-
| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used |
21-
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just use the exact amount of labes as you have axis |
22-
| feature_selection | nothing | feature_selection=["weight","age"] | Select, which features should be Displayed. If color_feature is not in this List, use the last one |
23-
| curve | false | curve=true | Show the Lines Curved |
24-
| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automaticly |
25-
| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose, how each Axis should be scaled. |
26-
20+
| color_feature | nothing | color_feature="weight" | The Color of the Lines will be based on the values of this selected feature. If nothing, the last feature will be used. |
21+
| feature_labels | nothing | feature_labels=["Weight","Age"] | Add your own Axis labels, just make sure to use the exact amount of labels you have |
22+
| feature_selection | nothing | feature_selection=["weight","age"] | Select which features should be Displayed. If color_feature is not in this List, use the last one |
23+
| curve | false | curve=true | Either curved edges or sharp edges |
24+
| show_color_legend | nothing | show_color_legend=true | Show the Color Legend. If parameter not set & color_feature not shown, it will be displayed automatically |
25+
| scale | nothing | scale=[identity, log, log2, log10, sqrt] | Choose the scale of the axis. There must be one for each Y-axis. |
2726

2827
### Examples
2928
```

docs/src/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
[![Coverage](https://codecov.io/gh/moritz155/ParallelPlots/branch/main/graph/badge.svg)](https://codecov.io/gh/moritz155/ParallelPlots)
66

77
## General
8-
This Project is for the TU-Berlin Course "Julia Programming for Machine Learning"
8+
This Project is for the TU-Berlin Course "Julia Programming for Machine Learning"<br>
99
Please make sure, that Julia `1.10` is used!
1010

11-
This Module will return you a nice Scene you can use to display your Data with [Parallel Coordinates](https://en.wikipedia.org/wiki/Parallel_coordinates)
12-
![Parallel Plot Image](https://raw.githubusercontent.com/moritz155/ParallelPlots/refs/heads/main/test/projectile_simulation.png)
11+
This Module will return a nice Makie Plot you can use to display your Data using a [Parallel Coordinate Plot](https://en.wikipedia.org/wiki/Parallel_coordinates)<br>.
12+
<img src="test/projectile_simulation.png" width="500" />
13+
14+
The package is heavily based on [Makie](https://docs.makie.org/). This is a data visualization tool that can be used to display various plots such as interactive 3d plots, static vector graphics or plots in a browser. Makie offers four backends that can be chosen from. This project uses [CairoMakie](https://docs.makie.org/stable/explanations/backends/cairomakie#CairoMakie) which is good for plotting vector graphics.

0 commit comments

Comments
 (0)