/* * Copyright (C) 2013 Vinu K.N * * 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/>. */ package org.domainmath.gui.packages.nnet; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.table.DefaultTableModel; import org.domainmath.gui.MainFrame; public class NnetFrame extends javax.swing.JFrame { public static DefaultTableModel model; private NewNetworkDialog newNetworkDialog; /** * Creates new form NnetFrame */ public NnetFrame() { model = new DefaultTableModel(); this.setIconImage(icon); initComponents(); model.addColumn("Network"); model.addColumn("Input Range"); model.addColumn("No. of Neurons"); model.addColumn("Transfer Function"); model.addColumn("Network Training Function"); model.addColumn("Weight/Bias Learning Function"); model.addColumn("Performance Function"); netTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); netTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); netTable.getTableHeader().setReorderingAllowed(false); netTable.setRowHeight(20); } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); netTable = new javax.swing.JTable(); newButton = new javax.swing.JButton(); deleteButton = new javax.swing.JButton(); simulateButton = new javax.swing.JButton(); trainButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); finishButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Nnet"); setResizable(false); netTable.setModel(model); jScrollPane1.setViewportView(netTable); newButton.setText("New Network"); newButton.setToolTipText("<html><div class=\"defun\">\n<p class=\"functionfile\"> Function File: <var>net</var>\n<b>=</b><var> <span style=\"font-weight: bold;\">newff</span>\n</var>(<var>Pr,ss,trf,btf,blf,pf</var>)<var><a\n name=\"index-g_t_003d-1\"></a></var><br>\n</p>\n<blockquote>\n <p><code>newff</code> create a feed-forward\nbackpropagation network </p>\n <pre class=\"example\"> <span\n style=\"font-weight: bold;\"> Pr</span> - R x 2 matrix of min and max values for R input elements<br> <span\n style=\"font-weight: bold;\">Ss</span> - 1 x Ni row vector with size of ith layer, for N layers<br> <span\n style=\"font-weight: bold;\">trf</span> - 1 x Ni list with transfer function of ith layer,<br> default = \"tansig\"<br> <span\n style=\"font-weight: bold;\">btf</span> - Batch network training function,<br> default = \"trainlm\"<br> <span\n style=\"font-weight: bold;\">blf</span> - Batch weight/bias learning function,<br> default = \"learngdm\"<br> <span\n style=\"font-weight: bold;\">pf</span> - Performance function,<br> default = \"mse\".<br></pre>\n <pre class=\"example\"> EXAMPLE 1<br> Pr = [0.1 0.8; 0.1 0.75; 0.01 0.8];<br> it's a 3 x 2 matrix, this means 3 input neurons<br> <br> net = newff(Pr, [4 1], {\"tansig\",\"purelin\"}, \"trainlm\", \"learngdm\", \"mse\");<br></pre>\n</blockquote>\n</div></html>\n"); newButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newButtonActionPerformed(evt); } }); deleteButton.setText("Delete Network"); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(evt); } }); simulateButton.setText("Simulate"); simulateButton.setToolTipText("<html><div class=\"defun\">\n<div class=\"defun\">\n<p class=\"functionfile\"> Function File: <var>netoutput</var>\n= <b>sim</b> (<var>net, mInput</var>)<var><a\n name=\"index-sim-1\"></a></var><br>\n</p>\n<blockquote>\n <p><code>sim</code> is usuable to simulate a before\ndefined neural network. <code>net</code> is created with\nnewff(<small class=\"dots\">...</small>) and <var>mInput</var>\nshould be the\ncorresponding input data set! </p>\n</blockquote></html>\n"); simulateButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { simulateButtonActionPerformed(evt); } }); trainButton.setText("Train"); trainButton.setToolTipText("<html><div class=\"defun\">\n<div class=\"defun\">\n<p class=\"functionfile\"> Function File: <b>[</b><var>net</var>]<var>\n= train </var>(<var>MLPnet,mInputN,mOutput,[],[],VV</var>)<var><a\n name=\"index-g_t_005b-1\"></a></var><br>\n</p>\n<blockquote>\n <p>A neural feed-forward network will be trained with <code>train</code>\n </p>\n <pre class=\"example\"> [net,tr,out,E] = train(MLPnet,mInputN,mOutput,[],[],VV);<br></pre>\n <p class=\"noindent\"> </p>\n <pre class=\"example\"> left side arguments:<br> <span\n style=\"font-weight: bold;\">net</span>: the trained network of the net structure <code>MLPnet</code>\n </pre>\n <p class=\"noindent\"> </p>\n <pre class=\"example\"> right side arguments:<br> <span\n style=\"font-weight: bold;\">MLPnet</span> : the untrained network, created with <code>newff</code><br> <span\n style=\"font-weight: bold;\">mInputN</span>: normalized input matrix<br> <span\n style=\"font-weight: bold;\">mOutput</span>: output matrix (normalized or not)<br> <span\n style=\"font-weight: bold;\">[]</span> : unused parameter<br> <span\n style=\"font-weight: bold;\">[]</span> : unused parameter<br> <span\n style=\"font-weight: bold;\">VV</span> : validize structure<br></pre>\n</blockquote>\n</div>\n</div></html>\n"); trainButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { trainButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); finishButton.setText("Finish"); finishButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { finishButtonActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 407, Short.MAX_VALUE) .addComponent(finishButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton)) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(newButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(deleteButton, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(simulateButton, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(trainButton, javax.swing.GroupLayout.Alignment.TRAILING)))) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteButton, newButton, simulateButton, trainButton}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(newButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(deleteButton) .addGap(18, 18, 18) .addComponent(simulateButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(trainButton)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(finishButton)) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {deleteButton, newButton, simulateButton, trainButton}); pack(); }// </editor-fold>//GEN-END:initComponents private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed dispose(); }//GEN-LAST:event_cancelButtonActionPerformed public static void declare(String name, String value) { MainFrame.octavePanel.eval(name+"="+value+";"); } private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed newNetworkDialog = new NewNetworkDialog(this,true); newNetworkDialog.setLocationRelativeTo(this); newNetworkDialog.setVisible(true); }//GEN-LAST:event_newButtonActionPerformed private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed model.removeRow(this.netTable.getSelectedRow()); if(netTable.getSelectedRow() >= 0) { MainFrame.octavePanel.evalWithOutput("clear '"+netTable.getValueAt(netTable.getSelectedRow(), 0)+"'"); NewNetworkDialog.minusIndex(); } }//GEN-LAST:event_deleteButtonActionPerformed private void finishButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishButtonActionPerformed dispose(); }//GEN-LAST:event_finishButtonActionPerformed private void simulateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulateButtonActionPerformed if(netTable.getSelectedRow() >= 0) { SimulateNetDialog simulateNetDialog = new SimulateNetDialog(this,true,netTable.getValueAt(netTable.getSelectedRow(), 0).toString()); simulateNetDialog.setLocationRelativeTo(this); simulateNetDialog.setVisible(true); } }//GEN-LAST:event_simulateButtonActionPerformed private void trainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trainButtonActionPerformed if(netTable.getSelectedRow() >= 0) { TrainNetDialog trainNetDialog = new TrainNetDialog(this,true,netTable.getValueAt(netTable.getSelectedRow(), 0).toString()); trainNetDialog.setLocationRelativeTo(this); trainNetDialog.setVisible(true); } }//GEN-LAST:event_trainButtonActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(NnetFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NnetFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NnetFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NnetFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NnetFrame().setVisible(true); } }); } public Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/org/domainmath/gui/resources/DomainMath.png")); // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JButton deleteButton; private javax.swing.JButton finishButton; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable netTable; private javax.swing.JButton newButton; private javax.swing.JButton simulateButton; private javax.swing.JButton trainButton; // End of variables declaration//GEN-END:variables }