Hi there,
I have been trying to figure out how I am getting this error:

Exception in thread "main" java.lang.NumberFormatException
at java.math.BigDecimal.<init>(BigDecimal.java:368)
at java.math.BigDecimal.<init>(BigDecimal.java:647)
at newtonsMethod1.sigmoidActivationFunction(newtonsMethod1.java:118)
at newtonsMethod1.feedForward(newtonsMethod1.java:136)

The following code :

for(int j =0; j< a; j++)
	       {
			   System.out.println("Enter into input neuron "+ j);
			   String r = in.readLine();
			   Double qq = Double.parseDouble(r);
               BigDecimal rr = new BigDecimal(qq);
			   targetInput[i][j] = rr;
			   if(j == a - 1){
			   System.out.println("Enter the desired output for it");
			   for(int n = 0; n < c; n++){
			   String p = in.readLine();
			   Double q = Double.parseDouble(p);
			   desiredOut[i][n]=q;}}
		   }
	    }
    System.out.println();
	System.out.println();

     int pee = 0;
     while( pee < f)
     {
	   for(int i = 0; i< e; i++)
	    {
			//test.buildWeightMatrix();
			test.feedForward(i, targetInput);
			//test.backwardComputation();
                                              
			//test.updateWeights();

         }
       pee++;
    }

calls the method feedForward() which is in another class. The method feedForward() is as shown belown:

public BigDecimal sigmoidActivationFunction(BigDecimal sum)
    {
	  Big_pi test2 = new Big_pi();
  	  BigDecimal Set = test2.exp(new BigDecimal("-sum"));
	  	Set = Set .setScale(20,RoundingMode.HALF_UP);
	  return Set;
  }

   public void feedForward(int m, BigDecimal [][] input)
   {
	   int i, j;
   BigDecimal sum;

	   for(i = 0; i < hiddenNeurons; i++)
	     {

			 sum = new BigDecimal("0");
			 for(j = 0; j < inputNeurons; j++)

			   sum = (sum .add (hiddenToInputWeight[i][j] .multiply(input[m][j])));

			 hiddenA[i] = sigmoidActivationFunction(sum);
		}

       System.out.println("These are the activations of the hidden neurons:");
       System.out.println();

		for( i = 0; i< hiddenA.length; i++)
		   {System.out.println(hiddenA[i]);
			System.out.println();}
			System.out.println();

	   for(i = 0; i < outputNeurons; i++)
	      {
			  sum = new BigDecimal("0");
			  for(j = 0; j < hiddenNeurons; j++)
			     sum = sum.add(outputToHiddenWeight[i][j].multiply (hiddenA[j]));
			  targetOutputA[i] = sum;
		  }

		System.out.println("This is the target output of the network:");
		System.out.println();
        for( i = 0; i< targetOutputA.length; i++)
					  System.out.println(targetOutputA[i]);
			  System.out.println();
   }

Can you figure what I am doing wrong, each time the feedForward method is called, please?

The stack trace is showing the error occurring in sigmoidActivationFunction

at newtonsMethod1.sigmoidActivationFunction(newtonsMethod1.java:118)

and if you look at the constructor you are using for BigDecimal there the error should be pretty clear. I doubt what you wrote there can be formatted as a number.

I used the BigDecimal constructor that takes string as its parameter. I tried using double parameter, but the negative sign beside the variable sum is causing a problem. Could you advise me on what i can use so that it can be formatted as a number, please?

Well, the string literal "-sum" will never be parsed as a number because "sum" is just a string there - not a variable.

What problem was the negative sign causing? This code seems to work just fine

double value = 2.345;
BigDecimal bdValue = new BigDecimal(-value);
System.out.println(bdValue);

I still got an error which stated that: operator - cannot be applied to java.math.BigDecimal
sum = new BigDecimal(-sum);
^
1 error
This is my code though:

public BigDecimal sigmoidActivationFunction(BigDecimal sum)
    {
	  Big_pi test2 = new Big_pi();
	  sum = new BigDecimal(-sum);
  	  BigDecimal Set = test2.exp(sum);
	  	Set = Set .setScale(20,RoundingMode.HALF_UP);
	  return Set;
  }

You said that you had problems using the double constructor, but that code is passing a BigDecimal. If you just need to negate the sum, why not use the method BigDecimal.negate()? Alternately you could multiply(-1.0). The api doc is your best friend for things like this.

Thanks very much, I ve solved that already.
Thanks for your time anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.