/// <summary> /// Returns a column vector corresponding to the numerical solution of the polynomial: p(1)*x^n + ... + p(n)*x + p(n+1) = 0. /// </summary> /// <param name="polynomial">Polynomial</param> /// <returns>Array</returns> public Complex32[] Compute(float[] polynomial) { // MATLAB roots method // represented by Valery Asiryan, 2018. // properties of polynomial: int length = polynomial.Length; int i, index = -1; // finding non-zero element: for (i = 0; i < length; i++) { if (polynomial[i] != 0) { index = i; break; } } // return null array: if (index == -1) { return(new Complex32[0]); } // get scaling factor: int m = length - index - 1; float scale = polynomial[index]; float[] c = new float[m]; // create new polynomial: for (i = 0; i < m; i++) { c[i] = polynomial[i + index + 1] / scale; } // Eigen-value decomposition for // companion matrix: eig = new EVD(Matrice.Companion(c), this.eps); // Complex result: return(eig.D); }
//Methods /// <summary> /// Computes max eigenvalue /// </summary> private double ComputeMaxEigenValue() { //Create weights matrix Matrix wMatrix = new Matrix(_neurons.Length, _neurons.Length); //Interconnections Parallel.For(0, _neuronNeuronConnectionsCollection.Length, row => { for (int connIdx = 0; connIdx < _neuronNeuronConnectionsCollection[row].Count; connIdx++) { int col = _neuronNeuronConnectionsCollection[row][connIdx].SourceNeuron.Placement.GlobalFlatIdx; double weight = _neuronNeuronConnectionsCollection[row][connIdx].Weight; wMatrix.Data[row][col] = weight; } }); EVD eigenvaluesDecomposition = new EVD(wMatrix); return(eigenvaluesDecomposition.MaxAbsRealEigenvalue); }