TOTO HARYANTO

Sedikit goresan menebar manfaat …..

Fuzzy Sugeno Menggunakan Java

Posted by totoharyanto on June 21st, 2012

Sugeno merupakan salah satu metode penalaran yang digunakan dalam Fuzzy Inference System (FIS). Berbeda dengan Mamdani , pada Sugeno bagian konsekuen ayau output bukan berupa himpunan fuzzy akan tetapi berupa nilai konstan atau kombinasi linear dari inputnya.

Nah, biasanya kita sering mengimplementasikan fuzzy dengan Matlab, namun kali ini saya mencoba untuk mengimplementasikan dengan bahasa pemrograman java via Netbean 7 sebagai IDE.

 

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* latihansugeno.java
*
* Created on May 31, 2012, 1:15:34 PM
*/
package latihansugeno;

/**
*
* @author haryanto
*/
public class latihansugeno extends javax.swing.JFrame {

public double[] output_rule_kel_2 = new double[6];
public double[] u_output_kel_2 = new double[6];
public double z_kelompok_2;
public double min_result_kelompok;
public double u_aset_SM;
public double u_aset_SKM;
public double u_jaminan_SM;
public double u_jaminan_CM;
public double u_jaminan_SKM;
public double kondisi_aset;
public double kondisi_jaminan;

/** Creates new form latihansugeno */
public latihansugeno() {

initComponents();

}

class Jaminan {

public double data_jaminan;

// Himpunan Sangat Kurang Mendukung
private double SangatKurangMendukung() {

if (data_jaminan == 0) {
return data_jaminan = 1;
} else if ((data_jaminan >= 1) && (data_jaminan < 7.5)) {
return (7.5 - data_jaminan) / (7.5 - 1);
} else {
return 0;
}
}

// Himpunan Cukup Mendukung

private double CukupMendukung() {

if ((data_jaminan >= 5) && (data_jaminan < 7.5)) {
return (data_jaminan - 5) / (7.5 - 5);
} else if (data_jaminan == 7.5) {
return data_jaminan = 1;
} else if ((data_jaminan > 7.5) && (data_jaminan <= 10)) {
return (10 - data_jaminan) / (10 - 7.5);
} else {

return 0;
}

} // end of cukup mendukung

private double SangatMendukung() {

if ((data_jaminan >= 7.5) && (data_jaminan <= 15)) {
return (data_jaminan - 7.5) / (15 - 7.5);
} else {

return 0;
}

} // end sangat mendukung
} //end class Jaminan

class Aset {

public double data_aset;

// Himpunan Sangat Kurang Mendukung
private double SangatKurangMendukung() {

if (data_aset == 0) {
return data_aset = 1;
} else if ((data_aset > 0) && (data_aset <= 300000000)) {
return (300000000 - data_aset) / (300000000 - 0);
} else {
return 0;
}
}

private double SangatMendukung() {

if (data_aset == 500000000) {
return data_aset = 1;
} else if ((data_aset >= 200000000) && (data_aset < 500000000)) {
return (data_aset - 200000000) / (500000000 - 200000000);
} else {

return 0;
}

} // end sangat mendukung
} //end class Aset

class KelayakanKelompok2 extends latihansugeno
{

public double[] nilai_kelayakan_kelompok2;

KelayakanKelompok2() {

nilai_kelayakan_kelompok2 = new double[6];
nilai_kelayakan_kelompok2[0] = (104 + 123) / 2;   // sangat layak dengan resiko rendah
nilai_kelayakan_kelompok2[1] = (80 + 104) / 2;    // layak dengan resiko tinggi
nilai_kelayakan_kelompok2[2] = (80 + 104) / 2;    // layak
nilai_kelayakan_kelompok2[3] = (44 + 80) / 2;    //  cukup layak
nilai_kelayakan_kelompok2[4] = (2 + 20) / 2;     //  kurang layak
nilai_kelayakan_kelompok2[5] = (2 + 20) / 2;      // sangat kurang layak
}
}

private void Compute_Membership() {

Jaminan jaminan = new Jaminan();
Aset aset = new Aset();

jaminan.data_jaminan = kondisi_jaminan;
aset.data_aset = kondisi_aset;

u_jaminan_SM = jaminan.SangatMendukung();
u_jaminan_CM = jaminan.CukupMendukung();
u_jaminan_SKM = jaminan.SangatKurangMendukung();

u_aset_SM = aset.SangatMendukung();
u_aset_SKM = aset.SangatKurangMendukung();

}

private double Cari_Min2(double a, double b) {

if (a < b) {
min_result_kelompok = a;
return min_result_kelompok;
} else {
min_result_kelompok = b;
return min_result_kelompok;
}

}

private void applyRule_Kelompok_2() {

KelayakanKelompok2 kelompok2 = new KelayakanKelompok2();

output_rule_kel_2[0] = Cari_Min2(u_jaminan_SM, u_aset_SM);
u_output_kel_2[0] = kelompok2.nilai_kelayakan_kelompok2[0];
output_rule_kel_2[1] = Cari_Min2(u_jaminan_SM, u_aset_SKM);
u_output_kel_2[1] = kelompok2.nilai_kelayakan_kelompok2[1];
output_rule_kel_2[2] = Cari_Min2(u_jaminan_CM, u_aset_SM);
u_output_kel_2[2] = kelompok2.nilai_kelayakan_kelompok2[2];
output_rule_kel_2[3] = Cari_Min2(u_jaminan_CM, u_aset_SKM);
u_output_kel_2[3] = kelompok2.nilai_kelayakan_kelompok2[3];
output_rule_kel_2[4] = Cari_Min2(u_jaminan_SKM, u_aset_SM);
u_output_kel_2[4] = kelompok2.nilai_kelayakan_kelompok2[4];
output_rule_kel_2[5] = Cari_Min2(u_jaminan_SKM, u_aset_SKM);
u_output_kel_2[5] = kelompok2.nilai_kelayakan_kelompok2[5];

}

private void Compute_Output_Kelompok_2() {

double temp_1 = 0;
double temp_2 = 0;
for (int i = 0; i < 6; i++) {
temp_1 += output_rule_kel_2[i] * u_output_kel_2[i];
temp_2 += output_rule_kel_2[i];
}
z_kelompok_2 = temp_1 / temp_2;

System.out.print("\n kelompok");

System.out.print("OutPut Kel-2 " + z_kelompok_2);

txt_evaluasi.setText(String.valueOf(z_kelompok_2));
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
txt_jaminan = new javax.swing.JFormattedTextField();
jLabel2 = new javax.swing.JLabel();
txt_aset = new javax.swing.JFormattedTextField();
jLabel3 = new javax.swing.JLabel();
txt_evaluasi = new javax.swing.JTextField();
btn_proses = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Jaminan");

txt_jaminan.setBackground(new java.awt.Color(204, 255, 204));

jLabel2.setText("Aset");

txt_aset.setBackground(new java.awt.Color(204, 255, 204));

jLabel3.setText("Skor Evaluasi");

txt_evaluasi.setBackground(new java.awt.Color(153, 255, 0));
txt_evaluasi.setEditable(false);

btn_proses.setText("Proses");
btn_proses.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_prosesActionPerformed(evt);
}
});

jLabel4.setText("Sistem Evaluasi Kelayakan Pembiayaan ");

jLabel5.setText("Model Fuzzy Sugeno");

jLabel6.setText("skala : [0 - 15]");

jLabel7.setText("skala : [0 - 500.000.000]");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_jaminan, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
.addComponent(txt_aset)
.addComponent(btn_proses)
.addComponent(txt_evaluasi))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel6)))
.addGroup(layout.createSequentialGroup()
.addGap(53, 53, 53)
.addComponent(jLabel4))
.addGroup(layout.createSequentialGroup()
.addGap(92, 92, 92)
.addComponent(jLabel5)))
.addContainerGap(22, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txt_jaminan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txt_aset, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txt_evaluasi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addComponent(btn_proses)
.addGap(24, 24, 24))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void btn_prosesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_prosesActionPerformed
// TODO add your handling code here:

kondisi_jaminan = Double.parseDouble(txt_jaminan.getText());
kondisi_aset = Double.parseDouble(txt_aset.getText());

Compute_Membership();
applyRule_Kelompok_2();
Compute_Output_Kelompok_2();

}//GEN-LAST:event_btn_prosesActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new latihansugeno().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btn_proses;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JFormattedTextField txt_aset;
private javax.swing.JTextField txt_evaluasi;
private javax.swing.JFormattedTextField txt_jaminan;
// End of variables declaration//GEN-END:variables
}

 

 

Selamat Mencoba ! [download]

 

 

 


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>