277294.ijbsn.asia
misc.dfPackage
2000-06-19T16:00:00Z
2000-06-19T16:00:00Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2000-06-19T16:00:00Z
Graph.java
2000-06-17T16:00:00Z
2000-06-17T16:00:00Z
<br/><TEXTAREA name="code" class="java" rows="16" cols="100">
import javax.swing.*;
import java.awt.*;
/**
* Title: Graph<p>
* Description: Simple program to produce a graph for the book<p>
* Copyright: Copyright (c) Mark Watson<p>
* Company: <p>
* @author Mark Watson
* @version 1.0
*/
public class Graph extends JFrame {
GraphPanel jPanel1;
float [] data1;
float [] data2;
public Graph() {
try {
int size = 500;
data1 = new float[size];
data2 = new float[size];
float xmin = -5;
float xmax = 5;
for (int i=0; i<size; i++) {
float x = i;
x = xmin + x * (xmax - xmin) / (float)size;
data1[i] = sigmoid(x);
data2[i] = sigmoidP(x);
}
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
protected float sigmoid(float x) {
return
(float)((1.0f/(1.0f+Math.exp((double)(-x))))-0.5f);
}
protected float sigmoidP(float x) {
double z = sigmoid(x) + 0.5f;
return (float)(z * (1.0f - z));
}
public static void main(String[] args) {
Graph untitled11 = new Graph();
}
private void jbInit() throws Exception {
jPanel1 = new GraphPanel(data1, data2);
jPanel1.setBackground(Color.white);
this.setDefaultCloseOperation(3);
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
setSize(550, 300);
jPanel1.setVisible(true);
setVisible(true);
}
}
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2000-06-17T16:00:00Z
GraphPanel.java
2000-06-17T16:00:00Z
2000-06-17T16:00:00Z
<br/><TEXTAREA name="code" class="java" rows="16" cols="100">/**
* Title: <p>
* Description: <p>
* Copyright: Copyright (c) <p>
* Company: <p>
* @author
* @version 1.0
*/
import javax.swing.*;
import java.awt.*;
public class GraphPanel extends java.awt.Canvas { // JPanel {
public GraphPanel(float [] data1, float []data2) {
super();
this.data1 = data1;
this.data2 = data2;
}
Color black = new Color(0, 0, 0);
float [] data1;
float [] data2;
public void paint(Graphics g) {
if (data1 == null || data2 == null) return;
int width = this.getWidth();
int height = this.getHeight();
System.out.println("height="+height);
float min = 99999999.9f;
float max = -min;
int maxindex = 0;
float maxval = 0.0f;
for (int i=0; i<data1.length; i++) { // assume length of data1 and data2 are the same
if (min > data1[i]) min = data1[i];
if (max < data1[i]) max = data1[i];
if (min > data2[i]) min = data2[i];
if (max < data2[i]) max = data2[i];
}
System.out.println("min=" + min +", max=" + max);
g.setColor(Color.red);
for (int i=0; i<data1.length - 1; i++) {
float y1 = height - 5 - 0.95f *height * ((data1[i] - min) / (max - min));
float y2 = height - 5 - 0.95f *height * ((data1[i+1] - min) / (max - min));
//System.out.println("data["+i+"]="+data[i]+", y1="+y1+", y2="+y2);
g.drawLine(i+20, (int)y1, i+21, (int)y2);
y1 = height - 5 - 0.95f *height * ((data2[i] - min) / (max - min));
y2 = height - 5 - 0.95f *height * ((data2[i+1] - min) / (max - min));
//System.out.println("data["+i+"]="+data[i]+", y1="+y1+", y2="+y2);
g.drawLine(i+20, (int)y1, i+21, (int)y2);
}
float yzero = height - 5 - 0.95f *height * ((0.0f - min) / (max - min));
g.setColor(black);
g.drawLine(20, (int)yzero, data2.length + 19, (int)yzero);
g.drawLine(width / 2, height/2 - 118, width/2, height/2 + 118);
g.drawString("Sigmoid", width / 2 - 100, 3 * height / 4 - 10);
g.drawString("SigmoidP", width / 3 - 5, 1 * height / 4 + 10);
g.drawString("-5", 4, (int)yzero);
g.drawString("5", width - 19, (int)yzero);
g.drawString("0.5", width/2 - 7, 12);
g.drawString("-0.5", width/2 - 9, height - 3);
}
}
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2000-06-17T16:00:00Z