package agents.anac.y2015.Phoenix.GP;/* This file is part of the jgpml Project.
* http://github.com/renzodenardi/jgpml
*
* Copyright (c) 2011 Renzo De Nardi and Hugo Gravato-Marques
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
import agents.Jama.Matrix;
/**
* Some useful operations defined over Matrices
*/
public class MatrixOperations {
/**
* Computes the exponential of the input Matrix
* @param A input Matrix
* @return exp(A) result
*/
public static Matrix exp(Matrix A){
Matrix out = new Matrix(A.getRowDimension(),A.getColumnDimension());
for(int i=0; iMatrix and return the result as a single column MAtrix
* @param A input Matrix
* @return result
*/
public static Matrix sumRows(Matrix A){
Matrix sum = new Matrix(A.getRowDimension(),1);
for(int i=0; iMatrix
* @param A Matrix
* @param val value to be added
* @return result
*/
public static Matrix addValue(Matrix A,double val){
for(int i=0; iMatrix (element by element)
* @param A input Matrix
* @return asin(A) result
*/
public static Matrix asin(Matrix A){
Matrix out = new Matrix(A.getRowDimension(),A.getColumnDimension());
for(int i=0; iMatrix (element by element)
* @param A input Matrix
* @return sqrt(A) result
*/
public static Matrix sqrt(Matrix A){
Matrix out = new Matrix(A.getRowDimension(),A.getColumnDimension());
for(int i=0; iMatrix it returns a new diagonal Matrix
* with the input as diagonal elements.
* If the argument is a Matrix
it returns the diagonal elements as a single column Matrix
* Is a clone of the Matlab's function diag(A)
* @param A input Matrix
* @return diag(A) result
*/
public static Matrix diag(Matrix A){
Matrix diag =null;
if(A.getColumnDimension()==1 || A.getRowDimension()==1){
if(A.getColumnDimension()==1) {
diag = new Matrix(A.getRowDimension(),A.getRowDimension());
for(int i=0; i