diff options
author | jvech <jmvalenciae@unal.edu.co> | 2023-10-21 21:43:36 -0500 |
---|---|---|
committer | jvech <jmvalenciae@unal.edu.co> | 2023-10-21 21:43:36 -0500 |
commit | 17b2cf8dc274f950865911185fc4c6a9ccf915d5 (patch) | |
tree | 81f11089540264ebdf187ba028a58ed7f57a34c3 | |
parent | 8abcac7b3b42609f349b8a9cb132bae9746ba576 (diff) |
setup: man page improved
Documentation:
Example sections was improved
Files sections was added
Fixes:
default config filepath was fixed
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | doc/ml.1 | 47 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/util.c | 13 |
4 files changed, 63 insertions, 16 deletions
@@ -35,6 +35,9 @@ uninstall: rm -v $(BINPREFIX)/${BIN} rm -v $(MANPREFIX)/man1/ml.1 +man: build + help2man -N ./ml -I doc/man.txt > doc/ml.1 + run: build @./${BIN} train data/sample_data.json | tee data/train_history.txt @./${BIN} predict data/sample_data.json | jq -r '.[] | [values[] as $$val | $$val] | @tsv' > data/net_data.tsv @@ -42,8 +45,8 @@ run: build @gnuplot utils/plot.gpi debug: build - gdb -x utils/commands.gdb --tui --args ${BIN} train data/sample_data.json - gdb -x utils/commands.gdb --tui --args ${BIN} predict data/sample_data.json + gdb -x utils/commands.gdb --tui --args ${BIN} train data/xor.json -e 100 + @#gdb -x utils/commands.gdb --tui --args ${BIN} predict data/sample_data.json clean: @rm $(OBJS) $(OBJDIR) -rv @@ -9,7 +9,8 @@ ml \- manual page for ml 0.1 .B ml \fI\,predict \/\fR[\fI\,-o FILE\/\fR] \fI\,FILE\/\fR .SH DESCRIPTION -Train and predict json data +ml is a simple neural network maker made to train and predict JSON data, +it is suitable to work on classification problems. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR @@ -23,13 +24,47 @@ Epochs to train the model (only works with train) .TP \fB\-o\fR, \fB\-\-output\fR=\fI\,FILE\/\fR Output file (only works with predict) +.TP +\fB\-c\fR, \fB\-\-config\fR=\fI\,FILE\/\fR +Configuration filepath [default=~/.config/ml/ml.cfg] +.SH FILES +~/.config/ml/ml.cfg + File path for network configuration, here you can setup the network + architecture and its training parameters .SH EXAMPLES -.IP -\f(CW$ ml train -e 150 -a 1e-4 housing.json\fR -.br -\f(CW$ ml predict housing.json -o predictions.json\fR + +Train a network to solve XOR problem, below is the training data: + + [ + { + "x": 0, + "y": 0, + "z": 0 + }, + { + "x": 1, + "y": 0, + "z": 1 + }, + { + "x": 0, + "y": 1, + "z": 1 + }, + { + "x": 1, + "y": 1, + "z": 0 + } + ] + +Use the default configuration file and train the model with: + $ ml train -e 150 xor.json + +And get the network output using: + $ ml predict xor.json .SH AUTHOR -Written by vech +Written by jvech .SH COPYRIGHT Copyright \(co 2023 jvech .PP @@ -194,6 +194,7 @@ struct Cost load_loss(struct Configs cfg) } int main(int argc, char *argv[]) { + char default_config_path[512]; struct Configs ml_configs = { .epochs = 100, .alpha = 1e-5, @@ -202,11 +203,18 @@ int main(int argc, char *argv[]) { .out_filepath = NULL, }; - // Try different config paths - load_config(&ml_configs, 3, "~/.config/ml/ml.cfg", "~/.ml/ml.cfg", ml_configs.config_filepath); + // First past to check if --config option was put + util_load_cli(&ml_configs, argc, argv); + optind = 1; + // Load configs with different possible paths + sprintf(default_config_path, "%s/%s", getenv("HOME"), ".config/ml/ml.cfg"); + load_config(&ml_configs, 2, ml_configs.config_filepath, default_config_path); + + // re-read cli options again, to overwrite file configuration options util_load_cli(&ml_configs, argc, argv); argc -= optind; argv += optind; + Layer *network = load_network(ml_configs); Array X, y; @@ -83,7 +83,7 @@ void version() "the Free Software Foundation, either version 3 of the License, or\n" "(at your option) any later version.\n\n" ); - printf("Written by vech\n"); + printf("Written by jvech\n"); exit(0); } @@ -93,17 +93,14 @@ void usage(int exit_code) fprintf(fp, "Usage: ml train [Options] JSON_FILE\n" " or: ml predict [-o FILE] FILE\n" - "Train and predict json data\n" "\n" "Options:\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" + " -c, --config=FILE Configuration filepath [default=~/.config/ml/ml.cfg]\n" "\n" - "Examples:\n" - " $ ml train -e 150 -a 1e-4 housing.json\n" - " $ ml predict housing.json -o predictions.json\n" ); exit(exit_code); } @@ -117,12 +114,13 @@ void util_load_cli(struct Configs *ml, int argc, char *argv[]) {"epochs", required_argument, 0, 'e'}, {"alpha", required_argument, 0, 'a'}, {"output", required_argument, 0, 'o'}, + {"config", required_argument, 0, 'c'}, {0, 0, 0, 0 }, }; int c; while (1) { - c = getopt_long(argc, argv, "hve:a:o:i:l:", long_opts, NULL); + c = getopt_long(argc, argv, "hvc:e:a:o:i:l:", long_opts, NULL); if (c == -1) { break; @@ -137,6 +135,9 @@ void util_load_cli(struct Configs *ml, int argc, char *argv[]) case 'o': ml->out_filepath = optarg; break; + case 'c': + ml->config_filepath = optarg; + break; case 'h': usage(0); case 'v': |