Ordo Ab Chao – Or Embrace Uncertainty

Masonic Motto: Ordo Ab Chao
Eternal Golden Braid

Only he who undertakes dizzying ventures is authentically human. A single chain of peaks links Prometheus with Siegfried.

~ Jean Mabire

Hello all first as always i hope everyone is safe. Second, i have not been able to write as much as i would have liked, life happens. More on that in later blogs this year.

Now to the current installment. i do not write about specific work topics at all however i am making an exception here as it pertains to the title of the blog. W.R.T. (with respect to) the title this is not some FreeMason diatribe so you can take off the tinfoil hats and stick with me, please dear reader.

If you saw this news Fransisco Partners of San Francisco, California purchased IBM, Watson Health of which i am currently the Global CTO and Chief Architect. Personally, i am extremely excited about this situation as it appears others were as well considering the number of inbound texts, emails, calls that i received. i truly appreciated all of the correspondence. It is an amazing opportunity with an amazing firm that understands the health technology industry with many well-placed investments.

Why does this pertain to the blog subject line? Change causes randomization, randomization can cause chaos. All of it yields Uncertainty. It also is an indicator of Entropy. I wrote a blog some time ago on Randomness.

One of my favorite equations and possible my favorite equation is one Entropy:

This is the original one based on Bolztman’s derivation:

$$S = k_\mathrm{B} \ln W$$

However, me being an information science type person i prefer the entropy of a channel made famous by one of my heroes Claude Shannon:

$$E = -1/N*\sum_{i}^{N}(p_{i})log(p_{i})$$

(Note: As 𝑁→∞ this gives an entropy which is solely related to the distribution shape and does not depend on 𝑁.)

Entropy (/ˈentrəpē/) is a measure of a thermodynamic quantity representing the unavailability of a system’s thermal energy for conversion into mechanical work, often interpreted as the degree of disorder or randomness in the system or lack of order or predictability; gradual decline into disorder ergo our current subject of this blog.

Many people want to think or be told that it will be A-OK. Or OK. Being a word nerd I looked up the etymology of both A-OK and OK. Here is what i found:

The expression A-Okay:

Means everything is fine. A-Okay is a space-age expression. It was used in 1961 during the flight of astronaut Alan Shepard. He was the first American to be launched into space. His flight ended when his spacecraft landed in the ocean, as planned. Shepard reported: “Everything is A-Okay.”

However, some experts say the expression did not begin with the space age. One story says it was first used during the early days of the telephone to tell an operator that a message had been received.

Then there is OK (Okay):

The gesture was popularized in the United States in 1840 as a symbol to support then Presidential candidate Martin Van Buren. This was because Van Buren’s nickname, Old Kinderhook, derived from his hometown of Kinderhook, NY, had the initials O. K. i had no idea.

There are also fun ways to say okay. Some people say okey-dokey or okey-doke. Now with text, we have kk in some cases. i have even heard people say I’m doing “hunky dory”. This American-coined adjective has been around since the 1860s, from the now-obsolete hunkey, “all right,” which stems from the New York slang hunk, “in a safe position,” and the Dutch root honk or “home.” So basically you’re fine at home. (It is also a great album by David Bowie).

So even if you not OK, there are situations where we engage in some physical activity or mental endeavor where most want to know when “the end or finish line is near.” “OMG when is this going to END?!” However, one important factor that i have personally found when the distance is unknown and the end is unknown is when you truly find out who You are on this Earth. Sometimes the process is in the putting. Going way past what you thought possible is where the magic happens.

Uncertainty is the basis for which we live. Technically if you think about it we live next to an exploding star in an ever-expanding universe.

As a comparison here is a chart of Alan Chamberlin of JPL/Caltech. The subject matter is near-earth asteroids. Interestingly enough the objects were not previously known and thus there was no early warning. We knew when we knew. Take your time and let this chart sink into the old wetware.

This list does not include any of the hundreds of objects that collided with Earth, which were not discovered in advance, but were recorded by sensors designed to detect the detonation of nuclear devices. Of the objects so detected, 78 had impact energy greater than that of a 1-kiloton device (equivalent to 1000 tons of TNT), including 11 which had impact energy greater than that of a 10-kiloton device i.e. comparable to the atomic bombs used in the Second World War.

Why am i posting these statistics? Entropy until we know a universe that runs in reverse time or loops time it is ever increasing thus randomness and uncertainty writ large are always increasing.

So what does one do? Well we can only truly deal with what we can control. Anything exterior to that is superfluous in our thought patterns or should be extraneous and superfluous.

I wrote a related blog entitled “What Is It You Want?” which posited a different view. First, you need to decide what you want and if you are unable to decide what you want there is a good chance that what you don’t want is a more known entity.

Envision the worst thing that could happen. Fired from your job? Bankrupt? No. Try Grief. True loss as in the death of a loved one (including animals). Someone that will never ever return. Finality. We have all been there with someone.

In the same psychological realm True Loss can also be the other side of an “Aha!” moment. For instance, let’s say you have been working for months possibly years on something creative or an idea and suddenly in an ephemeral flash of lucidity you finally arrive at the ideation incarnate and grasp the totality of understanding. At that moment on the other side, you can no longer duplicate that feeling. It is gone. True Loss. For some that do not have family or friends, this is equivalent. Even for those that have family, friends and beloved animals, this is equivalent.

Yet we want to think in absolutes that someone somewhere will make it “OK”.

I say unto you: one must still have chaos in oneself to be able to give birth to a dancing star. I say unto you: you still have chaos in yourselves.

Zarathustra

Well as we say here in The South. “It’s OK until It Aint.” The only remedy is preparation but not analysis to paralysis. Train and train well.

The only other remedy is just GO and DO and move and make it happen. Only move in the direction of what YOU desire and want – it will make a huge difference.

The most intelligent humans, like the strongest, find their happiness where others find only disaster: in the labyrinth, in being hard with themselves and others, in effort, their delight is self mastery; in them asceticism becomes second nature, a necessity, an instinct.  They regard a difficult task as a privilege; it is to them a recreation to play with burdens that would crush all others.

R.A.C.

Humans are designed via the evolutionary process to work under stress. i believe we operate better when we are under the gun, under a deadline, reaching for goals, or striving for whatever it is that drives Us. Some prefer the sameness that comes with a 9-5 job. For me personally, i like to obtain order out of chaos.

So whenever you find yourself worried about what May-Be-Happening think instead of what IS-To-Be and make it happen. Alan Watts famously discussed the issue with no surprises in life is you know how everything turns out and if that is the case then that is living in the past.

Until Then,

#iwishyouwater <- Mavericks in Half Moon Bay doing its thing 3.22

@tcjr

Muzak To Blog By: Jeff Buckley’s Album “You and I”. Huge that this was all demos. Astounding talent left us to soon. He took a night swim in the Mississippi River and hit by a paddwheel boat. Random? Entropy? Safe? His autopsy showed no drugs or alchohol in a body.

Snake_Byte[6] Algorithm Complexity

The Lighter Side of Complexity - The Complexity Project
Your software design?

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius and a lot of courage to move in the opposite direction.

E.F. Schumacher

First, i hope everyone is safe.

Second, i had meant this for reading over Thanksgiving but transparently I was having technical difficulties with \LATEX rendering and it appears that both MATHJAX and native LATEX are not working on my site. For those interested i even injected the MATHJAX code into my .php header. Hence i had to rewrite a bunch of stuff alas with no equations. Although for some reason unbenowst to me my table worked.

Third, Hey its time for a Snake_Byte [] !

In this installment, i will be discussing Algorithm Complexity and will be using a Python method that i previously wrote about in Snake_Byte[5]: Range.

So what is algorithm complexity?  Well, you may remember in your mathematics or computer science classes “Big Oh” notation.  For those that don’t know this involves both space and time complexity not to be confused with Space-Time Continuums.  

Let’s hit the LazyWeb and particularly Wikipedia:

“Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. It is a member of a family of notations invented by Paul Bachmann, Edmund Landau, and others collectively called Bachmann–Landau notation or asymptotic notation.”

— Wikipedia’s definition of Big O notation

Hmmm.   Let’s try to parse that a little better shall we?

So you want to figure out how slow or hopefully how fast your code is using fancy algebraic terms and terminology.  So you want to measure the algorithmic behavior as a function of two variables with time complexity and space complexity.  Time is both the throughput as well as how fast from t0-tni1 the algorithm operates.  Then we have space complexity which is literally how much memory (either in memory or persistent memory) the algorithms require as a function of the input.  As an added bonus you can throw around the word asymptotic:

From Dictionary.com

/ (ˌæsɪmˈtɒtɪk) / adjective. of or referring to an asymptote. (of a function, series, formula, etc) approaching a given value or condition, as a variable or an expression containing a variable approaches a limit, usually infinity.

Ergo asymptotic analysis means how the algorithm responds “to” or “with” values that approach ∞.

So “Hey what’s the asymptotic response of the algorithm?”

Hence we need a language that will allow us to say that the computing time, as a function of (n), grows ‘on the order of n3,’ or ‘at most as fast as n3,’ or ‘at least as fast as n *log*n,’ etc.

There are five symbols that are used in the language of comparing the rates of growth of functions they are the following five: ‘o’ (read ‘is little oh of’), O (read ‘is big oh of’), ‘θ’ (read ‘is theta of’), ‘∼’ (read ‘is asymptotically equal to’ or, irreverently, as ‘twiddles’), and Ω (read ‘is omega of’). It is interesting to note there are discrepancies amongst the ranks of computer science and mathematics as to the accuracy and validity of each. We will just keep it simple and say Big-Oh.

So given f(x) and g(x) be two functions of x. Where each of the five symbols above are intended to compare the rapidity of growth of f and g. If we say that f(x) = o(g(x)), then informally we are saying that f grows more slowly than g does when x is very large.

Let’s address the time complexity piece i don’t want to get philosophical on What is Time? So for now and this blog i will make the bounds it just like an arrow t(0) – t(n-1)

That said the analysis of the algorithm is for an order of magnitude not the actual running time. There is a python function called time that we can use to do an exact analysis for the running time.  Remember this is to save you time upfront to gain an understanding of the time complexity before and while you are designing said algorithm.

Most arithmetic operations are constant time; multiplication usually takes longer than addition and subtraction, and division takes even longer, but these run times don’t depend on the magnitude of the operands. Very large integers are an exception; in that case, the run time increases with the number of digits.

So for Indexing operations whether reading or writing elements in a sequence or dictionary are also constant time, regardless of the size of the data structure.

A for loop that traverses a sequence or dictionary is usually linear, as long as all of the operations in the body of the loop are constant time.

The built-in function sum is also linear because it does the same thing, but it tends to be faster because it is a more efficient implementation; in the language of algorithmic analysis, it has a smaller leading coefficient.

If you use the same loop to “add” a list of strings, the run time is quadratic because string concatenation is linear.

The string method join is usually faster because it is linear in the total length of the strings.

So let’s look at an example using the previous aforementioned range built-in function:

So this is much like the linear example above: The lowest complexity is O(1). When we have a loop:


k = 0
for i in range(n):
    for j in range(m):
        print(i)
        k=k+1

In this case for nested loops we multiply the time complexity thus O(n*m). it also works the same for a loop with time complexity (n) we call a function a function with time complexity (m). When calculating complexity we omit the constant regardless if its execution 5 or 100 times.

When you are performing an analysis look for worst-case boundary conditions or examples.

Linear O(n):

for i in range(n):
 if t[i] == 0:
   return 0
return 1

Quadratic O(n**2):

res = 0
for i in range (n):
   for in range (m):
      res += 1
return (res)

There are other types if time complexity like exponential time and factorial time. Exponential Time is O(2**n) and Factorial Time is O(n!).

For space complexity memory has a limit especially if you have ever chased down a heap allocation or trash collection bug. Like we said earlier there is no free lunch you either trade space for time or time for space. Data-driven architectures respond to the input size of the data. Thus the dimensionality of the input space needs to be addressed. If you have a constant number of variables: O(1). If you need to declare an array like using numpy for instance with (n) elements then you have linear space complexity O(n). Remember these are independent of the size of the problem.

For a great book on Algorithm Design and Analysis i highly recommend:

The Algorithm Design Manual by Steven S. Skiena (click it takes you to amazon)

It goes in-depth to growth rates and dominance relations etc `as it relates to graph algorithms, search and sorting as well as cryptographic functions.

There is also a trilogy of sorts called Algorithms Unlocked and Illuminated by Roughgarden and Cormen which are great and less mathematically rigorous if that is not your forte.

Well, i hope this gave you a taste. i had meant this to be a much longer and more in-depth blog however i need to fix this latex issue so i can properly address the matters at hand.

Until then,

#iwishyouwater <- Alexey Molchanov new world freedive record. He is a really awesome human.

Muzak To Blog By: Maddalena (Original Motion Picture Soundtrack) by the Maestro Ennio Morricone – Rest in Power Maestro i have spent many hours listening to your works.

Snake_Byte[5]: Range

Now… We are going in a loop.

~ Ramakrishna, Springs of Indian Wisdom
1K+ Loop Pictures | Download Free Images on Unsplash
Loops All The Way Down

First, i trust everyone is safe.

Second, i’ll will be moving the frequency of Snake_Bytes [] to every other Wednesday. This is to provide higher quality information and also to allow me space and time to write other blogs. i trust dear reader y’all do not mind.

Third, i noticed i was remiss in explaining a function i used in a previous Snake_Byte [ ] that of the Python built-in function called range.

Range is a very useful function for, well, creating iterations on variables and loops.

# lets see how this works:
range(4)
[0,1,2,3]

How easy can that be?

Four items were returned. Now we can create a range or a for loop over that list – very meta huh?

Please note in the above example the list starts off with 0. So what if you want your range function to start with 1 base index instead of 0? You can specify that in the range function:

# Start with 1 for intial index
range (1,4)
[1,2,3]

Note the last number in the index in order to be inclusive for the entire index.

Lets try something a little more advanced with some eye candy:

%matplotlib inline
x_cords = range(-50,50)
y_cords = [x*x for x in x_cords]

plt.plot(x_cords, y_cords)
plt.show()

X^2 Function aka Parabola

We passed a computation into the loop to compute over the indices of range x in this case.

In one of the previous Snake_Bytes[] i utilized a for loop and range which is extremely powerful to iterate over sequences:

for i in range (3):
    print(i,"Pythons")
0 Pythons
1 Pythons 
2 Pythons

For those that really need power when it comes to indexing, sequencing and iteration you can change the list for instance, as we move across it. For example:

L = [1,2,3,4,5,6]
#no add one to each row 
# or L[1] = L[i] +1 used all 
# the time in matrix operations
for i in range(len(L)): 
    L[i] += 1
print (L)
[2,3,4,5,6,7]

Note there is a more “slick” way to do this with list comprehension without changing the original list in place. However, that’s outside the scope if you will of this Snake_Byte[] . Maybe i should do that for the next one?

Well, i hope you have a slight idea of the power of range.

Also, i think this was more “byte-able” and not tl;dr. Let me know!

Until Then,

#iwshyouwater <- another good one here click!

@tctjr

Muzak To Blog By: Roger Eno & Brian Eno – Mixing Colors (this album is spectacular)

What Is It You WANT?

Hey, it’s not your and its not mine

Hey, I’m just here to share your time

Don’t you pay those spinning wheels no mind

~ Tedeschi Trucks Band

First, i trust this finds everyone safe.

Second, as we head into the holiday season i was thoughting about an interview question i always ask people:

“What is it you want?”

i usually get either contorted faces or a blank stare.  No i didn’t ask you to write a Markov chain algorithm to predict the next meme cryptocurrency or describe the differences between NATS or Kafka distributed processing systems or where do you want to be in five years type of questions.

Let me repeat:

“What is it you want?”

i usually have to prompt folks.  

“Ok, like you want a G5 Gulfstream or an island?  How about a puppy?”

“You want to be a writer?  A painter, a musician, or a teacher?”

Invariably when they answer they want to be doing “something else” as the above profession if money were no object, i always respond, “Then why are you interviewing here? Go do what you just said you wanted to do in the first place.”

Unless you think you want a puppy or a plane. However, there is an unending number of ways to be compensated for your passion. You can have your proverbial cake and eat it as well.

This usually gets people pretty animated.  

Then i ask:

‘Which would you rather be?  Famous or Rich?”

Blanks stares.

You see most people truly don’t think about what they deeply truly desire and want in life.

So i am going to be taking the rest of the year in my non-copious free time to thought about and reflect on what i truly want and desire.

The reason i am using thoughting is that most if not all have thought about this very issue with no answers.  

It’s very interesting at least from what i can tell in western civilization we are not taught to think about what we want when most if not all of what drives us is obtaining something.

Then i have a third question:

“Which is worse a lie or greed?”

None of these questions are as difficult as the first.  However the last one i have people who i have hired in the past who have discussed this question with me for decades.

Most people are petrified of success.  What do you do when you get everything you want?

Charlie don’t forget what happeneed to the man who suddenly got everything he always wanted… He lived Happily Ever After!

~ Willy Wonka

You have to reassess what you want – yet again.

Maybe you don’t really know what you want? It appears most folks just want predictability and control. Well if you could have that isn’t that living in the past because you already know what is going to happen? Just a thought as it were. Maybe you don’t like surprises. Then again the wonder of life is the unexpected.

Or maybe they want power. Power over what exactly?

So go give it some thought.  In the meantime here is a great piece by Alan Watts. He even mentions a Klien Bottle which amazingly someone sent me one which i greatly cherish.

As always would love to see some comments on the posts.

Until then,

#iwishyouwater

tctjr

Muzak To Blog By:  Tedeschi Trucks Band 

Snake_Byte[4]: Random and PseudoRandom Numbers

Expose yourself to as much randomness as possible.


~ Ben Casnocha
Visualization of the algorithmic random data
A Visualization Of Randomness

First i trust everyone is safe.

Second it is WEDNESDAY and that must mean a Snake_Byte or you are working in a startup because every day is WEDNESDAY in a startup!

i almost didn’t get this one done because well life happens but i want to remain true to the goals herewith to the best of my ability.

So in today’s Snake_Byte we are going to cover Random and PseudoRandom Numbers.  i really liked this one because it was more in line with scientific computing and numerical optimization.

The random module in Python generates what is called pseudorandom numbers.  It is in the vernacular a pseudorandom number generator (PRNG).  This generation includes different types of distributions for said numbers. 

So what is a pseudorandom number:

“A pseudorandom number generator (PRNG), also known as a deterministic random bit generator, is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers.” ~ Wikipedia

The important aspect here is:  the properties approximate sequences of random numbers.  So this means that it is statistically random even though it was generated by a deterministic response.

While i have used the random module and have even generated various random number algorithms i learned something new in this blog.  The pseudorandom number generator in Python uses an algorithm called the Mersenne Twister algorithm.  The period of said algorithm is length 2**19937-1 for the 32 bit version and there is also a 64-bit version.  The underlying implementation in C is both fast and thread-safe. The Mersenne Twister is one of the most extensively tested random number generators in existence. One issue though is that due to the deterministic nature of the algorithm it is not suitable for cryptographic methods.

Let us delve down into some code into the various random module offerings, shall we?

i like using %system in Jupyter Lab to create an interactive session. First we import random. Lets look at random.random() which returns a uniform distribution and when multiplied by a integer bounds it within that distribution range:

%system
import random
for i in range (5):
    x = random.random() * 100
    print (x)
63.281889167063035
0.13679757425121286
47.697874648329
96.66882808709684
76.63300711554905

Next let us check out random.choice(seq) which returns a random element from the non-empty sequence seq. If seq is empty, raises IndexError:

for z in range (5):
mySurfBoardlist = ["longboard", "shortboard", "boogieboard"]
print(random.choice(mySurfBoardlist))
longboard
boogieboard
boogieboard
longboard
shortboard

Next let us look at random.randrange(startstop[, step]) which returns a randomly selected element from range(start, stop, step). This is equivalent to choice(range(start, stop, step)) but doesn’t actually build a range object.

ParameterDescription
startOptional. An integer specifying at which position to start.
Default 0
stopRequired. An integer specifying at which position to end.
stepOptional. An integer specifying the incrementation.
Default 1
random.ranrange parameters
for i in range (5): 
      print(random.randrange(10, 100,1))
84
21
94
91
87

Now let us move on to some calls that you would use in signal processing, statistics or machine learning. The first one is gauss(). gauss() returns a gaussian distribution using the following mathematics:

\[\Large f(x) = \frac{1}{\sigma\sqrt{2\pi}}\exp\left(-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^{2}\right)\]

Gaussian distribution (also known as normal distribution) is a bell-shaped curve (aka the bell curve), and it is assumed that during any measurement values will follow a normal distribution with an equal number of measurements above and below the mean value.

ParameterDescription
muthe mean
sigmathe standard deviation
returns a random gaussian distribution floating number
gauss() parameters
# import the required libraries 
import random 
import matplotlib.pyplot as plt 
#set the inline magic
%matplotlib inline   
# store the random numbers in a list 
nums = [] 
mu = 100
sigma = 50
    
for i in range(100000): 
    temp = random.gauss(mu, sigma) 
    nums.append(temp) 
        
# plot the distribution 
plt.hist(nums, bins = 500, ec="red") 
plt.show()
Gaussian Distribution in Red

There are several more parameters in the random module, setter functions, seed functions and very complex statistical functions. Hit stack overflow and give it a try! Also it doesn’t hurt if you dust off that probability and statistics textbook!

As a last thought which came first the framework of entropy or the framework of randomness? As well as is everything truly random? i would love to hear your thought in the comments!

Until then,

#iwishyouwater <- click here on this one!

tctjr

References:

Python In A Nutshell by Alex Martelli

M. Matsumoto and T. Nishimura, “Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator”, ACM Transactions on Modeling and Computer Simulation Vol. 8, No. 1, January pp.3–30 1998

Muzak To Muzak To Blog By:  Black Sabbath  – The End: Live In Birmingham

Snake_Byte[3]: Getting Strung Out

There is geometry in the humming of the strings, there is music in the spacing of the spheres.

Pythagoras
How to Change Those Guitar Strings. | Superprof
We are not talking Guitar Strings

First, i  trust everyone is safe.

Second, this is the SB[3].  We are going to be covering some basics in Python of what constitutes a string, modifying a string, and explaining several string manipulation methods.

I also realized in the last Snake_Byte that i didn’t reference the book that i randomly open and choose the subject for the Snake_Byte.  I will be adding that as a reference at the end of the blog.

Strings can be used to represent just about anything.

They can be binary values of bytes, internet addresses, names, and Unicode for international localization.

They are part of a larger class of objects called sequences.  In fact, python strings are immutable sequences.  Immutability means you cannot change the sequence or the sequence does not change over time.

The most simplistic string is an empty string:

a = “ “ # with either singe or double quotes

There are numerous expression operations, modules, and methods for string manipulations.  

Python also supports much more advanced operations for those familiar with regular expressions (regex) it supports them via reEven more advanced operations are available such as XML parsing and the like.

Python is really into strings.

So let us get literal, shall we?

For String Literals there are countless ways to create and manipulate strings in your code:

Single Quotes:

a = `i w”ish you water’

Double Quotes;

A = “i w’ish you water”

Even triple quotes (made me think of the “tres commas” episode from Silicon Valley)

A = ```... i wish you water ```

Single and double quotes are by far the most used.  I prefer double quotes probably due to the other languages i learned before Python.

Python also supports the liberal use of backslashes aka escape sequences.  I’m sure everyone is familiar with said character `\`.  

Escape sequences let us embed bytecodes into strings that are otherwise difficult to type.

So let’s see here:

s = 't\nc\nt\njr'
print (s)
t
c
t
jr

So here i used ‘\n’ to represent the byte containing the binary value for newline character which is ASCII code 10.  There are several accessible representations:

‘\a\’ # bell

‘\b\’ #backspace

‘\f’ # formfeed for all the dot matrix printers we use 

‘\r’ #carriage return

You can even do different Unicode hex values:

‘\Uhhhhhhhh’ #32 bit hex count the number of h’s

With respect to binary file representations of note in Python 3.0 binary file content is represented by an actual byte string with operations similar to normal strings. 

One big difference between Python and another language like C is that that the zero (null) byte doesn’t terminate and in fact, there are no character string terminations in Python.  Also, the strings length and text reside in memory. 

s = 'a\0b\0c'
print (s)
len (s)
abc
5

So what can we do with strings in Python?

Well, we can concatenate:

a = "i wish"
print(len (a))
b = " you water"
print (len(b))
c = a + b
print (len(c))
print (c)
6
10
16
i wish you water

So adding two strings creates a new string object and a new address in memory.  It is also a form of operator overloading in place.  The ‘ + ‘ sign does the job for strings and can add numerics.  You also don’t have to “pre-declare” and allocate memory which is one of the advantages of Python.  In Python, computational processes are described directly by the programmer. A declarative language abstracts away procedural details however Python isn’t purely declarative which is outside the scope of the blog.  

So what else?  Well, there is indexing and slicing:

Strings are ordered collections of characters ergo we can access the characters by the positions within the ordering.

You access the component by providing a numerical offset via square brackets this is indexing.  

S = "i wish you water"
print (S[0], S[4], S[-1])
i s r

Since we can index we can slice:

S = "i wish you water"
print (S[1:3], S[2:10], S[9:10])
w wish you u

Slicing is a particular form of indexing more akin to parsing where you analyze the structure.

Python once again creates a new object containing the contiguous section identified by the offset pair.  It is important to note the left offset is taken to be the inclusive lower bound and the right is the non-inclusive upper bound. The inclusive definition is important here:  Including the endpoints of an interval. For example, “the interval from 1 to 2, inclusive” means the closed interval written [1, 2].  This means Python fetches all items from the lower bound up to but not including the upper bound. 

What about changing a string?

Let’s try it:

S = "i wish you water"
S[0] = "x"
---------------------------------------------------------------------------
TypeError Traceback (most recent call last) <ipython-input-67-a6fd56571822> 
in <module> 1 S = "i wish you water" ----> 2 S[0] = "x"
TypeError: 'str' object does not support item assignment

Ok, what just happened?  Well, remember the word immutable? You cannot change it in place.

To change a string you need to create a new one through various methods.  In the current case we will use a combination of concatenation, indexing, and slicing to bring it all together:

S = "i wish you water"
S = 'x ' + S[2]  +  S[3:17]
print (S)
x wish you water

This brings us to methods.

Stings in Python provide a set of methods that implements much more complex text processing.  Just like in other languages a method or function takes parameters and returns a value. A “method” is a specific type of function: it must be part of a “class”, so has access to the class’ member variables. A function is usually discrete and all variables must be passed into the function.

Given the previous example there is a replace method:

S = "i wish you water"
S = S.replace ('i wish you water', 'x wish you water')
print (S)
x wish you water

Let’s try some other methods;

# captialize the first letter in a string:
S = "i wish you water"
S.capitalize()
'I wish you water'

# capitalize all the letters in a string:
S = "i wish you water"
S.upper()
'I WISH YOU WATER'

# check if the string is a digit:
S = "i wish you water"
S.isdigit()
False

# check it again:
S = "999"
S.isdigit()
TRUE

# strip trailing spaces in a string:
S = "i wish you water     "
x = S.rstrip()
print("of all fruits", x, "is my favorite") 
of all fruits i wish you water is my favorite

The list is seemingly endless.  

One more caveat emptor you should use stings methods, not the original string module that was deprecated in Python 3.0

We could in fact write multiple chapters on strings by themselves.  However, this is supposed to be a little nibble of what the Snake language can offer.  We have added the reference that we used to make this blog at the end.  I believe it is one of the best books out there for learning Python.

Until Then,

#iwishyouwater

Tctjr

References:

Learning Python by Mark Lutz

Muzak To Blog By:  Mr. Robot Vol1 Original Television Soundtrack

Snake_Byte[2]: Comparisons and Equality

Contrariwise, continued Tweedledee, if it was so, it might be, and if it were so, it would be; but as it isn’t, it ain’t. That’s logic!

TweedleDee
Algebra, trigonometry and mathematical logic lessons by Janetvr | Fiverr
It’s all rational isn’t it?

First, i trust everyone is safe.

Second, i am going to be pushing a blog out every Wednesday called Snake_Bytes.  This is the second one hot off the press.  Snake as in Python and Bytes as in well you get it. Yes, it is a bad pun but hey most are bad. 

i will pick one of the myriads of python based books i have in my library and randomly open it to a page.  No matter how basic or advanced i will start from there and i will create a short concise blog on said subject.  For some possibly many the content will be rather pedantic for others i hope you gain a little insight.  As a former professor told me “to know a subject in many ways is to know it well.”  Just like martial arts or music performing the basics hopefully makes everything else effortless at some point.

Ok so in today’s installment we have Comparison and Equality.

I suppose more philosophically what is the Truth?

All Python objects at some level respond to some form of comparisons such as a test for equality or a magnitude comparison or even binary TRUE and FALSE.

For all comparisons in Python, the language traverses all parts of compound objects until a result can be ascertained and this includes nested objects and data structures.  The traversal for data structures is applied recursively from left to right.  

So let us jump into some simple snippets there starting with lists objects.  

List objects compare all of their components automatically.

%system #command line majik in Jupyterlab
# same value with unique objects
A1 = [2, (‘b’, 3)] 
A2 = [2, (‘b’, 3)]

#Are they equivalent?  Same Objects?
A1 == A2, A1 is A2
(True, False)

 So what happened here?  A1 and A2 are assigned lists which in fact are equivalent but distinct objects.  

So for comparisons how does that work?

  •  The ==  tests value equivalence

Python recursively tests nested comparisons until a result is ascertained.

  • The is operator tests object identity

Python tests whether the two are really the same object and live at the same address in memory.

So let’s compare some strings, shall we?

StringThing1 = "water"
StringThing2 = "water"
StringThing1 == StringThing2, StringThing1 is StringThing2
(True, True)

Ok, what just happened?  We need to be very careful here and i have seen this cause some really ugly bugs when performing long-chained regex stuff with health data.  Python internally caches and reuses some strings as an optimization technique.  Here there is really just a single string ‘water’ in memory shared by S1, S2 thus the identity operator evaluates to True.

The workaround is thus:

StringThing1 = "i wish you water"
StringThing2 = "i wish you water"
StringThing1 == StringThing2,StringThing1 is StringThing2
(True, False)

Given the logic of this lets see how we have conditional logic comparisons.

I believe Python 2.5 introduced ternary operators.  Once again interesting word:

Ternary operators ternary means composed of three parts or three as a base.

The operators are the fabled if/else you see in almost all programming languages.

Whentrue if condition else whenfalse

The condition is evaluated first.  If condition is true the result is whentrue; otherwise the result is whenfalse.  Only one of the two subexpressions whentrue and whenfalse evaluates depending on the truth value of condition.

Stylistically you want to palace parentheses around the whole expression.

Example of operator this was taken directly out the Python docs with a slight change as i thought it was funny:

is_nice = True
state = "nice" if is_nice else "ain’t nice"
print(state)

Which also shows how Python treats True and False.

In most programming languages an integer 0 is FALSE and an integer 1 is TRUE.

However, Python looks at an empty data structure as False.  True and False as illustrated above are inherent properties of every object in Python.

So in general Python compares types as follows:

  • Numbers are compared by the relative magnitude
  • Non-numeric mixed types comparisons where ( 3 < ‘water’) doesn’t fly in Python 3.0  However they are allowed in Python 2.6 where they use a fixed arbitrary rule.  Same with sorts non-numeric mixed type collections cannot be sorted in Python 3.0
  • Strings are compared lexicographically (ok cool word what does it mean?). Iin mathematics, the lexicographic or lexicographical order is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of a totally ordered set. In other words like a dictionary. Character by character where (“abc” < “ac”)
  • Lists and tuples are compared component by component left to right
  • Dictionaries are compared as equal if their sorted (key, value) lists are equal.  However relative magnitude comparisons are not supported in Python 3.0

With structured objects as one would think the comparison happens as though you had written the objects as literal and compared all the components one at a time left to right.  

Further, you can chain the comparisons such as:

a < b <= c < d

Which functionally is the same thing as:

a < b and b <= c and c < d

The chain form is more compact and more readable and evaluates each subexpression once at the most.

Being that most reading this should be using Python 3.0 a couple of words on dictionaries per the last commentary.  In Python 2.6 dictionaries supported magnitude comparisons as though you were comparing (key,value) lists.

In Python 3.0 magnitude comparisons for dictionaries are removed because they incur too much overhead when performing equality computations.  Python 3.0 from what i can gather uses an in-optimized scheme for equality comparisons.  So you write loops or compare them manually.  Once again no free lunch. The documentation can be found here: Ordering Comparisons in Python 3.0.

One last thing.  There is a special object called None.  It’s a special data type in Python in fact i think the only special data type.  None is equivalent to a Null pointer in C.  

This comes in handy if your list size is not known:

MyList = [None] * 50
Print (MyList)
[None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]

The output makes me think of a Monty Python skit. See what I did there? While the comparison to a NULL pointer is correct the way in which it allocates memory and doesn’t limit the size of the list it allocates presets an initial size to allow for future indexing assignments. In this way, it kind of reminds me of malloc in C.  Purist please don’t shoot the messenger. 

Well, i got a little long in the tooth as they say.  See what i did again?  Teeth, Snakes and Python.

See y’all next week.

Until Then,

#iwishyouwater

@tctjr

Muzak To Blog By: various tunes by : Pink Martini, Pixies, Steve Miller.

Book Review: How To Read A Book

Reading is a basic tool in the living of a good life.

Mortimer Adler
My copy of HTRAB

First, i hope everyone is safe.

Second, i decided to write this blog based on two unrelated events: (1) as of late during the pandemic i have been reading commentary “online” of varying degrees such as “I want to read more books” and “Can you recommend some books to read?”  (2) i was setting out to write a technical blog on a core machine learning subject and whilst putting together the bibliography i realized i wasn’t truly performing or rather obtaining “level four reading” as outlined in the book i am going to review and by definition recommend.

i also am an admitted bibliomaniac and even more so nowadays an autodidact. i contracted the reading bug from my mother at an early age. i read Webster’s Dictionary twice in grade school. Still to this day she sends me the first edition or rare books to read. Thanks, Mom.

This is the stack of references.

As part of this book review and hopefully subsequent blog on a technical subject within machine learning, i decided to read the book a third time.  Which for this blog and review is an important facet.

As i was thinking about the best way to approach this particular book review i was pondering reading and books in general.  Which i came yet again to the conclusion:

There is much magic and wonder in this world.  Reading to me is a magical process.

It’s a miracle a child learns to speak a language!  It’s a miracle we can read! It’s even more of a miracle given the two previous observations that Humans are such astounding language generators (and authors)! 

One section of many in my library office

What an astonishing thing a book is. It’s a flat object made from a tree with flexible parts on which are imprinted lots of funny dark squiggles. But one glance at it and you’re inside the mind of another person, maybe somebody dead for thousands of years. Across the millennia, an author is speaking clearly and silently inside your head, directly to you. Writing is perhaps the greatest of human inventions, binding together people who never knew each other, citizens of distant epochs. Books break the shackles of time. A book is proof that humans are capable of working magic.

Carl Sagan

i consider a  book a “dual-sided marketplace” for magical access.

“How To Read a Book” by Mortimer J. Adler was originally published in 1940 with a re-issue in 1972.  The 1970s were considered the decade of reading in the United States.

In the 70’s the average reading level in the United States for most content speeches, magazines, books, etc was the 6th grade.  It is now surmised the average reading level and reading content is hovering around the 4-5th grade.

This brings us to the matter at hand the book review. 

The book’s author ​​Mortimer Jerome Adler (December 28, 1902 – June 28, 2001) was an American philosopher, educator, encyclopedist, and popular author. As a philosopher, he worked within the Aristotelian and Thomistic traditions. He taught at Columbia University and the University of Chicago, served as chairman of the Encyclopædia Britannica Board of Editors, and founded his own Institute for Philosophical Research.  

There is no friend as loyal as a book.

Ernest Hemmingway

The book states upfront that there is great inequality in reading with respect to understanding and that understanding must be overcome.  Reading for understanding is not just gaining information.  There is being informed and there is being enlightened when reading a book.  How To Read A Book (HTRAB) is precisely concerned with the latter.  If you remember what you read you have been informed. If you are enlightened from a book you know what the author is attempting to say, know what he means by what they say, and can concisely explain the subject matter. Of course, being informed is a prerequisite to being enlightened.

Professor Adler mentions in the book via Montaingne where he speaks of “An abecedarian ignorance that precedes knowledge, and a doctoral ignorance that comes after it.” 

Let’s first deal with Abcederian:  It essentially means dealing with alphabetized, elementary, rudimentary, or novel levels.  Ergo the novice ignorance arrives first.  The second are those who misread books.  Reading a ton of books is not reading well.  Professor Adler calls them literate ignoramus.  The said another way there are those that have read too widely and not well. 

Widely read and well-read are two vastly different endeavors.

The Greek word for learning and folly is sophomore. From google translate sophomore in Greek: δευτεροετής φοιτητής

This book pulls no punches when it comes to helping you help yourself.

HTRAB is in fact just that how to gain the most out of a book.  The book explains the four levels of reading:

  1. Elementary reading, rudimentary reading, basic reading or initial reading.  This is where one goes from complete illiteracy to at the very least being able to read the words on the page.  
  2. Inspectional reading.  This is where one attempts to get the most out of a book in a prescribed about of time.  What is this book about?
  3. Analytical reading places heavy demands on the reader.  It is also called thorough reading, complete reading or good reading.  This is the best reading you can do.  The analytical reader must ask themselves several questions of inquiry, organizational and objective natures.  The reader grasps the book.  The book at this point becomes her own.  This level of reading is precisely for the sake of understanding.  Also you cannot bring your mind from understanding less to understanding more unless you have skill in the area of analytical reading. 
  4. Syntopical Reading is the highest level.  It is the most complex and systematic reading and it makes the most demands on the reader.  Another name for this level is comparative reading.  When reading syntopically the reader accesses and reads many books placing them in relation to one another where the reader is able to construct and an analysis of knowledge that previously did not exist.  Knowledge creation and synthesis is the key here.

This is what i realized i wasn’t doing with respect to the machine learning blog.  Yes, i ranked and compared the references against one another but did i truly synthesize a net new knowledge with respect to my reading?  

Tools of The Art of Reading

The HTRAB goes on to dissect the processes of each of these four steps and how to obtain them and then move on to the next level.  This reminds me of a knowledge dojo a kind of belt test for readership.

The book also goes on to discuss how to not have any predetermined biases about what the book is or is not.  This is very important i have fallen prey to such behaviors and cannot emphasize enough you must proceed into the book breach with a clear mind

Further, the author took their valuable time to write the book and you took the cash and time to obtain the book. 

Give the respect the book deserves.

Some books are to be tasted, others to be swallowed, and some few to be chewed and digested.

Francis Bacon

The book goes in-depth about how we move from one level of reading to eventually synoptical reading and the basis for this is reading over and over whilst at every read the book is anew and alive with fresh edible if you will information.

To read and to ruminate is derived from the cow.  From Wikipedia we have:

“Ruminants are large hoofed herbivorous grazing or browsing mammals that are able to acquire nutrients from plant-based food by fermenting it in a specialized stomach prior to digestion, principally through microbial actions.”

So to chew the cud or re-chew if you will over and over – ruminating upon the subject matter. The book states in most cases that it takes three reads to obtain synoptical reading levels.  Thus my comment previously about reading this a third time.  Amazingly it clicked.

The folks who need self-help books don’t read them and those that don’t need them do read them.

A.S.L.

The book further explains how to read everything from mathematics to theology.  With very precise steps.  

i recommend this book over and over to folks and i usually get online comments like “so meta’ or “LOL”.  In-person i get raise eyebrows or laughter.

This is not a laughing matter oh dear reader.

The two following lectures deal with HRTAB from the son of someone who worked directly with Professor Adler. His name is Shaykh Hamza Yusuf. Professor Yusuf is an American neo-traditionalist Islamic scholar and co-founder of Zaytuna College. He is a proponent of classical learning in Islam and has promoted Islamic sciences and classical teaching methodologies throughout the world. He is a huge proponent of HRTAB and recommends it in many of his lectures and uses it as a basis for his teachings in many forms. In no shape or form am I endorsing any religious or political stance with posting these videos. i am only posting for the information-rich and amazing lectures alone. He covers several areas of academics as well as several areas of religion and even pop-fad behaviors with respect to reading.

Here are both parts of the lecture:

Get the book to learn how to arrive at chewing and digesting your beloved books to the level of syntopical nirvana.  Your mind and others’ minds will thank you for it. Here is a link on Amazon:

Until then,

#iwishyou water.

Be safe.

@tctjr

Muzak To Blog by:  Cheap Trick Albums.  I had forgotten how good they were.  

Review: Zappa (The Official Documentary)

Art is making something out of nothing, and selling it.

Frank zappa
Frank Zappa

First i hope everyone is safe.

Second i’ll am writing about something off my usual beaten path and that is a movie review.  Yes once in a while i watch ye  ole “boob tube” as they used to call it back in the day.

This movie is a special movie to me as it is about the life of Frank Zappa the rock and roll guitar player, the composer, the artist, the movie maker, the recoding engineer, the American representative to Czechoslovakia, (or Czecho-Slovakia)  and most importantly a man who fervently fought for free speech.  Mainly at least for me it is a testament to someone who was constantly creating and recording that creation as well as documenting and saving those creations. While i’ve been into Zappa since a teenager i really started trying to understand the magnitude whilst in graduate school at the University of Miami where i was lucky enough to engineer and work with a group called the Zappa Ensemble. The musicianship and complexity blew my mind and it was hilarious all at the same time! It finally clicked!

Kerry Mcnabb and Frank Zappa getting physical in the mixing process (photo courtesy Magnolia Pictures)

Alex Winter was the main creative force behind Zappa with Frank Zappa’s oldest son Ahment Zappa producing. 

Zappa Trailer:

One of my greatest enjoyments is being part of making or being in deep active listening of this thing human’s call music and Frank Zappa to me is one of the greatest composers of the 20th century of which this movie showcases.  His ability to meld performance, musician ship and lyrical satire i believe will never be seen again in my time or possibly anyones time.

lf you’re going to deal with reality, you’re going to have to make one big discovery: Reality is something that belongs to you as an individual. If you wanna grow up, which most people don’t, the thing to do is take responsibility for your own reality and deal with it on your own terms. Don’t expect that because you pay some money to somebody else or take a pledge or join a club or run down the street or wear a special bunch of clothes or play a certain sport or even drink Perrier water, it’s going to take care of everything for you.

Frank Zappa

The movie deeply focuses on the extreme drive Zappa had to create and duplicate the sound that he heard in his head transferring it from paper to little dots of which we call musical notation then taking it to the studio and attempting to reproduce it as accurately as possible to the sound being heard inside his head.  The recording process to me is truly astounding.  It’s what i term “a perceptual to parameterization to physical transform”.  He was self taught in all aspects of his creative pursuits of which he was what i consider to be an ultimate autodidactic.

This movie starts off with Frank’s last guitar performance then cuts to him  in his Vault of recordings and VHS tapes identifying original master recordings.  I was awestruck.  

You’ve got to be digging it while it’s happening ’cause it just might be a one shot deal.

Frank Zappa

Through my research on the film i found out that alex Winter was Bill in the “Bill and Ted” films although i have no idea what those are as i haven’t seen them only heard about them.  Evidently he has been making documentaries for a decade. He approached Zappa’s widow Gail (the film is dedicated to her as she died in 2015)  for permission on the project.  The result is a a cacophony of a life lived loud with constant feeding the disease of composition and creativity.

Winter was given complete access to the Zappa family archives which as i mention above was called The Vault.  There are many shots of The Vault which is a treasure trove of both audio and video recordings all shapes sizes and formats.  

There is also a ton of footage of his family and how he grew up.  Initially his family completely opposed him getting involved with music and Zappa also notes that they were extremely poor. They also note Zappa was interested chemistry at an early age and tried to blow his school up.

The illusion of freedom will continue as long as it’s profitable to continue the illusion. At the point where the illusion becomes too expensive to maintain, they will just take down the scenery, they will pull back the curtains, they will move the tables and chairs out of the way and you will see the brick wall at the back of the theater.

Frank Zappa

There is a great section of Frank “On The Hill”  testifying before the senate during the PMRC hearings on album and music lyrics which he definitely as i do consider censorship.  The movie then details his pursuit of anything that looks or smells like censorship.  If it weren’t for him doing this at every turn i believe things would be very different even a much a it is now. Then i wonder, today in this environment, he probably couldn’t publish a lot of the music he wrote.

The salient point i was reminded of in this movie is  don’t waste your time go make a dent in this thing we call life and create at all costs even if no one – not one person – views, listens or uses the creation at least one person will and that will be the person of You.  

Never compromise and always choose quality over quantity and remember give “them” a good laugh.  They might not get the joke but at least you can laugh.  

Why do you necessarily have to be wrong just because a few million people think you are?

Frank Zappa

To give you an idea of the sheer output and dedication to the art while alive Zappa released 62 albums. Since 1994, the Zappa Family Trust has released 54 posthumous albums as of July 2020, making a total of 116 albums/album sets.

This dear reader should remind you of one aspect of your life:  Find your passion and dwell on it deeply, daily, hourly, minute by precious minute.  

Personally i hope The Vault is all mined, uncovered, reformatted and converted so that the world knows about the volume and creativity.

If you think that Zappa was all about raunchy lyrics, complex poly rhythms and symphonies most ensembles and orchestras couldn’t play i urge you to listen to this song that ends the documentary.  The documentary ends with amazing shots of his house  and uses a live version that is recorded in 1978 as the back drop. Below are several versions including the studio version from Joe’s Garage album because the comments by the “Central Scrutinizer” are hilarious and are juxtaposed against what i consider to be one of the most amazing pieces of guitar work ever recorded.  The sadness and lamenting of the piece is deafening.  However at the same time as someone who i have met in the land of suspicious coincidence said it is intoxicating.  

For completeness here is the live version in 1978

And here is a version in 2013 by his son dweezil zappa crying while he is playing.  

There is a four “disc” set on itunes of the documentary soundtrack here: Zappa Soundtrack.

Frank Zappa died on December 4, 1993 of prostate cancer.  He is survived by his four progeny: Moon, Dweezil, Ahment and Diva Zappa.  

Until then,

#iwishyouwater

@tctjr

Muzak To Blog By:  Zappa Soundtrack

Snake_Byte[1]_PyForest

The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code — not in reams of trivial code that bores the reader to death.

Guido van Rossum

Hi all first always i trust everyone is doing well and safe.

Second i had started writing another blog on some first principles design issues in machine learning but this morning while i was just browsing i came across a python library called Pyforest. Pyforest claims to have 99% of your import library woes solved.

At one of my previous companies, we created this flow from the time you walk in get your rig and sit down you have access to a superpack.tar.gz with all of the necessary python dependencies in fact even any bash scripts that you might need once you got your rig to start doing PRs the same day you started work.  This was pre-anaconda days so it worked well then most moved over to dependency management via anaconda.  However, this didn’t solve one of the main issues.  What when and how do you import?

i am sure if you are like me i keep the proverbial “untitled.ipynb” sitting around just for a notepad of sorts for the main imports (just don’t click and press X accidentally!).

Which is where pyforest comes into the reptilian purview.

The github is funny it says:

pyforest – feel the bliss of automated imports.”

Then it goes on to say:

“Writing the same imports over and over again is below your capacity. Let pyforest do the job for you.”

Being this isn’t supposed to be tl;dr blog (only a little nibble from a reptile) lets get started.

Installation:

You need to have python version 3.6 or above.  The github is once again funny (we like f-strings).  

So first make sure you are in your venv. 

 python3 --version
 pip install --upgrade pyforest
 python -m pyforest install_extensions 

Low and behold: 

Downloading pyforest-1.0.3.tar.gz

Needless to say i was skeptical.  

Questions – autocomplete? Stomping on variables?  Grinding to a halt because maybe import *?

Nope. Here is proof:

Ok nice parlor trick.

Lets try plotting something because i always space out and just type plt:

Ok now you have my attention.

i then tried a simple linear regression with sklearn

So this library definitely saves you time and the folks over at bamboolib have a great sense of humor which i really appreciate.

You can check to see a list of imported libraries dir(pyforest) kinda like a micro pip freeze.

Here is the github: pyforest github.

+1 for my recommendation.

until then,

#iwishyouwater

@tctjr

Muzak To Blog To: Cold Fact by Rodriguez 

Fwiw if you get a chance watch “Searching For Sugarman” which is a documentary about Rodriguez.  Astounding.