/*
 This is a proprietary part of DataMelt package.
 License: the Creative Commons Attribution-Share Alike License; either version 3.0 of the License, 
 or any later version.
 http://creativecommons.org/licenses/by-sa/3.0/
 

Redistributions of the source code, or parts of the source codes, must retain the copyright notice, this list of conditions and the following disclaimer (all at the top of each source code) and requires the written permission from DataMelt.

Redistribution in binary form of all or parts of a class must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution and requires the written permission of ScaVis

Details about license agreement or commercial use are: http://jwork.org/scavis/ */ package jhpro.nnet; /** * * * The connection structure between two neuron layers of a neural net. Its * elements, the weights, are changed during the net's learning process. Each * neural net has at least one weight matrix. * * @author sergei * */ public class WeightMatrix implements java.io.Serializable { public WeightMatrix(int i, int j, boolean flag) { weight = new float[i][j]; bias = new float[j]; for (int k = 0; k < j; k++) bias[k] = 1.0F; size = i * j; if (flag) size += j; } public void init() { for (int i = 0; i < weight.length; i++) { for (int j = 0; j < weight[0].length; j++) weight[i][j] = (float) Math.random() * 2.0F - 1.0F; } for (int k = 0; k < weight[0].length; k++) bias[k] = (float) Math.random() * 2.0F - 1.0F; } public void init(float af[][]) { for (int i = 0; i < weight.length; i++) { for (int j = 0; j < weight[0].length; j++) weight[i][j] = af[i][j]; } } public void init(InputValue ainputvalue[], int i) { switch (i) { case 1: // '\001' for (int j = 0; j < weight[0].length; j++) weight[0][j] = (float)ainputvalue[j].getX(); return; case 2: // '\002' for (int k = 0; k < weight[0].length; k++) { weight[0][k] = (float)ainputvalue[k].getX(); weight[1][k] = (float)ainputvalue[k].getY(); } return; case 3: // '\003' for (int l = 0; l < weight[0].length; l++) { weight[0][l] = (float)ainputvalue[l].getX(); weight[1][l] = (float)ainputvalue[l].getY(); weight[2][l] = (float)ainputvalue[l].getZ(); } return; } } public void changeWeights(float af[], float af1[], double d) { for (int i = 0; i < weight.length; i++) if (af[i] != 0.0F) { for (int j = 0; j < weight[0].length; j++) if (af1[j] != 1.0F && af1[j] != 0.0F) { float f = weight[i][j]; weight[i][j] = 0.0F; weight[i][j] = f + af[i] * af1[j] * (1.0F - af1[j]) * (float) d; } } for (int k = 0; k < bias.length; k++) if (af1[k] != 1.0F && af1[k] != 0.0F) { float f1 = bias[k]; bias[k] = 0.0F; bias[k] = f1 + af1[k] * (1.0F - af1[k]) * (float) d; } } public void changeWeightsKFM(float af[], float af1[], double d) { for (int i = 0; i < weight.length; i++) { for (int j = 0; j < weight[0].length; j++) if (af[i] != weight[i][j] && af1[j] != 0.0F) { float f = weight[i][j]; weight[i][j] = 0.0F; weight[i][j] = f + af1[j] * (af[i] - f) * (float) d; } } } public float[] getInputWeights(int i) { float af[] = new float[weight.length + 1]; for (int j = 0; j < weight.length; j++) af[j] = weight[j][i]; af[weight.length] = bias[i]; return af; } public float[] getOutputWeights(int i) { float af[] = new float[weight[0].length]; for (int j = 0; j < weight[0].length; j++) af[j] = weight[i][j]; return af; } public int size() { return size; } public float[][] getWeights() { return weight; } public float[] getBiases() { return bias; } float weight[][]; float bias[]; int size; }

Ads help maintain this website.