/*
* Encog Workbench v1.x
* http://www.heatonresearch.com/encog/
* http://code.google.com/p/encog-java/
*
* Copyright 2008, Heaton Research Inc., and individual contributors.
* See the copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.encog.visualize;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.structure.AnalyzeNetwork;
import org.encog.workbench.WorkBenchError;
import org.encog.workbench.frames.document.tree.ProjectEGFile;
import org.encog.workbench.frames.document.tree.ProjectFile;
import org.encog.workbench.tabs.EncogCommonTab;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.xy.IntervalXYDataset;
import org.encog.neural.networks.BasicNetwork;
import org.encog.workbench.frames.EncogCommonFrame;
import org.encog.workbench.frames.document.tree.ProjectEGFile;
import org.encog.workbench.tabs.mlmethod.MLMethodTab;
import org.encog.workbench.tabs.visualize.weights.*;
public class NetworkWeightsFrame extends EncogCommonFrame {
/**
* Visualaze weights of the NN.
* S.Chekanov.
*/
private static final long serialVersionUID = 1L;
private JButton buttonClose;
private JTabbedPane tabs;
private WeightInfo weightInfo;
private AnalyzeNetwork analyze;
private BasicNetwork network;
private HistogramDataset dataAll;
private HistogramDataset dataWeights;
private HistogramDataset dataBiases;
public NetworkWeightsFrame(final BasicNetwork network) {
this.network = network;
addWindowListener((WindowListener) this);
setTitle("Visualize Weights");
getContentPane().add(setPannels(), BorderLayout.CENTER);
setSize(520, 500);
}
public void actionPerformed(final ActionEvent e) {
}
public void mouseClicked(final MouseEvent e) {
// TODO Auto-generated method stub
}
public void windowOpened(final WindowEvent e) {
}
private JPanel setPannels(){
JPanel main = new JPanel();
this.analyze = new AnalyzeNetwork(this.network);
System.out.println("Debug network=\n"+this.analyze.toString());
this.setLayout(new BorderLayout());
JPanel buttonPanel = new JPanel();
main.add(buttonPanel,BorderLayout.SOUTH);
this.buttonClose = new JButton("Close");
buttonPanel.add(this.buttonClose);
this.buttonClose.addActionListener(this);
// this.weightInfo = new WeightInfo(this.analyze);
// this.weightInfo = new WeightInfo();
// main.add(this.weightInfo,BorderLayout.NORTH);
//
createAllDataset();
ChartPanel allChart = new ChartPanel(createChart(this.dataAll));
ChartPanel weightChart = new ChartPanel(createChart(this.dataWeights));
ChartPanel biasesChart = new ChartPanel(createChart(this.dataBiases));
this.tabs = new JTabbedPane();
this.tabs.addTab("Weights & Biases", allChart);
this.tabs.addTab("Weights", weightChart);
this.tabs.addTab("Biases", biasesChart);
main.add(tabs,BorderLayout.CENTER);
return main;
}
private void createAllDataset() {
// all values
this.dataAll = new HistogramDataset();
double[] values = this.analyze.getAllValues();
if (values != null && values.length>0) this.dataAll.addSeries("Weights & Biases", values, 50);
// weight values
this.dataBiases = new HistogramDataset();
double[] values2 = this.analyze.getWeightValues();
if (values2 != null && values2.length>0) this.dataBiases.addSeries("Biases", values2, 50);
// threshold values
this.dataWeights = new HistogramDataset();
double[] values3 = this.analyze.getBiasValues();
if (values3 != null && values3.length>0) this.dataWeights.addSeries("Weights", values3, 50);
}
/**
* Creates a chart.
*
* @param dataset a dataset.
*
* @return The chart.
*/
private JFreeChart createChart(IntervalXYDataset dataset) {
JFreeChart chart = ChartFactory.createHistogram(
null,
null,
null,
dataset,
PlotOrientation.VERTICAL,
true,
false,
false
);
chart.getXYPlot().setForegroundAlpha(0.75f);
return chart;
}
public AnalyzeNetwork getAnalyze()
{
return this.analyze;
}
@Override
public String getName() {
return "Visualize Weights";
}
}
Ads help maintain this website.