Graphviz: align subgraphs vertically - width

I’ve got four subgraphs that I’d like to (a) have the same width and (b) be aligned vertically (red > yellow > green > purple). I can’t figure out how to do that.
Here is the dot code, simplified for clarity:
digraph {
rankdir = "TB";
compound=true;
node [shape=box, style=filled,color=white];
subgraph cluster_pre_proto_greek {
label="Pre-Proto-Greek";
style=filled;
color=red;
c1 [label = "1. Change of word-final *ms to *ns"];
c2 [label = "2. Loss of word-final *i̯ after a long vowel"];
c3 [label = "3. Change of dental stop to *s before dental stop"];
}
subgraph cluster_pre_proto_attic_ionic {
label="Pre-Proto-Attic-Ionic";
style=filled;
color=yellow;
c4 [label = "4. Merger of *K̑ with *K"];
c5 [label = "5. Merger of *Ku̯ and *Kʷ"];
c6 [label = "6. Loss of laryngeals"];
}
subgraph cluster_pre_homeric {
label="Pre-Homeric";
style=filled;
color=green;
c7 [label = "7. Early vowel contractions and rise of tones"];
c8 [label = "8. Metathesis of *TK to *KT"];
c9 [label = "9. Vowel epenthesis before word-initial *r"];
}
subgraph cluster_homeric {
label="Homeric";
style=filled;
color=purple;
c10 [label = "10. Devoicing of voiced aspirates"];
c11 [label = "11. Vocalisation of syllabic sonorants before vowel or *i̯"];
c12 [label = "12. Vocalisation of syllabic nasals"];
}
c1 -> c12;
c3 -> c6;
c3 -> c9;
c4 -> c5;
c5 -> c11;
c6 -> c7;
c6 -> c11;
c6 -> c12;
c7 -> c8;
c9 -> c10;
c10 -> c11;
c10 -> c12;
c11 -> c12;
}
And here is the output (from edotor.net):
Graphviz Graph (updated)
Any help is greatly appreciated!
Edit: Here is what I’d like to get at:
Graphviz Graph: modified

I believe the problem comes about because it is trying to minimize the vertical height, a way to fix this is to pass minlen=2 to some of the edges so try:
c1 -> c12
c3 -> c6;
c3 -> c9;
c4 -> c5;
c5 -> c11;
c6 -> c7 [minlen=2];
c6 -> c11;
c6 -> c12;
c7 -> c8;
c9 -> c10 [minlen=2];
c10 -> c11;
c10 -> c12;
c11 -> c12;
You can also try commenting out various edges to see what effect they are having on the final image, and you can add constraint=false if you want to remove it's effect.

Related

how to substract value present in one row to other row within same table?

I'm trying to subtract two rows of different columns. Example table
C1
C2
C3
A1
2
A2
3
B1
4
So essentially, I want A2-A1 from C3 and C2 columns respectively. My approach was to somehow get values in C2New column and then subtract.
C1
C2
C2New
C3
C4
A1
2
2
A2
2
3
1
B1
4
If you are using explorer, here is how you can create the table:
let X = datatable( c1:string , c2:int , c3:int )
[ 'a1',2,3,
'a2', 0,3,
'b1', 0,4
];
X
| project c1, c2, c3
I have tried different joins, selfjoins, lookups and toscalar etc., expecting it would populate a value in empty cells and I would then create a new column or scalar with the difference in values. I'm totally new to coding and querying. Your help is appreciated.
KQL script:
let X = datatable( c1:string , c2:int , c3:int )
[ 'a1',2,3,
'a2', 0,3,
'b1', 0,4
];
X
| project c1, c2, c3
| serialize
| extend prevC2 = prev(c2,1)
| extend c4 = c3 - prevC2
Use Serialize operator to the table and then use prev function to get the previous row value.
Then subtract the c3 value from previous row c2 value.
Updated Script
As per David דודו Markovitz's comment, I updated script.
let X = datatable( c1:string , c2:int , c3:int )
[ 'a1',2,3,
'a2', 0,3,
'b1', 0,4
];
X| serialize c4 = c3 - prev(c2)
Output data
c1
c2
c3
prevc2
c4
a1
2
3
a2
0
3
2
1
b1
0
4
0
4

Table Calculation in python-3.x

I am still early on in my python journey and I have encountered a problem. I have a fairly large table similar to the one shown below;
Haz
Fault - floats
Mit - floats
H1
F1
M1
H1
F1
M2
H1
F1
M3
H1
F1
M4
H1
F2
M5
H1
F3
M6
H1
F3
M7
H1
F3
M8
H2
F4
M8
H2
F4
M9
..
..
..
H20
F87
M435
For each unique "Fault", I need to obtain a probability value (FM) through the following equation;
FM = [(1-M1)*(1-M2)...*(1-Mn)] * Fn
And then, for each unique "Haz", I need to obtain a probability value (HM) through the following equation;
HM = 1-[(1-FM1)*(1-FM2)...*(1-FMn)]
Any guidance on how I should approach this problem?

Making a vector of specific length with random numbers

I tried writing a program that would give me the i,j and k components of a vector of a specified magnitude.
import random
import math
while True:
a = random.uniform(0,1000)
b = random.uniform(0,1000)
c = random.uniform(0,1000)
d = 69.420
if math.sqrt(a**2 + b**2 + c**2) == d:
print(a,b,c)
break
But it seems that this program might take literally forever to give me an output.
What would faster or possible solution be?
#Update
import random
import math
while True:
a2 = random.uniform(1,1000)
b2 = random.uniform(1,1000)
c2 = random.uniform(1,1000)
d = 69.420
d2 = a2 + b2 + c2
a2 *= d/d2
b2 *= d/d2
c2 *= d/d2
a = math.sqrt(a2)
b = math.sqrt(b2)
c = math.sqrt(c2)
if math.sqrt(a**2 + b**2 + c**2) == d:
print(a,b,c)
break
As per suggested, but still taking a very long time to compute
Get three random numbers a2, b2, and c2. Those are your random squares. Add them up to get d2. You want the sum of the squares to be d squared, so multiply a2, b2, and c2 by d*d/d2. These are your new squares that add up to d squared. Now assign the square roots of a2, b2, and c2 to a, b, and c. Does that make sense?
Avoid dividing by zero. If d2 happens to be zero, just start over.

How do you create and use datatypes in Haskell?

I am an Absolute Newbie to Haskell. But I really like it. I have been reading Learn You A Haskell and Real World Haskell and practicing along. I am on the Functionally Solving Problems section in the Learn You A Haskell book and I need someone to explain the following to me:
data Node = Node Road Road | EndNode Road
data Road = Road Int Node
Questions:
Is this some recursive data type creation?
Why Can't I do: Node "A" "B" and get a valid Node type? When I try something I can an error saying that Haskell can't match [Char] with Expected Road and I understand that. But I can't create a Node X Y without a Road Int Node. I thought Road was a type synonym for String but since it isn't declared it certainly is not. If anyone read the book and understood this thing PLEASE EXPLAIN WHAT THOSE DATA TYPES MEAN AND PROVIDE EXAMPLE IF POSSIBLE.
Edit: The Chapter In Question >> Heathrow to London problem
Yes, these are mutually recursive data types.
To create values of these types you are likely to use recursion too. For example, here's a minimal road system - two nodes where each one lets you drive to the other:
nodeA, nodeB :: Node
nodeA = EndNode (Road 99 nodeB)
nodeB = EndNode (Road 99 nodeA)
Note how the definition of nodeA refers to nodeB and vice versa.
If I read the example in the book correctly it can be written like this:
aRoad, bRoad :: Road
aRoad = Road 50 a1
bRoad = Road 10 b1
a1, a2, a3, a4 :: Node
a1 = Node (Road 5 a2) (Road 30 b1)
a2 = Node (Road 40 a3) (Road 20 b2)
a3 = Node (Road 10 a4) (Road 25 b3)
a4 = EndNode (Road 0 b4)
b1, b2, b3, b4 :: Node
b1 = Node (Road 90 b2) (Road 30 a1)
b2 = Node (Road 2 b3) (Road 20 a2)
b3 = Node (Road 8 b4) (Road 25 a3)
b4 = EndNode (Road 0 a4)
Note again the mutual recursion of a1 and b1, a2 and b2 etc. for the crossing roads.
I've written the roads inline but of course you could name them all if you wanted:
roadA1ToB1 :: Road
roadA1ToB1 = Road 30 b1
If you did it this way the cycle of definitions would involve four of them - the definition of (the node) a1 would use roadA1ToB1, which would use b1, which would use roadB1ToA1, which would use a1.

What is the significance order of this Verilog initialization syntax?

This is a simple SystemVerilog question that I am having a surprisingly difficult time finding the answer for.
In this kind of bit array initialization syntax, is the b[0] part assigned to a's most significant bit, or the least significant bit?
bit a[7:0];
bit b[7:0] = 8'hff;
bit c[7:0] = 8'h00;
a = {b[0], c[6:0]};
So does a[0] == 1 or a[7] == 1?
The reason you've found it hard to find an answer is because the result is dependent on how you've declared things.
You've declared a to be [7:0]. Therefore the bits in a are arranged like this:
a7 a6 a5 a4 a3 a2 a1 a0
You then assign {b[0], c[6:0} to a:
a7 a6 a5 a4 a3 a2 a1 a0 = b0 c6 c5 c4 c3 c2 c1 c0
1 0 0 0 0 0 0 0 = 1 0 0 0 0 0 0 0
A[7] == 1
If you'd declared a to be [0:7] the result would have been:
a0 a1 a2 a3 a4 a5 a6 a7 = b0 c6 c5 c4 c3 c2 c1 c0
1 0 0 0 0 0 0 0 = 1 0 0 0 0 0 0 0
A[0] == 1
b[0] is assigned to the most significant bit, a[7]; i.e. a[7] == 1.
However, I'm not sure it's typo or your intention to use unpacked declaration. bit a[7:0] is an unpacked array, it does not mean continuous storage and it can not be directly assigned packed or integral value.
Following is adopted from SystemVerilog for Design, P.114, 5.3.1 Unpacked arrays
Unpacked array stores each element independently, but grouped under a common array name.
P.122, 5.3.5 Assigning values to arrays
SystemVerilog extends Verilog with two additional ways to assign values to unpacked arrays:
- The entire array can be assigned a list of values
- A slice of the array can be assigned a list of values.
The list of values is specified between '{ } braces, the same as with initializing unpacked arrays.
For packed array, bit [7:0] a, we do have correct answer from Paul.

Resources