/* * Calculate outputs from given inputs using calculated weights */ public double[] calculateOutput(double[] inputDimValues) { //Only accepts the same number of input values as the RBF will take if (inputDimValues.Length != m_numInputDimensions) { throw new ArgumentOutOfRangeException(); } double[] outputValues = new double[m_numOutputDimensions]; Matrix A = new Matrix(1, m_trainingPoints.Count); for (int outputIndex = 0; outputIndex < m_numOutputDimensions; outputIndex++) { for (int trainingIndex = 0; trainingIndex < m_trainingPoints.Count; trainingIndex++) { double[] distPoints = new double[m_numInputDimensions]; for (int inputIndex = 0; inputIndex < m_numInputDimensions; inputIndex++) { distPoints[inputIndex] = inputDimValues[inputIndex] - m_trainingPoints[trainingIndex].inputDim[inputIndex]; } A[0, trainingIndex] = RBFFunctions.gaussKernel(summedDistance(distPoints), m_sigma); } Matrix dot = A.Multiply(m_weights[outputIndex]); outputValues[outputIndex] = dot[0, 0]; } return(outputValues); }
/* * Calculate weight values from training points */ public List <Matrix> calculateWeights() { Matrix A = new Matrix(m_trainingPoints.Count); int i = 0; int j = 0; //Constructs A matrix using RBF function (gaussian) for (i = 0; i < m_trainingPoints.Count; i++) { for (j = 0; j < m_trainingPoints.Count; j++) { double[] distPoints = new double[m_numInputDimensions]; for (int inputIndex = 0; inputIndex < m_numInputDimensions; inputIndex++) { distPoints[inputIndex] = m_trainingPoints[i].inputDim[inputIndex] - m_trainingPoints[j].inputDim[inputIndex]; } A[i, j] = RBFFunctions.gaussKernel(summedDistance(distPoints), m_sigma); } } Matrix Ainv = A.Inverse(); //Get weights from inverse A matrix and training outputs for (i = 0; i < m_numOutputDimensions; i++) { double[] groupDim = getDimensionFromGroup(m_trainingPoints, DimensionType.OUTPUT, i); //Converts double array to single column matrix Matrix col = new Matrix(m_trainingPoints.Count, 1); for (j = 0; j < groupDim.Length; j++) { col[j, 0] = groupDim[j]; } Matrix mult = Ainv.Multiply(col); m_weights.Add(mult); } return(m_weights); }