Community RSS Feed
https://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions in tag Modeling sorted by activeMake each agent interact with every possible neighbor?
https://community.wolfram.com/groups/-/m/t/1930208
I am trying to modify an excellent code by Christopher Wolfram: https://community.wolfram.com/groups/-/m/t/1907703
The code sets that each step of the simulation, each agent will pick some subset of its neighbors to meet with. The code specifies the distribution that determines how many neighbors each agent will meet with at each step. An exponential distribution was chosen in the beginning.
meetingCounts =
AssociationThread[Keys[neighbors], ExponentialDistribution[2]]
Later, meetings are determined using this code
meetings = DeleteDuplicatesBy[Flatten[
Function[a,
{a, #} & /@
RandomSample[
neighbors[a],
Clip[
Round[RandomVariate[meetingCounts[a]]], {0,
Length[neighbors[a]]}]]
] /@ Keys[neighbors],
1], Sort]
What I want to do is make each agent interact with every possible neighbor, not a random subset of neighbors, as in the original code.
I came up with the following solution:
meetingCounts =
AssociationThread[Keys[neighbors], UniformDistribution[{Length[neighbors[1]], Length[neighbors[1]]}]]]
So, since in my code the maximum number of neighbors is achieved in agent 1, the code above can do the job, but it is not an ideal solution.
I guess that a simple modification of the meeting function above would be sufficient for my needs, but I am not very familiar with the Mathematica syntax.
Can anybody have an idea of how to modify the meeting function above so each agent will pick every neighbor to interact, instead of a random sample of possible neighbors?
ThanksRafael Guariento2020-04-09T00:05:47Z[Notebook] Epidemiological Models for Influenza and COVID-19
https://community.wolfram.com/groups/-/m/t/1896178
*MODERATOR NOTE: coronavirus resources & updates:* https://wolfr.am/coronavirus
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/rnachbar/Published/EpidemiologicalModelsForInfluenzaAndCOVID-19.nbRobert Nachbar2020-03-11T17:39:06ZModeling the COVID-19 Epidemic as a Logistic Equilibrium
https://community.wolfram.com/groups/-/m/t/1931922
Ladies and Gentlemen at Wolfram Research (Steve and Eric)
My virus free pdf attachment, a Mathematica Notebook modeling the COVID19 epidemic in the state of Illinois. How does it work?
First, scroll down to page 10. Do you see the chart reading Time (days) on the X axis and Velocity on the Y axis? The graph (bell shaped red line) gives the change in the velocity of the epidemic over time. Now turn your gaze to the line just below the chart. Do you see the words ‘Find Maximum’? The phrase {t > 26.3037} indicates the epidemic made it half way to the maximum number of new cases, new infections on day 26 in the state of Illinois (5 April 2020).
Second, scroll back up to page 6. Study the chart with the heading at the top reading: Show[KinetE1LMdl,dtplt1a]. The red dots represents total cases diagnosed from one day to the next. The green smooth line gives my derivation of the Logistic Equation fit to the data points and extending on out to 60 days. Do you see the words underneath the chart reading: ‘Find Maximum’ with the results: {23612. , {t > 1110.}}? Those numbers mean. If the Logistic Model holds true and correct for the near future there will be 23,612 (twenty three thousand six hundred and twelve) cases in the state of Illinois some 1110 (one thousand one hundred and ten) days after the first day, 10 March 2020. (Actually, it’s a lot worse than that. There will probably be 23,000 or so cases by day 60 of the epidemic).
How to use this model in practical application? I’m planning on adding fresh new numbers to the second data point set dtpts1b as they appear on the Illinois Department of Public Health web page. http://www.dph.illinois.gov/topicsservices/diseasesandconditions/diseasesazlist/coronavirus
If the graph of the second data point set (dtpts1b) falls down and away from the graph of the first set (dtpts1a) over time we can assume the crisis will be coming to an end in the foreseeable future. If the graph of the second data point set (dtpts1b) either holds to the curve or climbs above the curve, we are in deep trouble.
Please ladies and gentlemen, please forward this email and notebook to as many Mathematica smart epidemiologists and mathematicians as you have on your email list.
Cordially and with best wishes, Alan White, Hickory Hills Illinois (708) 325 – 8979Alan White2020-04-09T20:19:27ZAn SEIR like model that fits the coronavirus infection data
https://community.wolfram.com/groups/-/m/t/1888335
SEIR models for data from China, Italy, US, and Finland; and for Spain, UK, France, Germany, and Austria, and again for Finland in responses at the end of the discussions in the post. For an explanation of SEIR models see Robert Nachbar's post:
https://community.wolfram.com/groups/-/m/t/1896178
The equations of the slightly modified SEIR model are given ahead. It is possible to model the data by assuming a low enough susceptibility. I explain in the discussion with Robert Nachbar below why the main effect of containment measures is to lower the effective number of susceptible individuals when it is imposed (relatively speaking, at the beginning). As a CAVEAT, these models are models of the DETECTED number of cases, not the TRUE number of cases.
In the SEIR models, the basic reproduction number (R0) is constant and it depends on the parameters of the equations below. If we do the usual calculation (roughly beta/gamma in the equations below), R0 in our models is about an order of magnitude larger than the estimated-observed R0. There is an intuitive explanation for that. If we were to model the DETECTED number of cases using the BELIEVED or TRUE number of susceptible individuals, thought to be an order of magnitude higher than the detected ones, then we would need to scale down beta by an order of magnitude to get our results, among other things. That would give us the R0 that is being measured (my understanding is that R0 was estimated on DETECTED number of cases - but if this is wrong, then my explanation for the disparity is not correct). The main effect of lockdown is to lower the number of people that can be exposed to the pathogen when it is imposed, roughly at the beginning of the outbreak (see reply to Rober Nachbar's response for a thought experiment that explains this). Recall, the basic reproduction number (R0) is constant.
Regardless of these considerations, our model allows us to understand how the disease evolves in time. At least, we were able, in the Chinese model, to predict an end of outbreak time well in advance (the evidence is in Rimmer's response to this post where a similar prediction is made based on our model).
The newer models are adjusted quite frequently, especially with respect to the number of susceptible individuals, as they continue to grow. They tend to stabilize about three weeks after control measures have been in place. After the I curve peaks, it is possible to begin to get an idea of how long the outbreak will last. Now the equations.
s'(t) = -Beta * s(t) * i(t) / p,
e'(t) = Beta * s(t) * i(t) / p - Sigma * e(t),
i'(t) = Sigma * e(t - m) - Gamma * i(t - n),
r'(t) = Gamma * i(t - n)
beta is the rate of infection, sigma is the rate at which an exposed individual becomes infective,
gamma is the removal rate, m and n are shift parameters to line up the curves (different countries release patients at different times). The parameter values are in the titles of the pictures for each country. In general we assume e(0)=i(0)=1 unless stated otherwise in the model label. Also, s(0)=p, and r(0)=0.
Directly in this post we find pictures for the models of China, Italy, the U.S., and one model for Finland. In a response, towards the bottom of the post, you can find two alternative models for Finland. In a separate response, models for France, Germany, Spain, the U.K., and Austria.
The data for the Finnish model comes from the Finnish Department of Health and Welfare (THL in Finnish). There is a delay in the release of the data of 1-2 days. however, the recovery data comes from Johns Hopkins University. According to the medical chief of staff of the infections diseases clinic at the Helsinki and Uusimaa hospital district, it was "important to define what people mean when they talk about recovery", and that "eventually it would be important to compile statistics to better understand the disease" and "was taking the numbers with a grain of salt" noting that "the criteria undrelying the data are not always clear and they are not always the same in each country". He also said that "tracking recovered patients was not a top priority". (quotes source is Yle news, the state run news agency). The number of recoveries given at the JHU site is a lump sum. We have serialized this datum into data according to how cases might have arisen in time to obtain a model. The recovery period appears to be 17 days or so. We are modifying the Finland section to reflect this new reality and will explore other models. If no new data is provided, we will extrapolate from our series the next elements according to a best fitting model to the data that we have. For Finland we provide additional information which can be used to verify the model, such as the peak date for the cumulative mean of the number of daily new cases (see Finland section). The model based curve and data based curve can be found in the Finland section (one of the last responses below).
I have removed the alternative model picture, which shows the effect of lowering sigma (flattens the curve).
In the Finland section, where there is space, I include a pdf document with a smoothened version (3 day moving average) of the daily tallies for several countries in Europe, as well as USA and South Korea. One can appreciate that contrary to what some European authorities are suggesting, hardly any European country is ready to move forward, according to this parameter.
April 10; updating
April 9: updating. In the Finland section there is a pdf document with the smooth version of the daily tallies for several Euro countries, USA, and South Korea. The Italy model seems very stable now.
April 8. Updating. Today I added, in the main part of the text above, an "intuitive" note about the basic reproduction number (R0) in these models and why they are about an order of magnitude larger than the measured rates.
April 6-7. Updating throughout the day. France and UK models temporarily suspended due to missing or inconsistent data, until more data is available
April 5: Updating throughout the day. There is a new model for Austria in the Europe section. It's I curve has peaked, and it will be the first country in Europe without an outbreak, at the end of this month, most likely.
April 4: Updating. The daily tallies for Finland, with the corrected time series, has been published now (3 PM EET) and the graph updated. The model was adjusted a tiny bit. In the model for Italy there is now a possible end of outbreak date, should the data stay on the curve. It is calculated using a threshold, which I do not explain here.
April 3: Updating. As expected, there is no recovery data for Finland so we are extrapolating from previous data.
April 2: Updating. As of April 1 I will use the official data from the Finnish Department of Health and Welfare (THL) for the Finnish model. The model is almost the same as before. There was a lack of recovery data, but yesterdays the recovery data was released as a lump sum the number of recoveries. We have stretched this datum into data according to how cases might have arisen in time to obtain a model. The recovery period appears to be 17 days or so (see more detailed explanation above). We are modifying the Finland section to reflect this new reality and will explore other models. Italy seems to be reaching the peak of its I curve at around the time I estimated it would, maybe a week later.
March 30-31: Updated
March 24-27 AM EET: All models updated; PM EET: Europe models (some are at the bottom of discussion) models updated. I UPDATED and CORRECTED the NOTEBOOK.
March 23 AM EET: China and US pictures updated, as well as the reply to the post at the bottom with the five major European countries other than Italy, and Finland. Italy picture updated in the pm. The hopefully good news is that all major European countries saw a decline in the number of daily new cases yesterday. In the PM, the numbers for Italy have declined for two days in a row. If the trend continues, the I curve will peak in about 11 days. The model has changed slightly.
March 21-22 AM EET: China and US pictures updated. Large Europe countries other than Italy will be updated in the morning EET. They are found in the PDF document. In the PM the Italy model is updated. It looks like the daily new cases might have peaked yesterday. The new picture has a theoretical new daily cases peak marked as a blue dot, after which we can expect 13 days before the actual peak of the I curve. Then comes the tail, with the end of the outbreak 1 to four months (or possibly more) later. I am hoping that indeed new daily cases peaked yesterday but only time can tell. At the end of the discussion, in a reply, there is now a model for Finland.
March 20, PM EET: China, USA updated. I have updated the notebook with the China model. The Italy model has changed substantially and is now much tighter.
March 19, PM EET: China, USA, and Italy models updated. The Italy model parameters have changed again to fit the data up to this point as there is no indication of the growth of the I curve slowing down. When I first posted this, in one of the discussions, we made a forecast that the first day with no new infections (not imported) would be March 23. Apparently this has happened already yesterday, March 19.
March 18, 8:00 PM EET: China model picture updated. I corrected a mistake in the label of the picture (p=81 K). US model added. Italy model updated.
March 17: Updated. In about a week there should be enough data for other countries. The China model has now been stable for quite a while, the Italy model I still change a little bit now and then. It is worth recalling that what makes this model successful is the low number for the effective susceptibility, something that I explained with a thought experiment earlier. Containment efforts essentially remove people from the infection path, lowering the number of susceptible individuals. Please read the discussions.
March 16 - NB: I have updated the China picture and the Italy model has stabilized, and is updated and unchanged. If the containment measure in Italy as working as it is hoped for, the I curve should be peaking in about a week or so. The curve is somewhat more spread out than for China, so that the recovery to current China levels would take about 80 days rather than 40 which it has in China. The overall number of cases should be of about the same size as well, a bit larger. We only hope for the best.
March 15: updated. It is almost a safe bet to say that the situation in Italy will end up being worse than in China. It seems other western countries are headed in the same direction, unfortunately, due to various sorts of circumstances, in each country its own, including the country where I live, Finland. When I have enough data, I will move out the alternative model picture and put up the picture of a new country.
March 14: updated.
March 13: I have tried to match the tail of the I curve and the R curve in the China model, since the data is necessarily more reliable there. I will try to include models for other countries in the notebook as I am able to ... maybe in a week. I cannot post all the pictures here, I think I can post up to 5 pictures, but I will include the models in a notebook and update it periodically, albeit, not daily.
March 12: I have made an important change in the China model. I have removed the correction factor for counting method change to agree with the number of current reported active cases. What this means is that during the climb phase of the I curve, there was some under reporting of cases; and for a few days, there was also over reporting. The blue curve now agrees with the red data in this respect. We will probably never know what exactly happened, but I believe the model tells the story. We also get a very good fit for the recovery curve. The new parameters are in the title label. The timeline now starts on Jan 11. The effective susceptible population, which is what we know now, stands at 81 K. I have updated the equations picture and the situation in Italy as well.
March 9-11: updated
March 8: I managed to access the internet. The China model has new parameters to adjust for what will possibly be a somewhat lower final total number of cases. The Italy model has the same parameters as the original China model, but I expect this to evolve rapidly. The parameters are now indicated in the picture title.
March 7: I am on travel ... I will update this post in a week. Briefly, the model for italy remains to be the blue model but with p=25000. I apologize I cannot update the pictures, I only have good internet access through my mobile device
March 6: I update the picture for China and for Italy. There is also (in the same picture) a probably better alternative model for Italy.
March 5: made a correction in the notebook (rendering) and updated the picture. I have added a picture for the situation in Italy. The model is the same, except for p=15000 and for shorter horizontal shifts ... the illness does not seem as prolonged. How this will turn out to be in the end is anybody's guess right now. I estimated the size for p based on the size of the population of the cordoned area. I have removed an old picture. I will update the notebook with the Italy (and other models) later.
March 4: picture updated, minor corrections. March 2 forecasts are now superseded by a virtual end of the outbreak by March 23 with some possible further cases later on. I have attached a notebook as a file, but I could not figure out how to login to post it - I am new here.
March 3: I have managed to remove all time dependencies from the parameters and get the same good fit. I am updating the picture and publishing the equations (see the picture at the end of the post with the equations and parameter values) of what is a somewhat simplified SEIR model which I have used. From it one can calculate R0 in the usual way, and it is much higher than what I reported before. I do not what to make of it. The effective susceptible population is now 82000. I developed this yesterday and it was good to see that no modifications were needed to fit today's data. Unless there are further changes that need explaining, I will refrain from posting for a few days or a couple of weeks, except for updating the picture. Recall that what makes this possible is noting that the effect of containment and lockdown is to effectively remove a large sector of the population from susceptibility ... see my the first post and my earlier replies to questions asked in the discussion. When I have time, I will clean my notebook and post it will all the data (it is not that much).
Today I am also adding a figure that illustrates the effect of lowering sigma to .03 (sigma is the rate at which the exposed becomes infective). It flattens the curve with a delay ... I don't know what measures can bring this down, but that is what is needed.
March 2: I am adding a second updated graph for comparison with the original, and will update that graph on a weekly or biweekly basis. I will now leave the model untouched for a week. In the latest graph, the initial population is 88000, the removal rate is now .3, and the delay is to onset of infection is 10% longer and slightly different. The calculated R0 is now 8. The model now predicts close to 85000 cases by the end of March, and close to 87500 towards the end of April. I have added the E curve in Cyan.
Feb 29: It is the end of February and there is one minor final correction that makes the fit still better (after this I will let this rest for a while). The green dots which are to be matched against the R (resistant) curve is now the sum of recoveries and fatalities. There is a new picture. The susceptible population is now 90000 and all the rest is the same.
If the model has any predictive power, I would expect to see about 84700 registered cases by the end of March, and about 88700 by the end of April. I will return to this towards the end of March, or earlier if this needs to be modified further.
Also, running a similar model without data at the moment for my community, the metropolitan area of Helsinki, if we assume only city and country isolation, we can expect an outbreak that lasts about 9 months if the virus is a year round virus (that is, not a "winter" virus). Likewise, an unchecked outbreak for the whole world would last about 15 months as of now if the virus is year round. About half of the population would be infected at one point.
Feb 28: I am updating this again because I have managed to get a much improved model by accounting for a delay in the onset of recovery as well as a delay in the onset of infection; moreover, I use my parameters uniformly throughout the equations, (some weeks down the road, when the data is "complete" I will publish the final equations of the model; I am hoping that the model as it stands now will stand the test of time). The infection rate is now 2.9, the susceptible population is 95000, the rate at which an exposed person becomes infected is now .057, and the removal rate is .25. Calculating R0 in the usual way, we get around 9, which is believable. I leave yesterday's text below, but I am changing the picture.
Feb 27: I am updating and correcting this post: a simple SEIR model with some modifications (like a delay factor for the onset of recovery) fits the available data of the coronavirus infection in China. The infection rate is 2.7, the removal rate is .1, the rate at which an exposed person becomes infective is .055, and the total susceptible poEnrique Garcia Moreno E.2020-02-26T16:43:12ZCOVID-19 - Policy Simulator - Can you find the perfect policy?
https://community.wolfram.com/groups/-/m/t/1931352
![Pandemic model and one scenario][1]
By now you have all heard that fighting the Corona virus is all about flattening the curve. It sounds easy, doesn't it?
![Flattening the curve][2]
However, despite that the maths behind the scenes is rather simple, flattening the curve turns out to be quite complicated. What happens if you don't do enough? How important is timing? What's the risk of doing too much?
With the help of System Modeler, the Wolfram Language, and my wonderful colleagues (thanks for having patience with me) I have developed a COVID-19 - Policy Simulator. The ambition is not to give any precise numbers, but to make it easier to understand how simple yet at the same time complicated it is to control a pandemic.
While developing the simulator I realized that my intuition was far from correct in many cases. I doubted the results more than once, and was sure there were mistakes in the model, but most of the time it turned out that it was not the model faulting - it was my intuition. Will your intuition be better than mine? Download the soon to be released [HighSchoolBiology Virtual Lab 1.1][3] (I have made a [pre release available here][4]) and use it together with this notebook to test your intuition!
The screenshot below shows a naive attempt to set policies. As seen it leads to a disaster at the end of the year.
![Naive policy][5]
I hope that using this simulator should give you a good idea of how complex it is to find the optimal path through a pandemic, and also to some extent why a recipe that works in one country does not apply to another.
## The simulator ##
*Important: Let me repeat that the simulator is not exact. Many rather rough assumptions are made for several different reasons. Most of these , but not all, are mentioned and discussed in a separate notebook. The development notebook shows how I proceeded to roughly tune the default parameters, so they reflect the state in Sweden in the beginning of April 2020. As countries differ in population density, traditions, political structure, age distribution, healthcare system, and so many other things the impact of different policies will vary substantially between countries. Therefore, I made it possible to vary the impact of the policies I have chosen to use. Is your country already very socially distant? Then, further social distancing will probably not have as big of an effect as in other places, and so on. In most cases the simulator allows you to modify some of the assumptions by your self.*
In this simulator you can enact the following policies:
- Improved hygiene (washing hands, cough in elbow, don't touch your
face, etc)
- Social distancing (keep away from each other, no handshaking, work
from home, etc)
- Isolate the sick (even stricter social distancing when your sick)
- Lockdown (close restaurants, schools, shops)
- Seasonal effect (not really a policy, but something that you might
hope for.., but will it always be beneficial on the long run?)
- Close borders (when borders are closed, they are hermetically closed,
so no infected persons at all enter the region)
Applying policies will typically decrease the exponential growth rate. However, if you have already enacted lockdown, then social distancing will give no further effects. In reality it might actually do that, however to avoid making the simulator overly complicated I have chosen this simplified solution. Other things that I have omitted are e.g. testing, masks, and tracking apps (partially because I have limited data to tune the model with, but mostly to keep the simulator simple).
![COVID-19 Policy Simulator][6]
On the right hand side of the simulator you can change several settings, including
- Infection properties
- Default is set to the currently believed mean values
- Policy effects
- The first five, will reduce the exponential growth
- Close borders, when the borders are not closed the number shows how many persons per 100k susceptible that are infected by travelling abroad each day
- Initial setting
- Change population and current state, e.g. start with no infected
- Vaccination
- Enact a vaccination policy, setting start date and how many percent of the susceptible population that is vaccinated per day
- Healthcare
- Set the number of available beds
- Additional plots
- Default - Adds a plot using the default values, to make it easier to see the effect of your current policies and changed assumptions
- No policies - Adds a plot using your current assumptions, but no policies
- Beds - Show the number of beds
- Susceptible, infected, and recovered - Add any of these three to the plot
- Simulation end time
- By default the plot is zoomed in to 120 days, to see what happens later (or to zoom in at earlier stages), you can change this.
Note again that there are many measures that are not included, but I believe these are the most important in order to understand the dynamics of a pandemic. Furthermore, I am assuming that the effect of an active policy does not change over time. In reality, of course, a lockdown is likely to me more respected in the beginning then after a few months. Finally, I am completely disregarding both short and long term side effects that policies might have, e.g. effects on economy, education, and healthcare.
Note that you can use the menus on the top right of the simulator to
- Hide controls
- Paste snapshot
- Reset to default values
Try to set your best policy, and comment on the strengths and weaknesses you see with it. If you like you can send us an email to virtuallabs@wolfram.com with your strategy or suggestions for improvements. Note, that by including a snapshot in your answer, you make it easier for us to see what you have done.
Example strategies
----------------
Let's just conclude this by showing three strategies:
- Do nothing
- Complete lockdown -waiting for a vaccine
- Compromise
The first one, is shown in the default simulation. It shows that more than 40,000 people will need intensive care at the end of April if we follow this tactic. With a limit of 2,100 beds this is a disaster.
![No policies][7]
Now let us enable improved hygiene,isolation of sick, social distancing, lockdown, and close border for a quarter and see what happens. It looks great to begin with, but as soon as the policies are lifted we have a problem that is almost just as big as in the first case.
![Delayed pain][8]
Finally, let us try to be a bit more clever. Turning the first three policies on and off over time, and then finally turning all off I got something that looks a lot more promising. In this simulation I am turning of the last policy beginning of February 2021. I am assuming that no vaccine will be available during this time and that there are no seasonal effect. Of course turning policies on and off is probably not the easiest thing to achieve in reality, but it is possible, at least as long as full quarantines are not needed.
![A bit more promising][9]
Alternative setups
------------------
As mentioned, the model has been roughly tuned to Swedish circumstances. In doing so I have assumed that Sweden has an R0 value of 2.65, i.e. exactly the mean value. In reality I would believe that we have a lower value (a pure guess would be 2). Changing this assumption will change other values as follows:
![Table][10]
I recommend you to test these scenarios by yourself. Note that on April 7, the estimated range of R0 of COVID-19 went up to 3.8 \[Dash] 8.9 on Wikipedia. How does this affect the model?
Find your best policy, or insight, and let send us an email to virtuallabs@wolfram.com with your strategy or suggestions for improvements.
*I have attached two notebooks to this post. the first is the interactive version of this post and the second contains more details on the model, assumptions, and code. Remember that you will need the [pre release][4]) of the [HighSchoolBiology Virtual Lab 1.1][3] (or wait until it is available)*
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p1.png&userId=149796
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p2.png&userId=149796
[3]: https://www.wolfram.com/system-modeler/libraries/high-school-biology/
[4]: https://download.wolfram.com/?key=FDW6Q5
[5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p3.png&userId=149796
[6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p4.png&userId=149796
[7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p5.png&userId=149796
[8]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p6.png&userId=149796
[9]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p7.png&userId=149796
[10]: https://community.wolfram.com//c/portal/getImageAttachment?filename=p8.png&userId=149796Jan Brugard2020-04-09T15:58:59ZExploring Epidemiological Modeling
https://community.wolfram.com/groups/-/m/t/1920119
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/jhasler/Published/ExploringEpidemiologicalModeling.nbJordan Hasler2020-04-03T20:07:39Z[NB] Computing COVID-19 Spread Rates in US Cities
https://community.wolfram.com/groups/-/m/t/1930261
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/9c47c3a6-f81b-4ae4-8dca-16127c5b5cccDaniel Lichtblau2020-04-09T03:44:37Z3D version of the built-in VoronoiDiagram
https://community.wolfram.com/groups/-/m/t/1561288
**[Open in Cloud][1] | [See Original][2] | Download to Desktop via Attachments Below**
![enter image description here][3]
Here I will show how to create 3D version of VoronoiDiagram in Wolfram Language.
Note that there's currently no way to represent a collection of 3D Voronoi mesh cells in a `MeshRegion` or `BoundaryMeshRegion`.
Here's a routine that takes the dual of the `DelaunayMesh` and returns an `Association` where the keys are the points and the values are their respective Voronoi cells.
pad[?_][{min_, max_}] := {min, max} + ?(max-min){-1, 1}
VoronoiCells[pts_] /; MatrixQ[pts, NumericQ] && 2 <= Last[Dimensions[pts]] <= 3 :=
Block[{bds, dm, conn, adj, lc, pc, cpts, hpts, hns, hp, vcells},
bds = pad[.1] /@ MinMax /@ Transpose[pts];
dm = DelaunayMesh[pts];
conn = dm["ConnectivityMatrix"[0, 1]];
adj = conn . Transpose[conn];
lc = conn["MatrixColumns"];
pc = adj["MatrixColumns"];
cpts = MeshCoordinates[dm];
vcells = Table[
hpts = PropertyValue[{dm, {1, lc[[i]]}}, MeshCellCentroid];
hns = Transpose[Transpose[cpts[[DeleteCases[pc[[i]], i]]]] - cpts[[i]]];
hp = MapThread[HalfSpace, {hns, hpts}];
BoundaryDiscretizeGraphics[#, PlotRange -> bds]& /@ hp,
{i, MeshCellCount[dm, 0]}
];
AssociationThread[cpts, RegionIntersection @@@ vcells]
]
Example:
SeedRandom[10000];
pts = RandomReal[1, {10, 3}];
vc = VoronoiCells[pts]
[![enter image description here][4]][5]
Show[MapIndexed[
BoundaryMeshRegion[#, MeshCellStyle -> {1 -> {Black, Thick}, 2 -> {ColorData[112][First[#2]]}}] &,
Values[vc]
]]
[![enter image description here][6]][7]
Show[
MapIndexed[
BoundaryMeshRegion[#, MeshCellStyle -> {1 -> Black, 2 -> {Opacity[0.5], ColorData[112][First[#2]]}}] &,
Values[vc]
],
Graphics3D[{PointSize[Large], Point[pts]}],
Method -> {"RelieveDPZFighting" -> True}
]
[![enter image description here][8]][9]
Note that this works in 2D too:
SeedRandom[10000];
pts = RandomReal[1, {10, 2}];
vc = VoronoiCells[pts];
Show[MapIndexed[
BoundaryMeshRegion[#, MeshCellStyle -> {1 -> {Black, Thick}, 2 -> {ColorData[112][First[#2]]}}] &,
Values[vc]
], Epilog -> {PointSize[Large], Point[pts]}]
[![enter image description here][10]][11]
[1]: https://www.wolframcloud.com/objects/wolfram-community/3D-version-of-the-built-in-VoronoiDiagram-by-Chip-Hurst
[2]: https://mathematica.stackexchange.com/questions/18893/how-can-i-define-a-3d-version-of-the-built-in-voronoidiagram-voronoimesh-in-v10
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=chip2.png&userId=20103
[4]: https://i.stack.imgur.com/jAV06.png
[5]: https://i.stack.imgur.com/jAV06.png
[6]: https://i.stack.imgur.com/Mb7jm.png
[7]: https://i.stack.imgur.com/Mb7jm.png
[8]: https://i.stack.imgur.com/fPEE1.png
[9]: https://i.stack.imgur.com/fPEE1.png
[10]: https://i.stack.imgur.com/TVptr.png
[11]: https://i.stack.imgur.com/TVptr.pngChip Hurst2018-11-28T19:03:50ZWhat exactly is "Standard Error" in the Parameter Table of LinearModelFit?
https://community.wolfram.com/groups/-/m/t/1927697
I'm fitting a model to some data, in this case I'm using LinearModelFit but I think it also applies to NonlinearModelFit as well. When I extract the fit parameters from the model, I can extract the Standard Error for each parameter. Is this the "standard deviation" of the parameter? Or is it a true "standard error" (i.e. standard deviation divided by the square root of the population size)? Or is it something else?
I want to propagate this extracted uncertainty through subsequent calculations. Specifically, I will use the Around function (i.e. Around[data,error]) to match up the parameters with their uncertainty. Do I have to perform some operation on the Standard Error I extract from the model before I can use it like this?
Thanks in advance!Ian Smith2020-04-07T13:01:15Z