I am trying to understand the the MCTAL output of a spherical TMESH tally. What I want is to create one tally bin that has the following boundaries 1.9 cm and 2.1 cm in the radial direction, 88 to 92 degrees in theta and 180 to 360 degrees in the phi direction. my input for the tally is
C tally card spherical mesh energy tally
TMESH
SMESH1:p DOSE 1 1 1 1.0 PEDEP MFACT 1 1 0 1.0
CORA1 1.9 2.1
CORB1 88 92
CORC1 180 360
Now what I expect is one result for that volume what I get are eight values as shown below.
ntal 1
1
tally 1 -1 -3
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
f 4 0 1 2 2
1.90000E+00 2.10000E+00
0.00000E+00 8.80000E+01 9.20000E+01
0.00000E+00 1.80000E+02 3.60000E+02
d 1
u 1
s 2
m 1
c 1
e 1
t 1
vals
5.57481E-04 0.0067 7.68088E-09 0.0493 8.24471E-03 0.0046 1.38395E-07 0.0639
5.53931E-04 0.0046 7.44313E-09 0.0287 8.24244E-03 0.0042 1.27868E-07 0.0553
I am assuming that these eight vals correspond to the eight points that that are listed under f. Does TMESH only give one values for individual points on a grid or can it be used to create a volume within which to obtain a result? lastly to what points do what vals correspond to ?
The matrix bellow the vals is true value of your meshtally result.
but
you must load data to Matlab and reshape it to your mesh tally matrix
With your SMESH setup you score both dose and energy deposition. This causes two bins along the segment axis (the "s 2" record in your mctal). Then, you have only 1 bin along the radial direction (1.9-2.1 cm) and actually TWO bins along each of the angular directions (0-88, 88-92, and 0-180, 180-360) which sums up to 2^3 = 8 bins. The mctal file format is described in the manual: it'a 11-dimension loop. In your case only the s, j and k axes are divided, so it's actully a 3D loop (in this exact order: s being the outer, k - the inner loop). Therefore the value for your volume is either the 4th (1.38395E-07 0.0639) or last (1.27868E-07 0.0553) record depending on whether you need dose or energy deposition.
I am exercising and wasn't sure if I got this correct. I had to draw 0* U 1*.
Update: This was correct
yh you are right , This NFA accepts either 0 or 1
so you can say NFA for 0 U 1
as epsilon concatenate with 1 results in 1
or epsilon concatenate with 0 results in 0
v=: ((1 2);(3 4);(0 5);(2 1))
diff=: ([{]) ,. ]
direction_vector=: <"1 #: (-"0 #:(-/"2 #: (>"0 #: (diff))))
distance=: +/"1 #: *: #: (>"2 #:(direction_vector))
I want to get a dissimilarity matrix that looks like
(0 distance v),. (1 distance v),. (2 distance v) ,. (3 distance v)
I tried
i.4 distance v
which gave me an index error
Anyone can help me on this?
Thank you!
You are close, but you have two issues to deal with. One is that you want to complete the calculation of i. 4 before you apply distance (which is why you get the index error). Parenthesis to change the order of calculation are the solution to this.
i. 4 distance v
|index error: diff
| i.4 distance v
(i. 4) distance v
0 0 0 0
The second issue is that you want to apply each atom of i.4 to the whole of v and you do this by using " (rank) to specify 0 (atoms) for the left argument and _ (infinity) for the whole of the right argument.
(i. 4) distance"0 _ v
0 8 10 2
8 0 10 10
10 10 0 20
2 10 20 0
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to assign a color brewer to my turtles in 2 different boxes each time they hatch and find the mean color of the turtles in each hatch.
I could have easily done it with the pallet extension but it hasn't been updated for Netlogo 5.1 and therefore, I am using a gradient extension which uses RGB colors ([ n n n]) as input and output and as a result, I cannot find the mean of colors.
This is the related part of my code:
hatch 1
[ set generation generation + 0.1
ifelse ( tlake = "A" )
[ set color gradient:scale [ [255 0 0 ] [255 255 0] [0 0 255] ] (generation) 0 500 ]
[ set color gradient:scale [ [255 0 0 ] [255 255 0] [0 0 255] ] (generation) 500 0 ]
set AVEA mean [color] of (turtles with [tlake = "A"])
set AVEB mean [color] of (turtles with [tlake = "B"])
....
]
And this is the error I am getting:
Can't find the mean of a list that contains non-numbers : [255 0 0] is a list.
How to create a color brewer or obtain the mean value of rgb color type?
As Seth pointed out in the comments, exactly what it means to take the average of two colors is complicated. That said, averaging each RGB component is relatively simple.
The most brute force way would be to just calculate the mean of each component separately:
let r mean [ item 0 color ] of turtles
let g mean [ item 1 color ] of turtles
let b mean [ item 2 color ] of turtles
let mean-color (list r g b)
We can clean this up a bit by using n-values:
let mean-color n-values 3 [ mean [ item ? color ] of turtles ]
With more arrogance than sense here is my attempt
The Trivial
to-report mean-rgb [in]
report rgb (mean [item 0 color] of in) (mean [item 1 color] of in) (mean [item 2 color] of in)
end
this scheme has the problems y'all talked about the mean of yellow and blue is gray but it is fast and simple.
The Tangential
don't use RGB use HSB the means are more meaningful. Although it is a bit more cumbersome.
to-report mean-color [in] report hsb (mean [item 0 to-hsb color] of in) (mean [item 1 to-hsb color] of in) (mean [item 2 to-hsb color] of in)
end
where to-hsb is a piece of code from an answer by Seth Tissue which I will put here for your convenience.
to-report to-hsb [ rgb-color ]
if is-number? rgb-color [ set rgb-color extract-rgb rgb-color ]
let r item 0 rgb-color / 255
let g item 1 rgb-color / 255
let b item 2 rgb-color / 255
let v max (list r g b)
let chroma v - (min (list r g b))
let h 0
let s ifelse-value (v = 0) [ 0 ] [ chroma / v ]
if chroma > 0 [
if v = r [
set h ((g - b) / chroma) mod 6
]
if v = g [
set h (b - r) / chroma + 2
]
if v = b [
set h (r - g) / chroma + 4
]
set h h / 6
]
report map [ precision (? * 255) 3 ] (list h s v)
end
In this scheme the mean of Yellow and Blue is Green, Red and Green is Amber.
Of course there some weirdness the mean of red yellow and blue is a sickly green
I hope that helps
I am trying to solve the below problem. I don't have much knowledge in Affine transformations. Could someone help me answer this question:
Find a 3x3 matrix representing a 2D affine transformation of homogeneous coordinates (i.e. every point [x,y] is represented as a column vector [x, y, 1]), which transforms a square [0,0],[1,0],[1,1],[0,1] into a parallelogram [0,1],[1,1],[2,2],[1,2].
Things I spotted about this question
1) You need to understand homogeneous co-ordinates
2) You need to know the difference between row and column major - read here
3) You need to know the basic affine transformations - rotate, scale/shear and translate and how to represent them in a matrix - read this page
Interestingly, I think the answer only needs a translate and a shear ( no rotation ).
Looking at the source and dest points, it looks like all dest points are translated +1 in y and sheared by 1 in X ( to give the parallelogram, probably best to draw it out to see what I mean )
So start with a 3 * 3 identity matrix which is
1 0 0
0 1 0
0 0 1
The shear will be
1 1 0
0 1 0
0 0 1
The translate will be
1 0 0
0 1 1
0 0 1
So putting it all together should be
1 1 0
0 1 1
0 0 1
I don't normally use column major so probably worth double checking!
Hope that helps
An affine transformation is a transformation of the form x ⟼ Ax + b, where x and b are vectors, and A is a square matrix. Geometrically, affine transformations map parallelograms to parallelograms and preserve relative distances along lines.
To solve a problem like this, we first note that for the origin, we have 0 ⟼ A0 + b = b. Since the problem tells us that [0,0] ⟼ [0,1], we know that b = [0,1].
Next we recall from linear algebra that multiplying a matrix by the standard basis vectors [0,1] and [1,0] simply extracts the first and second columns of the matrix, respectively:
[a b] [1] = [a], [a b] [0] = [b].
[c d] [0] [c] [c d] [1] [d]
We are given that [1,0] ⟼ [1,1] and [0,1] ⟼ [1,2]. From this we obtain
[1,1] = A[1,0] + b = [a,c] + [0,1] ⟹ [a,c] = [1,0],
[1,2] = A[0,1] + b = [b,d] + [0,1] ⟹ [b,d] = [1,1].
This gives us our affine transformation
Ax + b = [1 1] x + [0].
[0 1] [1]
Homogeneous coordinates are a trick which let us write affine transformations as matrices, just with one extra coordinate that is always set to 1. The matrix formula is
[A b] [x] = [Ax+b].
[0 1] [1] [ 1]
Here A is actually a 2×2 matrix, while b and x are 2-vectors, and the 0 in the bottom left is really [0 0]. So overall, we are dealing with a 3×3 matrix and 3-vectors.
So our solution is
[1 1 0]
[0 1 1],
[0 0 1]
and for good measure we check that it works properly for the final point:
[1 1 0] [1] [2]
[0 1 1] [1] = [2].
[0 0 1] [1] [1]
You'll have read the Wikipedia page on the subject, of course.
Once upon an aeon or so ago, I read Foley and van Dam in one of the predecessor versions (this would have been 1983 or 1984), and it covered techniques for manipulating 2D and 3D coordinates with augmented matrices and vectors as described in the question. However, enough time has lapsed since then that I've forgotten all the details (and no longer have the book--too many moves of house). There was also a book by Newman and Sproul, I seem to remember.
A = [ a b c ] B = [ 0 1 1 0 ] C = [ 0 1 2 1 ]
[ d e f ] [ 0 0 1 1 ] [ 1 1 2 2 ]
[ g h 1 ] [ 1 1 1 1 ] [ 1 1 1 1 ]
The columns of B represent the corners of the square; the columns of C represent the corners of the parallelogram; and the matrix equation A x B = C has to be solved. IIRC, the matrix A has a 1 in the bottom right corner; it is possible that the values c, f, g, and h also have presecribed values (they'd probably be zeroes). The non-zero values apply a linear (affine) transform, scaling, shearing and rotating the input shape.
You'd need to look for similar information in a text book. Or in the Wiki page - I didn't look hard at it (the information above is working from ancient memory).
I just wanted to point out that four points over constrain a 2D affine transformation. In the comment of Jonathan Leffler, you can see this from the fact that you would need to invert a non-square matrix. So, either choose three of the points or set up a least-squares system. The over-constrained, least-squares solution could be solved with the following matrices
A = [ a b c ] B = [ 0 1 1 0 ] C = [ 0 1 2 1 ]
[ d e f ] [ 0 0 1 1 ] [ 1 1 2 2 ]
[ g h 1 ] [ 1 1 1 1 ] [ 1 1 1 1 ]
so that solving using the normal equations gives
A B = C
(A B)^T = B^T A^T = C^T
B B^T A^T = B C^T
A^T = (B B^T)^-1 B C^T
undoing that transpose gives
A = ((B B^T)^-1 B C^T)^T