SlideShare a Scribd company logo
1 of 3
Page1
Algoritma Kecerdsan Buatan
Sudirman : D082192007
Buku Halaman 61
Page2
Program 1 Program 2
#include <iostream>
using namespace std;
main(){
int x1[]={1,1,0,0};
int x2[]={1,0,1,0};
int t[]={1,-1,-1,-1};
float w1=0, w2=0, y=0,bias=0;
float alfa=1, teta=0.2;
float y_in;
int counter=0;
int epoh=1;
//int indeks=0;
while(counter!=4)
{
counter=0;
cout<<"Epoh ke
"<<epoh<<endl<<endl;
for(int
indeks=0;indeks<4;indeks++)
{
//
cout<<"Baris data ke
"<<indeks<<endl<<endl;
y_in = bias +
(x1[indeks]*w1) + (x2[indeks]*w2);
cout<<"y_in = "<<bias<<" +
"
<<"("<<x1[indeks]<<" * "<<w1<<") +
( "<<x2[indeks]<<" * "<<w2<<")"
<<endl<<"Nilai dari
y_in = "<<y_in<<endl<<endl;
//cari nilai y
//step 4
if (y_in > teta)
{
y=1;
cout<<" Karena
y_in > teta"<<endl
<<" Nilai
Y = "<<y<<endl<<endl;
}
else if((y_in >= -teta )
and (y_in <= teta))
{
y=0;
cout<<" Karena
y_in >= teta dan y_in <= teta"<<endl
<<" Nilai
Y = "<<y<<endl<<endl;
}
else if (y_in < -teta)
{
y=-1;
cout<<" Karena
y_in < -teta"<<endl
<<" Nilai
Y = "<<y<<endl<<endl;
}
//pengecekan perubahan
bobot
//step 5
if (y!=t[indeks])
{ cout<<" Update
bobotnya !!!"<<endl
<<" w1
= "<<w1<<" + ( "<<alfa<<" *
"<<t[indeks]<<" * "<<x1[indeks]<<"
)"<<endl
<<" w2
= "<<w1<<" + ( "<<alfa<<" *
"<<t[indeks]<<" * "<<x2[indeks]<<"
)"<<endl
<<"
bias = "<<bias<<" + ( "<<alfa<<" *
"<<t[indeks]<<" )"<<endl<<endl;
w1=w1+(alfa*t[indeks]*x1[indeks]);
w2=w2+(alfa*t[indeks]*x2[indeks]);
bias=bias+(alfa*t[indeks]);
}
else
{
counter++;
}
}//for
cout<<"Akhir Epoh "<<epoh<<" ----
----------------------------"<<endl;
epoh++;
}//while
cout<<"Nilai W1 = "<<w1<<endl
<<"Nilai W2 = "<<w2<<endl
<<"Nilai bias =
"<<bias<<endl<<endl;
/*
Pelatihan Berhasil
*/
//by@ dymand
}
#include <iostream>
using namespace std;
main(){
int x1[]={1,1,0,0};
int x2[]={1,0,1,0};
int t[]={1,-1,-1,-1};
float w1=0, w2=0, y=0,bias=0;
float alfa=1, teta=0.2;
float y_in;
int counter=0;
int epoh=1;
//int indeks=0;
while(counter!=4)
{
counter=0;
cout<<"Epoh ke
"<<epoh<<endl<<endl;
for(int
indeks=0;indeks<4;indeks++)
{
//
cout<<"Baris data ke
"<<indeks<<endl<<endl;
y_in = bias +
(x1[indeks]*w1) + (x2[indeks]*w2);
cout<<"y_in = "<<bias<<" +
"
<<"("<<x1[indeks]<<" * "<<w1<<") +
( "<<x2[indeks]<<" * "<<w2<<")"
<<endl<<"Nilai dari
y_in = "<<y_in<<endl<<endl;
//cari nilai y
//step 4
if (y_in > teta)
{
y=1;
cout<<" Karena
y_in > teta"<<endl
<<" Nilai
Y = "<<y<<endl<<endl;
}
else if((y_in >= -teta )
and (y_in <= teta))
{
y=0;
cout<<" Karena
y_in >= teta dan y_in <= teta"<<endl
<<" Nilai
Y = "<<y<<endl<<endl;
}
else if (y_in < -teta)
{
y=-1;
cout<<" Karena
y_in < -teta"<<endl
<<" Nilai
Y = "<<y<<endl<<endl;
}
//pengecekan perubahan
bobot
//step 5
if (y!=t[indeks])
{ cout<<" Update
bobotnya !!!"<<endl
<<" w1
= "<<w1<<" + ( "<<alfa<<" *
"<<t[indeks]<<" * "<<x1[indeks]<<"
)"<<endl
<<" w2
= "<<w1<<" + ( "<<alfa<<" *
"<<t[indeks]<<" * "<<x2[indeks]<<"
)"<<endl
<<"
bias = "<<bias<<" + ( "<<alfa<<" *
"<<t[indeks]<<" )"<<endl<<endl;
w1=w1+(alfa*t[indeks]*x1[indeks]);
w2=w2+(alfa*t[indeks]*x2[indeks]);
bias=bias+(alfa*t[indeks]);
}
else
{
counter++;
}
}//for
cout<<"Akhir Epoh "<<epoh<<" ----
----------------------------"<<endl;
epoh++;
}//while
cout<<"Nilai W1 = "<<w1<<endl
<<"Nilai W2 = "<<w2<<endl
<<"Nilai bias =
"<<bias<<endl<<endl;
cout<<"++++++++++++++++++++++++++++++++++
++++++++++++++++++"<<endl<<endl;
// Selanjutnya Pengujian
//data baru masuk
int x1_baru[]={0,0,1,1};
int x2_baru[]={0,1,0,1};
Page3
Output Program 1
Output Program 2

More Related Content

What's hot

What's hot (20)

Inteligencia artificial 4
Inteligencia artificial 4Inteligencia artificial 4
Inteligencia artificial 4
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
Bits, bytes and characters
Bits, bytes and charactersBits, bytes and characters
Bits, bytes and characters
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
Master's Thesis
Master's ThesisMaster's Thesis
Master's Thesis
 
The Ring programming language version 1.2 book - Part 30 of 84
The Ring programming language version 1.2 book - Part 30 of 84The Ring programming language version 1.2 book - Part 30 of 84
The Ring programming language version 1.2 book - Part 30 of 84
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
1D Array
1D Array1D Array
1D Array
 
The Ring programming language version 1.6 book - Part 44 of 189
The Ring programming language version 1.6 book - Part 44 of 189The Ring programming language version 1.6 book - Part 44 of 189
The Ring programming language version 1.6 book - Part 44 of 189
 
Vancouver Canada MuleSoft Meetup Nov 2020
Vancouver Canada MuleSoft Meetup Nov 2020Vancouver Canada MuleSoft Meetup Nov 2020
Vancouver Canada MuleSoft Meetup Nov 2020
 
Vcs17
Vcs17Vcs17
Vcs17
 
The Ring programming language version 1.7 book - Part 46 of 196
The Ring programming language version 1.7 book - Part 46 of 196The Ring programming language version 1.7 book - Part 46 of 196
The Ring programming language version 1.7 book - Part 46 of 196
 
Comparisons
ComparisonsComparisons
Comparisons
 
AM2 MATLAB
AM2 MATLABAM2 MATLAB
AM2 MATLAB
 
Los dskn
Los dsknLos dskn
Los dskn
 
A proper introduction to Elm
A proper introduction to ElmA proper introduction to Elm
A proper introduction to Elm
 
Ocr code
Ocr codeOcr code
Ocr code
 

Similar to Perceptron

Programa.eje
Programa.ejePrograma.eje
Programa.ejeguapi387
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docxajoy21
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfapexelectronices01
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better codeDror Helper
 
Program(Output)
Program(Output)Program(Output)
Program(Output)princy75
 
Binary addition using class concept in c++
Binary addition using class concept in c++Binary addition using class concept in c++
Binary addition using class concept in c++Swarup Boro
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFTimur Safin
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringSri Harsha Pamu
 

Similar to Perceptron (20)

Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
 
cosc 281 hw2
cosc 281 hw2cosc 281 hw2
cosc 281 hw2
 
Program(Output)
Program(Output)Program(Output)
Program(Output)
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
Binary addition using class concept in c++
Binary addition using class concept in c++Binary addition using class concept in c++
Binary addition using class concept in c++
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
Caropro
CaroproCaropro
Caropro
 
Property-based testing
Property-based testingProperty-based testing
Property-based testing
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

Perceptron

  • 1. Page1 Algoritma Kecerdsan Buatan Sudirman : D082192007 Buku Halaman 61
  • 2. Page2 Program 1 Program 2 #include <iostream> using namespace std; main(){ int x1[]={1,1,0,0}; int x2[]={1,0,1,0}; int t[]={1,-1,-1,-1}; float w1=0, w2=0, y=0,bias=0; float alfa=1, teta=0.2; float y_in; int counter=0; int epoh=1; //int indeks=0; while(counter!=4) { counter=0; cout<<"Epoh ke "<<epoh<<endl<<endl; for(int indeks=0;indeks<4;indeks++) { // cout<<"Baris data ke "<<indeks<<endl<<endl; y_in = bias + (x1[indeks]*w1) + (x2[indeks]*w2); cout<<"y_in = "<<bias<<" + " <<"("<<x1[indeks]<<" * "<<w1<<") + ( "<<x2[indeks]<<" * "<<w2<<")" <<endl<<"Nilai dari y_in = "<<y_in<<endl<<endl; //cari nilai y //step 4 if (y_in > teta) { y=1; cout<<" Karena y_in > teta"<<endl <<" Nilai Y = "<<y<<endl<<endl; } else if((y_in >= -teta ) and (y_in <= teta)) { y=0; cout<<" Karena y_in >= teta dan y_in <= teta"<<endl <<" Nilai Y = "<<y<<endl<<endl; } else if (y_in < -teta) { y=-1; cout<<" Karena y_in < -teta"<<endl <<" Nilai Y = "<<y<<endl<<endl; } //pengecekan perubahan bobot //step 5 if (y!=t[indeks]) { cout<<" Update bobotnya !!!"<<endl <<" w1 = "<<w1<<" + ( "<<alfa<<" * "<<t[indeks]<<" * "<<x1[indeks]<<" )"<<endl <<" w2 = "<<w1<<" + ( "<<alfa<<" * "<<t[indeks]<<" * "<<x2[indeks]<<" )"<<endl <<" bias = "<<bias<<" + ( "<<alfa<<" * "<<t[indeks]<<" )"<<endl<<endl; w1=w1+(alfa*t[indeks]*x1[indeks]); w2=w2+(alfa*t[indeks]*x2[indeks]); bias=bias+(alfa*t[indeks]); } else { counter++; } }//for cout<<"Akhir Epoh "<<epoh<<" ---- ----------------------------"<<endl; epoh++; }//while cout<<"Nilai W1 = "<<w1<<endl <<"Nilai W2 = "<<w2<<endl <<"Nilai bias = "<<bias<<endl<<endl; /* Pelatihan Berhasil */ //by@ dymand } #include <iostream> using namespace std; main(){ int x1[]={1,1,0,0}; int x2[]={1,0,1,0}; int t[]={1,-1,-1,-1}; float w1=0, w2=0, y=0,bias=0; float alfa=1, teta=0.2; float y_in; int counter=0; int epoh=1; //int indeks=0; while(counter!=4) { counter=0; cout<<"Epoh ke "<<epoh<<endl<<endl; for(int indeks=0;indeks<4;indeks++) { // cout<<"Baris data ke "<<indeks<<endl<<endl; y_in = bias + (x1[indeks]*w1) + (x2[indeks]*w2); cout<<"y_in = "<<bias<<" + " <<"("<<x1[indeks]<<" * "<<w1<<") + ( "<<x2[indeks]<<" * "<<w2<<")" <<endl<<"Nilai dari y_in = "<<y_in<<endl<<endl; //cari nilai y //step 4 if (y_in > teta) { y=1; cout<<" Karena y_in > teta"<<endl <<" Nilai Y = "<<y<<endl<<endl; } else if((y_in >= -teta ) and (y_in <= teta)) { y=0; cout<<" Karena y_in >= teta dan y_in <= teta"<<endl <<" Nilai Y = "<<y<<endl<<endl; } else if (y_in < -teta) { y=-1; cout<<" Karena y_in < -teta"<<endl <<" Nilai Y = "<<y<<endl<<endl; } //pengecekan perubahan bobot //step 5 if (y!=t[indeks]) { cout<<" Update bobotnya !!!"<<endl <<" w1 = "<<w1<<" + ( "<<alfa<<" * "<<t[indeks]<<" * "<<x1[indeks]<<" )"<<endl <<" w2 = "<<w1<<" + ( "<<alfa<<" * "<<t[indeks]<<" * "<<x2[indeks]<<" )"<<endl <<" bias = "<<bias<<" + ( "<<alfa<<" * "<<t[indeks]<<" )"<<endl<<endl; w1=w1+(alfa*t[indeks]*x1[indeks]); w2=w2+(alfa*t[indeks]*x2[indeks]); bias=bias+(alfa*t[indeks]); } else { counter++; } }//for cout<<"Akhir Epoh "<<epoh<<" ---- ----------------------------"<<endl; epoh++; }//while cout<<"Nilai W1 = "<<w1<<endl <<"Nilai W2 = "<<w2<<endl <<"Nilai bias = "<<bias<<endl<<endl; cout<<"++++++++++++++++++++++++++++++++++ ++++++++++++++++++"<<endl<<endl; // Selanjutnya Pengujian //data baru masuk int x1_baru[]={0,0,1,1}; int x2_baru[]={0,1,0,1};