📄 neuralinput.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.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Michael Thess
* @version 1.2
*/
package com.prudsys.pdm.Models.Regression.NeuralNetwork;
import com.prudsys.pdm.Adapters.PmmlVersion20.DerivedField;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Transform.OneToOneMapping;
/**
* An input unit of a Neural Network. Just runs a transformation of the
* input attribute. <p>
*
* Corresponds to PMML element NeuralInput.
*
* @see com.prudsys.pdm.Adapters.PmmlVersion20.NeuralInput
*/
public class NeuralInput extends NeuralNode {
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Transformation object of this class. */
protected OneToOneMapping oneToOneMapping = null;
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
public NeuralInput() {
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns input value.
*
* @return input value
*/
public double getInput() {
return input;
}
/**
* Sets input value.
*
* @param input new input value
*/
public void setInput(double input) {
this.input = input;
}
/**
* Returns input one-to-one mapping.
*
* @return input mapping
*/
public OneToOneMapping getOneToOneMapping() {
return oneToOneMapping;
}
/**
* Sets input one-to-one mapping.
*
* @param oneToOneMapping new mapping
*/
public void setOneToOneMapping(OneToOneMapping oneToOneMapping) {
this.oneToOneMapping = oneToOneMapping;
}
// -----------------------------------------------------------------------
// Calculation methods
// -----------------------------------------------------------------------
/**
* Reset all internal calculation values.
*/
public void resetValues() {
if ( !Category.isMissingValue(output) || !Category.isMissingValue(error) ) {
output = Category.MISSING_VALUE;
error = Category.MISSING_VALUE;
weightsUpdated = false;
}
}
/**
* Calculates input of the neural input. This is just the input value itself.
*
* @param newcalc calculate the input new
* @return input value, missing if not calculated
* @exception MiningException error while calculating input value
*/
public double inputValue(boolean newcalc) throws MiningException {
return input;
}
/**
* Calculates output of the neural input. Just applies the
* transformation to the input value.
*
* @param newcalc calculate the output new
* @return output value, missing if not calculated
* @exception MiningException error while calculating output value
*/
public double outputValue(boolean newcalc) throws MiningException {
if ( Category.isMissingValue(output) && newcalc ) {
// Transformation:
output = oneToOneMapping.transformAttributeValue(input);
}
return output;
}
/**
* Calculate error of neuron.
*
* @param newcalc calculate the error new
* @return error value, missing if not calculated
* @exception MiningException error while calculating error value
*/
public double errorValue(boolean newcalc) throws MiningException {
if ( Category.isMissingValue(error) && !Category.isMissingValue(input) && newcalc ) {
// Error back propagation:
error = 0.0;
for (int i = 0; i < getChildCount(); i++) {
NeuralNode NN = (NeuralNode) getChildAt(i);
double weight = NN.getWeightAt( NN.getParentIndex(this) );
error = error + NN.errorValue(true)*weight;
}
// Identity:
error = error*1.0;
}
return error;
}
// -----------------------------------------------------------------------
// Methods of PMML handling
// -----------------------------------------------------------------------
/**
* Write neural input to PMML element.
*
* @return PMML element of neural input
* @exception MiningException
*/
public Object createPmmlObject() throws MiningException
{
// Create neural input:
com.prudsys.pdm.Adapters.PmmlVersion20.NeuralInput ninput =
new com.prudsys.pdm.Adapters.PmmlVersion20.NeuralInput();
// Set neural input ID:
ninput.setId(id);
// Set derived field if one-to-one mapping:
if (oneToOneMapping != null)
ninput.setDerivedField( (DerivedField) oneToOneMapping.createPmmlObject() );
return ninput;
}
/**
* Read neural input from PMML element.
*
* @param pmmlObject PMML element to read in
* @exception MiningException always thrown
*/
public void parsePmmlObject( Object pmmlObject ) throws MiningException
{
// Get neural input:
com.prudsys.pdm.Adapters.PmmlVersion20.NeuralInput ninput =
(com.prudsys.pdm.Adapters.PmmlVersion20.NeuralInput) pmmlObject;
// Get neural input ID:
this.id = ninput.getId();
// Get one-to-one mapping field:
DerivedField derivedField = ninput.getDerivedField();
oneToOneMapping = OneToOneMapping.createOneToOneMappingFromPmml( derivedField );
if ( oneToOneMapping != null )
oneToOneMapping.parsePmmlObject( derivedField );
}
// -----------------------------------------------------------------------
// Further methods
// -----------------------------------------------------------------------
/**
* Delivers string representation of neural input.
*
* @return string representation of neural input
*/
public String toString() {
String s = "Neural Input, " + super.toString() + ", input value = " + input;
return s;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -