This project implements a neural network with a genetic algorithm approach to learn patterns in binary strings. The goal is to build a network that can predict the legality of new binary strings based on the learned patterns. There are two separate problems addressed in this project, each requiring a different program.
Buildnet0 program is designed to build a neural network for the first legality problem. It takes a learning file and a test file as input and outputs the structure definitions of the network and the weights of the network.
To run buildnet0 program:
- Clone the repository:
git clone https://github.com/alonravid1/comp_bio_ex3.git
- Two options to set the data:
- run by defalut:
Place the training and test data files in the same folder as the buildnet0 program. Name the files
training_set0.txt
andtest_set0.txt
. When the program asked the file paths press enter. - run by giving the train and test data path files - the program will ask for path of each, write the path and press enter.
- run by defalut:
Place the training and test data files in the same folder as the buildnet0 program. Name the files
- Double-click on the
buildnet0.exe
file. - When prompted, choose whether to see information about the program (y/n).
- Enter the path to the training data file or press Enter to use the default file name.
- Enter the path to the test data file or press Enter to use the default file name.
- Wait for the program to run. The running time will be displayed.
- Press Enter to exit the program.
The output file wnet0.txt
will be generated in the same folder as the buildnet0 program.
Runnet0 program takes the output file wnet0.txt
generated by buildnet0 and a data file of 20,000 binary strings as input. It predicts the legality of each string based on the learned network and outputs the predictions to a text file.
To run runnet0 program:
- Clone the repository:
git clone https://github.com/alonravid1/comp_bio_ex3.git
- Place the
wnet0.txt
file generated by buildnet0 and the data file in the same folder as the runnet0 program. Name the data file as desired. - Double-click on the
runnet0.exe
file. - Press Enter to start the program.
- Wait for the program to complete.
- The predictions will be saved in the file
predictions0.txt
in the same folder as the runnet0 program.
Buildnet1 program is similar to buildnet0 but for the second legality problem. It takes a learning file and a test file as input and outputs the structure definitions of the network and the weights of the network.
To run buildnet1 program:
- Clone the repository:
git clone https://github.com/alonravid1/comp_bio_ex3.git
- Two options to set the data:
- run by defalut:
Place the training and test data files in the same folder as the buildnet1 program. Name the files
training_set1.txt
andtest_set1.txt
. When the program asked the file paths press enter. - run by giving the train and test data path files - the program will ask for path of each, write the path and press enter.
- run by defalut:
Place the training and test data files in the same folder as the buildnet1 program. Name the files
- Double-click on the
buildnet1.exe
file. - When prompted, choose whether to see information about the program (y/n).
- Enter the path to the training data file or press Enter to use the default file name.
- Enter the path to the test data file or press Enter to use the default file name.
- Wait for the program to run. The running time will be displayed.
- Press Enter to exit the program.
The output file wnet1.txt
will be generated in the same folder as the buildnet1 program.
Runnet1 program is similar to runnet0 but for the second legality problem. It takes the output file wnet1.txt
generated by buildnet1 and a data
file of 20,000 binary strings as input. It predicts the legality of each string based on the learned network and outputs the predictions to a text file.
To run runnet1 program:
- Clone the repository:
git clone https://github.com/alonravid1/comp_bio_ex3.git
- Place the
wnet1.txt
file generated by buildnet1 and the data file in the same folder as the runnet1 program. Name the data file as desired. - Double-click on the
runnet1.exe
file. - Press Enter to start the program.
- Wait for the program to complete.
- The predictions will be saved in the file
predictions1.txt
in the same folder as the runnet1 program.
The input data files (training_set0.txt
, test_set0.txt
, training_set1.txt
, test_set1.txt
, and the data file for runnet0/runnet1) should contain one binary string per line. Each string should consist of 16 binary digits (0s and 1s).
The neural network structure used for both problems is defined as [1, 16, 32, 16], where the first number represents the input layer, the last number represents the output layer, and the middle numbers represent hidden layers.
The genetic algorithm parameters used for training the networks are specified in the programs and can be adjusted if desired. They include population size, maximum generations, replication rate, mutation rate, learning rate, and tournament size.
The output files generated by the programs are as follows:
wnet0.txt
: Structure definitions and weights of the network trained by buildnet0.predictions0.txt
: Predictions of the legality for each string in the data file, generated by runnet0.wnet1.txt
: Structure definitions and weights of the network trained by buildnet1.predictions1.txt
: Predictions of the legality for each string in the data file, generated by runnet1.