In Matlab I do A ^ -0.5 to find the negative fractional power of matrix A. What is the equivalent in Armadillo C++ library? The pow() function performs element wise operation.
You can do
expmat(-0.5 * logmat(A))
Use the powmat() function, like so:
mat A(5,5,fill::randu);
cx_mat B = powmat(A, -0.5);
Or use a combination of inv() and sqrtmat().
Related
I am trying to apply cvxpy python to solve an LMI
How can I define a strictly positive definite matrix here?
For about a matrix of order 10 for example this is the syntax
X = cp.Variable((100, 100), PSD=True)
but it is for X when X>=0
I need X>0.
I have read the cvxpy and search in it but there was not such an item.
Thanks in advance.
Strict inequalities are not possible because what does that mean when computations are done in finite precision floating numbers.
But you can do
(X - I*eps) is PSD
where I is the identity matrix and eps is small positive number say 1.0e-6.
It should not be too small.
I am using Armadillo C++ library to perform the eigen decomposition of a Hermitian matrix R of size 49x49. The resulting eigenvectors have NaN columns sometimes. When I perform the same decomposition in matlab there is no such issue.
My Armadillo code is something like this:
cx_mat R = (S_n_centered * S_n_centered.t()) / S_n.n_cols;
cx_mat E;
vec d;
bool success = eig_sym(d,E,R);
For example when R is this, the eigenvectors corresponding to the three largest eigenvalues are these. The success flag is true and eigenvalues are correct (almost the same as in Matlab).
I am using Armadillo version 7.960.0 and using blas_win64_MT.dll and lapack_win64_MT.dll both of which are included in the examples folder.
Decomposing the same Matrix in Matlab doesn't cause any issues but the eigenvectors are all different.
Could this be a bug in Armadillo or the Lapack library?
I1 is an rgb image. 'Out' variable basically stores one colour channel of the whole image.
The in-built functions mean, variance and standard deviation when calculated on 'out' gives an error asking for a real vector or matrix as input.
This can be seen in image given below
But when min or max is used, no error is reported.But these in-built function take in the same parameters as mentioned in the Scilab documentation which is of type vector or matrix of integers.
On further examination, it seems that variable 'out' is of type matrix of graphic handles when it should be a matrix of integers.
I can't seem to understand why the error is coming if it works for min and max functions ?
How can I solve this problem?
The output of imread() is a hypermatrix of integers, not of floating point numbers.
This is shown by the fact that min(out) is displayed as "4" (without decimal point), not as "4."
Now, mean() and stdev() do not work with integers, only with real or complex numbers.
The solution is to convert integers into decimal numbers:
mean(double(out))
https://help.scilab.org/docs/6.1.1/en_US/double.html
I would like to generate numbers into an array that has normal distribution. Is there any function in objective-c or c that can help to get the result easily without any math?
Use the the Box-Muller-Transformation:
1.) you need two uniform distributed random numbers u and v as doubles in the interval (0,1] (0 needs to be excluded):
double u =(double)(random() %100000 + 1)/100000; //for precision
double v =(double)(random() %100000 + 1)/100000; //for precision
2.) calculate the uniform distributed value with average of 0 and the standard deviation sigma of 1:
double x = sqrt(-2*log(u))*cos(2*pi*v); //or sin(2*pi*v)
3.) if needed add sigma and average for your target distribution like this:
double y = x * sigmaValue + averageValue;
4.) put it in an array
[randomNumberArray addObject:[NSNumber numberWithDouble:y]]
There is no function norminv for objc. So, math is needed here.
Edit: I like using random() to be able to seed the random value generator
Let me preface this by saying, please, correct me if I'm wrong!
It's my understanding that the Box-Muller Transformation relies on the source numbers being them selves uniformly distributed, thus using random() or rand() as the source data-set for Box-Muller will NOT necessarily produce a uniform distribution.
It is instead intended to take a generic set of uniformly distributed random numbers, and produce independent pairs of random numbers uniformly distributed in a 2D coordinate system.
Wikipedia: Box-Muller Transform
There is however another way:
On most Unix systems (and thus Objective C on iOS or OSX) using the rand48 library of functions:
Reference: drand
double drand48(void);
void srand48(long int seedval);
srand48() seeds the generator, and drand48() produces random numbers uniformly distributed over the interval [0.0 - 1.0]
I am using OpenCV library. It doesn't have a modulo operator that can be applied to WHOLE matrix.
It has a Multiplication, Subtraction operators for a matrix.
Is there any way I can combine these operations to have an alternative to modulo operation?
I am looking for modulo of 2*pi.
If there are multiple of 2*pi in a row of matrix, the product of that row will be zero. It will ease my life and save considerable performance compare to looping every element of matrix.
Thanks.
If you've also got Division and Floor, you can use:
mod(a,b) = a - floor(a/b) * b