Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:
I've got a lot of irons in the fire with perl now, but I have one in particular that has been tickling in the back of my head for this pandemic. I've been trying to make an accounting of fomites, and there isn't a lot out there for rigorous data, but I started here. To excerpt:
Both viruses exhibited exponential decay in virus titer across all experimental conditions, as 41 indicated by linear decrease in the log 10 TCID 50 /mL over time (Figure 1B). HCoV-19 and SARS-CoV-1 42 exhibited similar half-lives in aerosols, with median estimates around 1.1-1.2 hours, and 95% credible 43 intervals of 0.64, 2.64 hours for HCoV-19 and 0.78 , 2.43 hours for SARS-CoV-1 (Figure 1C, Table 44 S1).What's more, I live with a party who is immunocompromised, so it's super important that I don't bring this back to her as I use the door hardware, stair railings, and plumbing fixtures. We routinely wipe things down with products having ammonium chloride (Lysol and WinCo brands). One can't wipe down a textile, so I attempted to come up with a "program" for disinfecting and rotating things like masks and gloves. My actionable ideas I've captured with photos and comments on my website.
What I'm counting on is disinfecting using the sun, heat, and moving air, but how would I build a realistic model of how long I need to leave a pair of gloves on my dashboard? My thoughts return to bliako's post from about a year ago here: Re: bracketology was Re^2: making a markovian "mad lib".
If that was a "markovian process" then we could describe it simply by a "transition matrix" which is a convenient way to convey the information of what the probability of "next" state is given "current" state in the form of a 2d array often called a stochastic matrix:In the above array, row represents current state and column the next state, e.g. the probability of rain when now is raining is 0.6, the prob of dry-cloudy when now is sunny is 0.2 etc. The important property of the above matrix is that the probabilities of all the possible events from a current state must sum to 1: all rows sum to 1. Why? If we are now in current state of "rain" we have 3 possible outcomes. And so their probabilities must sum to one because one of them will happen with absolute certainty (as far as our model goes).rain sunny dry-cloudy rain 0.6 0.2 0.2 sunny 0.3 0.5 0.2 dry-cloudy 0.4 0.3 0.3
He continues:
The Graph or matrix can also be constructed by hand from imagination. Feed that information to your simulator in order to run the random process. That's probably how a computer game would calculate the weather in Mars.Okay, then... Q1) How do I perform this simulation with perl with the above simple model?
And then, once we're able to do that with an elementary example, how do we make a stochastic matrix with the breadth of outcomes from NOAA:
$ ./2.icons.pl { "\@context" => [], "icons" => { bkn => { description => "Mostly cloudy" }, blizzard => { description => "Blizzard" }, cold => { description => "Cold" }, dust => { description => "Dust" }, few => { description => "A few clouds" }, fog => { description => "Fog/mist" }, fzra => { description => "Freezing rain" }, haze => { description => "Haze" }, hot => { description => "Hot" }, hurricane => { description => "Hurricane conditions" }, ovc => { description => "Overcast" }, rain => { description => "Rain" }, rain_fzra => { description => "Rain/freezing rain" }, rain_showers => { description => "Rain showers (high cloud cove +r)" }, rain_showers_hi => { description => "Rain showers (low cloud cover +)" }, rain_sleet => { description => "Rain/sleet" }, rain_snow => { description => "Rain/snow" }, sct => { description => "Partly cloudy" }, skc => { description => "Fair/clear" }, sleet => { description => "Sleet" }, smoke => { description => "Smoke" }, snow => { description => "Snow" }, snow_fzra => { description => "Freezing rain/snow" }, snow_sleet => { description => "Rain/sleet" }, tornado => { description => "Tornado" }, tropical_storm => { description => "Tropical storm conditions" }, tsra => { description => "Thunderstorm (high cloud cove +r)" }, tsra_hi => { description => "Thunderstorm (low cloud cover +)" }, tsra_sct => { description => "Thunderstorm (medium cloud co +ver)" }, wind_bkn => { description => "Mostly cloudy and windy" }, wind_few => { description => "A few clouds and windy" }, wind_ovc => { description => "Overcast and windy" }, wind_sct => { description => "Partly cloudy and windy" }, wind_skc => { description => "Fair/clear and windy" }, }, } ======================== Stochastic Matrix with side: hurricane rain_showers_hi few fzra rain_snow bkn snow_fzra snow snow_sleet wind_ovc blizzard cold smoke tropical_storm skc haze wind_few sct rain sleet ovc tsra tornado tsra_sct hot fog wind_bkn rain_fzra dust wind_sct tsra_hi rain_showers rain_sleet wind_skc ======================== URL = https://api.weather.gov/icons/land/day/tsra_sct,20/tsra_sct,40?s +ize=medium tsra_sct => 'Thunderstorm (medium cloud cover)' URL = https://api.weather.gov/icons/land/day/rain_showers,30/tsra_hi,3 +0?size=medium tsra_hi => 'Thunderstorm (low cloud cover)' URL = https://api.weather.gov/icons/land/night/rain_showers,30/rain_sh +owers?size=medium rain_showers => 'Rain showers (high cloud cover)' URL = https://api.weather.gov/icons/land/day/bkn?size=medium bkn => 'Mostly cloudy' $ cat 2.icons.pl #!/usr/bin/perl -w use strict; use LWP::UserAgent; use Data::Dump; use JSON::Parse 'parse_json'; use 5.016; my $ua = LWP::UserAgent->new( 'send_te' => '0' ); my $r = HTTP::Request->new( 'GET' => 'https://api.weather.gov/icons', [ 'Cache-Control' => 'max-age=0', 'Connection' => 'keep-alive', 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*; +q=0.8', 'Accept-Encoding' => 'gzip, x-gzip, deflate, x-bzip2, bzip2', 'Accept-Language' => 'en-US,en;q=0.5', 'Host' => 'api.weather.gov:443', 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firef +ox/74.0', 'Upgrade-Insecure-Requests' => '1', ], ); my $out; my $res = $ua->request( $r, ); if ( $res->is_success ) { my $json = $res->decoded_content; $out = parse_json $json; } else { print "Error: " . $res->status_line . "\n"; } dd $out; my %xlated_abbrev; #simple abbreviation table => description foreach my $key ( keys %{ $out->{icons} } ) #gen simple xlate table { $xlated_abbrev{$key} = $out->{icons}{$key}{description}; } my @keys2 = keys %xlated_abbrev; say "========================"; say "Stochastic Matrix with side: "; for (@keys2){ say "$_"; }; say "========================"; my @urls = ( 'https://api.weather.gov/icons/land/day/tsra_sct,20/tsra_sct,40?size +=medium', 'https://api.weather.gov/icons/land/day/rain_showers,30/tsra_hi,30?s +ize=medium', 'https://api.weather.gov/icons/land/night/rain_showers,30/rain_showe +rs?size=medium', 'https://api.weather.gov/icons/land/day/bkn?size=medium' ); foreach my $url (@urls) { my $last_path = ( split( '/', $url ) )[-1]; my ($abbrev_to_xlate) = $last_path =~ /^(\w+)/; print "URL = $url\n"; print " $abbrev_to_xlate => \'$xlated_abbrev{$abbrev_to_xlate}\'\n +\n"; } __END__ Created from curl command line curl 'https://api.weather.gov/icons' -H 'User-Agent: Mozilla/5.0 (X11; + Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0' -H 'Acce +pt: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp, +*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Conn +ection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'Cache-Contr +ol: max-age=0' $
Thanks all for comments and know that not all Americans are as insouciant, impatient, and selfish in this crisis as our loud right-wing minority.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using a stochastic matrix to simulate weather conditions
by bliako (Abbot) on Apr 23, 2020 at 20:44 UTC | |
by Aldebaran (Curate) on May 01, 2020 at 22:57 UTC | |
by hippo (Archbishop) on May 02, 2020 at 08:11 UTC | |
|
Re: using a stochastic matrix to simulate weather conditions
by bliako (Abbot) on Apr 23, 2020 at 22:22 UTC | |
|
Re: using a stochastic matrix to simulate weather conditions
by rizzo (Curate) on Apr 23, 2020 at 22:19 UTC |