impure subroutine pca(this, matrix, npc, method, coeff, score, latent, explained, matrix_app)
#else
pure subroutine pca(this, matrix, npc, method, coeff, score, latent, explained, matrix_app)
#endif
class(tpca), intent(inout) :: this
real(rk), dimension(:,:), intent(in) :: matrix
integer, intent(in), optional :: npc
character(*), intent(in), optional :: method
real(rk), dimension(:,:), allocatable, intent(out) :: coeff
real(rk), dimension(:,:), allocatable, intent(out), optional :: score
real(rk), dimension(:), allocatable, intent(out), optional :: latent
real(rk), dimension(:), allocatable, intent(out), optional :: explained
real(rk), dimension(:,:), allocatable, intent(out), optional :: matrix_app
call this%initialize(matrix, npc, method)
call this%compute_coeff()
coeff = this%coeff
if(present(score)) then
call this%compute_score()
score = this%score
end if
if(present(latent)) then
latent = this%latent
end if
if(present(explained)) then
call this%cmp_explained_variance()
explained = this%explained_variance*100.0_rk
end if
if(present(matrix_app)) then
call this%reconstruct_data()
matrix_app = this%matrix_app
end if
end subroutine pca