Wednesday
Jul182018

The Black and White Illustrated me

 

 

And the mathematica notebook jumble (so idea mess, sorry: but this post is in good part for me, so I remember how I did this nifty thing in a few years)



 

Friday
Jul132018

Rayon Makes Rust Worthwhile

Rust 1.27 the programming language, I think I like, well,  I like it mostly I guess.  Ownership, borrowing, bracebracket parenthesis <> syntax that chaffes against other computer language conventions.  Getting a for-loop to step is like pulling teeth.  Variable type conversion is formal enough to call it not exactly automatic.  Data abstraction and data structure options are lovely, as best I can tell, so long as you don't yearn for a concurrently accessed, circular dynamically linked lists without begining or end... like "ten million cpu workers weeding god-only-knowns how much ringworld data fields in forever forward marching cycles" - well if that's your thing, Rust might trigger intense emotional responses from time to time.

Cargo, the package manager is well done, and so use it well because of built in feature/function minimalism.  Rust seems lean in file build size.  Compile time optimizations are off by default leading first time users to think rust runs slow. Scope, borrowing and ownership rules are first time user mischief makers - don't worry, soon enough they will be your best friends.  Vector implementations are richly typed*- HA that's a joke, as in you'll do lots of typing- on the keyboard.  Get it?    Maybe that's more confusing than funny,  but I like to think its funny because its true: Let ha_ha : Vec<usize> = Vec::new();  ha_ha.push(1);  ha_ha.push(2);   

But despite no small amount of quirk and sass, Rust feels like the future of computer programming to me.

Why? That rust aims for a systems programming mission trifectia of safe speedy concurrency by almost banning garbage collection, race conditions, segfaults, memory leaks, sloppy variable type conversion and buffer overruns helps.   But those same things also make rust feel like the programming equivalent of wearing stilts - great strides are easy but there are downsides.  So what makes rust loveable?    

In part, the aforementioned loveable mischief makers, powerful strides made following two rules that keep you safe and still the ability to ditch the rules, pretty good compiler feedback, and at least one amazing multi-thread processing crate.        

RAYON!  Rayon is a external crate for rust and is sweet way to multithread.  The only way I could be more impressed would be if it supported both GPUs and CPUs.  Consider the following toy prime finding program (coded by me except for the square root function supplied by users.rust-lang.org/t/integer-square-root-algorithm/13529/13 user Leonardo and displayed beautifully in InteliJ J IDEA with integerated developer enviroment code tweaks with the text tucked under the image:

 


extern crate rayon; use std::time::Instant; use rayon::prelude::*; fn isqrt(num: u32) -> u32 { let r= (num as f64).sqrt() as u32; //float point precision vs integer discrete if r<4096 {return r} // compute root of num and return, large root may have error delta (num/r + r)/2 // so divide num by delta root for anti-delta root, average result & return } } fn prime_b(testprime:u32, primelist:&Vec) -> bool { let limit = isqrt(testprime); //run ordered low to high, no reason to check above square root let mut prime:bool = false; //default assumption is not a prime 'calculation: for i in primelist{ if *i > limit { prime=true; //if i is larger than test limit num must be prime break 'calculation;} //example 7: 7%2 !=0, 7%3 else { if testprime % *i == 0 { //if remainder is 0, testprime is not a prime, break 'calculation; } // break calculation loop } } return prime } fn main() { let mut known_primes:Vec = Vec::new(); known_primes.extend([2,3,5,7,11].iter()); let start_timer= Instant::now(); for _building_knowledge in 1..4 { //knowledge loop splits finding primes and adding them to list of known primes let mut start_at :u32= 1+ &known_primes[&known_primes.len() - 1] ; //start after last prime found let mut block_end :u32= &start_at * &start_at - 1; //for odd prime n, n^2 not prime, n^2 -1 %2 is even ∴ not prime let found_primes:Vec = (start_at..block_end) .into_par_iter() .filter_map(|x| { if prime_b(x,&known_primes) {Some(x)} else {None } } ) .collect(); }//End of building knowledge scope, now found_primes are available for use println!("Multithread {:?}",start_timer.elapsed() ); println!("found {} primes up to a value of {}",known_primes.len(),known_primes[&known_primes.len()-1]); // print!("{{"); for value in known_primes { print!("{}, ",value) }; print!("0 }}") }

 

on my computer my imperfect "start-finish blocks overlap what was I thinking that's not ideal code" finds 9,147,542 primes, up to a prime value of 162,894,161 in just a titch over 6 seconds.  Not bad for a 6 core computer built in 2013.  That's damn fast really. Running the same task on a single cpu takes 46.4 seconds, so rayon provides a 6.8x speedup on 6 cores!

Rayon is super fast, and (range_start..range_stop).into_par_iter().filter_map.(|var| {if function(var) {Some(otherfunction(var))} else {None}  }  ).collect() is a sweet sweet thing.  If you are not a programmer, a for loop is like a fireing squad bringing out one prisoner at a time vs. rust's  firing squad taking down seven in one go.   Rayon is polite too, my machine doesn't act like the cpu's are pegged 100% when the cpu's are actually pegged 100%... rayon respects other cpu tasks and is good at snatching free cycles.  Maybe "no memory garbage collection" plus apple's Mojave grand central dispach keeps the mouse and os acting buttery smooth.   **magical bonus points: the nine million results all seem to be in the right order, I wasn't expecting to be able to avoid a sort after multithreading a prime number search.  Rayon is beautiful for data parallelism and multi - threads.  

Rayon is winning me over to the rust side.  Its all about those great strides.

*a note for beginners like me about types, not keyboard typing:  Type systems just keep the 1's and 0's in computers organized. 0010000 could be a number 64, a "execute return from interupt" command, the letter 'a', or part of something bigger like a memory address or long variable that contains the entire digital contents of the library of congress.  There are more than one way to be organized and tidy, and many computer languages exist solely because someone wanted to find the worst way possible to solve this common but vexing computer problem.

** a differences test shows them to increase in order.   A pipe into mathematica confirms primality and set size.

Wednesday
Jun132018

Deficit of the Dead in Puerto Rico 

Today CNN reports that Puerto Rico released ~24000 post huricane death records to two news outlets out of concern that hurricane related deaths are being under reported.  So I'm confused, and don't have access to the dataset.

There is something odd obout that number, let me explain.  Its been by my accounting 265 days post Maria, and there are 365.2422 days in a year, and Puerto Rico has a population of approximately 3,742,016 people with a life expectancy of 79.57 years.  If Maria never happened there should of been about 34,121 deaths (265 days /365.2422 days/year * 3742016 lives /79.57 years per life = 34121 anticipated deaths).  

 Are they reporting unexpected deaths alone and not all deaths?  And how good is the reporting?  The CDC asks "But for the disaster, would the person have died when they did?"   Certainly 10,000 lives were not saved by Maria's!  

 The Congressional Task Force on Economic Growth in Puerto Rico estimated half a million people left, even so that would leave a natural expectation of 29,561 deaths.   This number would seem to be low as hitting ballpark 24000 deaths require 1,109,960 people (or more) to leave Puerto Rico.  Almost one in three.

That's staggering and heart breaking!  I can't use this circular model to get to the true causalty of Maria.   All I can state is roughly, island population departure rate + unreported death rate are approximately equal to 29.7%.    If the the island departure rate was about 13% (per the CTFEGPR estimate), then about 17% of natural deaths, perhaps four thousand in 266 days, were not officially recorded by Puerto Rico or took place outside Puerto Rico.  

The disaster has "fog of war" in the data.  Doubtless, survival is more important than perfect record keeping.   

Sunday
Jun102018

RIP Net Neutrality

Tomorrow marks the birth of a new US internet, perhaps a better one.  Certainly it will be better if better means more ways for a pipe to charge users and producers alike.

Think of it, what sheer delights could a Disney flavored internet hold.  Oh.. wait, scratch that... Disney is a content provider.  

What sheer delights could a Time Warner Cable company flavored internet bring, perhaps "Individual access charges by website?"  Who knows perhaps a Comcast flavored internet tastes like "Everything is framed with our Banner Ads all the time?"   Maybe Cablevision and Verizon will offer unique "man in the middle" flavored internets, while ATT sticks with its tried and true flavor, "Big Brother is Watching You."  And could not Cox Communications offer a "Premium Adult Rock Hard Cox" internet flavor?

One thing is for certain, these companies are suddenly worth a lot more to companies that are flush with cash than they use to be.  Why rebuy your own corporate stock when you could be rebuying access to your customers and limiting your competitions access to theirs?  

I expect a rally in this "shouldn't be worth much but now is" sector.

Let the new internet free for all begin, greed has made it so.

----------

New note: September 21, 2018.   The net still seem much the same- "One China" might well be the first of the flavored internets. 

Thursday
May312018

ABC Fires Roseanne After She Defames Two Large Advertisers

Apparently Roseanne enjoyed exercising her rights to free speech on Monday, Memorial Day and continued Tuesday with a peppering of tweets defaming Valerie Jarrett, Chelsea Clinton and George Soros.  Soros, a billionare that in the past has owned large holdings of Disney, has a multimillion dollar advertising buget across several networks.   

Disney ABC executives Channing Dungey (ABC Entertainment President), Ben Sherwood (President Television Group) and Bob Iger (Disney CEO) apparently reached out to Roseanne that morning.  Roseanne responded on twitter that she was "Leaving Twitter" and moreover blamed her seemingly impared judgement on a product manufacuted by YET another active ABC advertiser, Sanofi's Ambien hypnotic sleep aid.   Ambien spends nearly $207 million in ad placements per year.

Sanofi promply replied via twitter to Barr's tweet.

Roseanne, the TV show, had estimated ad revenue of $45 million set against costs of approximately 26 million dollars for 9 hours of television.   

Roseanne Barr was fired around 11am, and without her, Roseanne the TV show was cancelled.  Some news outlets have suggested the firing was motivated by a sense of social justice and not the blind cognition of corporate America.  I'm not 100% certain.

Page 1 ... 4 5 6 7 8 ... 28 Next 5 Entries »