symmetric

Symmetric matrix is not symmetric

和自甴很熟 提交于 2019-12-10 23:32:40
问题 I have recently written code for finite element method. Since my algorithm is generating a symmetric matrix, after gathering data for each element the resulting matrix should be symmetric. However, after I run loop over element, the resulting global matrix is not symmetric. The basic code structure is like this: A=zeros(dof,dof) for (each element) loc_A = v'*(diagonal matrix)*v % (v is 1xN row vector) % loc_A is symmetric matrix A(K,K) = A(K,K)+loc_A % (K is Nx1 column vector) end Since I add

How to force tensorflow tensors to be symmetric?

﹥>﹥吖頭↗ 提交于 2019-12-10 03:21:17
问题 I have a set of MxM symmetric matrix Variables in a graph whose values I'd like to optimize. Is there a way to enforce the symmetric condition? I've thought about adding a term to the loss function to enforce it, but this seems awkward and roundabout. What I'd hoped for is something like tf.matmul(A,B,symmA=True) where only a triangular portion of A would be used and learned. Or maybe something like tf.upperTriangularToFull(A) which would create a dense matrix from a triangular part. 回答1:

Checking if array is symmetric

徘徊边缘 提交于 2019-12-08 02:17:06
问题 public class symm { /* * Returns true if array A is symmetric. * Returns false otherwise. * n is the number of elements A contains. * * The running time of your algorithm is O( ). * You may add a brief explanation here if you wish. */ public static boolean symmetric( int[] A, int n ) { return symmHelper(A, n, 0); } private static boolean symmHelper(int[] A, int n, int i) { if(n==1) return true; if((n==2) && (A[i] == A[n-1-i])) return true; if((i == n-1-i) && (A[i] == A[n-1-i] )) return true;

Prolog — symetrical predicates

半腔热情 提交于 2019-12-06 08:14:13
问题 I have to simulate family tree in prolog. And i have problem of symetrical predicates. Facts: parent(x,y). male(x). female(y). age(x, number). Rules: blood_relation is giving me headache. this is what i have done: blood_relation(X,Y):-ancestor(X,Y). blood_relation(X,Y):-uncle(X,Y);brother(X,Y);sister(X,Y);(mother(Z,Y),sister(X,Z));(father(Z,Y),sister(X,Z));(father(Z,Y),brother(X,Z)). blood_relation(X,Y):-uncle(X,Z),blood_relation(Z,Y). and I am getting i think satisfactory results(i have

Checking if array is symmetric

别等时光非礼了梦想. 提交于 2019-12-06 06:04:16
public class symm { /* * Returns true if array A is symmetric. * Returns false otherwise. * n is the number of elements A contains. * * The running time of your algorithm is O( ). * You may add a brief explanation here if you wish. */ public static boolean symmetric( int[] A, int n ) { return symmHelper(A, n, 0); } private static boolean symmHelper(int[] A, int n, int i) { if(n==1) return true; if((n==2) && (A[i] == A[n-1-i])) return true; if((i == n-1-i) && (A[i] == A[n-1-i] )) return true; if(A[i] == A[n-1-i] && i < n/2 ) return symmHelper(A, n, i+1); return false; } } Test cases: I passed

C++ Symmetric Binary Operators with Different Types

断了今生、忘了曾经 提交于 2019-12-05 10:05:37
I am learning C++ and I was wondering if I could gain some insight into the preferred way of creating binary operators that work on instances of two different types. Here is an example that I've made to illustrate my concerns: class A; class B; class A { private: int x; public: A(int x); int getX() const; int operator + (const B& b); }; class B { private: int x; public: B(int x); int getX() const; int operator + (const A& A); }; A::A(int x) : x(x) {} int A::getX() const { return x; } // Method 1 int A::operator + (const B& b) { return getX() + b.getX(); } B::B(int x) : x(x) {} int B::getX()

Prolog — symetrical predicates

半腔热情 提交于 2019-12-04 14:46:37
I have to simulate family tree in prolog. And i have problem of symetrical predicates. Facts: parent(x,y). male(x). female(y). age(x, number). Rules: blood_relation is giving me headache. this is what i have done: blood_relation(X,Y):-ancestor(X,Y). blood_relation(X,Y):-uncle(X,Y);brother(X,Y);sister(X,Y);(mother(Z,Y),sister(X,Z));(father(Z,Y),sister(X,Z));(father(Z,Y),brother(X,Z)). blood_relation(X,Y):-uncle(X,Z),blood_relation(Z,Y). and I am getting i think satisfactory results(i have double prints - can i fix this), problem is that i want that this relation be symmetrical. It is not now.

Is JavaScript's double equals (==) always symmetric?

我与影子孤独终老i 提交于 2019-11-30 05:39:28
There are many cases in which JavaScript's type-coercing equality operator is not transitive. For example, see " JavaScript equality transitivity is weird ." However, are there any cases in which == isn't symmetric ? That is, where a == b is true and b == a is false ? SLaks In Javascript, == is always symmetric . The spec says : NOTE 2 The equality operators maintain the following invariants: A != B is equivalent to !(A == B) . A == B is equivalent to B == A , except in the order of evaluation of A and B . It's supposed to be symmetric. However, there is an asymmetric case in some versions of

Creating a symmetric matrix in R

大兔子大兔子 提交于 2019-11-27 13:08:21
I have a matrix in R that is supposed to be symmetric, however, due to machine precision the matrix is never symmetric (the values differ by around 10^-16). Since I know the matrix is symmetric I have been doing this so far to get around the problem: s.diag = diag(s) s[lower.tri(s,diag=T)] = 0 s = s + t(s) + diag(s.diag,S) Is there a better one line command for this? Is the workaround really necessary if the values only differ by that much? Someone pointed out that my previous answer was wrong. I like some of the other ones better, but since I can't delete this one (accepted by a user who left

Creating a symmetric matrix in R

谁说我不能喝 提交于 2019-11-26 22:22:22
问题 I have a matrix in R that is supposed to be symmetric, however, due to machine precision the matrix is never symmetric (the values differ by around 10^-16). Since I know the matrix is symmetric I have been doing this so far to get around the problem: s.diag = diag(s) s[lower.tri(s,diag=T)] = 0 s = s + t(s) + diag(s.diag,S) Is there a better one line command for this? 回答1: Is the workaround really necessary if the values only differ by that much? Someone pointed out that my previous answer was