Looping through timeseries points of voronoi

Hi, I want to loop through the voronoi triangles, get their (x,y) cordinates and then check for the density values which i have in a form of 2d array. How can i do that?
This is my code:

using Distributions

mean_signal = [1.0, 2.0, 3.0, 4.0, 5.0, 1.0, 2, 0, 3, 0]
std_dev = [0.9, 0.2, 0.1, 0.3, 0.2, 0.3, 0.9, 0.3]

density_values = [pdf(Distributions.Normal(mean, std), x) for (mean, std) in zip(mean_signal, std_dev), x in range(0, 10, length=10)]
@show (density_values)

fig = Figure()
ax = Axis(fig[1, 1])

heatmap!(ax, density_values, colormap=:viridis)
tri = triangulate(points)
vorn = voronoi(tri)
ax2 = PlotConfig.configure_plot(fig, 1, 2, "Voronoi", "x", "y")
ax3 = PlotConfig.configure_plot(fig, 2, 1, "Centroids", "x", "y")
voronoiplot!(ax2, vorn, show_generators=false)
centroids = zeros(2, num_polygons(vorn))
for (j, i) in enumerate(each_polygon_index(vorn))
    centroids[:, j] .= DelaunayTriangulation.get_centroid(vorn, i)
end
GLMakie.scatter!(ax3, centroids)

resize_to_layout!(fig)
display(fig)

Your code doesn’t run for me. I don’t think your example needs to include any plotting for this either.

  1. What are Voronoi triangles? Do you mean the Voronoi cells, or are you referring to the triangles in the dual Delaunay triangulation?

  2. What are the (x, y) coordinates associated with (assuming the answer to the above is Voronoi cells) a Voronoi cell? Do you mean its vertices, or a singular (x, y) value which seems to be the centroid from your example?

  3. What do you mean “check for the density values”?

Hi, to answer

the points is not defined, hence the code isnt running for you.

  1. Yes its voronoi cells
  2. (x,y) positions of the triangles and centroid
  3. In the above code, i’m computing normal distribution of mean and std, now i want to check for each voronoi cells if the centroid has a density of less than 0.5, then i want to split if not delete the cell and so on.

The problem as described doesn’t seem fully defined so here’s some more questions.

hence the code isnt running for you.

My point being that it’s most helpful to provide runnable code that others can work with. There’s also missing packages and I’m not sure what PlotConfig is

(x,y) positions of the triangles and centroid

What triangles?

centroid has a density of less than 0.5

What is the density of a centroid? You have a whole set of density functions there, it’s not clear to me what density you are choosing. Is the density some interpolation of those objects? Whatever the function p is that defines your density, just check p(x, y) < 0.5 where (x, y) is the centroid I suppose.

then i want to split if not delete the cell and so on

Not part of your question, but just incase you don’t know this step: For deleting the cell, you’ll need to use delete_point!(tri, i) where tri is the triangulation and i is the index of the cell. You’ll then recompute the tessellation (currently I have no implementation of e.g. delete_cell!(vorn, i), it’s not hard just I haven’t done it). For splitting, I assume you mean adding in a point so e.g. add_point!(tri, x, y) and then again recompute the tessellation.

1 Like

It would be more helpful to try and be a bit more generic in describing in what you’re doing. Keeping the application around is making it confusing. Simple, concise, runnable code is what this is good for. What is wrong with

Whatever the function p is that defines your density, just check p(x,y)<0.5 where p(x,y) is the centroid I suppose.

in my reply above? You seem to define p in this last reply.

ok to get started with generic, I want to get the density values at point (x,y)

density_values = [pdf(Distributions.Normal(mean, std), x) for (mean, std) in zip(mean_signal, std_dev), x in range(0, 10, length=10)]

But how are you extending the 1D density pdf(Normal(mean, std), x) to 2D? Are you trying to evaluate a 2D (multivariate) normal density? I don’t know what your definition of density is and how your values for the mean and standard deviation relate to the points in the Voronoi tessellation.

If density is to mean a probability density, is the probability distribution in question referring to the distribution of values inside the band in your “Uncertain time series” plot? And you want to take a point (x, y) inside the Voronoi tessellation and determine the density associated with that point inside the band? If so, it seems like Voronoi isn’t actually relevant here and you want to just determine how to find a probability density associated with a confidence band mean +/- std. Else I’m just not seeing what you are trying to compute.