1. Homepage
  2. Programming
  3. CS112 Lab 09: Neural Networks

CS112 Lab 09: Neural Networks

Engage in a Conversation
USFCACS112Introduction to CS IIMachine LearningJavaNeural Networks

INTRODUCTION CourseNana.COM

CS112 - Fall 2024 CourseNana.COM

Later this semester, you will create a working neural network in Java, using only your own code. In later classes, you will probably use neural network libraries developed by others to learn about many facets of Machine Learning. But in this class, you will learn that there is no magic in making a neural networkit is something you can build yourself...though the fact that neural networks perform so well does seem like magic.
CourseNana.COM

What is a neuron? CourseNana.COM

A neuron is a nerve cell or brain cell. They are found in any animal with a brain or some approximation of a brain. (This is almost every type of multicellular animal: people, insects, fish, even jellyfish...but not sea sponges!) CourseNana.COM

Nerve cells have multiple inputs and a single output. The inputs come from other nerve cells or from "sensors" such as the eye's retina or the ear, and the outputs go to other nerve cells or to "actuators" such as muscles or organs. CourseNana.COM

Ok, What is a Neuron in a Computer? CourseNana.COM

Researchers were intrigued by the ability of large networks of animal neurons that is, "brains" to store information, make decisions, and learn. They began experimenting with simple computer functions that mimicked the understood bioelectrical operation of neurons, and they got surprisingly good results on a variety of different tasks. CourseNana.COM

A popular computer function, the "perceptron", was introduced by Frank Rosenblatt in 1957. The basic operation of a perceptron is: CourseNana.COM

  • wi are a set of weights CourseNana.COM

  • inputi are the inputs to the perceptron CourseNana.COM

  • b is an additive bias CourseNana.COM

  • activation() is an "activation function", a nonlinear function CourseNana.COM

    What Kind of Problems?
    CourseNana.COM

    In Paul's last project before leaving the video industry, he learned about neural networks and used them to answer the following question: "If a TV operator wants to process N video channels, and each video CourseNana.COM

channel has a spatial resolution of X pixels wide by Y pixels high, and some encoded bit-rate of B megabits per second, how many computer servers are needed to process the videos without overloading?"1 The solution was a neural network that took in the resolutions and bit-rates as inputs and returned a number of servers. This solution saved Paul's employer over $1M per year in cloud computing costs.
CourseNana.COM

Another problem frequently solved by neural networks is image recognition. A neural network can be trained with images of cats, dogs, lions, tigers, sheep, elephants, etc. And then when a new image is fed to the network, it correctly answers what type of animal is shown in the image. CourseNana.COM

And of course, Large Language Models such as ChatGPT use Neural Networks to answer questions. CourseNana.COM

What is "Training"? CourseNana.COM

The output of a neuron of course depends on the values of the weights and bias (and the activation function). The output of a neural networka network of neuronsdepends on the weights and biases of all of the neurons in a network. CourseNana.COM

"Training" is a computational process that takes a large set of inputs, and corresponding known outputs, and adjusts every neuron's weights and bias, so that the output of the neural network gets closer and closer to the known output for every input. When training is complete, a new input can be fed to the neural network, even if the input was not in the set used for training, and it should produce a correct output. CourseNana.COM

Why do neural networks work? This is not really understood--just like we don't understand how brains work, at any large scale. There are plenty of alternative computational models for making decisions, but this model seems to work quite well.
CourseNana.COM

This Week's Lab CourseNana.COM

For this week, you will build and test a Neuron. In a file RELUNeuron.java please write a class RELUNeuron. For the activation function, use the "RELU function": 2 CourseNana.COM

double activation(double x) {
     x /= 20.0;
     return x > 0 ? x : 0.0;
}

1 This is somewhat simplified from the actual question...
2 "RELU" stands for "Rectified Linear Unit" which doesn't make things any clearer, does it? In this context, "rectified" comes from Electrical Engineering, where a "rectifier" blocks electrical currents that are "less than 0" i.e going in the wrong direction, but permits currents in the proper direction. CourseNana.COM

For class RELUNeuron:
CourseNana.COM

  • -  The constructor takes in the number of inputs for the Neuron, and initializes all weights and bias values to a random value between -1.0 and +1.0. CourseNana.COM

  • -  an output() method takes in a double[] array of inputs and calculates the proper output value CourseNana.COM

  • -  a write() method to write the neuron's weights and bias to a DataOutputStream (see DataOutputStream's writeDouble() method) CourseNana.COM

  • -  a read() method to read the neuron's weights and bias from a DataInputStream (see readDouble() method). CourseNana.COM

    You'll need several class variables, of course. Weights, bias, and maybe more. CourseNana.COM

    To train your Neuron, I will give you a bunch of training data files, each of which contains 501 double values each. These values are not saved as textthey are saved as raw binary double values (I used a DataOutputStream). For each file: CourseNana.COM

  • the first 500 values are inputs to your Neuron, CourseNana.COM

  • the last value is the expected output from your Neuron. CourseNana.COM

    In class, we will discuss the details of how to train your Neuron. Can you improve this basic training recipe? To reach a smaller error faster? CourseNana.COM

    After you train your Neuron on the provided training data, please save your resulting weights and bias (using your write() method) to a file called weights.dbl . CourseNana.COM

    A critical part of this week's lab is for you to design, execute, and document a set of tests for your Neuron. For this week, please write another Java file TestNeuron.java. This class of course tests your Neuron. You should think about how to do this! CourseNana.COM

  • You must test all of your Neuron's methods, to make sure they work properly. o Howdoyoutesttheconstructor?
    o Howdoyoutestwrite()andread()?
    o Howtotestoutput()? CourseNana.COM

    o Howtotesttrain()? CourseNana.COM

  • You must write up a 1-2 page document describing how you tested, how your TestNeuron CourseNana.COM

    class works, and your test results. (You do not need to talk about your Neuron class.) CourseNana.COM

Conclusion CourseNana.COM

In this project you learned how to build and test a computer "neuron" using nothing but ordinary arithmetic and Boolean logic. In a few weeks we will build, train, and test a real Neural Network. CourseNana.COM

Rubric CourseNana.COM

0-20 points for code quality and proper operation and training of RELUNeuron.java 10 points if you weights.dbl gives a reasonable error with test files
0-20 points for your TestNeuron.java
0-20 points on your test writeup CourseNana.COM

Further Reading CourseNana.COM

"How LLM's work." LINK CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
USFCA代写,CS112代写,Introduction to CS II代写,Machine Learning代写,Java代写,Neural Networks代写,USFCA代编,CS112代编,Introduction to CS II代编,Machine Learning代编,Java代编,Neural Networks代编,USFCA代考,CS112代考,Introduction to CS II代考,Machine Learning代考,Java代考,Neural Networks代考,USFCAhelp,CS112help,Introduction to CS IIhelp,Machine Learninghelp,Javahelp,Neural Networkshelp,USFCA作业代写,CS112作业代写,Introduction to CS II作业代写,Machine Learning作业代写,Java作业代写,Neural Networks作业代写,USFCA编程代写,CS112编程代写,Introduction to CS II编程代写,Machine Learning编程代写,Java编程代写,Neural Networks编程代写,USFCAprogramming help,CS112programming help,Introduction to CS IIprogramming help,Machine Learningprogramming help,Javaprogramming help,Neural Networksprogramming help,USFCAassignment help,CS112assignment help,Introduction to CS IIassignment help,Machine Learningassignment help,Javaassignment help,Neural Networksassignment help,USFCAsolution,CS112solution,Introduction to CS IIsolution,Machine Learningsolution,Javasolution,Neural Networkssolution,