








En esta correción, los valores son de 1 a n a diferencia del anterior de 1 a 5 (perceptrón)
package neuronai;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
public class InterfazGrafica extends javax.swing.JFrame {
DefaultListModel persep=new DefaultListModel();
DefaultListModel peso=new DefaultListModel();
public InterfazGrafica() {
initComponents();
}
@SuppressWarnings("unchecked")
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel5 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
jList2 = new javax.swing.JList();
jLabel6 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jLabel7 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Neurona+*-+*-+*-+*-");
jLabel1.setText("Agente NEURONA---------");
jLabel2.setText("Introdicir el número de percepciones");
jLabel3.setText("P");
jLabel4.setText("W");
jScrollPane1.setViewportView(jList1);
jLabel5.setText("n = ");
jScrollPane2.setViewportView(jList2);
jLabel6.setText("Función = ");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "hardlim", "hardlims", "poslin", "purelin", "satlin", "satlins", "logsig", "tansig", "compet" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jLabel7.setText("a = ");
jButton1.setText("Calcular");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(56, 56, 56)
.addComponent(jLabel4)
.addGap(42, 42, 42)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(14, 14, 14))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, 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.LEADING)
.addComponent(jLabel7)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
.addComponent(jScrollPane2))
.addContainerGap(19, Short.MAX_VALUE))
);
pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
/**Variables a usar,
* persepciones: en este apartado, el usuario insertará el número de persepciones, de 1 a n
* p: es la percepsión en la que se acumulará en un list, la captura se realiza con un
* mensage de diálogo
* w: es el peso la percepsión en la que se acumulará en un list, la captura se realiza
* con un mensage de diálogo.
* multiplicacion: en esta variable se multiplica w*p
* n: Es la sumatoria de la multiplicacion
*/
float percepsiones,p,w,multiplicacion,n=0;
percepsiones = Integer.parseInt(jTextField1.getText());
for (float acumulador=1;acumulador<=percepsiones;acumulador++){
p=Float.parseFloat(JOptionPane.showInputDialog("Favor de introducir la percepción"));
persep.addElement(p);
jList1.setModel(persep);
w=Float.parseFloat(JOptionPane.showInputDialog("Favor de introducir el peso"));
peso.addElement(w);
jList2.setModel(peso);
multiplicacion=p*w;
n=n+multiplicacion;
// Se evalúa cpor medio de la función hardlim
if (jComboBox1.getSelectedItem()== "hardlim"){
if(n<0){
jTextField3.setText("0");
}
if(n>=0){
jTextField3.setText("1");
}
}
jTextField2.setText(""+n);
}
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
//Se evalúa en el combobox, la función a realizar
float valorN,a;
valorN = Float.parseFloat(jTextField2.getText());
if (jComboBox1.getSelectedItem()== "hardlim"){
if(valorN<0){
jTextField3.setText("0");
}
if(valorN>=0){
jTextField3.setText("1");
}
}
if (jComboBox1.getSelectedItem()== "hardlims"){
if(valorN<0){
jTextField3.setText("-1");
}
if(valorN>=0){
jTextField3.setText("+1");
}
}
if (jComboBox1.getSelectedItem()== "poslin"){
if(valorN<0){
jTextField3.setText("0");
}
if(valorN>=0){
jTextField3.setText(""+valorN);
}
}
if (jComboBox1.getSelectedItem()== "purelin"){
jTextField3.setText(""+valorN);
}
if (jComboBox1.getSelectedItem()== "satlin"){
if(valorN<0){
jTextField3.setText("0");
}
if(valorN>=0 && valorN<=1){
jTextField3.setText(""+valorN);
}
if(valorN>1){
jTextField3.setText("1");
}
}
if (jComboBox1.getSelectedItem()== "satlins"){
if(valorN<-1){
jTextField3.setText("-1");
}
if(valorN>=-1 && valorN<=1){
jTextField3.setText(""+valorN);
}
if(valorN<1){
jTextField3.setText("+1");
}
}
if (jComboBox1.getSelectedItem()== "logsig"){
float expn=(float)(Math.exp(-valorN));
a=1/(1+expn);
jTextField3.setText(""+a);
}
if (jComboBox1.getSelectedItem()== "tansig"){
float expn=(float)(Math.exp(-valorN)),expn1=(float)(Math.exp(valorN));
a=(expn1-expn)/(expn1+expn);
jTextField3.setText(""+a);
}
if (jComboBox1.getSelectedItem()== "compet"){
jTextField3.setText("compet");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new InterfazGrafica().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
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.JList jList1;
private javax.swing.JList jList2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}
Main
package redneurona;
public class Main {
public static void main(String[] args) {
InterfazGrafica interfaz = new InterfazGrafica();
interfaz.setVisible(true);
}
}
No hay comentarios:
Publicar un comentario