如何获取 java 中的指数函数值以及如何对指数函数进行编码

How to get values of exponential functions in java and how to code the exponential functions

我想为我的代码获取指数函数的值,但我不知道如何在 Java 中编写指数函数的代码。 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) )
         */
    }

}

因此,无论您在计算方法中写入什么内容,您的代码都应该有这个。

Return 计算方法的结果或全局设置结果或您想要使用它的方式。

  double d = 1+ Math.exp(-z);
  double result = 1/d;

按照这里说的方式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));
        }
}