2016-01-13 122 views
-3

我想要獲取指數函數的值給我的代碼,但我不知道如何編寫Java中的指數函數。在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)) 
     */ 
    } 

} 
+2

提到我們不能爲你做你的功課。你可以做的是向我們展示你迄今爲止所寫的內容,以及你的理解。然後我們可以幫助你。 – Kon

+0

對不起,我問了這個問題,因爲我真的不知道如何在java中編寫指數值。這裏是我的代碼 –

+0

試試這個:http://www.tutorialspoint.com/java/number_exp.htm –

回答

1

所以,你的代碼應該有這個後,無論你已經寫在你的計算方法。

從計算方法返回結果或設置全局結果或您希望使用的結果。根據辦法

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

Thanksyou,我也在上面的鏈接中找到了答案 –

+0

您能接受答案,以便它可以幫助未來的讀者。 –

0

如這裏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)); 
     } 
}