Questions tagged [linear-algebra]

0

votes
0

answer
5

Views

Computing Chebyshev center in R

I'm searching for a way to compute the Chebyshev center of a convex polytope, in R. I would like to have a funcion of the type: x0 = chebycenter(A,b); where x0 is the vector of coordinates of the Chebyshev center and the convex polytope is defined by A*x
Bplanque
0

votes
0

answer
3

Views

How to add magnitude or value to a vector in Python?

I am using this function to calculate distance between 2 vectors a,b, of size 300, word2vec, I get the distance between 'hot' and 'cold' to be equal 1. How to add this value (1) to a vector, becz i thought simply new_vec=model['hot']+1, but when I do the calc dist(new_vec,model['hot'])=17? import...
Jay Qadan
2

votes
0

answer
12

Views

Solving eigenvectors/eigenvalues of sparse matrix in different ranges successively

I'm looking for eigenvalues/eigenvectors of a huge sparse matrix A (250k*250k) that lie in different eigenvalue ranges without calculating all the eigenvalues in between since it would just take too much time. My consideration was Step1: I'm trying to find k certain eigenvalues/eigenvectors of the m...
Allbrightable
1

votes
1

answer
113

Views

How to understand “individual neurons are the basis directions of activation space”?

In a recent article at Distill (link) about visualizing internal representation of convolutional neural networks, there is the following passage (bold is mine): If neurons are not the right way to understand neural nets, what is? In real life, combinations of neurons work together to represent image...
Fazzolini
1

votes
2

answer
45

Views

Scalar-Vector multiplication with meshgrid (Matlab)

I have an expression such as s=aU+bV, where a and b are scalars and U and V 3-component vectors. The output s is clearly a 3-component vector. Let's assume I want to plot the first component of s find out how this varies when I change a and b. In order to plot I have to use surf, which takes matrice...
usumdelphini
1

votes
1

answer
100

Views

Solving an overdetermined sparse linear system produces high error solution

My Code So I have written an algorithm which iteratively solves a sparse overdetermined linear system. That means my code looks like this: construct_A_matrix(); construct_B_matrix(); while(someCondition){ x=solveSystem(A,B) //solve Ax=B. This system is overdetermined //since A has more rows than co...
Iason Manolas
1

votes
1

answer
67

Views

Solve a redundant system of linear equations in R

I have a noninvertible matrix A and a vector b for which I believe there is a solution x to Ax = b. I would like to find an example of such x. When I try solve(A,b) in R it produces an error because A is singular. Is there any way to make R give me a random solution?
1

votes
1

answer
145

Views

Inverting a ZZ_p matrix in NTL

I am trying to generate a random binary matrix and its inverse mod q where q is a power of 2. Sometimes when the determinant of my matrix is invertible modulo q (so the matrix over Z_q is invertible), I am getting the error 'InvMod:inverse undefined Aborted (core dumped)' and other times the inverse...
user11235
1

votes
1

answer
493

Views

Inverting a matrix using the LU decomposition

I have written the following Matrix class in cython for the matrix inversion and some other linear algebra operations. I tried to use the LU decomposition, in order to compute the inverse of a matrix. The speed of code is good. I tried to implement this code in cython. I have checked every line of m...
Dalek
1

votes
0

answer
309

Views

Fastest Way of Calculating The Length of Projection of Vector on Linear Space in Python

I have a linear space represented by a matrix, and their rows are not orthogonal. I would like to find the vector in another set of vectors with the shortest projection onto this linear space. I have a few algorithms for this, such as calculating the coefficients of projection as a linear combinatio...
DiveIntoML
1

votes
0

answer
57

Views

Efficient computation of a bilinear norm over sparse vectors in Python

Given two column vectors x, y : scipy.sparse.csc_matrix, where len(x) == len(y) == N and max(x.nnz, y.nnz) == M, and a symmetric N × N matrix A : scipy.sparse.csc_matrix, where for all columns j, A[j].nnz = C, I need to compute x.T * A * y = ∑∑ᵢ,ⱼ x[i] * a[j][i] * y[j] efficiently in at mos...
Witiko
1

votes
0

answer
290

Views

Vectorize Conway's Game of Life in pure numpy?

I'm wondering if there is a way to implement Conway's game of life without resorting to for loops, if statements and other control structures typical of programming. It should be pretty easy to vectorize for loops, but how would you convert the checks on the neighborhood to a matrix operation? The...
Daniele Grattarola
1

votes
0

answer
389

Views

Trying to fill in a region of a graph between 3 lines [duplicate]

This question already has an answer here: Matplotlib fill between multiple lines 3 answers Difficulty shading in feasible area on plot using matplotlib [duplicate] 1 answer I wrote code plotting 3 equations on a graph using python. What I would like to do is fill in a region of a graph using fill_...
user7298979
3

votes
0

answer
16

Views

Quaternion division

Quaternion multiplication is well-defined, and is known to me as 'Hamilton product': // hamilton product vec4 qmul(in vec4 q1, in vec4 q2) { return vec4( q1.w * q2.xyz + q2.w * q1.xyz - cross(q1.xyz, q2.xyz), q1.w*q2.w - dot(q1.xyz, q2.xyz) ); } However, for implementing qtanh() quaternionic functio...
xakepp35
1

votes
0

answer
84

Views

Arrays, vectors and matrices in Scala

I'm trying to use TFOCS to solve linear programming problems. In the documentation, the 'Constraint matrix' is an array of vectors: val A = sc.parallelize(Array( Vectors.sparse(3, Seq((0, 0.88))), Vectors.sparse(3, Seq((1, 0.63))), Vectors.sparse(3, Seq((0, 0.29), (2, 0.18)))), 2) Are Vectors equiva...
1

votes
1

answer
94

Views

Solving for Lx=b and Px=b when A=LLt

I am decomposing a sparse SPD matrix A using Eigen. It will either be a LLt or a LDLt deomposition (Cholesky), so we can assume the matrix will be decomposed as A = P-1 LDLt P where P is a permutation matrix, L is triangular lower and D diagonal (possibly identity). If I do SolverClassName solver; s...
yannick
1

votes
0

answer
29

Views

Finding the dominant eigenvalue of a symbolic matrix and simplifying it in Matlab

I have the following symbolic matrix and I want to find its dominant eigenvalue using Matlab. r = [ (c*r1)/(d1 + c*d4 - d1*p), (c*r1)/(d1 + c*d4 - d1*p), (c*r1)/(d1 + c*d4 - d1*p)] [ (a1*c*q*r2)/(d1*d5 + c*d4*d5 - d1*d5*p), (r2*(d1...
clarkson
1

votes
1

answer
103

Views

How to get average of elements along columns or rows in an ojAlgo matrix?

Is there a way to compute the average of the primitive elements along the columns or rows of a matrix, such that we obtain vectors with the average values? For example, let A = [[1, 2, 3],[4, 5, 6]] be a 2x3 matrix. The column-wise average would be retrieved in a 3-element vector, like [2.5, 3.5,...
YoungMin
1

votes
2

answer
64

Views

Karhunen Loeve Procedure

I'm trying to apply the Karhunen Loeve procedure to a translation-invariant data set. I understand the KL procedure, and how to create a mask to smooth out missing data. However, I'm having a hard time creating a program to model my Translation invariant data set. The data set that I need to plot in...
Arthur Smith
1

votes
0

answer
117

Views

Where is the returning values of cv2.solvePnP actually holding the camera's position?

There's a cube and a camera in the real world. Each point coordinates are shown in the following figure. It is clear that the camera's coordinate is at [0,0,1]. We can calculate each position's displayed coordinates on screen. import numpy as np import cv2 import math world = np.array(\ [\ ( 5.00,...
Izumi Kawashima
1

votes
0

answer
20

Views

Why is the RMSE on the training set decreasing while my matrix completion program is training, and the RMSE on the test set is rising?

I am writing a naive matrix completion program. Curiously, the RMSE on the training set is decreasing during training, but the RMSE on the test set is soaring at first and then slowly decreasing. I don't know if this is normal. Here is the running log: Iter 0: cost=122720.2005, TRN_rmse=0.0991, T...
Lizhi Liu
1

votes
2

answer
55

Views

Java/Processing how to do Matrix Multipication with the dot product

Hello i am using processing (wich is essentially just Java) and I wanted to have a realy simpel matrix class to help me with my Neural-Network . It works fine but the 'matrix-multipication' part dosent realy work . I know my code is wrong but i can't seem to find a fix . The start of the class looks...
Justus Laube
1

votes
1

answer
43

Views

NURBS: Where can I find these two Linear Algebra utility functions?

I am working through The NURBS Book by Piegl and Tiller. For the global interpolation algorithm, they require you to provide two utility routines for solving a system of linear equations: LUDecomposition(A, q, sbw) to decompose the q x q coefficient matrix with semibandwidth sbw into lower and uppe...
nonremovable
1

votes
0

answer
217

Views

Inverse of a binary matrix in C

I have a binary matrix (zeros and ones) D[][] of dimension nxn where n is large (approximately around 1500 - 2000). I want to find the inverse of this matrix in C. Since I'm new to C, I started with a 3 x 3 matrix and working around to generalize it to N x N. This works for int values, however since...
Cherry
1

votes
1

answer
52

Views

Gaussian elimination and solution to reduced system

I am trying to implement Gaussian elimination with pivoting in C, but solutions come out wrong even with the simplest input. Here's the code I wrote #include #include #define N 15 void gauss(float a[][N], float *b, int n); void solution(float a[][N], float *b, float *x, int n); int main(void) { in...
ioioio
1

votes
0

answer
52

Views

Multilateration of Sound in 3D Space

TL:DR - How can you find the 3D coordinates of a emitter than transmits an impulse signal? STORY: I'm working on something to improve my bird-watching. I've got a camera that can take pictures of the birds when I'm not around, but currently it has to be zoomed out all the way to guarantee they're i...
David Robie
1

votes
1

answer
255

Views

Python multiprocessing diagonalization

I am looking for help since it seems I can't find any solutions. The task I am interested in is to diagonalize (large) matrices that depend on a parameter (let's call it m). I first did the calculations on my Mac laptop by using a simple for loop and it seems to use all the availbale cores (4) by d...
Tazwiie
1

votes
0

answer
85

Views

How do I solve a matrix equation of non commuting variables in Mathematica

I would like to solve the system A*B=I for the elements of B in terms of the elements of A. A and B are square, the elements of A and B don't commute (i.e. A[1,1]*B[1,1]=/=B[1,1]*A[1,1]), and A and B are of size nxn. Here is what I've tried so far: In[16]:= n = 2; In[34]:= Reduce[Flatten[Table[ Sum...
avgn
1

votes
0

answer
56

Views

How to solve a linear system with cholesky decomposition with sparse matrix in Python?

I have a sparse matrix and i performed Cholesky decomposition with Theano with this line: theano.tensor.slinalg.Cholesky(lower=True) where it said it worked and showed this: Cholesky{lower=, destructive=False, on_error='raise'} How should i solve the system and find x? I tried with theano.tensor.sl...
user9951038
1

votes
0

answer
98

Views

Customer segmentation: backward calculation

I am doing customer segmentation, each customer has 3 attributes X, Y and Z. Based on the values of these 3 attributes, I separate them into 6 groups, say A - F. X Y Z Group John D. 300 35 1000 A Adam S. 230 40 2500 B Will Y. 500 55 3000 C Then I count th...
Lopavit
1

votes
2

answer
75

Views

calculating 3D coordinates from a flattened 3D array

I have a linear index, flattened in column major order, and I like to get back the 3D coordinates [x,y,z]. I found this for row major https://math.stackexchange.com/questions/19765/calculating-coordinates-from-a-flattened-3d-array-when-you-know-the-size-index , but can't figure out the column major?
user3178756
1

votes
1

answer
99

Views

Sorting of eigenvalues in Python in for-loop

I am calculating and plotting the eigenvalues of a 5x5 array as a function of a parameter x. I know that I have to sort the eigenvalues since they are not necessarily ordered with numpy, so the easiest way is to use argsort() and sort them from smallest to largest (or vice versa): import matplotlib....
Daniel Kortu
1

votes
1

answer
24

Views

How to solve backward for an unknown given a condition in R?

For a set of input (see below), when I run the following R code, I get two answers stored in ncp. But I want to know what should df2 be such that the difference between these two answers in ncp (i.e., abs(ncp[2] - ncp[1])) is say .15? So, everything else fixed, just what should df2 be so that abs(nc...
rnorouzian
1

votes
1

answer
42

Views

Is uniroot() confusing the input values in R?

I'm wondering in the following, why when I directly provide the value of q (see f2), uniroot() works perfectly fine BUT when instead I provide q as a function of other input values uniroot() (see f1) fails? In the code, everything that has ...1 suffix (e.g., f1) relates to when I indirectly provide...
rnorouzian
1

votes
0

answer
25

Views

Assigning values to R matrix or data frame with adjacency vectors (specifically using row names and column names)

I have seen other questions about getting the values of a matrix based on the vectors or tuples of indices but none about updating those values. I would like this: mat
Damon
1

votes
0

answer
35

Views

efficient matrix operations on the JVM for a large quantity of medium sized matrices

Is it worth to go native without MKL? I have a matrix of about 450 elements in size and want to perform some multiplications and decompositions to calculate: a gaussian process correlations My problem is that I will have several million of these matrices and I wonder which option on the jvm should...
Georg Heiler
1

votes
0

answer
115

Views

solving sparse Ax=b in scipy

I need to solve Ax=b where A is the matrix that represents finite difference method for PDEs. Typical size of A for a 2D problem is around (256^2)x(256^2), and it consists of a few diagonals. The following sample code is how I construct A: N = Nx*Ny # Nx is no. of cols (size in x-direction), Ny is...
Physicist
1

votes
0

answer
315

Views

Calculate rotation matrix to transform one vector to another?

There are several questions about this on Stack Overflow, but most use Quaternions and I am looking for something that does not. And this question is all over the web, but it is surprisingly hard to find a straightforward example in code. I am looking for a C/C++, or GLSL/Metal solution for the ro...
bsabiston
1

votes
1

answer
63

Views

Issue using cblas_dgemm to compute pseudoinverse

I am trying to compute the pseudoinverse of a matrix stored in LAPACK_ROW_MAJOR layout using Intel MKL. A_5x4 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 I am using gesvd function to compute the compact form of the SVD: info = LAPACKE_dges...
AFP
1

votes
1

answer
45

Views

Why use MKL's Zgemm when gemm3m is the same but faster?

According to MKL's documentation: The ?gemm3m routines perform a matrix-matrix operation with general complex matrices. These routines are similar to the ?gemm routines, but they use fewer matrix multiplication operations. and These routines perform a complex matrix multiplication by forming the r...
avgn

View additional questions