source:branches/parallel/Ipopt/contrib/RInterface/man/print.sparseness.Rd@1887

Last change on this file since 1887 was 1887, checked in by andreasw, 3 years ago

synchronized with trunk rev 1886; fixed bug in Matrix-vector product for parallel matrix

File size: 2.7 KB
Line
1\name{print.sparseness}
2\alias{print.sparseness}
3\title{
4Show sparseness structure of matrix
5}
6\description{
7This function shows the sparseness structure of a matrix in the format that is required by ipoptr.
8}
9\usage{
10print.sparseness( x, indices=TRUE, data=NULL, ncol=NULL, ... )
11}
12\arguments{
13  \item{x}{
14    list of vectors with indices. Each element of the list corresponds to a row in
15    the matrix. Each index corresponds to a non-zero element in the matrix.
16  }
17  \item{indices}{
18    Logical. Should we show the order of the non-zero elements or just whether an element is non-zero?
19  }
20  \item{data}{
21    vector with non-zero elements of the sparse matrix.
22  }
23  \item{ncol}{
24    integer supplying the number of columns of the sparse matrix. If this is not supplied,
25    we take the number of columns as the largest index in \code{s}.
26  }
27  \item{...}{
28    further arguments passed to or from other methods.
29  }
30}
31\value{
32    A matrix showing the sparseness structure is returned.
33}
34\author{
35Jelmer Ypma
36}
37\seealso{
41}
42\examples{
43library('ipoptr')
44
45# print lower-diagonal 4x4 matrix
46print.sparseness( list( c(1), c(1,2), c(1,2,3), c(1,2,3,4) ) )
47
48# print diagonal 3x3 matrix without indices counts
49print.sparseness( list( c(1), c(2), c(3) ), indices=FALSE )
50
51# print a third sparse matrix
52print.sparseness( list( c(1,3,6,8), c(2,5), c(3,7,9) ) )
53
54# and a fourth one, where the elements are in a different order
55print.sparseness( list( c(3,1,6,8), c(2,5), c(3,9,7) ) )
56
57# print lower-diagonal 5x5 matrix generated with make.sparse
58A_lower <- make.sparse( lower.tri( matrix(1, nrow=5, ncol=5), diag=TRUE ) )
59print.sparseness( A_lower )
60
61# print a diagonal 5x5 matrix without indices counts
62A_diag  <- make.sparse( diag(5) > 0 )
63print.sparseness( A_diag )
64
65# example from tests/lasso.R
66n <- 100    # number of observations
67m <- 5      # number of variables
68
69# define hessian function
70hessian <- function( A ) {
71    H <- t(A) %*% A
72    H <- unlist( lapply( 1:m, function(i) { H[i,1:i] } ) )
73
74    return( H )
75}
76
77# define the structure
78hessian_structure <- c( lapply( 1:m, function(x) { return( c(1:x) ) } ),
79                        lapply( 1:m, function(x) { return( c() ) } ) )
80
81# generate data
82set.seed( 3141 )
83A <- hessian( matrix( rnorm( n*m ), nrow=n, ncol=m ) )
84print.sparseness( x       = hessian_structure,
85                  indices = TRUE,
86                  data    = format( A, digits=2, nsmall=2, justify='right'),
87                  ncol    = 2*m )
88}
89% Add one or more standard keywords, see file 'KEYWORDS' in the
90% R documentation directory.
91\keyword{ optimize }
92\keyword{ interface }
Note: See TracBrowser for help on using the repository browser.