Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Tuesday, December 24, 2024

Spirobrowlf: A Free Gift for You!






Tuesday, October 6, 2020

The Superspreader

LabKitty Mad Scientist logo
As a result of recent events, the internet is simply full-to-bursting with words like "karma" and phrases like "everything Trump touches dies." But to be honest, it's impossible to get any kind of an accurate read on the situation.

We're told the president tested positive for COVID, as did his fluffer Hope Hicks, truth scarecrow Kellyanne Conway, administration eye candy Kayleigh McEnany, Senators Mike Lee, Thom Tillis, and Ron Johnson, RNC person Ronna McDaniel, professional hanger-on Chris Christie, three WH reporters, and a WH staffer. Also the president of Notre Dame, this significant as he introduced the guest of honor at Mitch McConnell's SCOTUS coming out party for jurist and Octomom wannabe Amy Coney Barrett.

Which sounds kinda bad, but who can say. It's possible all of these people have tested positive, or some of them have, or none of them have. Because nothing claimed by this administration can be trusted. Nothing. Trump has been nothing but a perjury firehose since the day he took office. Even Charlie Brown would have stopped kicking at this particular football by now. As far as we know, every single elected Republican is dead and the country is being run by Bill Barr in a Trump mask. Or perhaps they all spent a week lounging 'round the pool at Mar-a-Lago sipping Mai Tais from an infant's skull and having a larf. Either scenario is equally likely. This is what four years of chaos has wrought.

But a tale need not be true in order for it to be a cautionary tale. There is an epidemiology lesson hiding in this story, and that lesson is titled The Superspreader.

Sunday, August 23, 2020

Exploring Herd Immunity

LabKitty Mad Scientist logo
Herd immunity is in the news these days, and, no, it has nothing to do with Devin Nunes. (Because cow. And cows come in herds. And Devin Nunes (R-CA) keeps suing a talking cow on Twitter. Because Congress doesn't have more pressing problems at the moment. Just a little joke to help soften the pain of watching the Republic die. But I digress.)

The idea is straightforward. To halt an epidemic, you don't need everyone immune, just enough people to break the chain of transmission. COVID isn't immortal. Think of infection as starting a clock. The virus has a finite window of opportunity to infect another host before its current host becomes inhospitable, either because the host's immune system has come on-line or the host has died. If it doesn't jump to a new host by the time the clock runs out, it goes down with the ship.

It's like The Hidden, except without Ferraris and strippers.

Now for the bad news.

Sunday, August 2, 2020

iCOVID: Individual Based Epidemic Modeling

LabKitty Mad Scientist logo
Previously on LabKitty, we attempted COVID simulation in the large, using what a professional epidemiologist would call mass action modeling. There it was assumed the variability and vagaries of individual actors can be glossed over, condensing all behavior into a mythical average behavior that is captured by a few numbers. In the SIR mass action model, the few numbers are the number of susceptible, infected, and recovered in the population plus the transmission and recovery parameters.

However, an alternate approach exists in which we literally follow each individual individually, a bottom-up attack that constructs the evolution of an epidemic as the sum of its parts. This goes by the name individual-based modeling. We generate a history for each individual in the population, then assemble the population response by mashing together everybody's story.

Which brings us, once again, to COVID.

Thursday, July 2, 2020

Politics and Exponential Growth

LabKitty Mad Scientist logo
The greatest shortcoming of the human race is our inability to understand the exponential function. This was Al Bartlett's mantra. His catchphrase. The alpha and omega of the lectures he gave on overpopulation before his death in 2013.

Bartlett was a physics professor. He understood natural phenomena often outstrip our brain's gronkulatory machinery. The very small (quantum mechanics). The very fast (relativity). But also exponential growth. So he spent his emeritus years educating the public. Breaking it down for the layperson. You may know some of his examples. Wheat and chessboards. The bacteria bottle. Doubling rates. If you don't, you should (Bartlett's lectures are available on YouTube).

The crux of our misunderstanding is the power of the exponential. If a process grows exponentially and its constraint does not, exponential growth will win every time. What kind of process? Human population growth, yes. But also the adoption of technology. The spread of rumors. Compound interest. Nuclear reactions. The transmission of disease. Tolian Soren notwithstanding, exponential growth is the fire in which we burn.

Which brings us to COVID.

Monday, June 29, 2020

The Consequences of an Asymptomatic Infectious Period on COVID-19 Spatiotemporal Dynamics

LabKitty Mad Scientist logo
Many years ago, a Dan O'Bannon script rumored to be in consideration for Alien^3 circulated on the Interwebs. O'Bannon's tale had teh Alien arriving on Earth in a form of a virus, one that converts the host directly sans a facehugger instar. In what was sure to have become an infamous scene, a Weyland-Yutani bean counter is PowerPointing to a crowded boardroom, coughs once or twice, then a fully-formed adult Alien bursts from his shuffled mortal coil as it splats to the carpet in a bloody heap.

Until that moment, the bean counter had no idea something was amiss. It's a strategem designed to achieve the viral gold standard of success: transmission. That is what a virus lives for (or doesn't live for, as it were).

Perfect organism, Ash called it.

Which brings us to COVID-19.

Friday, March 20, 2020

The Circus has Arrived

LabKitty Mad Scientist logo
Now that the Trump administration's spectacular incompetence* is literally getting people killed, one naturally wonders what calamity tomorrow will bring. Poetic justice would be if Trump himself and his ring of enablers were culled by COVID-19, but I'm not holding my breath (I mean I am, but that's only because you're standing too close). If you think any comeuppance whatsoever will ever inconvenience these guys, you are practicing for your coma. As Jessie observed of Walter White, Donald Trump is the devil.

Which brings us to sequesterfying.

In Part I LINK of LabKitty's Plague Song Trilogy, we examined the spatiotemporal properties of infectious disease to model the global spread of COVID-19, from its humble beginnings in a Pangolin's alveoli to a pervasive plague rivaling the Black Death, rap, or Facebook. In Part II, we examined the rationale of the response, which the Internetigensia has taken to calling "flattening the curve." Now here in Part III we examine the mechanics of that response.

Call it what you will -- sheltering in place, avoiding public spaces, social distancing, that thing we nerds have been doing since Gymboree -- paramount is one question: Will it work?

You're not going to like the answer.

Sunday, March 15, 2020

Flattening the Curve

LabKitty Mad Scientist logo
Now that amateur epidemiology is all the rage, what with the White House's official COVID-19 response consisting of whatever Jerry Kushner can find on Facebook (not kidding), it falls to the Interwebs to help us make sense of the world. It seems like only yesterday all was snips and snails and puppy dog tails, and today we're chained to the front of Furiosa's minivan. Except instead of a heavy metal guitar player shooting fire, the soundtrack is just an endless loop of Yakety Sax. If you don't understand God sent this as punishment for electing Donald Trump, you're not paying attention.

On a related note, I hate it when I'm right.

Which brings us to "flattening the curve." The pandemic lingo de jure, which to the uninitiated means not much. Who curve? Where flat? What it do, and when it be?

Well LabKitty is here to help. Since we can't go to the pub anymore, or the liquor store, or the pub, there's more time for illustrative Javascript. Let's dive into a little epidemiology modeling and decipher why medicos don't want us going to the pub anymore. Or the liquor store. Or anywhere, really. As it happens, the idea is almost a century old, emerging from the seminal work of Scottish biochemist Anderson Kermack and Scottish physician William McKendrick, published in 1927.

Read on.

Tuesday, March 3, 2020

LabKitty Pandemic Simulator

LabKitty Mad Scientist logo
Recent events have rekindled my long-standing interest in epidemiology, as yet another emergent virus currently does a slow burn across the globe. COVID-19 arrives against a backdrop of influenza currently doing a slow burn across the globe, not to mention reduced herd immunity, declining antibiotic efficacy, and an incoherent public health response. Experts call this "instability in the disease dynamical manifold" but what they really mean is "asking for it."

We may never know how coronavirus came to be, although packing eleventy billion humans into an ecosystem seems to my way of thinking relevant. In any event, it didn't take long for politicians to exploit the situation. Republicans declared the virus was clearly designed in a Chinese weapons laboratory, because China has coronavirus and weapons laboratories. Yes, the logic is as airtight as the rationale. Are there votes to be had by gloating over dead Chinese? Apparently so in the red states of our waning republic.

Which got me thinking about designing a virus. Suppose you wanted to create a pandemic. How would you go about it? What would be the ideal virus? What parameters would you select? Where would you release the thing? How long would it take? What could anyone do to stop it?

There are CDC scientists studying such questions on supercomputers as we speak. One hopes. For the rest of us -- and perhaps for the CDC too, what with their recent budget cuts (thank you Donald Trump) -- there is Javascript.

I give you: jPandemic.

Sunday, October 13, 2019

Generating Normal Random Variables in Javascript

LabKitty Javascript Logo
One occasionally needs a normal random variable whilst doing the Javascript, and whilst there's a Math function for uniform rv (Math.random(), to wit), the WWW or the Freemasons or somebody didn't provide a function for Gaussian rv (fer cat's sake, dudes: Math.randomn(). How hard would that have been?).

Anyhoo, I'm sure there's something in math.js for this, if you're not into the whole brevity thing. OTOP, you could cut and paste about 10 lines of code into your app to do the deed.

Where can one find such magical lines of code?

It's funny you asked.

Sunday, April 14, 2019

Animation in JavaScript

LabKitty Javascript Logo
You gotta move, Gino Vannelli exhorted. Who better to decide the issue (the only white boy to headline on Soul Train -- true fact!). So should you want to be spicing up your website blog, working some animation into the content is a good place to start.

The concept hasn't changed since Steamboat Willy: repeatedly draw a series of images quickly. JavaScript has tools to help. Its Canvas object provides methods for drawing which, let's be honest, aren't great but let you do interesting things with enough imagination and effort. The "repeatedly" part comes from either (the older) setInterval or (the newer) requestAnimationFrame. We're told the latter is the better option, producing smoother animation by cooperating with the browser refresh internals as well as halting animation if a window is hidden, which saves battery and earns points for style.

There's lots of example JavaScript animation code out there. Alas, the examples I find make my fur puffy. Invariably, the authors are so absorbed in their minimal footprint and anonymous functions and strict adherence to a DOM workflow and CSS reusability they make the thing look more complicated than it is.

What you need is simple example code. Rudimentary example code. Code with no pride or shame.

That's exactly the kind of JavaScript I write.

Thursday, August 23, 2018

Eigenpotato

LabKitty Javascript Logo
Synopsis: Titled to be maximally search engine hostile, today's post is a whimsical look at computing eigenvalues, and computing eigenvalues in Javascript, and gives you the code for free. Eigenvalues!

LabKitty loves eigenvalues. That's fairly well established in both the Internet and squishy realms. Odd, then, that I suck at computing eigenvalues. Sure, I can work a 2x2 like Sunday morning, but beyond that I am hopeless. Finding roots of a polynomial (read: characteristic equation) is my bête noire. Quintics are of course right out. I'm told there exist formulas for quartics and cubics, but my brain has rejected that proposal like a failed organ transplant. Évariste Galois died for my sins.

Thus I turn to gronkulation, only to immediately confront a different breed of horror. My off-the-shelf computing skills are able to extract precisely one eigenvalue, and it better be real and dominant and algebraic multiplicity one. Yes, the famous Rayleigh algorithm (whom I am always confusing with the guy in the can. Prince Albert. That's a different guy, correct?). Literally beating a dead horse until it coughs up the goodies, and I cannot lie: It has a kind of appeal.

All this rather takes the fun out of eigenvalues. Bored at the party, waiting at the checkout, working double time in the seduction line, thoughts turn to eigenthoughts. But confined to a 2x2 prison I am, which come to think of it describes my experience with off-campus housing. Yes, I could model stage-structured growth or that quantum system, attractive stranger, if you would permit me to return to my office and release the Kracken ("Kracken" === R2016b running on a Darwin multicore). But if you are expecting results here and now, you, my friend, are living a lie.

Which brings us to Press.

Tuesday, September 6, 2016

JSpinArt -- A Free Gift for You!

There are many things in the standard childhood canon LabKitty did not experience as a child. I didn't have a dog. I didn't join the scouts. I didn't participate in pee wee this or little league that. (My family once went to watch a baseball contest and it got rained out. The incident permanently soured us on sport.)

My father in particular didn't seem to understand childhood. While other dads took their kids fishing or to the demolition derby, mine took me to lectures on reconstructive surgery. On weekends we would cruise garage sales for old math books and discarded lab equipment bought for pennies on the dollar (as a teen, I had one of the most impressive collections of scientific glassware in the Circle Pines metro area). Dad also taught me to shoot, which in retrospect is a right puzzle. It's as if I was being groomed for a curious kind of zombie apocalypse demanding equal aptitude for executing unerring headshots and executing Laplace transforms in the quiet moments between attacks.

One Christmas I got a fetal pig.

Saturday, August 27, 2016

Poison Math Frogs of the Amazon

Good morrow cousin! Perhaps you're feeling good about yourself this fine day. Well that will be just about enough of that. For I have an equation for you to solve:

    y = x − sin(x)

No, I don't give you x and ask for y -- that would be too easy. You do the other thing.

Suppose y = 1. Solve for x.

Friday, May 13, 2016

JOrrery -- A Free Gift for You!

So, I had this thought the other day: I wonder what the solar system looks like right now?

I don't mean what it looks like in the night sky; I mean the view from afar. The big picture. What the Vogon invasion fleet would be seeing as they crossed the heliopause or the tropopause or whatever the pause is called. I don't really grok all the hip astrolingo, which is why it took me all weekend to stumble across what I was looking for in Google: An orrery.

An orrery is a model of the solar system (not to be confused with ephemeris, which describes how to find stuff using a telescope, presumably from Earth but I guess it could be from Mars if you're Matt Damon). In old timey days, this was a mechanical model -- gears and levers and wind-up springs and whatnot. Museum quality specimens still exist and are quite something to behold. Modern efforts have largely turned to software, albeit the commitment to detail no less committed. Examples one finds on the web include a great deal of detail indeed. Planets and moons, oort clouds and eccentricities, accurate masses and orbital radii, implemented at many sites using exotic HTML my browser refuses to parse.

Fun fact: The orrery is named after the fourth Earl of Orrery, for whom the first orrery was constructed. See? We're learning already!

Monday, April 25, 2016

Chess Potato -- A Free Gift for You!

In the cinema tonight, they sit and watch the robots fight. The human beings don't have much to say. -- Joe Jackson

Chess is one of those things nerds are supposed to be good at, like long division and the violin and quoting Monty Python movies. I am only good at one of those things, although I am able to play Wild Thing on the guitar and could once list the firing order of a 351 Cleveland off the top of my head. I suppose that's what comes from misspending one's youth in beer and dating.

Still, we forever seek the approval of our peers, so I have spent many an hour getting humiliated by various and sundry chess programs. This went as far back as the Atari 2600, which if I recall correctly didn't so much win as it did throw up a "thinking" screen until you either lost interest or pulled the plug. Checkmate, squishy biped. These days there's MINIMAX and tree pruning and conjugate gradient with simulated annealing, but I think advances in chess games mostly come down to hardware with a MFLOP redline some radians beyond what a Z80 could offer. As they say, a large enough quantitative change becomes a qualitative change.

What does any of this have to do with Javascript? Read on.

Friday, April 1, 2016

JCortex -- A Free Gift for You!

Einstein once famously lamented: Now that the mathematicians have got hold of my theory, I myself no longer understand it. This seems to have been a genuine sentiment and not just the usual big-shot faux humility (Feynman, for example, was also famous for eschewing obfuscation, apparently forgetting his Nobel was based on infinite dimensional path integrals in Banach space). Indeed, I once read Albert's slender Relativity on spring break, the Boca motel hotties giving me odd looks and a cold shoulder as usual. I suppose the mathematician's analog would be Wheeler's 200 pound Gravitation, which is a mess of Christoffel symbols and diffeomorphism. Not really the sort of thing you flip through at poolside. Der Herr Gott doesn't play dice, and He ain't exactly keen on covariant derivatives either.

Those of us in the neurogonical arts take a bemused view of these intellectual cat fights. For when the life of the mind is shot though the harsh lens of bastard neuroscience, the whole business reduces to pattern generation. Inside your noggin there are no differential equations. No integrals, no derivatives. No Banach spaces or Sigma algebras. There is only an ongoing pattern of neural firing, a pattern tempered by arriving stimuli. Pop, pop. The quadratic equation is a pattern. E = mc^2 is a pattern. Quantum electrodynamics is a pattern. Witnessing an apple falling from a tree is a pattern. Positing the same force holds the moon in place as the apple is also a pattern, one generated in Newton's noggin but not in others (apparently this made Newton "smart" and others not-so). The version of Relativity Albert understood as well as the one he did not? Different patterns. I think you see the pattern.

What does any of this have to do with Javascript? Read on.

Saturday, December 26, 2015

Zombie Apocalypse Individual Life Outcome Simulator (ZAILOS)

Zombie apocalypse is popular end times entertainment fare. I have a theory as to why this is. Everyone imagines themselves the hero or heroine, steadfast rugged individual quick of draw and dead of eye, mowing down the zombie hordes and roving bandits alike with unerring headshots.

Nobody considers the alternative, that you're going to be shambling the wasteland vacant and stinky, and probably sooner rather than later.

Monday, December 14, 2015

Let's play a game. (SHH! DON'T TELL ANYBODY IT'S MATH!!!)

In the opening of Star Trek IV, a freshly-minted Spock is training with the Vulcan equivalent of Trivial Pursuit, answering a series of computer-posited questions on philosophy and physics and whatnot, but mostly Star Trek physics like how to rearrange a dilithium crystal so that antiprotons can pass and antineutrons cannot. This made a deep impression on the young LabKitty, I think because I had no idea what those were and Gene Roddenberry probably didn't either.

These days Star Trek doesn't have physics, it just has lens flares and explosions. Hollywood doesn't dare remind the viewer there's things out there they don't understand but might with a little effort. Like Spock returning from the grave with his fancy lernin' gizmo substituting for the formal education one might presume necessary, which now that I think about it is the same thing that happened to Uhura after Nomad fried her noggin. Blu-ee? Hilarious!

Friday, October 30, 2015

Flashcards -- A Free Gift for You!

There's lots of downtime in the workday. Sad but true. Whether you're waiting for the next customer to savage you at the call center or waiting for the results of the biopsy to come back before stitching up the patient, a tragic fact of this broken modern world is lots of waiting around doing nothing. All the while, the sands of your little life drain away one grain at a time, leaving you no better at the end of the day save crawling a little closer to the finish line we call death.