Given the structure of input and target data described below, and using the XOR-
ID: 3835518 • Letter: G
Question
Given the structure of input and target data described below, and using the XOR-data file as your example, decide on structure for inputs, and another for the target output(s). The structure chosen (#1) above should work, with minor modifications, for any problem, not just the XOR problem. Write C code to read in all entries, and their associated target output. Write another, separate "function" to echo out the content of the data structures you've coded. Line #1 - # of input/target patterns that follow (also equal to the number of lines that follow). Line #2 - list of input values, separated by spaces, and list of target values, separated by spaces for pattern #1 Line #3 - list of input values, separated by spaces, and list of target values, separated by spaces for pattern #2 XOR data file contents: XOR-weights: PART TWO Utilize the data file from PART ONE, and the function written to input data. (Disable the function that "echoes" out the data from the file). Write a simulation of the "process" portion of the network (i.e. write a program in C). USE: Unipolar Neurons Sigmoid Activation Function Weights Provided Above. Create a "reporting" function that will compare your "processed" output to the target output and keeps track of "HITS" and "MISSES." Report the accuracy of your network in percentage of HITS. Line #1 - all weights, separated by spaces, for neuron #1 Line #2 - all weights, separated by spaces, for neuron #2 Line #3 - all weights, separated by spaces, for neuron #3 Write a function that embeds in the code structure utilized to date that implements the BP Learning Algorithm. Make sure that the initial weights are small, random values. Ensure that after the learning phase has completed, ensure that your code runs through a "Forward Processing" phase (Project-Part TWO) with the "learned weights, and reports the accuracy of your network. Once the XOR problem is working, test code with a "real world" data set. Classification accuracy of your network is the most important task.Explanation / Answer
main.cpp
#include "Network.h"
int main(int argc, char **argv){
Network ANN;
if(argc < 3){
std::cout << "usage: [1]I/O Vector File [2]Weights File" << std::endl;
return -1;
}
if(!ANN.LoadIOFile(argv[1])){
std::cout << "Failed to load input ouput vector file " << argv[1] << std::endl;
return -1;
}
if(!ANN.LoadWeightsFile(argv[2])){
std::cout << "Failed to load input weights file " << argv[2] << std::endl;
return -1;
}
return 1;
}
Layer.h
class Layer{
public:
Layer();
~Layer();
private:
int _LayerSize;
};
Layer.cpp
#include "Layer.h"
Layer::Layer(){
_LayerSize = 0;
}
Layer::~Layer(){
}
Network.h
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include "Layer.h"
class Network{
public:
Network();
~Network();
int LoadIOFile(char *file);
int LoadWeightsFile(char *file);
private:
int _InputVectorSize;
int _OutputVectorSize;
std::vector<float> IOVector;
std::vector<float> Weights;
std::vector<Layer> HiddenLayers;
};
Network.cpp
#include "Network.h"
Network::Network(){
_InputVectorSize = 0;
_OutputVectorSize = 0;
}
Network::~Network(){
}
int Network::LoadIOFile(char *file){
std::ifstream IOfile(file);
std::string line;
std::stringstream ss;
float vector_entry;
if(!IOfile){
return -1;
}
std::getline(IOfile, line);
ss.clear();
ss.str("");
ss << line;
ss >> _InputVectorSize;
ss >> _OutputVectorSize;
std::cout << _InputVectorSize << std::endl;
std::cout << _OutputVectorSize << std::endl;
while(std::getline(IOfile, line)){
ss.clear();
ss.str("");
ss << line;
while(ss >> vector_entry){
IOVector.push_back(vector_entry);
}
}
return 1;
}
int Network::LoadWeightsFile(char *file){
std::ifstream IOfile(file);
std::string line;
std::stringstream ss;
float vector_entry;
if(!IOfile){
return -1;
}
while(std::getline(IOfile, line)){
ss.clear();
ss.str("");
ss << line;
while(ss >> vector_entry){
Weights.push_back(vector_entry);
std::cout << std::fixed << vector_entry << std::endl;
}
}
return 1;
}
input.txt
2 1
0.0 0.0 0.0
0.0 1.0 1.0
1.0 0.0 1.0
1.0 1.0 0.0
input2.txt
4 3 4
1.0 2.0 8.0 1.0 1.0 1.0 0.0
1.0 5.0 0.0 4.0 4.0 1.0 5.0
1.0 7.0 6.0 6.0 7.0 2.0 4.0
1.0 4.0 0.0 0.0 0.0 3.0 7.0
weights.txt
1.750829 -5.614923 -5.759118
4.212150 -2.971594 -2.987631
-2.403425 -6.538477 5.791071
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.