Sekarang kita akan memasukkan fungsi aktifasi atau fungsi transfer kedalam program kita.
/*
<ANNInputWeightBias.java. The program performs summation for
Input, Weight, and Bias .>
Copyright (C) <2016> <Joko Adianto>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ class ActivationFunction {
//Hard Limit
public double hardLim(double s){
if (s < 0) s=0.0;
else s = 1.0;
return s;
}
//Symmetric Hard Limit
public double symHardLim(double s){
if (s < 0) {
s=-1.0;
}
else {
s = 1.0;
}
return s;
}
//Linear
public double lin(double s){
return s;
}
//Saturated Linear
public double satLin(double s){
if (s < 0){
s=0;
}
else if (s >=0 && s<=1){
s = s;
}
else {
s=1;
}
return s;
}
//Symmetric Saturated Linear
public double symSatLin(double s){
if (s < -1){
s=-1;
}
else if (s >=-1 && s<=1){
s = s;
}
else {
s=1;
}
return s;
}
/**Log Sigmoid
*
* @param s
* @return 1/(1+java.lang.Math.pow(java.lang.Math.E, -s)
*/
public static double logSig(double s){
return 1/(1+java.lang.Math.pow(java.lang.Math.E, -s));
}
/**Hyperbolic Tangent Sigmoid
*
* @param s
* @return s
*/
public double tanSig(double s){
return (java.lang.Math.pow(java.lang.Math.E, s)-
java.lang.Math.pow(java.lang.Math.E, -s))/
(java.lang.Math.pow(java.lang.Math.E, s)+
java.lang.Math.pow(java.lang.Math.E, -s));
}
}
public class ANNInputWeightBias {
/**
* @param p
* @param w
* @param o
* @return double
*/
public static double getSum( double[] p, double[][]w, double b ){
double o =0; //o adalah akumulator
int k = p.length; //panjang array p
int j = 0; //pencacah
for (j=0;j<k;j++){
o=o+p[j]*w[j][0];
}
o=o+b;
return o;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ActivationFunction af = new ActivationFunction();
double o=0;
double b=1; //b adalah bias
double[] p = {1,2,3}; //p adalah input
double[][] w = {{2}, {4}, {6}}; //w adalah weight
o=getSum(p,w,b);
o=af.logSig(0);
System.out.println(o);
}
}
