Find all subgraphs which has a single input edge and a single output edge in a graph - graph

Given a graph, I want to find all the subgraphs that only has 1 input edge and 1 output edge. For example, in this graph, the subgraphs will be [1, 2, 3, 4], [5, 6, 7, 8]. I don't know how to describe this problem in a formal way so just putting a graph here.
Edit:
Thanks to the comment. The subgraphs shouldn't overlap with each other. Fro example, I don't want [2, 3] since it is part of [1, 2, 3, 4].

Related

umap for dictionary in Julia

I'm given a dictionary with keys(ids) and values.
> Dict{Int64, Vector{Float64}} with 122 entries:
3828 => [1, 2, 3, 4...
2672 => [6,7,5,8...
...
Now I need to apply umap on it. I have the code that
embedding = umap(mat, 2; n_neighbors=15, min_dist=0.001, n_epochs=200)
println(size(embedding))
Plots.scatter(embedding[1,:],embedding[2,:])
Here mat is the matrix
1, 2, 3, 4
6, 7, 5, 8
....
So I got the embedding matrix and the umap plot. But in the plot all points are same color and no labels. How do I do so that I can get points with labels(keys in the dictionary)?
Looking at UMAP.jl, the input matrix should have the shape (n_features x n_samples). If each entry in your dictionary is a sample and I’m interpreting your matrix notation correctly, it appears you have this reversed.
You should be able to add the keys of the dictionary as annotations to the plot as follows (potentially with an optional additional offset to each coordinate):
Plots.annotate!(
embedding[1,:] .+ x_offset,
embedding[2,:] .+ y_offset,
string.(collect(keys(yourdict)))
)
Finally, I’m not sure what variable you actually want to map to the color of the markers in the scatterplot. If it’s the integer value of the keys you should pass this to the scatter function just like above except without turning them into strings.

How to connect points using plot() in Julia

I would like to connect points on a cartesian coordinates system, like the image below:
x = 1:10;
y = rand(10);
plot(x, y)
In the image above these points are random and the x axis can only take the values from 1 to 10.
I want to create a similar plot where I can assign the position of specific points ( let us name these points: [x_i, y_i] ) and connect them. Here is an example of some values for [x_i, y_i]
[0,2], [4,-10], [5, 12], [12, 6]
From the docs:
you can plot a line by calling plot on two vectors of numbers.
You can pass as first argument to plot a vector of the x_is, and a vector of the y_is as the second argument. Then plot will draw a line. For example:
plot([0, 4, 5, 12], [2, -10, 12, 6])
If you must take the input as pairs of [x_i, y_i], you can just do a little preprocessing before you plot. E.g.
input = [[0,2], [4,-10], [5,12], [12,6]]
4-element Vector{Vector{Int64}}:
[0, 2]
[4, -10]
[5, 12]
[12, 6]
plot([x for (x, y) in input], [y for (x, y) in input])
Both produce the output:

Igraph Random Graph

I want to create a graph in python using Igraph. I did not create the edges. I want to know how to create the random edges between the nodes that have already been created. I tried to use Graph.GRG but it did not work.
g.add_vertices(3)
g.add_edges() is what you need. This method takes a list of pairs of vertex numbers. Here is a simple example:
from igraph import *
import random
## Generate graph with 8 vertices and no edges
g = Graph()
g.add_vertices(8)
## Now generate random edges
random.seed(123)
RandEdges = []
for x in range(1, 13):
RandEdges.append(random.sample(range(0,g.vcount()), 2))
RandEdges
[[0, 2],
[1, 6],
[6, 2],
[1, 6],
[0, 3],
[5, 2],
[0, 1],
[2, 7],
[5, 7],
[3, 1],
[0, 3],
[1, 4]]
With this format, you can add the edges.
## Add edges and plot
g.add_edges(RandEdges)
plot(g)
Some additional examples of adding edges are available in the igraph tutorial

How to create a cumulative graph in R

Is there a cumulative graph package in R? Or how might I create a cumulative graph in R?
For example, given values of 2, 4, 2, 2, they values should be plotted as 2, 6, 8, 10 d3 example here. Then forming a stair step pattern as with other cumulative records
As per ?plot.default - there is a "stairs" plotting method, which can be combined with cumsum() to give the result you want I think:
plot(cumsum(c(2,4,2,2)), type="s")

Maxima plot2d discrete with points

I have a samples list with a collection of (x,y) coordinates pairs. I want to use plot2d to create a discrete plot from these points, not showing lines connecting each point.
This is my script:
plot2d(
[discrete, samples],
[style, [points, 1, 5, 1]],
[legend, "Samples"],
[gnuplot_term, "svg size 640,480"],
[gnuplot_out_file, "graph_samples.svg"]
)$
But the result is a plot with connected points, as can be seen in the picture below. Despite the use of the [style, [points, 1, 5, 1]] option, the plot connects each point. The style definition seems to be ignored.
Does anyone have a clue why is this happening? I know I could alternatively use draw2d but I'd rather use plot2d if possible.
You can also quote a symbol to prevent evaluation:
points: [1, 2, 3];
x: 42;
plot2d('x^2, ['x, 1, 2], ['style, 'points]);
The problem was that I had a points matrix previously declared that was conflicting with the style definition. Changed its name and worked like a charm.

Resources