Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
What programming language is used in the picture?
I do not kown the following language that maybe R or pseudo-code.
'''
1: procedure Discriminator Gd(0)
2: δ ← 0.01
3: ξ D,0 ← ξ D
4: d 0 ← L()
5: b D ← [0,0]
6: for i ← 1 to 2 do
7: c ← c + 1
8: ξ D [i] ← ξ D [i] + δ
9: d ← L()
10: b D [i] ← (d − d 0 )/δ
11: ξ D ← ξ D,0
12: end for
13: b D ← b D /norm(b D )
14: return b D
15: end procedure
'''
This is a psuedo-code block rather than an example block of a specific language, just as you expected.
The sample code can be found here on page 5 (Algorithm 4) in a paper containing supplementary materials regarding Quantum Generative Adversarial Learning. The additional variable names are meant to be subscripts. They use this form of psuedo-code throughout the paper, as mentioned beneath Algorithm 1 on page 2.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
matrix m:
1 2 3
4 5 6
7 8 9
output: (matrix r)
1 3 6
5 12 21
12 27 45
How we get the results is:
staring index = (0,0)
for example,
element at the (1,1) position of the result matrix would be,
r[1][1] = m[0][0] + m[0][1] + m[1][0] + m[1][1]
sum of the elements inside the red box:
element at the (2,1) position of the result matrix would be,
r[2][1] = matrix[0][0] + m[0][1] + m[1][0] + m[1][1] + m[2][0] + m[2][1]
sum of the elements inside the red box:
One important observation here is that for i > 0 and j > 0:
r[i][j] = m[i][j] + r[i-1][j] + r[i][j-1]
^ ^
When i == 0 or j == 0 then just drop the terms from the above expression that become invalid.
So:
r[0][0] = m[0][0]
And:
r[0][1] = m[0][1] + r[0][0]
If you continue with the first row from left to right and then the next rows in the same fashion, you'll always have the information needed to calculate r[i][j].
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
We have the test image with M rows and N columns as
f(x,y), for x∈ [1,M] and y∈ [1,N ]. The horizontal absolute
difference value of a pixel is defined by
D (x, y) = |f (x, y +1) − f (x, y −1)|.
need help in how to implement it in matlab
This will generate same size matrix, that you need:
mat1 = [zeros(2,size(f,2)); f];% adds 2 rows of zeros to begining
mat2 = [f;zeros(2,size(f,2))]; %adds 2 row of zeros to the end
Dd = mat1-mat2;
D = Dd(2:((size(Dd,1)-1)),:);%crop Dd matrix to size(f)
D = abs( f(1:end-1,:) - f(2:end,:) );
check out diff command as well. Note that D has 1 row less than f.
aux = abs(diff(f,[],2));
D = max(aux(:,1:end-1), aux(:,2:end));
For example: given
f = [3 5 6 4
2 5 4 3
8 9 3 1];
the result is
>> D
D =
2 2
3 1
6 6
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Given an integer x in the interval [1 .. 6], I am looking for two mathematical functions y1 and y2 so that:
y1(x) ∈ [1 .. 6], y2(x) ∈ [1 .. 6]
y1(x) ≠ y2(x) ≠ x
y1(x) and y2(x) are integers
I tried y1(x) = 7-x and y2(x) = (1+x)%6 where % is the remainder or modulo operation.
That solution does not work for x=6. I get y1(x) = y2(x) = 1, which does not fulfills the condition 2. Neither for x=3 and x=5.
Does anyone sees a working solution?
You can use for example:
y1=(x % 6) +1
y2=((x+1) % 6) +1
Functions as table:
x y1 y2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 1
6 1 2
Technically, y1=1+((x+1) %6) and y2=(1+(x+2) %6) both satisfy your request.
I guess though you were thinking about something with a unified distribution of some sort (which is usually the motivation for such attempts...).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
We have this matrix of 4x4:
a b c d
e f g h
1 2 3 4
5 6 7 8
By transposing the matrix we get:
a e 1 5
b f 2 6
c g 3 7
d h 4 8
My question is:
What matrix do we get by "transposing column 2 with row 4?"
I need to understand the operation in itself, what does it imply/mean? I never thought of "transposing a column with a line".
AFAIK, It means you are to swap column 2 and row 4, instead of column 1 with row 1 and column2 with row 2 etc.
The code is basically the same as a full transposition, except you only have one column/row
Matrix transposition is a mathematical operation in which a matrix's rows become its columns. From a mathematical perspective, there's no real benefit to transposing only one row in a M x N matrix, but the code to transpose one row is not much different than transposing an entire matrix.
The matrix you get after the transposition would be:
a b 1 d
e f 2 h
c g 3 7
5 6 4 8
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Problem:
Consider the problem of adding two n-bit binary integers, stored in two n-element arrays A and B. The sum of the two integers should be stored in binary form in an (n + 1)-element array C. State the problem formally and write pseudocode for adding the two integers.
Solution:
C ← [1 ... n + 1] ▹ C is zero-filled.
for i ← 1 to n
do sum ← A[i] + B[i] + C[i]
C[i] ← sum % 2
C[i + 1] ← sum / 2 ▹ Integer division.
output C
Question:
I thought the C[i] is A[i]+B[i] why are you adding sum ← A[i] + B[i] + C[i] in step 3?
why sum % 2 (why need to use modulo in step 4?)
why sum / 2 (why need to use division in step 5?)
Could you please explain above solution with real example? Thanks.
C is both the solution and the carry. For a real example, let's add 11 + 3. I'll write in binary with decimal in parens)
A = 1011 (11) + B = 0011 (3) [C starts as 00000 (0)]
^ ^ ^
The ^s mark the first position, and we go left, since we read left to right, but math goes right to left. Also, we divide integers, so 3/2 = 1, not 1.5. Now the steps.
1. sum = 1+1+0 = 10 (2), c[1] = 2 % 2 = 0, c[2] = 2/2 = 1
2. sum = 1+1+1 = 11 (3), c[2] = 3 % 2 = 1, c[3] = 3/2 = 1
3. sum = 0+0+1 = 01 (1), c[3] = 1 % 2 = 1, c[4] = 1/2 = 0
4. sum = 1+0+0 = 01 (1), c[4] = 1 % 2 = 1, c[5] = 1/2 = 0
^ ^ ^ ^ ^
i A B C, all at position i note that we store the carry for the NEXT step
Result: C = 01110 (14)
You add C[i] as well because C[i] may contain a carry bit from when you added A[i-1] + B[i-1] + C[i-1] in the previous iteration. For example if we do 1 + 1, our first iteration sum = 1 + 1 + 0 = 2, but since this is binary we have to carry the 1 and put it on C[1] and put the remainder (2 % 2 = 0) in C[0]. This gives us 10
C[i] gets sum % 2 because the sum of A[i] + B[i] + C[i] could be more than 1, but 1 is the most that will fit in that digit. The rest of the sum (if there is any) will be put in the carry bit. And that brings us to...
C[i+1] gets assigned sum / 2 because sum / 2 is the carry amount. It will be used in the next iteration when we do A[i] + B[i] + C[i] for i = i + 1.
You can think of adding binary numbers the same way you add base 10 numbers: there is an "add" step and a "carry" step to perform at each digit.
So, let's take the math one bit at a time. Say we're adding:
101
+
011
For the first step, we start on the far-right. (In your example, this corresponds to i=1). We add (1+1)%2, which gives us 0. What's really going on here? 1+1 is 2, which in binary is a two-digit number ("10"). We can only write the lower-order digit ("0"), so expressing the sum "mod 2" is really just saying "don't worry about the carry-over sum for now." So we've got:
101
+
011
---
0 (carrying a 1)
Now we implement the "carry a 1" by doing integer division ("sum / 2"), and temporarily storing it:
101
+
011
---
10
Now we are ready to add the 2nd digits: (0+1)%2 -- but we must add in the carry-over 1 that we've been keeping track of, so we take (0+1+1)%2 yielding:
101
+
011
---
00
Again we need to keep track of carry bit, giving us (0+1+1)=1:
101
+
011
---
100
Finally we add the 3rd bits: (1+0+1)%2 to give the answer:
101
+
011
---
1000