I have a use case where I have 3 nodes connected by 2 edges.
In the example below, how can I constrain the relationship between the nodes so that I can only traverse the graph from A1 to C1 and A2 to C2 but I shouldn't be able to go from A1 to C2 or A2 to C1.
A1 <--edge--> B1 <--edge--> C1
A2 <--edge--> B1 <--edge--> C2
Example use case:
Character(A) PlayedBy(edge) Actor(B) In(edge) Movie(C)
where multiple characters can by played by a single actor in multiple movies but not all characters appeared in all movies linked by the actor. It's a many to one to many relationship where A is also linked to C.
Related
I'm reading a textbook containing the following question:
Given the following relation R {A,B,C,D,E,H} and the functional
dependencies AB->CD, BC->D, C->H, D->HB, CH->AE
does the following decomposition is dependency preserving?
R1(A,C,E,H) R2(B,D,H), R3(A,B,C), R4(B,C,D)
The answer of the textbook was that it is in fact functional dependency preserving, where I thought it wasn't because of the dependency AB->D
Reading this answer made it even more confusing, because it made it seems like if there is a key inside one of the sub relations, the decomposition must be dependency preserving
A counter example that I couldn't dispute is For the two rows
a1 b1 c1 d1 h1 e2
and
a2 b1 c2 d2 h2 e2 all the F.D of R hold, but now R3 has a1 b1 c1 and a2 b1 c2
and R4 has
b1 c1 d1
and
b1 c2 d2, joining R3 and R4 on B gives a1 b1 c2 d2 which breaks the AB->D F.D
In the example the dependencies are preserved as indicated by AntC in the comments.
The condition that a candidate key of the original relation is present in a decomposed relation is not a guarantee that dependencies are preserved.
Consider for instance the relation R(A B C D E) with dependencies {A → E, BCE → A, D → C} and the decomposition R1(A B D), R2(A E), R3(C D). The relation R1 contains one of the candidate keys of the original relation ({ABD}), but in the decomposition the dependency {BCE → A} is not preserved.
The fact that one of the original keys is present in one decomposed relation could be an indication that the decomposition is lossless, but in general there is no relation between lossless decomposition and dependencies preservation (see for instance this). There is however a result that connects in some way the two properties, as shown in an answer to the question cited.
We have a set of sequences with taxi positions. We want to cluster the data by considering the sequential patterns in the data lines.
For example:
T1, T2, T3, T4 be the travels and a,b,c,d,e be set of places.
The data we have is like,
T1 b c b a d
T2 a
T3 a b a b a b c e d
T4 b c d c b d c a
But the problem is the length of the data are not variable. How can we cluster these type of data using EM. Since it does not accept variable length data is there way we can customize it.
EM is a general principle. You can use it with very different models.
Probably the most popular model for EM is Gaussian Mixture Modeling, GMM.
Naturally, if you use covariances, GMM requires a fixed dimensionality.
But if you use other models, there is no reason it cannot work with variable length vectors. For example, there are EM variants that process text data, and text usually does have different length.
I want to run the keep command in a do-file in Stata 12:
keep a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4
What I want is to do the following:
keep {a1 a2 a3 a4 a5
b1 b2 b3 b4 b5
c1 c2 c3 c4}
I know the {} brackets don't do the trick but I'm looking for the command that does it. Using #delimiter ; does not work either.
I want to do this because subgroups of variables have a relation among themselves (which I intended to signal above by using a, b and c) and I want to have that clear in my code. I permanently add and delete variables. Note that I don't want to use the drop command (in which case the solution is trivial).
There are several ways. One is using ///. An example:
clear all
set more off
*----- example data -----
set obs 1
forvalues i = 1/25 {
gen var`i' = `i'
}
describe
*----- what you want -----
keep var1 var2 ///
var3-var7 ///
var8 var11
describe
#delimit will work if used correctly. An example:
<snip>
*----- what you want -----
#delimit ;
keep var1 var2
var3-var7
var8 var11 ;
#delimit cr
describe
There is still another way. help delimit (which you already knew about) states:
See [U] 16.1.3 Long lines in do-files for more information.
That manual entry points you directly to the relevant information.
I suspect lack of research/effort in this case. A Google search (with "stata + break lines in do files") would have easily gotten you there. I'm not recommending this be your first strategy when trying to solve problems in Stata. Rather, start with Stata resources: I recommend reading
[U] 3 Resources for learning and using Stata
[U] 4 Stata’s help and search facilities.
This is just a very simple trick to complement the real solutions by Roberto. Since you have so many variables, one thing I found sometimes useful is to use macros to group variables, especially if you can use the grouping in more than one occasion.
loca a a1 a2 a3 a4 a5
loca b b1 b2 b3 b4 b5
loca c c1 c2 c3 c4 c5
keep `a' `b' `c'
Let's say I have changeset A, and I make changesets B1, B2, and B3 on top of A, while another developer makes changesets C1, C2, and C3 on top of A:
B1 --- B2 --- B3
/
--- A
\
C1 --- C2 --- C3
The other developer pushes his code to the central repository, and now I want to push my code, but I can't because there are multiple heads. I could rebase my changesets to go on top of his (and this is what I've been doing), but it would be more accurate to merge.
However, as far as I'm aware, I can only merge one changeset at a time. So I'd have to merge B1 onto C3 creating M1, and B2 onto M1 creating M2, and and B3 onto M2 creating M3. That's three merges I have to perform, and three new merge changesets cluttering up the repository! Is there a way that I can merge B1, B2, and B3 onto C3 all at once, or do I have to settle for modifying history using a rebase?
You can merge B3 and C3 to get:
B1 --- B2 --- B3
/ \
--- A M
\ /
C1 --- C2 --- C3
That is the traditional way to reconsile the two lines of development. The merge changeset will have two parents (merges always have two parents in Mercurial) B3 and C3, but you're still merging the combined effect of B1 to B3 with the combined effect of C1 to C3.
In fact, merges are only concerned with three states: A, B3, and C3. Since the state B3 include the changes you made in B1 and B2, you end up merging the changes in B1 to B3 into the state C3.
What you describe with three merges is actually what rebase does internally! After creating M1 to M3, it deletes the second parent of these merge commits and deletes B1 to B3. That leaves you with
--- A --- C1 --- C2 --- C3 --- M1 --- M2 --- M3
where Mi ~= Bi. As you note, this is a less accurate picture of what actually happened in the repository because you've linearized history what was really done in parallel.
I have multichannel serial data from an 8 channel ADC chip that I'm connecting to my computer via a serial-USB cable. I want to use these separate channels in Pure Data, but the pd_comport object doesn't read multi-channel serial data. I've scoured the Pd discussion fora but there's no mention of how to do this.
Any thoughts on how I can go about it?
per definition a serial connection is only single-channel. if you have multiple (synchronized) channels, it's called parallel.
so your problem is basically one of the two following:
parallel serial streams
if you are transmitting the 8 ADC-channels via different serial connections, your (special) cable should register 8 different devices (e.g. /dev/ttyUSB5, /dev/ttyUSB6, .../dev/ttyUSB12).
in this case, simply use multiple [comport] objects (one for each serial device you want to interface)
single multiplex stream
in the (more likely) case, that your ADC transmits it's 8 channels in a single serial connection by multiplexing the data, you will have to demultiplex the serial stream yourself. how to do this, is very much depending on the actual format of the data.
assuming your ADCs are only 8bit and you have only 4 channels (for simplicity), then you might receive a serial stream like: ... A1 B1 C1 D1 A2 B2 C2 D2 A3 B3 .... (with A, B,... being the samples for the 4 channels; and 1,2,... being the sample frames), then you could demultiplex the signal into 4 streams with something like
|
[t b f]
| |
| +------------+ |
[i ]/[+ 1]/[% 4]/ |
| |
[pack 0 0]
|
[route 0 1 2 3]
| | | |
in practice your protocol might look slightly different (e.g. there ought to be a way to specify frame boundaries (there's no way by just looking at the numbers, whether you are actually seeing A1 B1 C1 D1 A2 B2 or B1 C1 D1 A2 B2 C2, so it's unclear whether the 1st sample belongs to channelA or channelB).
thus you really must get your hands on the protocol definition and interpret the data you get from [comport]