Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
SigmoidUnit.java
Package: Weka-3-2.rar [view]
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:
Windows Develop
Development Platform:
Java
- /*
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- /*
- * SigmoidUnit.java
- * Copyright (C) 2001 Malcolm Ware
- */
- package weka.classifiers.functions.neural;
- /**
- * This can be used by the
- * neuralnode to perform all it's computations (as a sigmoid unit).
- *
- * @author Malcolm Ware (mfw4@cs.waikato.ac.nz)
- * @version $Revision: 1.3 $
- */
- public class SigmoidUnit implements NeuralMethod {
- /**
- * This function calculates what the output value should be.
- * @param node The node to calculate the value for.
- * @return The value.
- */
- public double outputValue(NeuralNode node) {
- double[] weights = node.getWeights();
- NeuralConnection[] inputs = node.getInputs();
- double value = weights[0];
- for (int noa = 0; noa < node.getNumInputs(); noa++) {
- value += inputs[noa].outputValue(true)
- * weights[noa+1];
- }
- //this I got from the Neural Network faq to combat overflow
- //pretty simple solution really :)
- if (value < -45) {
- value = 0;
- }
- else if (value > 45) {
- value = 1;
- }
- else {
- value = 1 / (1 + Math.exp(-value));
- }
- return value;
- }
- /**
- * This function calculates what the error value should be.
- * @param node The node to calculate the error for.
- * @return The error.
- */
- public double errorValue(NeuralNode node) {
- //then calculate the error.
- NeuralConnection[] outputs = node.getOutputs();
- int[] oNums = node.getOutputNums();
- double error = 0;
- for (int noa = 0; noa < node.getNumOutputs(); noa++) {
- error += outputs[noa].errorValue(true)
- * outputs[noa].weightValue(oNums[noa]);
- }
- double value = node.outputValue(false);
- error *= value * (1 - value);
- return error;
- }
- /**
- * This function will calculate what the change in weights should be
- * and also update them.
- * @param node The node to update the weights for.
- * @param learn The learning rate to use.
- * @param momentum The momentum to use.
- */
- public void updateWeights(NeuralNode node, double learn, double momentum) {
- NeuralConnection[] inputs = node.getInputs();
- double[] cWeights = node.getChangeInWeights();
- double[] weights = node.getWeights();
- double learnTimesError = 0;
- try {
- learnTimesError = learn * node.errorValue(false);
- } catch(Exception e) {}
- double c = learnTimesError + momentum * cWeights[0];
- weights[0] += c;
- cWeights[0] = c;
- int stopValue = node.getNumInputs() + 1;
- for (int noa = 1; noa < stopValue; noa++) {
- c = learnTimesError * inputs[noa-1].outputValue(false);
- c += momentum * cWeights[noa];
- weights[noa] += c;
- cWeights[noa] = c;
- }
- }
- }