aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2023-08-26 11:02:37 -0500
committerjvech <jmvalenciae@unal.edu.co>2023-08-26 11:02:37 -0500
commit624c04b33afff299121a5ded475070a2f0236cff (patch)
tree031e56c4c5fb552ec6b768d9fefe412b0959fbc0
parentad016f5bc55c6093c1c67e64ad931192291b5c62 (diff)
fix: cfg syntax verification and usage messages improved
-rw-r--r--src/util.c31
-rw-r--r--src/util.h1
-rw-r--r--utils/settings.cfg16
3 files changed, 38 insertions, 10 deletions
diff --git a/src/util.c b/src/util.c
index 4ccec06..2c94236 100644
--- a/src/util.c
+++ b/src/util.c
@@ -72,10 +72,10 @@ void usage(int exit_code)
"Train and predict json data\n"
"\n"
"Options:\n"
- " -a, --alpha=ALPHA Learning rate (only works with train) [default: 1e-5]\n"
- " -e, --epochs=EPOCHS Number of epochs to train the model (only works with train)\n"
- " [default: 100]\n"
- " -o, --output FILE Output file (only works with predict)\n"
+ " -h, --help Show this message\n"
+ " -a, --alpha=ALPHA Learning rate (only works with train)\n"
+ " -e, --epochs=EPOCHS Epochs to train the model (only works with train)\n"
+ " -o, --output=FILE Output file (only works with predict)\n"
"\n"
"Examples:\n"
" $ ml train -e 150 -a 1e-4 housing.json\n"
@@ -179,6 +179,9 @@ void util_load_config(struct Configs *ml, char *filepath)
ml->network_size++;
add_lyr(ml);
ml->neurons[ml->network_size-1] = ml->n_label_keys;
+ } else {
+ die("util_load_config() Error: Unknown section '%s' on %s",
+ line_buffer, filepath);
}
continue;
}
@@ -199,10 +202,18 @@ void util_load_config(struct Configs *ml, char *filepath)
|| (*line_ptr < 0x61 && *line_ptr > 0x7A))
goto util_load_config_error;
- /* Load Key Value */
- char *key, *value;
char *ptr_buffer;
strtok_r(line_buffer, ";#", &ptr_buffer); // omit comments
+
+ /* Check For invalid = characters*/
+ int eq_count;
+ for (eq_count = 0, line_ptr = line_buffer;
+ *line_ptr != '\0';
+ line_ptr++, eq_count += (*line_ptr == '='));
+ if (eq_count > 1) goto util_load_config_error;
+
+ /* Load Key Value */
+ char *key, *value;
key = strtok_r(line_buffer, " =", &ptr_buffer);
value = strtok_r(NULL, "= ,\n", &ptr_buffer);
if (value == NULL) goto util_load_config_error;
@@ -216,9 +227,9 @@ void util_load_config(struct Configs *ml, char *filepath)
break;
case OUT_LAYER:
load_lyr_cfgs(ml, key, value, filepath);
- if (!strcmp("neurons", key) && atof(value) != ml->n_label_keys) {
- die("util_load_config() Error: out layer neurons '%zu' differ from the number of labels '%zu'",
- ml->n_label_keys, atof(value));
+ if (!strcmp("neurons", key) && (size_t)atol(value) != ml->n_label_keys) {
+ die("util_load_config() Error: out layer neurons (%zu) differ from the number of labels (%zu)",
+ (size_t)atol(value), ml->n_label_keys);
}
break;
default:
@@ -230,7 +241,7 @@ void util_load_config(struct Configs *ml, char *filepath)
return;
util_load_config_error:
- die("util_load_config() Error: Invalid format on file %s.\n %d: %s",
+ die("util_load_config() Error: Invalid format on %s.\n %d: %s",
filepath, line_number, line_buffer_original);
}
diff --git a/src/util.h b/src/util.h
index d5cb403..00567a8 100644
--- a/src/util.h
+++ b/src/util.h
@@ -23,6 +23,7 @@ struct Configs {
void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);
+void *erealloc(void *ptr, size_t size);
void util_load_cli(struct Configs *ml, int argc, char *argv[]);
void util_load_config(struct Configs *ml, char *filepath);
void util_free_config(struct Configs *ml);
diff --git a/utils/settings.cfg b/utils/settings.cfg
new file mode 100644
index 0000000..806f895
--- /dev/null
+++ b/utils/settings.cfg
@@ -0,0 +1,16 @@
+[net]
+loss = square ; options (square)
+epochs = 40 ; comment
+alpha = 1e-4
+weights_path = ~/.config/ml/weights.bin
+inputs = x, y
+labels = z
+
+; activation options (relu, sigmoid, softplus, leaky_relu)
+
+[layer]
+neurons=3
+activation=relu
+
+[outlayer]
+activation = sigmoid
Feel free to download, copy and edit any repo