Tips for effectively training my Neural Network

I am currently working on training a neural network to determine directional decisions based on its inputted life level. The neural network is designed to take in three inputs: [x, y, life]. If life => 0.2, it should output the angle from [x, y] to (1, 1). If life < 0.2, it should output the angle from [x, y] to (0, 0).

Since the inputs and outputs of neurons should fall within the range of 0 to 1, I normalize the angle by dividing it by 2 * Math.PI.

Below is the code snippet:

var network = new synaptic.Architect.Perceptron(3,4,1);

for(var i = 0; i < 50000; i++){
  var x = Math.random();
  var y = Math.random();
  var angle1 = angleToPoint(x, y, 0, 0) / (2 * Math.PI);
  var angle2 = angleToPoint(x, y, 1, 1) / (2 * Math.PI);
  for(var j = 0; j < 100; j++){
    network.activate([x,y,j/100]);
    if(j < 20){
      network.propagate(0.3, [angle1]);
    } else {
      network.propagate(0.3, [angle2]);
    }
  }
}

Test it out here: jsfiddle

Now, when I input [0, 1, 0.19], I anticipate the neural network to output a value close to [0.75] (1.5PI / 2PI). However, the results are inconsistent with no clear correlation to the input provided.

What mistake might I be making in training my Neural network?

Although I have successfully trained a neural network to output 1 when provided with [a, b, c] where c => 0.2 and 0 when c < 0.2, and to output an angle based on input [x, y], I am facing challenges in combining the two aspects.


Furthermore, I have developed a code that utilizes two Neural Networks to achieve the desired output. The first neural network converts the life level into 0 or 1, while the second neural network outputs an angle based on the output from the first neural network. Here is the code:

// This network outputs 1 when life => 0.2, otherwise 0
var network1 = new synaptic.Architect.Perceptron(3,3,1);
// This network outputs the angle to a certain point based on life
var network2 = new synaptic.Architect.Perceptron(3,3,1);

for (var i = 0; i < 50000; i++){
  var x = Math.random();
  var y = Math.random();
  var angle1 = angleToPoint(x, y, 0, 0) / (2 * Math.PI);
  var angle2 = angleToPoint(x, y, 1, 1) / (2 * Math.PI);

  for(var j = 0; j < 100; j++){
    network1.activate([x,y,j/100]);
    if(j < 20){
      network1.propagate(0.1, [0]);
    } else {
      network1.propagate(0.1, [1]);
    }
     network2.activate([x,y,0]);
    network2.propagate(0.1, [angle1]);
    network2.activate([x,y,1]);
    network2.propagate(0.1, [angle2]);
  }
}

Feel free to try it out here: jsfiddle

As demonstrated in this example, the code manages to achieve the desired output closely. Increasing the number of iterations can improve the accuracy even further.

Answer №1

Insights

  1. Biased Distribution in Training Set

    It appears that the training set you are using is skewed towards certain values of the life parameter. This bias can affect the way your training function prioritizes certain data subsets, potentially leading to inaccurate results.

  2. Lack of Data Shuffling

    Training your network sequentially without shuffling the data can introduce bias and cause the network to focus more on particular data points. It is recommended to shuffle your training set to ensure fair representation of all data points.

    This issue compounds with the biased distribution, further emphasizing certain values of the life parameter.

  3. Evaluation of Training Performance

    While your network performed reasonably well, discrepancies between training and testing errors suggest differences in sample distributions. It may be helpful to categorize data points based on the life parameter to account for discontinuities in the function being analyzed.

  4. Consider Network Complexity

    To enhance the capabilities of your network, consider structuring it with multiple layers to build on learned concepts. By introducing layers of nodes, you can increase the ability of the network to grasp complex relationships within the data.

Code Sample

Upon running the provided code, the training/testing error rates were 0.0004 and 0.0002 respectively.

https://jsfiddle.net/hekqj5jq/11/

// Code sample omitted for brevity

Additional Notes

It's important to clarify the concept of the "angle between vectors" in your function angleToPoint, as the direction of (0,0) has no bearing on angle calculations. Consider refining this aspect for more accurate results in your network training.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

slider not functioning properly at the moment

I am in need of assistance with Fraction Slider from @jacksbox. I have read through the documentation multiple times, but I cannot seem to get my slider to display the effects it is meant to. The website I am working on can be found at . Here is an example ...

The ajax form submit function does not have the capability to automatically post content

On this particular webpage, there is a visible form labeled form A which contains a submit button with a post action. <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> I am looking to cre ...

I've received an array of objects, but I require the objects to be consolidated into a single array using a MongoDB query

Hello, I am a newcomer to mongodb and I am attempting to generate a specific output using the mongodb aggregate function. I am aiming for a unified array of objects rather than multiple arrays of objects. Can someone assist me in achieving this desired out ...

Preventing multiple clicks by toggling the HTML tag on and off

Here is the jQuery structure that I am currently working with: $(document).on('click', '.view-details', function () { $(this).prop("disabled", true); // API call1 // API call2 // API call3 $(this).prop("disabled" ...

Analyze and tally occurrences in two arrays

I have two arrays $array1=('18753933','18753933','18771982') $array2=('18753933','18771982') My goal is to compare the values that are the same in both arrays. var countArticlesLoaded=0; for(var $i=0;$i ...

Navigating through JSON data that has been returned

When I use AJAX (jQuery) to query my database, the data I receive back is causing some difficulties. While searching for a solution, I came across similar issues posted by others who pointed out that the PHP code (specifically how data is stored in the arr ...

When you hover over an image, its opacity will change and text will overlay

I am looking for a way to decrease the opacity and overlay text on a thumbnail image when it is hovered over. I have considered a few methods, but I am concerned that they may not be efficient or elegant. Creating a duplicated image in Photoshop with the ...

Identify and emphasize fields that contain identical, non-empty values

I am attempting to compare the values of textboxes and highlight them if they are the same, excluding any textboxes that are empty. Feel free to view an example on this JSFiddle link: http://jsfiddle.net/qjqa1et2/61/ Below is the jQuery code I am current ...

What causes the function execution to not be delayed by setTimeout?

function attemptDownloadingWebsite(link) { iframe = document.getElementById('downloadIFrame'); iframe.src = link; setTimeout(removeFile(link), 25000); } This is the remove file function: function removeFile(link){ $.ajax ...

Is there a way to export a modified OBJ geometry from a Three.js scene?

Every time I make changes and export my Three.js scene with a SkinnedMesh model, the original imported model gets saved instead of the updated version. Despite rotating bones and adjusting morph targets, the exported model remains unchanged. Even though t ...

Attach a child element to the bottom of its parent div when the parent div reaches the bottom

I'm looking to make a child div stick to the bottom when the parent div reaches the bottom of the browser window. Note: This behavior should only occur when the parent div is pushed down, not when the page is scrolled down. For instance, in my demon ...

Using jQuery to smoothly scroll to a specific class name

I am faced with an HTML code snippet that looks like this: <div data-stored="storenow" data-save="save" class="saveIcon" data-unique="game">Save</div> My intention is to use jQuery to scroll to the game number 456 as shown below. var contain ...

Ways to select a single checkbox when other checkboxes are selected in JavaScript

var select_all = document.getElementById("select_all"); //reference to select all checkbox var checkboxes = document.getElementsByName("testc"); //retrieving checkbox items //function to select all checkboxes select_all.addEventListener("change", function ...

Guide on extracting value from XML data using $.ajax and then displaying it within a $.each loop

As part of our study project, we have a task that involves comparing an array of strings with an XML database. My approach was to break it down into two parts since we need to perform the comparison function twice. First, I iterate through the array using ...

Limit the radio button to being clickable

Ugh, I'm really struggling with this. I want to create a quiz where only the radio button is clickable, not the text itself. Can anyone help me figure out how to do this? I have two codes below that I don't quite understand. I'll include th ...

Managing the transition of the object in question

I am in the process of designing a navigation bar. I have created an array to store the information of the tabs present in the nav bar. tabs: [ { name: 'All',id: "dash.courses.all", to: 'all', curre ...

Removing cookies after sending a beacon during the window unload event in Chrome

Here's the situation: I need to make sure that when the browser is closed or the tab is closed, the following steps are taken: Send a reliable post request to my server every time. After sending the request, delete the cookies using my synchronous fu ...

After using browserify, when attempting to call the function in the browser, an Uncaught ReferenceError occurs

I am currently in the process of creating a compact NPM package. Here is a basic prototype: function bar() { return 'bar'; } module.exports = bar; This package is meant to be compatible with web browsers as well. To achieve this, I have inst ...

When implementing dynatable with Meteor, the outcomes may vary between the demonstration in a fiddle and the actual application

Here is the fiddle I created for this question: https://jsfiddle.net/ereday/82wzwem8/2/ In the fiddle, you'll notice that the table header has a green background. Now, let me share the code snippet from my meteor project: simple-todos.html <head ...

Retrieving all options from a dropdown list in HTML using ASP.net C#

I am currently working with a select list that looks like this: <select name="Section" id="Section" size="5"> <option>Section1</option> <option>Section2</option> <option>Section3</option> <option>Section4< ...