Skip to content

Commit 512fd3a

Browse files
committed
prune old code
1 parent 8c17929 commit 512fd3a

1 file changed

Lines changed: 34 additions & 203 deletions

File tree

constellation/constellation.c

Lines changed: 34 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void CustomUpdateCamera(Camera *camera, float orbitSpeed) {
6161
const Color PUFF_CYAN = (Color){0, 187, 187, 255};
6262
const Color PUFF_WHITE = (Color){241, 241, 241, 241};
6363
const Color PUFF_BACKGROUND = (Color){6, 24, 24, 255};
64-
const Color CONSTELLATION = (Color){255, 255, 255, 128};
6564

6665
typedef struct Glyph {
6766
float x;
@@ -249,38 +248,6 @@ void draw_axes(PlotArgs args) {
249248
args.width - args.right_margin, args.height - args.bottom_margin, PUFF_WHITE);
250249
}
251250

252-
void draw_labels(PlotArgs args) {
253-
// X label
254-
Vector2 x_font_size = MeasureTextEx(args.font, args.x_label, args.axis_font_size, 0);
255-
DrawTextEx(
256-
args.font,
257-
args.x_label,
258-
(Vector2){
259-
args.width/2 - x_font_size.x/2,
260-
args.height - x_font_size.y,
261-
},
262-
args.axis_font_size,
263-
0,
264-
PUFF_WHITE
265-
);
266-
267-
// Y label
268-
Vector2 y_font_size = MeasureTextEx(args.font, args.y_label, args.axis_font_size, 0);
269-
DrawTextPro(
270-
args.font,
271-
args.y_label,
272-
(Vector2){
273-
0,
274-
args.height/2 + y_font_size.x/2
275-
},
276-
(Vector2){ 0, 0 },
277-
-90,
278-
args.axis_font_size,
279-
0,
280-
PUFF_WHITE
281-
);
282-
}
283-
284251
void draw_x_tick(char* label, float x_pos, PlotArgs args) {
285252
float y_pos = args.height - args.bottom_margin;
286253
DrawLine(
@@ -420,44 +387,6 @@ void draw_axes3() {
420387
);
421388
}
422389

423-
float hyper_min(Dataset *data, char* key, int start, int end) {
424-
float mmin = FLT_MAX;
425-
for (int env=start; env<end; env++) {
426-
for (int i=0; i<data->envs[env].n; i++) {
427-
Hyper* hyper = &data->envs[env].hypers[i];
428-
if (strcmp(hyper->key, key) != 0) {
429-
continue;
430-
}
431-
for (int j=0; j<hyper->n; j++) {
432-
float val = hyper->ary[j];
433-
if (val < mmin){
434-
mmin = val;
435-
}
436-
}
437-
}
438-
}
439-
return mmin;
440-
}
441-
442-
float hyper_max(Dataset *data, char* key, int start, int end) {
443-
float mmax = -FLT_MAX;
444-
for (int i=start; i<end; i++) {
445-
for (int j=0; j<data->envs[i].n; j++) {
446-
Hyper* hyper = &data->envs[i].hypers[j];
447-
if (strcmp(hyper->key, key) != 0) {
448-
continue;
449-
}
450-
for (int k=0; k<hyper->n; k++) {
451-
float val = hyper->ary[k];
452-
if (val > mmax){
453-
mmax = val;
454-
}
455-
}
456-
}
457-
}
458-
return mmax;
459-
}
460-
461390
void boxplot(Hyper* hyper, int x_scale, int i, int hyper_count, PlotArgs args, Color color, bool* filter) {
462391
int width = args.width;
463392
int height = args.height;
@@ -541,28 +470,6 @@ int cleanup(Hyper *map, int map_count, cJSON *root, char *json_str) {
541470
return 1;
542471
}
543472

544-
typedef struct GuiAxisScale {
545-
int x, y, axis_width, scale_width, height;
546-
char* axis_options;
547-
int axis_selection;
548-
bool axis_active;
549-
char* scale_options;
550-
int scale_selection;
551-
bool scale_active;
552-
char* scale_text;
553-
} GuiAxisScale;
554-
555-
void gui_axis_scale(GuiAxisScale *scale) {
556-
Rectangle axis_rect = {scale->x, scale->y, scale->axis_width, scale->height};
557-
if (GuiDropdownBox(axis_rect, scale->axis_options, &scale->axis_selection, scale->axis_active)) {
558-
scale->axis_active = !scale->axis_active;
559-
}
560-
Rectangle scale_rect = {scale->x + axis_rect.width , scale->y, scale->scale_width, scale->height};
561-
if (GuiDropdownBox(scale_rect, scale->scale_options, &scale->scale_selection, scale->scale_active)) {
562-
scale->scale_active = !scale->scale_active;
563-
}
564-
}
565-
566473
void GuiDropdownCheckbox(int x, int y, char* options, int *selection, bool *active, char *text, bool *checked) {
567474
Rectangle rect = {x, y, DROPDOWN_WIDTH, SETTINGS_HEIGHT};
568475
if (GuiDropdownBox(rect, options, selection, *active)) {
@@ -599,15 +506,6 @@ void apply_filter(bool* filter, Hyper* param, float min, float max) {
599506
}
600507
}
601508

602-
float scale_param(float val, float min, float max, bool log) {
603-
if (log) {
604-
val = safe_log10(val);
605-
min = safe_log10(min);
606-
max = safe_log10(max);
607-
}
608-
return (val - min)/(max - min);
609-
}
610-
611509
void autoscale(Point* points, int size, PlotArgs *args) {
612510
float x_min = FLT_MAX;
613511
float x_max = -FLT_MAX;
@@ -759,32 +657,6 @@ void copy_hypers_to_clipboard(Env *env, char* buffer, int ary_idx) {
759657
SetClipboardText(start);
760658
}
761659

762-
void compute_constellation(Dataset *data, int* env_idxs, float* env_dists,
763-
float env_perf, float perf_threshold, Vector2 tsne, float tsne_thresh) {
764-
for (int i=0; i<data->n; i++) {
765-
Env* env = &data->envs[i];
766-
Hyper* perf = get_hyper(data, env->key, "env/perf");
767-
Hyper* tsne1 = get_hyper(data, env->key, "tsne1");
768-
Hyper* tsne2 = get_hyper(data, env->key, "tsne2");
769-
for (int j=0; j<tsne1->n; j++) {
770-
if (perf->ary[j] < perf_threshold) {
771-
continue;
772-
}
773-
float t1_dist = tsne1->ary[j] - tsne.x;
774-
float t2_dist = tsne2->ary[j] - tsne.y;
775-
float tsne_dist = t1_dist*t1_dist + t2_dist*t2_dist;
776-
if (tsne_dist > tsne_thresh) {
777-
continue;
778-
}
779-
if (tsne_dist < env_dists[i]) {
780-
env_dists[i] = tsne_dist;
781-
env_idxs[i] = j;
782-
}
783-
}
784-
}
785-
}
786-
787-
788660
//strof bottlenecks loads
789661
float fast_atof(char **s) {
790662
char *p = *s;
@@ -960,7 +832,7 @@ int main(void) {
960832
strcat(env_options, data.envs[i].key);
961833
}
962834

963-
char* clipboard = malloc(8192);
835+
char* clipboard = malloc(16384);
964836

965837
// Points
966838
Point* points = calloc(total_points, sizeof(Point));
@@ -993,7 +865,6 @@ int main(void) {
993865
glEnable(GL_PROGRAM_POINT_SIZE);
994866
#endif
995867

996-
Camera3D camera = (Camera3D){ 0 };
997868
PlotArgs args1 = DEFAULT_PLOT_ARGS;
998869
args1.camera = (Camera3D){ 0 };
999870
args1.camera.position = (Vector3){ 1.5f, 1.25f, 1.5f };
@@ -1039,25 +910,8 @@ int main(void) {
1039910

1040911
char* scale_options = "linear;log;logit";
1041912

1042-
/*
1043-
GuiAxisScale fig1x_opts = {
1044-
.x = DROPDOWN_WIDTH,
1045-
.y = 0,
1046-
.axis_width = DROPDOWN_WIDTH,
1047-
.scale_width = TOGGLE_WIDTH,
1048-
.height = SETTINGS_HEIGHT,
1049-
.axis_options = options,
1050-
.axis_selection = 0,
1051-
.axis_active = false,
1052-
.scale_options = "log;linear",
1053-
.scale_selection = 0,
1054-
.scale_active = false,
1055-
};
1056-
*/
1057-
1058913
PlotArgs args2 = DEFAULT_PLOT_ARGS;
1059914
RenderTexture2D fig2 = LoadRenderTexture(args2.width, args2.height);
1060-
//SetTextureFilter(fig2.texture, TEXTURE_FILTER_POINT);
1061915
args2.right_margin = 50;
1062916
args2.x_scale = 1;
1063917

@@ -1106,52 +960,7 @@ int main(void) {
1106960

1107961
Vector2 focus = {0, 0};
1108962

1109-
// Find best hypers
1110-
float tsne_thresh = 100.0f;
1111-
memset(best_n, 0, sizeof(int)*4);
1112-
memset(best_srci, 0, sizeof(int)*4);
1113-
for (int env_i=0; env_i<data.n; env_i++) {
1114-
Env* src = &data.envs[env_i];
1115-
Hyper* src_perf = get_hyper(&data, src->key, "env/perf");
1116-
Hyper* src_tsne1 = get_hyper(&data, src->key, "tsne1");
1117-
Hyper* src_tsne2 = get_hyper(&data, src->key, "tsne2");
1118-
for (int i=0; i<src_tsne1->n; i++) {
1119-
float perfi = src_perf->ary[i];
1120-
Vector2 tsnei = (Vector2){src_tsne1->ary[i], src_tsne2->ary[i]};
1121-
for (int ki=0; ki<4; ki++) {
1122-
if (perfi < perf_thresholds[ki]) {
1123-
continue;
1124-
}
1125-
for (int kj=0; kj<data.n; kj++) {
1126-
temp_idx[ki][kj] = -1;
1127-
temp_dist[ki][kj] = FLT_MAX;
1128-
}
1129-
compute_constellation(&data, temp_idx[ki], temp_dist[ki], perfi, perf_thresholds[ki], tsnei, tsne_thresh);
1130-
int temp_n = 0;
1131-
for (int kj=0; kj<data.n; kj++) {
1132-
if (temp_idx[ki][kj] != -1) {
1133-
temp_n++;
1134-
}
1135-
}
1136-
if (temp_n > best_n[ki]) {
1137-
best_n[ki] = temp_n;
1138-
best_srci[ki] = env_i;
1139-
for (int kj=0; kj<data.n; kj++) {
1140-
best_idx[ki][kj] = temp_idx[ki][kj];
1141-
}
1142-
if (best_idx[ki][env_i] == -1) {
1143-
compute_constellation(&data, temp_idx[ki], temp_dist[ki], perfi, perf_thresholds[ki], tsnei, tsne_thresh);
1144-
printf("Error: Best index not found\n");
1145-
exit(1);
1146-
}
1147-
}
1148-
}
1149-
}
1150-
}
1151-
1152-
1153963
while (!WindowShouldClose()) {
1154-
int screen_points_count = 0;
1155964
bool right_clicked = false;
1156965

1157966
BeginDrawing();
@@ -1531,16 +1340,6 @@ int main(void) {
15311340
Vector2 tsne = (Vector2){tsne1, tsne2};
15321341

15331342
if (tooltip.active) {
1534-
/*
1535-
float idx[env->n];
1536-
float dist[env->n];
1537-
compute_constellation(&data, idx, dist, perf, perf, tsne, tsne_thresh);
1538-
for (int i=0; i<env->n; i++) {
1539-
if (idx[i] == -1) {
1540-
continue;
1541-
}
1542-
*/
1543-
15441343
char* text = TextFormat("%s\nscore = %f\ncost = %f\nsteps = %f", env_key, score, cost, steps);
15451344
Vector2 text_size = MeasureTextEx(args1.font_small, text, args1.axis_tick_font_size, 0);
15461345
float x = tooltip.x;
@@ -1564,7 +1363,39 @@ int main(void) {
15641363
}
15651364
}
15661365

1366+
// Cleanup
1367+
for (int i = 0; i < data.n; i++) {
1368+
for (int j = 0; j < envs[i].n; j++) {
1369+
free(envs[i].hypers[j].ary);
1370+
}
1371+
free(envs[i].hypers);
1372+
}
1373+
free(envs);
1374+
cJSON_Delete(root);
1375+
free(json_str);
1376+
free(options);
1377+
free(env_hyper_options);
1378+
free(env_options);
1379+
free(clipboard);
1380+
free(points);
1381+
free(glyphs);
1382+
free(env_indices);
1383+
free(filter);
1384+
for (int i = 0; i < 4; i++) {
1385+
free(best_idx[i]);
1386+
free(temp_dist[i]);
1387+
free(temp_idx[i]);
1388+
}
1389+
1390+
// Raylib resources
15671391
UnloadShader(shader);
1568-
CloseWindow();
1392+
UnloadShader(blur_shader);
1393+
UnloadRenderTexture(fig1);
1394+
UnloadRenderTexture(fig1_overlay);
1395+
UnloadRenderTexture(fig2);
1396+
UnloadRenderTexture(fig3);
1397+
UnloadRenderTexture(fig3_overlay);
1398+
UnloadRenderTexture(fig4);
1399+
CloseWindow();
15691400
return 0;
15701401
}

0 commit comments

Comments
 (0)