Question
Below is a sketch of a small C++ program to implement simple fixed-size perceptrons (three nodes, two edges). It includes a main program that once
Below is a sketch of a small C++ program to implement simple fixed-size perceptrons (three nodes, two edges). It includes a main program that once the functions are working correctly will print the truth tables for AND, OR, and NAND! See the sections marked TODO. Here is the expected output:
AND:
0 0: 0
0 1: 0
1 0: 0
1 1: 1
OR:
0 0: 0
0 1: 1
1 0: 1
1 1: 1
NAND:
0 0: 1
0 1: 1
1 0: 1
1 1: 0
// Simple perceptron logic gate implementation
#include
using namespace std;
float step_function(float threshold, float value)
{
// TODO
return 0;
}
float run_perceptron(float weightA, float weightB, float valueA, float valueB, float threshold)
{
// TODO
return 0;
}
void show_truth_table(float weightA, float weightB, float threshold)
{
// TODO: call run_perceptron 4 times,
// feeding it all four values of A,B.
}
int main()
{
cout << "AND: ";
show_truth_table(0.4, 0.4, 0.5);
cout << "OR: ";
show_truth_table(0.6, 0.6, 0.5);
// TODO: can you figure out two weights and a threshold
// that will implement "NAND"? This is the opposite of AND.
cout << "NAND: ";
show_truth_table(0,0,0);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started