-4

I want to get value of an exponential function to my code, but I don't know how to code to exponential functions in Java. What is the way to code exponential functions in Java?

public class Demo {

    // inputs are declared
    private int x[] = {1, 0, 1, 0};
    //weights are declared
    private double w[] = {0.4, 0.6, 0.7, 0.8};
    private double temp = 0;

    private double z = 0;
    private int desiredOutput[] = {0, 1, 1, 1};

    private double sigmoidOutput[] = {1, 1, 1, 1};

    public void calculate() {
        for(int i =0; i < 4; i++) {
            temp = x[i] * w[i];
            z += temp;
        }
        /*
             I want to get the value of 1/(1+e to the power (-z) )
         */
    }

}
Lii
  • 11,553
  • 8
  • 64
  • 88
Kasun Siyambalapitiya
  • 3,956
  • 8
  • 38
  • 58

2 Answers2

1

So you code should have this after whatever you have written in your calculate method.

Return the result from the calculate method or set result globally or however way you want to use it.

  double d = 1+ Math.exp(-z);
  double result = 1/d;
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
0

As according to the way mentioned here Math Exponential

import java.lang.Math;

public class Demo {
        // inputs are declared
        private int x[]={1,0,1,0};
        //weights are declared
        private double w[]={0.4,0.6,0.7,0.8};
        private double temp=0;

        private double z=0;
        private int desiredOutput[]={0,1,1,1};

        private double sigmoidOutput[]={1,1,1,1};

        public void calculate(){
            for(int i =0; i<4; i++){
                temp=x[i]*w[i];
                z+=temp;
            }
            /*
             * I want to get the value of 1/(1+e to the power (-z) )
             */
            double value=(1/(1+Math.exp(-z));
        }
}
MWiesner
  • 8,868
  • 11
  • 36
  • 70
Kasun Siyambalapitiya
  • 3,956
  • 8
  • 38
  • 58