SnakeByte[16]: Enhancing Your Code Analysis with pyastgrep

Dalle 3’s idea of an Abstract Syntax Tree in R^3 space

If you would know strength and patience, welcome the company of trees.

~ Hal Borland

First, I hope everyone is safe. Second, I am changing my usual SnakeByte [] stance process. I am pulling this from a website I ran across. I saw the library mentioned, so I decided to pull from the LazyWebTM instead of the usual snake-based tomes I have in my library.

As a Python developer, understanding and navigating your codebase efficiently is crucial, especially as it grows in size and complexity. Trust me, it will, as does Entropy. Traditional search tools like grep or IDE-based search functionalities can be helpful, but they cannot often “‘understand” the structure of Python code – sans some of the Co-Pilot developments. (I’m using understand here *very* loosely Oh Dear Reader).

This is where pyastgrep it comes into play, offering a powerful way to search and analyze your Python codebase using Abstract Syntax Trees (ASTs). While going into the theory of ASTs is tl;dr for a SnakeByte[] , and there appears to be some ambiguity on the history and definition of Who actually invented ASTs, i have placed some references at the end of the blog for your reading pleasure, Oh Dear Reader. In parlance, if you have ever worked on compilers or core embedded systems, Abstract Syntax Trees are data structures widely used in compilers and the like to represent the structure of program code. An AST is usually the result of the syntax analysis phase of a compiler. It often serves as an intermediate representation of the program through several stages that the compiler requires and has a strong impact on the final output of the compiler.

So what is the Python Library that you speak of? i’m Glad you asked.

What is pyastgrep?

pyastgrep is a command-line tool designed to search Python codebases with an understanding of Python’s syntax and structure. Unlike traditional text-based search tools, pyastgrep it leverages the AST, allowing you to search for specific syntactic constructs rather than just raw text. This makes it an invaluable tool for code refactoring, auditing, and general code analysis.

Why Use pyastgrep?

Here are a few scenarios where pyastgrep excels:

  1. Refactoring: Identify all instances of a particular pattern, such as function definitions, class instantiations, or specific argument names.
  2. Code Auditing: Find usages of deprecated functions, unsafe code patterns, or adherence to coding standards.
  3. Learning: Explore and understand unfamiliar codebases by searching for specific constructs.

I have a mantra: Reduce, Refactor, and Reuse. Please raise your hand of y’all need to refactor your code? (C’mon now no one is watching… tell the truth…). See if it is possible to reduce the code footprint, refactor the code into more optimized transforms, and then let others reuse it across the enterprise.

Getting Started with pyastgrep

Let’s explore some practical examples of using pyastgrep to enhance your code analysis workflow.

Installing pyastgrep

Before we dive into how to use pyastgrep, let’s get it installed. You can install pyastgrep via pip:

(base)tcjr% pip install pyastgrep #dont actually type the tctjr part that is my virtualenv

Example 1: Finding Function Definitions

Suppose you want to find all function definitions in your codebase. With pyastgrep, this is straightforward:

pyastgrep 'FunctionDef'

This command searches for all function definitions (FunctionDef) in your codebase, providing a list of files and line numbers where these definitions occur. Ok pretty basic string search.

Example 2: Searching for Specific Argument Names

Imagine you need to find all functions that take an argument named config. This is how you can do it:

pyastgrep 'arg(arg=config)'

This query searches for function arguments named config, helping you quickly locate where configuration arguments are being used.

Example 3: Finding Class Instantiations

To find all instances where a particular class, say MyClass, is instantiated, you can use:

pyastgrep 'Call(func=Name(id=MyClass))'

This command searches for instantiations of MyClass, making it easier to track how and where specific classes are utilized in your project.

Advanced Usage of pyastgrep

For more complex queries, you can combine multiple AST nodes. For instance, to find all print statements in your code, you might use:

pyastgrep 'Call(func=Name(id=print))'

This command finds all calls to the print function. You can also use more detailed queries to find nested structures or specific code patterns.

Integrating pyastgrep into Your Workflow

Integrating pyastgrep into your development workflow can greatly enhance your ability to analyze and maintain your code. Here are a few tips:

  1. Pre-commit Hooks: Use pyastgrep in pre-commit hooks to enforce coding standards or check for deprecated patterns.
  2. Code Reviews: Employ pyastgrep during code reviews to quickly identify and discuss specific code constructs.
  3. Documentation: Generate documentation or code summaries by extracting specific patterns or structures from your codebase.

Example Script

To get you started, here’s a simple Python script using pyastgrep to search for all function definitions in a directory:

import os
from subprocess import run

def search_function_definitions(directory):
result = run(['pyastgrep', 'FunctionDef', directory], capture_output=True, text=True)
print(result.stdout)

if __name__ == "__main__":
directory = "path/to/your/codebase" #yes this is not optimal folks just an example.
search_function_definitions(directory)

Replace "path/to/your/codebase" with the actual path to your Python codebase, and run the script to see pyastgrep in action.

Conclusion

pyastgrep is a powerful tool that brings the capabilities of AST-based searching to your fingertips. Understanding and leveraging the syntax and structure of your Python code, pyastgrep allows for more precise and meaningful code searches. Whether you’re refactoring, auditing, or simply exploring code, pyastgrep it can significantly enhance your productivity and code quality. This is a great direct addition to your arsenal. Hope it helps and i hope you found this interesting.

Until Then,

#iwishyouwater <- The best of the best at Day1 Tahiti Pro presented by Outerknown 2024

𝕋𝕖𝕕 ℂ. 𝕋𝕒𝕟𝕟𝕖𝕣 𝕁𝕣. (@tctjr) / X

MUZAK to Blog By: SweetLeaf: A Stoner Rock Salute to Black Sabbath. While i do not really like bands that do covers, this is very well done. For other references to the Best Band In Existence ( Black Sabbath) i also refer you to Nativity in Black Volumes 1&2.

References:

[1] Basics Of AST

[2] The person who made pyastgrep

[3] Wikipedia page on AST

SnakeByte [15]: Debugging With pdb In The Trenches

Dalle3 idea of debugging code from the view of the code itself.

If debugging is the process of removing software bugs, then programming must be the process of putting them in.

~ Edsger W. Dijkstra

Image Explanation: Above is the image showing the perspective of debugging code from the viewpoint of the code itself. The scene features lines of code on a large monitor, with sections highlighted to indicate errors. In the foreground, anthropomorphic code characters are working to fix these highlighted sections, set against a digital landscape of code lines forming a cityscape.

So meta and canonical.

In any event Dear Readers, it is Wednesday! That means as usual everyday is Wednesday in a startup, you actually work at a company where you enjoy the work or it is SnakeByte [ ] time!

i haven’t written a SnakeByte is quite some time. Also, recently, in a previous blog, I mentioned that I had a little oversite on my part, and my blog went down. i didn’t have alerting turned on ye ole AWS and those gosh darn binlogs where not deleting in ye ole WordPress as such we took the proverbial digger into downtime land. i re-provisioned with an additional sizing of the volume and changed the disc from magnetic to SSD, turned on alerts and we are back in business.

So per my usual routine i grab one of the python books from the book shelf randomly open then read about command or commands and attempt to write a blog as fast as possible.

Today’s random command from Python In A Nutshell is pdb, the Python Debugger. i’ll walk you through the basic of using pdb to debug your Python code, which, as it turns out is better than a bunch of print().

Getting Started with pdb

To leverage pdb, import it in your Python script. You can then set breakpoints manually with pdb.set_trace(). When the execution hits this line, the script pauses, allowing you to engage in an interactive debugging session.

Consider this straightforward example:

# example.py
import pdb

def add(a, b):
result = a + b
return result

def main():
x = 10
y = 20
pdb.set_trace() # Breakpoint set here
total = add(x, y)
print(f'Total: {total}')

if __name__ == '__main__':
main()

Here, we have a simple add function and a main function that invokes add. The pdb.set_trace() in the main function sets a breakpoint where the debugger will halt execution.

Running the Code with pdb

Execute the script from the command line to initiate the debugger:

python example.py

When the execution reaches pdb.set_trace(), you will see the debugger prompt ((Pdb)):

> /path/to/example.py(11)main()
-> total = add(x, y)
(Pdb)

Essential pdb Commands

Once at the debugger prompt, several commands can help you navigate and inspect your code. Key commands include:

  • l (list): Displays the surrounding source code.
  • n (next): Moves to the next line within the same function.
  • s (step): Steps into the next function call.
  • c (continue): Resumes execution until the next breakpoint.
  • p (print): Evaluates and prints an expression.
  • q (quit): Exits the debugger and terminates the program.

Let’s walk through using these commands in our example:

List the surrounding code:

Pdb) 1
  6         def main():
  7             x = 10
  8             y = 20
  9             pdb.set_trace()  # Breakpoint here
 10  ->         total = add(x, y)
 11             print(f'Total: {total}')
 12     
 13         if __name__ == '__main__':
 14             main()

Print variable values:

(Pdb) p x
10
(Pdb) p y
20

Step into the add function:

(Pdb) s
> /path/to/example.py(3)add()
-> result = a + b
(Pdb)

Inspect parameters a and b:

(Pdb) p a
10
(Pdb) p b
20

Continue execution:

(Pdb) c
Total: 30

Advanced pdb Features

For more nuanced debugging needs, pdb offers advanced capabilities:

Conditional Breakpoints: Trigger breakpoints based on specific conditions:

if x == 10:
    pdb.set_trace()

Post-Mortem Debugging: Analyze code after an exception occurs:

import pdb

def faulty_function():
    return 1 / 0

try:
    faulty_function()
except ZeroDivisionError:
    pdb.post_mortem() #they need to add a pre-mortem what can go wrong will...

Command Line Invocation: Run a script under pdb control directly from the command line like the first simple example:

python -m pdb example.py

Effective debugging is crucial for building robust and maintainable software. pdb provides a powerful, interactive way to understand and fix your Python code. By mastering pdb, you can streamline your debugging process, saving time and enhancing your productivity.

pdb, the Python Debugger, is an indispensable tool for any developer. It allows us to set breakpoints, step through code, inspect variables, and evaluate expressions on the fly. This level of control is crucial for diagnosing and resolving issues efficiently. While i used cli in the examples it also works with Jupyter Notebooks.

We’ve covered the basics and advanced features of pdb, equipping you with the knowledge to tackle even the most challenging bugs. As you integrate these techniques into your workflow, you’ll find that debugging becomes less of a chore and more of a strategic advantage unless you create a perfect design which is no code at all!

Until then,

#iwishyouwater <- La Vaca Gigante Wipeouts 2024

𝕋𝕖𝕕 ℂ. 𝕋𝕒𝕟𝕟𝕖𝕣 𝕁𝕣. (@tctjr)

Muzak to Blog By: Apostrophe (‘) by Frank Zappa. i was part of something called the Zappa Ensemble in graduate school as one of the engineers. The musicians where amazing. Apostrohe (‘)is an amazing album. The solo on Uncle Remus is just astounding well as is most of his solos.

Review: Flow Research Collective

Bonafide in The Art of The Flow

I will persist until I succeed.

I was not delivered unto this world in defeat, nor does failure course in my veins. I am not a sheep waiting to be prodded by my shepherd. I am a lion and I refuse to talk, to walk, to sleep with the sheep. I will hear not those who weep and complain, for their disease is contagious. Let them join the sheep. The slaughterhouse of failure is not my destiny.

I will persist until I succeed.

OG Mandino

First as always Dear Readers i trust everyone is safe. Second, whilst i have not written i in a while that does not mean i have not been “thoughting” of things to write about for You Oh Dear Reader. Third, software is hard and there was a glitch in the matrix and my site was down for a bit.

Starting last year on April 24th, 2023, with Matthew McConaughey’s “Art Of Living” worldwide class that was, in fact, a precursor to a class with him and Tony Robbins dedicated to looking into yourself and figuring out exactly what you want – sound familiar? However, this was not for me to use for others but for me – period. I knew that this was a stepping stone to the class that I was going to write about, a class given by the Flow Research Collective. After i took “The Art of Living” class i knew a Flow Research Collective Class was starting over “The Holidays” in December 2023. Knowing full well that i would be in the throes of work at my new gig and also “The Holidays”, i told myself just like i tell others: “The best time to plant a tree is yesterday. The best time to plant a tree is Now.” So i registered for the 9 week class. At the time, i was very familiar with Stephen Kotler, the founder of FRC given i had read many of his books:

  1. Abundance: The Future Is Better Than You Think” (2012) – Co-authored with Peter H. Diamandis
  2. Bold: How to Go Big, Create Wealth and Impact the World” (2015) – Co-authored with Peter H. Diamandis
  3. The Rise of Superman: Decoding the Science of Ultimate Human Performance” (2014)
  4. Tomorrowland: Our Journey from Science Fiction to Science Fact” (2015) – Co-authored with Peter H. Diamandis
  5. Stealing Fire: How Silicon Valley, the Navy SEALs, and Maverick Scientists Are Revolutionizing the Way We Live and Work” (2017) – Co-authored with Jamie Wheal
  6. The Future is Faster Than You Think: How Converging Technologies Are Transforming Business, Industries, and Our Lives” (2020) – Co-authored with Peter H. Diamandis
  7. The Art of The Impossible: A Peak Performance Primer” (2021)
  8. Gnar Country: Growing Old and Staying Rad” (2023)

I have read all of the ones concerning human performance.

Why did I push this off till now? Well, denial is an amazing psychological force.

In the realm of human performance, few concepts hold as much promise and intrigue as the state of flow. Coined by psychologist Mihaly Csikszentmihalyi, flow refers to a mental state of complete immersion and energized focus in an activity, where individuals experience profound enjoyment and peak performance. Flow is not just a fleeting moment of productivity; it’s a state where time seems to warp, self-vanishes, and optimal performance becomes effortless. Harnessing the power of flow can unlock human potential in remarkable ways.

The Flow Research Collective (FRC) is an organization that has made it its mission to understand, master, and utilize the principles of flow to help individuals and organizations achieve peak performance consistently. Founded by Steven Kotler, a prolific author and leading expert on the subject, and Rian Doris, the CEO, the FRC has journeyed from humble beginnings to becoming a powerhouse in the field of human performance enhancement.

Origins: The Spark of Inspiration

The story of the Flow Research Collective begins with Steven Kotler’s own personal journey. Struggling with Lyme disease, Kotler found himself facing physical and cognitive limitations that profoundly impacted his life and work. Determined to overcome these challenges, he delved deep into the science of human performance, stumbling upon the concept of flow.

Kotler’s fascination with flow led him to explore its intricacies, drawing from neuroscience, psychology, and various research fields. As he began understanding flow mechanics and its transformative potential, he realized the need to share this knowledge with the world. Thus, the seeds of the Flow Research Collective were planted.

Building Momentum: From Vision to Reality

Armed with a vision to unlock human potential through flow, Kotler embarked on a journey to build the Flow Research Collective from the ground up. Collaborating with like-minded individuals and experts in various domains, he set out to create a platform that would serve as a hub for research, education, and practical flow applications.

The early days were marked by relentless dedication and a commitment to excellence. Kotler and his team immersed themselves in the latest scientific literature, conducted experiments, and engaged with practitioners from diverse fields to gain insights into the nature of flow. Through trial and error, they refined their methodologies, developing frameworks and tools to help individuals cultivate flow and achieve peak performance.

Cultivating a Community: The Power of Connection

Central to the Flow Research Collective’s success is its ability to foster a vibrant and engaged community of flow enthusiasts. Through workshops, seminars, online courses, and collaborative projects, the FRC has brought together individuals from all walks of life who share a common passion for unlocking human potential.

The community’s collective nature has been instrumental in accelerating learning and innovation. By sharing experiences, exchanging ideas, and supporting one another, members of the FRC have been able to tap into the group’s collective wisdom, amplifying their individual efforts and achievements.

From Zero to Dangerous: Mastering the Art of Flow

The term “zero to dangerous” (ZTD) encapsulates the ultimate goal of the Flow Research Collective: to empower individuals to transition from a state of inexperience or mediocrity to one of mastery and excellence. Drawing inspiration from the language of fighter pilots who aim to go from zero to dangerous in their skill level, the FRC seeks to help individuals reach a level of proficiency where they can navigate life’s challenges with confidence and grace.

Achieving this level of mastery requires more than just theoretical knowledge; it demands practice, discipline, and a willingness to push beyond one’s comfort zone. Through a combination of cutting-edge research, immersive training experiences, and personalized coaching, the FRC equips individuals with the tools and techniques they need to harness the power of flow and unleash their full potential.

Looking Ahead: A Future of Possibilities

As the Flow Research Collective grows and evolves, the possibilities are endless. From helping athletes and artists achieve peak performance to revolutionizing the way businesses operate, the principles of flow have the potential to transform every aspect of human endeavor.

With advances in technology, neuroscience, and our understanding of human psychology, the FRC is poised to unlock new frontiers in human performance enhancement. By staying true to its mission of understanding, mastering, and leveraging the power of flow, the Flow Research Collective is paving the way for a future where individuals and organizations can thrive like never before.

What is FLOW?

Specifically, “Flow” occurs when individuals are fully immersed in a task, experiencing deep focus, high levels of enjoyment, and a sense of timelessness. In this state, individuals often report feeling in control, highly motivated, and completely absorbed in the activity at hand. Flow typically occurs when the challenge of a task matches an individual’s skill level, leading to a harmonious balance that encourages peak performance and creativity. Achieving flow can enhance productivity, increased well-being, and a sense of fulfillment. The class mentioned herewith trains you to optimize and balance the release of neurochemicals.

In the state of flow, several neurotransmitters and neurochemicals are released, contributing to the heightened sense of focus, motivation, and well-being experienced by individuals. Some of the key neurochemicals involved include:

  1. Dopamine: Often referred to as the “feel-good” neurotransmitter, dopamine is associated with motivation, reward, and pleasure. During flow, dopamine levels increase, reinforcing the behavior and enhancing the feeling of satisfaction associated with being in the zone.
  2. Endorphins: Endorphins are natural painkillers produced by the body and contribute to feelings of euphoria and well-being. In flow, endorphin levels rise, potentially reducing the perception of discomfort or fatigue and promoting a sense of exhilaration.
  3. Serotonin: Serotonin affects mood regulation, emotional balance, and overall well-being. Increased serotonin levels during flow can contribute to a sense of calmness, contentment, and happiness.
  4. Anandamide: Anandamide is a neurotransmitter associated with bliss, joy, and relaxation. Elevated levels of anandamide during flow may enhance individuals’ overall sense of well-being and pleasure.
  5. Norepinephrine: Norepinephrine plays a role in attention, focus, and arousal. In flow, norepinephrine levels increase, heightening alertness, enhancing concentration, and promoting a state of intense focus on the task at hand.

So this class was much more than just a recipe for flow. It was mapping what is called your Maximally Transformative Process.

The Maximally Transformative process (MTP) refers to a structured approach or methodology designed to help individuals achieve peak performance states such as flow more consistently and experience significant personal and professional growth.

This process typically involves a combination of research-based strategies, tools, and techniques derived from fields such as neuroscience, psychology, and peak performance coaching. It aims to help individuals identify and leverage their strengths, optimize their environment for flow, and cultivate the necessary mindset and skills to enter flow states more reliably.

The maximally transformative process often includes elements such as:

  1. Flow Triggers: Identifying specific triggers or conditions that reliably induce flow states for an individual, such as clear goals, immediate feedback, and a balance between challenge and skill.
  2. Flow Cycles: Understanding the stages of the flow cycle (struggle, release, flow, and recovery) and learning to navigate through them effectively to maximize performance and growth.
  3. Psychological Skills Training: Developing mental skills such as focus, resilience, and mindfulness to enhance the ability to enter and sustain flow states under varying conditions.
  4. Environmental Optimization: Structuring one’s physical and social environment to minimize distractions, maximize motivation, and promote optimal conditions for flow.
  5. Feedback and Reflection: Cultivating a practice of self-awareness, reflection, and continuous learning to refine performance and maintain momentum over time.

The actual class was related to achieving this process. As I mentioned earlier, there was a registration process. Upon registration, one is contacted by a representative from RFC. The person who contacted me for a qualifying interview was Maleke Fuentes. He was amazing during the qualification process. He discussed his background and how he became involved with FRC. He was very forthcoming, and I directly asked if FRC accepted all applicants. He flatly stated – NO.

Once you are accepted, you are dropped into both virtual and live classes. Relative to this, the class operationally consists of a pod that meets twice weekly, and then you have 1:1 time with the respective coach.

My coach was the amazing Marcus Lefton. He was very forthcoming and extremely insightful. He openly shared his amazing background and was very candid in pod and 1:1 classes. Given his background, he led by example and proverbially “at his own dog food,” as they say in the software space. He could go vertically deep and horizontally in recommending operationally, physically, and psychologically, as the FRC is extremely life-changing.

The class is broken into deeper steps into the rabbit hole. As one would expect, this can become extremely self-referential, which is the goal of the class.

For instance, there is a class where we are given 90 seconds to write down at least 15 things YOU do well. I, in full transparency, fully failed. I got to about two, maybe three. In one of Stephen Kotler’s books, he stated to write down 25 things you do well. It is difficult. Further, the suggestions and they are brutal in many cases are counter-intuitive, and they work.

Near the end of the class, we had a 1:1, during which we really drilled down into “my” Maximally Transformative Process. He was extremely candid and stated, “Ted, you are usually the shaman and or the genie that grants everyone else’s wishes. Now the genie is standing before you, asking you what you truly want?” i was very taken back as i don’t think in these terms. i just amplify folks at best.

i have not been the same since. Thank you Marcus.

In short, go look into the class. While it is not cheap, how much is your mental and physical health really worth?

As a wise man once said, “People who don’t need self-help books read them, and people who need them don’t read them.” This is usually the case here as all the folks in the pod i was included in were very performant.

The journey of the Flow Research Collective from Zero To Dangerous is a testament to the transformative power of flow. By unlocking the secrets of peak performance and sharing them with the world, the FRC is helping individuals tap into their innate potential and achieve extraordinary feats. One thing is clear as we look to the future: the flow revolution is just beginning, and the possibilities are limitless.

Personally, I can’t say enough about the class and people. Here is the link to the class -> Flow Research Class.

Go invest in yourself.

Until Then,

#iwishyouwater <- Cloudbreak from the surfing, waves and soundtrack.

Muzak To Blarg by : “Bach Synthesis: 15 Inventions”. Amazing.

Snake_Byte[15] Fourier, Discrete and Fast Transformers

The frequency domain of mind (a mind, it must be stressed, is an unextended, massless, immaterial singularity) can produce an extended, spacetime domain of matter via ontological Fourier mathematics, and the two domains interact via inverse and forward Fourier transforms.

~ Dr. Cody Newman, The Ontological Self: The Ontological Mathematics of Consciousness

I am Optimus Transformer Ruler Of The AutoCorrelation Bots

First i trust everyone is safe. i haven’t written technical blog in a while so figured i would write a Snake_Byte on one of my favorite equations The Fourier Transform:

    \[\hat{f} (\xi)=\int_{-\infty}^{\infty}f(x)e^{-2\pi ix\xi}dx\]

More specifically we will be dealing with the Fast Fourier Transform which is an implementation of The Discrete Fourier Transform. The Fourier Transform operates on continuous signals and while i do believe we will have analog computing devices (again) in the future we have to operate on 0’s and 1’s at this juncture thus we have a discrete version thereof. The discrete version:

    \[F(x) &= f\f[k] &= \sum_{j=0}^{N-1} x[j]\left(e^{-2\pi i k/N}\right)^j\0 &\leq k < N\]

where:

    \[f[k] &= f_e[k]+e^{-2\pi i k/N}f_o[k]\f[k+N/2] &= f_e[k]-e^{-2\pi i k/N}f_o[k]\]

The Discrete Fourier Transform (DFT) is a mathematical operation. The Fast Fourier Transform (FFT) is an efficient algorithm for the evaluation of that operation (actually, a family of such algorithms). However, it is easy to get these two confused. Often, one may see a phrase like “take the FFT of this sequence”, which really means to take the DFT of that sequence using the FFT algorithm to do it efficiently.

The Fourier sequence is a kernel operation for any number of transforms where the kernel is matched to the signal if possible. The Fourier Transform is a series of sin(\theta) and cos(\theta) which makes it really useful for audio and radar analysis.

For the FFT it only takes O(n\log{}n) for the sequence computation and as one would imagine this is a substantial gain. The most commonly used FFT algorithm is the Cooley-Tukey algorithm, which was named after J. W. Cooley and John Tukey. It’s a divide and conquer algorithm for the machine calculation of complex Fourier series. It breaks the DFT into smaller DFTs. Other FFT algorithms include the Rader’s algorithm, Winograd Fourier transform algorithm, Chirp Z-transform algorithm, etc. The only rub comes as a function of the delay throughput.

There have been amazing text books written on this subject and i will list them at the end of the blarg[1,2,3]

So lets get on with some code. First we do the usual houskeeping on import libraries as well as doing some majik for inline display if you are using JupyterNotebooks. Of note ffpack which is a package of Fortran subroutines for the fast Fourier transform. It includes complex, real, sine, cosine, and quarter-wave transforms. It was developed by Paul Swarztrauber of the National Center for Atmospheric Research, and is included in the general-purpose mathematical library SLATEC.

# House keeping libraries imports and inline plots:
import numpy as np
from scipy import fftpack
%matplotlib inline
import matplotlib.pyplot as pl

We now set up some signals where we create a sinusoid with a sample rate. We use linspace to set up the amplitude and signal length.

#frequency in cycles per second or Hertz
#this is equivalent to concert A

Frequency = 20 
# Sampling rate or the number of measurements per second
# This is the rate of digital audio

Sampling_Frequency = 100 

# set up the signal space:
time = np.linspace(0,2,2 * Sampling_Frequency, endpoint = False)
signal = np.sin(Frequency * 2 * np.pi * time)

Next we plot the sinusoid under consideration:

# plot the signal:
fif, ax = plt.subplots()
ax.plot(time, signal)
ax.set_xlabel('Time [seconds]')
ax.set_ylabel('Signal Amplitude')

Next we apply the Fast Fourier Transform and transform into the frequency domain:

X_Hat = fftpack.fft(signal)
Frequency_Component = fftpack.fftfreq(len(signal)) * Sampling_Frequency

We now plot the transformed sinusoid depicting the frequencies we generated:

# plot frequency components of the signal:
fig, ax = plt.subplots()
ax.stem(Frequency_Component, np.abs(X_Hat)) # absolute value of spectrum
ax.set_xlabel ('Frequency in Hertz [HZ] Of Transformed Signal')
ax.set_ylabel ('Frequency Domain (Spectrum) Magnitude')
ax.set_xlim(-Sampling_Frequency / 2, Sampling_Frequency / 2)
ax.set_ylim(-5,110)

To note you will see two frequency components, this is because there are positive and negative (real and imaginary) components to the transform which is what we see using the stem plots as expected. This is because the kernel as mentioned before is both sin(\theta) and cos(\theta).

So something really cool happens when using the FFT. It is called the convolution theorem as well as Dual Domain Theory. Convolution in the time domain yields multiplication in the frequency domain. Mathematically, the convolution theorem states that under suitable conditions the Fourier transform of a convolution of two functions (or signals) is the poin-twise (Hadamard multiplication) product of their Fourier transforms. More generally, convolution in one domain (e.g., time domain) equals point-wise multiplication in the other domain (e.g., frequency domain).

Where:

    \[x(t)*h(t) &= y(t)\]

    \[X(f) H(f) &= Y(f)\]

So there you have it. A little taster on the powerful Fourier Transform.

Until Then,

#iwishyouwater <- Cloudbreak this past year

Muzak To Blarg by: Voyager Essential Max Ricther. Phenomenal. November is truly staggering.

References:

[1] The Fourier Transform and Its Applications by Dr Ronald N Bracewell. i had the honor of taking the actual class at Stanford University from Professor Bracewell.

[2] The Fourier Transform and Its Applications by E. Roan Brigham. Graet book on butterfly and overlap-add derivations thereof.

[3] Adaptive Digital Signal Processing by Dr. Claude Lindquist. A phenomenal book on frequency domain signal processing and kernel analysis. A book ahead of its time. Professor Lindquist was a mentor and had a direct effect and affect on my career and the way i approach information theory.

¿Por qué haces apnea? (Why Do You Freedive?) and 9/11

Me Manifesting And Searching (photo by @clay.motus.liquidum)

I need the sea because it teaches me. I don’t know if I learn music or awareness, if it’s a single wave or its vast existence, or only its harsh voice or its shining suggestion of fishes and ships. The fact is that until I fall asleep, in some magnetic way I move in
the university of the waves.

~ Pablo Neruda

First i trust everyone is safe. Second today is a day that will live forever in most minds as a day that i call ‘When Belief Systems Run Amuck (WBSRA)”.

To those who lost loves ones on 9.11 my condolences. To those who are permanently scarred may peace eventually see its’ way unto and into you.

It is not random that one of my dear friends “JH” is relocating this very week to Charleston, SC. He was in the North tower on the 87th floor when the “WBSRA” occurred.

He is a great human. We are going to have a blast when he gets here.

Recently more than ever humans around me have been talking more and more about “stuff” they do besides “working” and inevitably as we are discussing these outside work endeavors someone mentions that i freedive.

Clay T. Talley Rappelling Underwater (photo Tanner Peterson @depthwishfreediving)

It goes something like this:

Human: Ted freedives.

Everyone: ( looking at me like i have obtained the classified UAP documents from the All-domain Anomaly Resolution Office (AARO)…)

Me: Yup.

Human: Wow really?

Me: (thinking… No i just lie about stuff like that…) Why Yes i do.

Me and @clay.motus.liquidum (photo courtesy of @depthwishfreediving)

Human: Have you seen “Deepest Breath” On Netflix?

Me: While i do not watch hardly any TV i did view it and yes it was amazing. The people in that video are the best of the best in the world and i have met one or two of them and have been coached and critiqued by some of them. i’m no where in their league.

Human: So really is it one breath? There must be some trick? How long can you hold your breath? How deep do you go?

Me: Yes, No, about 4:00+ minutes and i have broken 100ft . None of it really matters as the folks who are great, i pale in comparison, but it is a starting point. It is also not a contest with others. While there are competitions the only competitor is you and the water.

Me coming up from looking at the sand somewhere (photo courtesy of @depthwishfreediving)

Human: What is it like?

Me: It is truth. If there is a truth to life it is closer to living with the exception at least for me, what i find in surfing. Although the two are very different, the results, from to time, are the same. Complete un-adulterated FLOW STATE. The free fall is very close to getting a full tube ride. It is all enveloping it is not like meditating as some people think it is, although, there is a somnambulistic component to the free fall.

Clay Talley and Jacob Talley the day Jacob was certified (photo courtesy of @depthwishfreediving)

Human: What is freefall?

Me: That is after you get down to about 14 meters which is around 45 feet that is 3 atmospheres of pressure you start getting pulled down the elevator shaft as i call it. You can feel the water rushing by you and the sounds rushing, depending on if your hooked to a line or just letting your hand brush the dive line. Then as you go deeper it gets more enveloping.

Me: See your Mammalian Dive Reflect kicks in, your MDR, the master switch as it were. The sensors are still in our face. This is why it feels so nice to splash water on your face or take a shower. All those negative ions getting you balanced into BlueMind. There is much we have forgotten as a race. There is an excellent book called BlueMind i highly recommend.

Me, Thomas Tanner (@itstomfoolery) and My Nephew, Ty Tanner (@tytanner_) the day they got certified

(photo courtesy of @depthwishfreediving)

Human: Yea but how can you hold your breath that long?

Me: Practice. Actually it all happened in one weekend at Performance Freediving Institute (PFI). Me and my waterman commrade Clay Talley went down on a Friday and took a class after we read a book called “One Breath” and got turned onto a song called “Waves” by Bahamas. We have been training with weights in the pool for about 15 years for surfing then this freediving wonderland rabbit hole came along. We could easily get you to over a 2:30 breath hold in one day. Nothing prepared us for what was to come.

Human: I don’t see how that is possible.

Me: Well, i suppose with an attitude like that nothing is possible, but at least we gave it the benefit of the doubt and when we got certified. It was really intense due to several factors that i would have to explain later. However by far my certification was in one of the top experiences of my life and about as close to a religious experience as one could get.

My Son Thomas Tanner getting certified with Tanner Peterson Lower Left (photo courtesy of @tctjr)

Then then THE question:

Human: Why do you do it?

Me: Do what? Freedive?

Human: Yes.

This, Oh Dear Reader is where we start getting to the essence of the blog. Hope Y’all are still tuned-in to the channel.

To every sailor the gods have given a comrade
While one sleeps the other keeps watch on the bridge
When one doubts the other gives him his faith
When one falls the other discovers the oasis of ice for both of them
When my comrade loses faith I laugh confidently
When my comrade sleeps I keep watch for him
When my comrade falls I fight on for the both of us
Because to every sailor the gods have given a comrade

~ Blood Axis

Me: Well it is complicated. One of my best friends died freediving. He was one of the few people who really knew me and and happened to be the best coding computer scientist i have ever met, as well as an expert Waterman.

Me wondering what the Puppies are Thinking. (photo courtesy @clay.motus.luquidum)

Human: Oh i had no idea i am so sorry.

Me: Oh please no need for condolences. i’ll never get over it but that is a different issue. That said to answer your question i got into it because i wanted to understand how one of the smartest most fit watermen i have ever met came to his demise doing what he loved. i had to know or at least try to understand what Steven was searching for given i knew him so well.

It’s not tragic to die doing something you love.

~ Mark Foo

Me: See i kinda blew it off years ago when he kept talking about freediving and how incredible it was and in fact the last thing he said to me was he was really happy. That is really all i cared about to be honest. However it still nagged at me about there was a facet of “The Water” i hadn’t addressed.

So through a very seemingly random occurrence which to me wasn’t random at all i ran across the book “One Breath” which was a story of the death of one of the greatest freedivers of all time. So we (me and my commrade Clay Talley) finally got around to getting down so to speak and since then it has been a continual Alice in Wonderland – Down The Rabbit Hole. Besides the fact that you burn about 800-1000 calories an hour freediving it only teaches you more about yourself. It is indeed a fractal situation – the more complex – the more complex – the more simple – the more simple.

Me ascending and hanging out in Bonaire with Carlos Coste

(photo courtesy of @carloscoste1 of @blueclassroom and @freediveeexplorations)

Ted, Its all in Your Mind, Get me? Understand What I am saying?!

~ Cole Heitt

Me: Its really a super performant sport. All of the people that i have met have been physicists, composers, lawyers, bankers, technical folks and many have walked away from those careers in full pursuit of freediving. Everyone is very open, welcoming and focused. There is little to no overhead with some of the crap that you get with other sports endeavors, it is very binary. As an aside i personally want to dive with Sperm Whales.

Human: Yes but what about your friend?

Me: Well if i could have a discussion with him first i would punch him for being stupid then i would hug him, tell him i love him and say lets go for a freedive and this time i’ll be up and you be down.

Clay Talley Searching For Clay T. Talley

Me: Feel free to come down and get in the pool or we can take you down and get certified.

Human: Really?

Me: Of course and you can’t blame me for what will happen afterward.

To everyone that has ever asked me this is why i freedive. I needed to understand why and it has turned into a mirror for me.

On September 11, 2005, Steven Swenson took his last breath. However i know he was happy in fact the happiest i have ever heard him.

Recently his favorite musician past away, Jimmy Buffett. Steven’s favorite song was Son of A Son of A Sailor. He also liked “That is What Living Is to Me” and “One Particular Harbor”. I would like to think they are sharing sailing stories with each other with wind in their hair and water in their shoes.

Do me a favor if you knew him go listen to any of those songs and if you didn’t know him go listen and raise a glass to the ocean. i would also greatly appreciate it.

Mickey Talley @mich.888 Pushing Past Her Own Thoughts (photo courtesy @clay.motus.liquidum)

So there you have it folks.

Until Then,

#iwishyouwater <- Me and Present Crew Getting After it @iwishyouwater

@tctjr

Music To Blog By: The version of “Little Wing/ Third Stone: From The Sun off SRV archives and some Jimmy Buffett. The Tuck and Patti version of Castles Made of Sand / Little Wing is amazing as well.

Note: With Much Love to Roma, Lief and Gage.

Quality Over Quantity (Part D’eux)

Determination, energy, and courage appear spontaneously when we care deeply about something. We take risks that are unimaginable in any other context.

Margaret J. Wheatley

First i trust everyone is safe. Second sometimes the LazyWebTM can actually be a really cool place. Someone out there used an amazing thing called a LARGE LANGUAGE MODEL AKA ARTIFICIAL INTELLIGENCE to make a song out of a book passage that closely relates to my previous blog on Quality Over Quantity. The book is entitled The Greatest Salesman In The World. Here is that passage:

“I will persist until I succeed.

I was not delivered unto this world in defeat, nor does failure course in my veins. I am not a sheep waiting to be prodded by my shepherd. I am a lion and I refuse to talk, to walk, to sleep with the sheep. I will hear not those who weep and complain, for their disease is contagious. Let them join the sheep. The slaughterhouse of failure is not my destiny.

I will persist until I succeed.

The prizes of life are at the end of each journey, not near the beginning; and it is not given to me to know how many steps are necessary in order to reach my goal. Failure I may still encounter at the thousandth step, yet success hides behind the next bend in the road. Never will I know how close it lies unless I turn the corner.

Always will I take another step. If that is of no avail I will take another, and yet another. In truth, one step at a time is not too difficult.

I will persist until I succeed.”1

Then they “told” ChatGPT the person(s) behind the green curtain to write a metal song using the above passage:

(Verse 1)
Hear my mantra echo, “Persist until success,
Born not to the world in defeat, nor failure’s caress.
Not a sheep in the herd, prodded, guided by the rest,
I am the lion roaring, refusal in my chest.

(Chorus)
I won’t be moved by tears and whines, their sickness I’ll resist,
In the abattoir of failure, I’ll never coexist.
The end of every journey hides the precious prize,
One more step around the bend, where success quietly lies.

(Verse 2)
Step by step, relentless, no distance is too great,
Every challenge faced is just another weight.
My efforts like the blade, the mighty oak I strike,
Insignificant they seem, but will fell the tree in time.

(Chorus)
Like rain that washes mountains, the ant that feasts on tigers bold,
I am the star that lights the earth, the tale that’s yet untold.
Building castles, brick by brick, with each repeated trial,
Persist until I succeed, in my journey, every mile.

(Bridge)
Defeat is not a concept, its words I shall erase,
Quitting, failure, impossible, all fall from grace.
Obstacles may rise, despair may cloud the way,
Yet above it all, my gaze is fixed, where greener pastures lay.

(Chorus)
Persist until I succeed, let this anthem ring,
Born a lion, not a sheep, to my purpose, I will cling.
Journey’s end may hide the prize, step by step I’ll tread,
In the echoes of the night, let my mantra be heard and said.

(Outro)
I will persist until I succeed, etched in stars, this creed,
For I am the lion roaring, fulfilling every need.
The end of every journey hides the precious prize,
Persist until I succeed, echoes my eternal cry.

The book talks about The Art Of Living wherein there is the World’s Greatest Salesmen who was given some scrolls he must past to another person who he must identify with as being the keeper of the scrolls. The book goes into depth and each chapter is a scroll. A teaching if you will for being the world’s greatest salesmen so you as being the reader are immersed into this world.

Maybe someone will put some music to these words. i was thinking something like a Thin Lizzy feel if you will.

Until Then,

#iwishyouwater. <- WSL Live. Teahpoo Tahiti.

tctjr.

  1. OG Mandino: The Greatest Salesman In the World also referring to the #ArtOfLiving a class created by McConaughey and Tony Robbins ↩︎

Quality Over Quantity

Dalle’s Idea of Quality Over Quantity

Be a yardstick of quality.

Some people aren’t used to an environment where excellence is expected.

S. Jobs

First i hope this finds everyone safe. Second, your humble narrator has been incognito of late and re-emerged safe and sound as the CTO of a really cool company called BigBear.ai . Third, for some reason or another several folks have been talking to me about risks and reward in life as of late. i haven’t written a blarg in a while so i figured i would take the time to jot down some thoughts.

i dedicate this blarg to my parents. Here is why.

A long time ago in a land far away i lived in a modest ranch style house in Charleston,SC and in the den area there was a sign that said:

It is better to live one year as a lion than 20 years as a chicken.

Anonymous

This is a modified quote that can be tracked to several people in history. i am by no means referencing any political or religious views herewith so please check yourself. Someone somewhere could play the same music and someone would hate them for it on the internet.

i read this everyday coming in and out of the house and it had a profound effect on me later in life. Without me even knowing it i gravitated towards living on the creative side or maker side of life or let’s say risk taking side of life.

If you obey all the rules, you’ll miss all the fun.

Katheryn Hepburn

In the same fashion, for some unknown reason, people have been asking or talking to me about the creative process as well as having hobbies that appear to be risk taking.

For the record i don’t view anything that i do as a i hobby nearly as dangerous as driving. i’ll probably do a blarg on one activity everyone seems to be asking about is freediving but that isnt the subject of this blarg.

Life is to be lived folks. Social norms keep many from going and doing and living a life they DREAM. i hear you saing: “Well you know how it is life gets in the way.” Nope boys and girls your brain gets in the way and says “Oh you could never do that what would people think?”. “My <insert person here> would just disown me.”

What if you do it and you are truly happy?

The other thing people have been saying to me lately is “How’d you do that?” Well i just went and did it. Once again someone somewhere isn’t going to like whatever you do and you can’t please everyone so you might as well please yourself as the song says. (Rick Nelson – Garden Party).

Most people who really care about you just want you to be happy. They might not like or agree with you when letting your freak flag fly or even imagine how you could live in such a manner but i guarantee you show up to those you love truly happy then everything will be really OK. This is on YOU as it is on THEM. This is a two way street folks. You choose a difficult path not everyone is going to be “accepting”. The road will be strewn with stones to your path of righteousness. Trust me – Caveat Emptor.

The goal is living in a high quality life over a mundane mediocre life. The moments that take your breath away versus the number of breaths in a life. Where do you see a coffee table book entitled “Lives Of The Mediocre.”

Which is very closely related to the creation process. Putting yourself out there is scary. “Yes but i don’t have the courage or the skills.” You know what? Neither did anyone else who went and did The Thing.

Go do the thing that scares you the most then get the courage. That fine line is living. In fact it has been my experience it is a near life experience. Standing at the edge and looking down. Where you even surprise yourself.

“Yea but what if something goes wrong?”

Once again great question. It will. Yes Oh Dear Reader it will but guess what sitting in the recliner or couch every night for the rest of your life or looking out the window and thinking “I wish i would have done…” is way more painful than either pissing someone off for a little while or a broken leg, All will heal with love and happiness.

So put me on a highway
Show me a sign
Take it to the limit
One more time

The Eagles

Recently after a lengthy discussion about risk taking, mental gymnastics or physical hobbies someone asked me about my injuries. Here is a partial list:

Right shoulder replaced, Plates and 8 screws in my right forearm, Two left shoulder reconstructions, Two hip replacements, Broken right ankle and leg twice, Broke ribs, hernia operation, broken nose, cracked back, whiplashes, concussions, the list goes on…

Why would someone put themselves through this? I don’t know sounds like a startup co-founder huh? Because you MUST.

Because living at that level of passion is everything. There is nothing else. Because you know what? The crash is almost as amazing as making it! Quality Over Quantity Folks!

Taking this view In sports, companies and most importantly your relationships is crucial. Most will say they cannot live like that and they do not understand. Well just hand them a big cup of NOPE YA CAN’T. They will get very frustrated as well. Most people of that nature want their predictable life and the ability to dictate to others their lives.

So this morning i called my parents. Luckily both my parents are alive and very married. I told them thank you for having that sign in the den and it would be great if they could find the sign. They informed me it “wore out”. Get the symbology there? They said they had toted it from house to house.

After hanging up i went online to everyone’s favorite online retailer and bought this for my home gym:

Because i needed a reminder. Just like when i was a kid.

Enjoy it while you can
It’s just like the weather
So quit complaining brother
No one lives forever

Let’s have a party there’s a full moon in the sky
It’s the hour of the wolf and I don’t want to’ die

Oingo Boingo

So go create, make, live, and love like there is no tomorrow. You and the people around you will be better off and you will definitely find out who loves you when you are truly happy. Trust me in this area of life you will not have many if any followers just those who truly desire you to be happy.

Until Then,

#iwishyouwater <- near life at Mavericks in 2022.

@tctjr

Muzak To Blag By: Danny Elfman’s “Big Mess”. He is truly a genius. Yes the same person who created Oingo Boingo and all of the great soundtracks.

NOTE: i can also recommend several books on these views such as Tim Ferris’ “Tools For Titans” and Rolo May’s “The Courage To Create”, hit me up on the comments if you want more. Also please tell me a story where you put yourself out there. i’d love it hear about it.

What Is Love?

DALLE’s Idea Of Love

Love is a complex and multifaceted emotion that is often defined differently depending on cultural, social, and individual perspectives. At its core, love typically involves strong feelings of affection, caring, and attachment towards another person, often accompanied by a desire for intimacy, closeness, and mutual support.

Love can take many different forms, including romantic love, familial love, platonic love, and self-love. It can also involve a range of different experiences, such as joy, happiness, excitement, passion, and sometimes even pain and heartbreak.

Ultimately, love is a powerful and transformative force that can have a profound impact on our lives, shaping our relationships, beliefs, and sense of self.

~ ChatGPT

First Oh Dear Reader, i trust you are safe. Second, we are taking a slight detour into squishy, non-exact, messy, and truly complicated land: Emotions. This comes on the heels of Snake_Byte[14] Coding In Philosophical Frameworks. Also if you haven’t seen the news, the Cognitive Computing Arms Race with Large Language Models is in full swing. Boy Howdy Do We Love Us Some Anthropomorphism! ( i personally think its funny the parlor trick of auto-typing makes ChatGPT and all the other ones appear human to most. )

Turns out there is a class at Stanford on Computational Philosophy which is in the same realm as what i would love to discuss however slightly obtuse. It is a good read.

If we can compute Philosophical frameworks, could we or do we need to compute emotions in the future?

It was not random i started with the terseness of Stoicism. As this philosophy trends towards being objective in your emotions, akin to a more recent philosophy, “Objectivism.” We can quantify the aspects thereof. Or at least we think we can quantify them to some extent.

We know from a physiological standpoint that bodily metrics and chemicals can be measured for systematic responses to emotions. Dopamine, Vasopressin, Oxytocin, Serotonin, heart rate, sweat level, skin clamminess, and eye dilation are just a few measurable considerations.

However what does it mean?

Let’s take some bookend emotions: Love, Hate, Fear.

Some consider Fear to be the only true emotion. Flight or Fight. i’m also positive we can duplicate this in a machine or at least make it plausible to appear the machine is scared. (Also, it will make humans “feel” better one day but that is for a different discussion and different blog.)

Being that Spring Is In The Air let us choose LOVE.

There are so many types and kinds of Love.

  • Love of a Mother to a child
  • The Love you have for your pets
  • The Love of eating a doughnut.

i’m not referring to these types i am referencing:

  • You are the Love of My Life Companionship – Love

Books, signs, poetry, and yes, humans’ most deplorable creation War has been created over Love of Another. It is genuinely innate in the Human_Condition.

People acting a fool, if you will. You have seen it many times, and maybe (hopefully) you have done it.

As the famous song says, “What does love have to do with IT? What is love but some secondhand emotion?”. Great questioning Tina. We love you.

Have you ever been in The Love? How do you know that person Loves YOU?

i asked one of my progeny that question:

Me: “Do i Love you?”

Them: “Yes.”

Me” “How do you know?”

Them: “Dad i just know.”

This is not to be confused with infatuation, which is in and of itself an extremely intense feeling usually associated with a physically idealized version of the receiving person. Infatuation is initially overwhelming but then quickly fades. Love, on the other hand, appears to be a much deeper, almost seemingly “infinite forever-giving” emotion.

i was wondering how many times “Love” has been mentioned over the years. Below is a plot thereof:

Love Over The Years

i thought the drop in the 1980’s was interesting. If anyone was around in the United States in the 80’s that was the period of certain illegal chemicals, neon, 80’s metal and madonna. The Me Generation.

So what has happened in this area with using technology of Love? Well we scan our noggin:

From The Journal of Frontiers in Human Neuroscience

When I take you in my arms gathered forever. Sometimes it feels like a dream. Sometimes it feels like a dream; to be with you.

~ Feels Like A Dream Lyrics

Research has shown that certain brain regions are activated when a person is in love or experiencing strong feelings of affection, including the insula, anterior cingulate cortex, and striatum. These regions are associated with reward, motivation, and emotional processing. Brain scans have also revealed that the levels of certain neurotransmitters, like dopamine and oxytocin, can change in response to being in love. So while there is no one-size-fits-all image of someone in love, there are certain brain patterns and chemical changes that can be detected in those experiencing the emotion.

Furthermore on the chemical brain related activity research has shown that during the early stages of romantic love, there is a decrease and increase in serotonin levels in the brain[1]. Serotonin can have direct affects on anxiety, insomnia and depression. For men there is a decrease and for women and increase in serotonin. Strangely this is similar to what is observed in individuals with obsessive-compulsive disorder, suggesting that the intense focus and preoccupation with the loved one may be related to changes in serotonin levels. Additionally, it has been found that long-term couples who remain in love have higher levels of serotonin than those who have fallen out of love. This suggests that serotonin may play a role in maintaining long-term relationships.

Our study provides the first evidence of love-related alterations in the underlying architecture of the brain, and the results shed new light on the mechanisms of romantic love.

~ Professor Xiaochu Zhang

So if there are (and there are injectable adjuncts to all of these chemicals) that can be augmented and tailored with specific dosages, this led me to ask the questions:

  • can we compute a model of Love?
  • can we fool the brain into thinking it is in Love?
  • do we want to augment the brain so we feel like we are in Love?
  • Do we want to make Love a thing of the past with future tech?
  • The list could go on…..

 Did my heart love till now? Forswear it, sight / For I ne’er saw true beauty till this night.

~ That Romeo Guy

When people meet, go on a date, shack up, get hitched or get married, i have heard it said:

  • “You will grow to love them.”
  • “Well, the person doesn’t really have the attributes i am looking for in a mate, but i can adapt.”
  • “They share the same interest as you!”
  • “They can cook or fix stuff for you!”

Why would we want to change or have that person change? Are social norms so strong that there are unwritten rules that we as a so-called society must follow, With a hard rule of it must be two consenting adults in a relationship, what is it of anyone’s business? Do most want to do what they feel they should do? Do we want a best friend to watch the big game with or play golf? Why not a companion that you can dance with now and when your old and just look at each other? To idealized? Oh life gets in the way. i see it is hard and you have stuff to do – yep i get it. Then is Love that important? If not then what is?

Love in a relationship is it needed?

How do you know when you’re really in Love? Do violins play when you’re touching the one your Lovin?

~ The Tubes

Most often, love is due to their connection with their partner. This connection can be emotional, physical, spiritual, or intellectual (or hopefully all of them). People may also fall in love or grow into love because they appreciate their partner’s qualities or values, such as kindness, honesty, or intelligence. Sometimes, people are drawn to others who are different from themselves because they find them intriguing or exciting.

This room is bare
This night is cold
We’re far apart, and I’m growing old
But while we live
We’ll meet again
So then, my love
We may whisper once more
It’s you I adore

~ Palabras de Amor from Queen

Other factors that contribute to love include shared experiences, common interests, and mutual respect. When people feel like they’re a team with their partner and can rely on them, it can deepen their love. Additionally, physical attraction and chemistry can significantly influence romantic love.

However, what if it is all of these with the same partner? Isn’t that what you truly desire? ALL THE THINGS! To truly know that there is one – what would you do to have that person show up on your porch?

This is what i believe we need to understand as we trend toward a world of distributed disconnected artificial intelligence.

In one kiss, you’ll know all I haven’t said.

~ Pablo Neruda[3]

Even post the pandemic, we see people hug and kiss less. There is less physicality which as we all know for most, a hug feels good for both and releases several proof-positive chemicals. i would tend to think at some point you want to rub against your significant other instead of smooching in cyberspace or sleeping in separate beds.

Is Love now an algorithm? i know in the age of match.com and tinder this appears to be monday morning quarterbacking but at least i believe there is something more to it than a list of attributes. In fact one of the startups i worked at started with the premise, “What are the three main questions you ask someone on a blind date?” Here they are:

  • What is your favorite travel spot?
  • What is your favorite wine (assuming one drinks)
  • What type of music do you like?
DALLE Generated Endless Love

From a cognitive standpoint the most difficult one was music recommendations. This by the way Oh Dear Reader was circa 2001 before Pandora, Shazam or any other music recommendation system. We based it on a cognitive model of music perception and cognitive psychology of inter-relations[2].

If we already know the future and can match it aren’t we living in a world of no surprises? What happens to that special glance? That special smile or touch or a good morning hug? That true everlasting one that loves you for you and only you not because your father mother or your in-laws approved. (If course it has been said you marry the family not the person. )

i am sure by now you have heard of the term Twin Flame. This is different than a soul mate. A Twin Flame is a mirror of oneself, a yin-yang type entity. The biggest distinction between a twin flame and any other type of soul mate is that twin flames are two halves of the same whole. A soul mate, on the other hand, can be thought of as someone cut from the same cloth as you. There’s a deep familiarity, and you feel very close, but you aren’t the same soul.

i wonder if we can compute and create a Twin Flame Agent of oneself?

i’m not sure i want to work on those future algorithms folks. Some things i want to be a mystery[4].

i’d love to hear some stories, comments, and possibly even rants as this is some very esoteric area we have paddled into so to speak. i’d love to know if you have the love of your life, twin flame or a tinder swipe of the night, i hope you just know.

Until Then,

#iwshyouwater <- alexy molchanov sets a new world record in Bonaire. i was just in the same spot freediving.

Muzak To Blog By: All The Love Songs by Queen. i miss you Freddy and recently brian may was knighted.

References:

[1] Scans Say Its True Love Link

[2] For the record, i tried the system, and no one liked strict cathedral organ works.

[3] Pablo Neruda is the most prolific poet when it comes to love and beaches i have ever read. there is a connection there.

[4] In blade runner, harrison ford knows full well racheal is a replicant yet he Loves her. Question is – Is He? That would be a twin flame. robot love.

Snake_Byte:[14] Coding In Philosophical Frameworks

Dalle-E Generated Philospher

Your vision will only become clear when you can look into your heart. Who looks outside, dreams; who looks inside, awakes. Knowing your own darkness is the best method for dealing with the darknesses of other people. We cannot change anything until we accept it.

~ C. Jung

(Caveat Emptor: This blog is rather long in the snakes tooth and actually more like a CHOMP instead of a BYTE. tl;dr)

First, Oh Dear Reader i trust everyone is safe, Second sure feels like we are living in an age of Deus Ex Machina, doesn’t it? Third with this in mind i wanted to write a Snake_Byte that have been “thoughting” about for quite some but never really knew how to approach it if truth be told. I cant take full credit for this ideation nor do i actually want to claim any ideation. Jay Sales and i were talking a long time after i believe i gave a presentation on creating Belief Systems using BeliefNetworks or some such nonsense.

The net of the discussion was we both believed that in the future we will code in philosophical frameworks.

Maybe we are here?

So how would one go about coding an agent-based distributed system that allowed one to create an agent or a piece of evolutionary code to exhibit said behaviors of a philosophical framework?

Well we must first attempt to define a philosophy and ensconce it into a quantized explanation.

Stoicism seemed to me at least the best first mover here as it appeared to be the tersest by definition.

So first those not familiar with said philosophy, Marcus Aurelius was probably the most famous practitioner of Stoicism. i have put some references that i have read at the end of this blog1.

Stoicism is a philosophical school that emphasizes rationality, self-control, and inner peace in the face of adversity. In thinking about this i figure To build an agent-based software system that embodies Stoicism, we would need to consider several key aspects of this philosophy.

  • Stoics believe in living in accordance with nature and the natural order of things. This could be represented in an agent-based system through a set of rules or constraints that guide the behavior of the agents, encouraging them to act in a way that is in harmony with their environment and circumstances.
  • Stoics believe in the importance of self-control and emotional regulation. This could be represented in an agent-based system through the use of decision-making algorithms that take into account the agent’s emotional state and prioritize rational, level-headed responses to stimuli.
  • Stoics believe in the concept of the “inner citadel,” or the idea that the mind is the only thing we truly have control over. This could be represented in an agent-based system through a focus on internal states and self-reflection, encouraging agents to take responsibility for their own thoughts and feelings and strive to cultivate a sense of inner calm and balance.
  • Stoics believe in the importance of living a virtuous life and acting with moral purpose. This could be represented in an agent-based system through the use of reward structures and incentives that encourage agents to act in accordance with Stoic values such as courage, wisdom, and justice.

So given a definition of Stoicism we then need to create a quantized model or discrete model of those behaviors that encompass a “Stoic Individual”. i figured we could use the evolutionary library called DEAP (Distributed Evolutionary Algorithms in Python ). DEAP contains both genetic algorithms and genetic programs utilities as well as evolutionary strategy methods for this type of programming.

Genetic algorithms and genetic programming are both techniques used in artificial intelligence and optimization, but they have some key differences.

This is important as people confuse the two.

Genetic algorithms are a type of optimization algorithm that use principles of natural selection to find the best solution to a problem. In a genetic algorithm, a population of potential solutions is generated and then evaluated based on their fitness. The fittest solutions are then selected for reproduction, and their genetic information is combined to create new offspring solutions. This process of selection and reproduction continues until a satisfactory solution is found.

On the other hand, genetic programming is a form of machine learning that involves the use of genetic algorithms to automatically create computer programs. Instead of searching for a single solution to a problem, genetic programming evolves a population of computer programs, which are represented as strings of code. The programs are evaluated based on their ability to solve a specific task, and the most successful programs are selected for reproduction, combining their genetic material to create new programs. This process continues until a program is evolved that solves the problem to a satisfactory level.

So the key difference between genetic algorithms and genetic programming is that genetic algorithms search for a solution to a specific problem, while genetic programming searches for a computer program that can solve the problem. Genetic programming is therefore a more general approach, as it can be used to solve a wide range of problems, but it can also be more computationally intensive due to the complexity of evolving computer programs2.

So returning back to the main() function as it were, we need create a genetic program that models Stoic behavior using the DEAP library,

First need to define the problem and the relevant fitness function. This is where the quantized part comes into play. Since Stoic behavior involves a combination of rationality, self-control, and moral purpose, we could define a fitness function that measures an individual’s ability to balance these traits and act in accordance with Stoic values.

So lets get to the code.

To create a genetic program that models Stoic behavior using the DEAP library in a Jupyter Notebook, we first need to install the DEAP library. We can do this by running the following command in a code cell:

pip install deap

Next, we can import the necessary modules and functions:

import random
import operator
import numpy as np
from deap import algorithms, base, creator, tools

We can then define the problem and the relevant fitness function. Since Stoic behavior involves a combination of rationality, self-control, and moral purpose, we could define a fitness function that measures an individual’s ability to balance these traits and act in accordance with Stoic values.

Here’s an example of how we might define a “fitness function” for this problem:

# Define the fitness function.  NOTE: # i am open to other ways of defining this and other models
# the definition of what is a behavior needs to be quantized or discretized and 
# trying to do that yields a lossy functions most times.  Its also self referential

def fitness_function(individual):
    # Calculate the fitness based on how closely the individual's behavior matches stoic principles
    fitness = 0
    # Add points for self-control, rationality, focus, resilience, and adaptability can haz Stoic?
    fitness += individual[0]  # self-control
    fitness += individual[1]  # rationality
    fitness += individual[2]  # focus
    fitness += individual[3]  # resilience
    fitness += individual[4]  # adaptability
    return fitness,

# Define the genetic programming problem
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)

# Initialize the genetic algorithm toolbox
toolbox = base.Toolbox()

# Define the genetic operators
toolbox.register("attribute", random.uniform, 0, 1)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attribute, n=5)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("evaluate", fitness_function)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=0.1, indpb=0.1)
toolbox.register("select", tools.selTournament, tournsize=3)

# Run the genetic algorithm
population = toolbox.population(n=10)
for generation in range(20):
    offspring = algorithms.varAnd(population, toolbox, cxpb=0.5, mutpb=0.1)
    fits = toolbox.map(toolbox.evaluate, offspring)
    for fit, ind in zip(fits, offspring):
        ind.fitness.values = fit
    population = toolbox.select(offspring, k=len(population))
    
# Print the best individual found
best_individual = tools.selBest(population, k=1)[0]

print ("Best Individual:", best_individual)
 

Here, we define the genetic programming parameters (i.e., the traits that we’re optimizing for) using the toolbox.register function. We also define the evaluation function (stoic_fitness), genetic operators (mate and mutate), and selection operator (select) using DEAP’s built-in functions.

We then define the fitness function that the genetic algorithm will optimize. This function takes an “individual” (represented as a list of five attributes) as input, and calculates the fitness based on how closely the individual’s behavior matches stoic principles.

We then define the genetic programming problem via the quantized attributes, and initialize the genetic algorithm toolbox with the necessary genetic operators.

Finally, we run the genetic algorithm for 20 generations, and print the best individual found. The selBest function is used to select the top individual fitness agent or a “behavior” if you will for that generation based on the iterations or epochs. This individual represents an agent that mimics the philosophy of stoicism in software, with behavior that is self-controlled, rational, focused, resilient, and adaptable.

Best Individual: [0.8150247518866958, 0.9678037028949047, 0.8844195735244268, 0.3970642186025506, 1.2091810770505023]

This denotes the best individual with those best balanced attributes or in this case the Most Stoic,

As i noted this is a first attempt at this problem i think there is a better way with a full GP solution as well as a tunable fitness function. In a larger distributed system you would then use this agent as a framework amongst other agents you would define.

i at least got this out of my head.

until then,

#iwishyouwater <- Alexey Molchanov and Dan Bilzerian at Deep Dive Dubai

Muzak To Blog By: Phil Lynott “The Philip Lynott Album”, if you dont know who this is there is a statue in Ireland of him that i walked a long way with my co-founder, Lisa Maki a long time ago to pay homage to the great Irish singer of the amazing band Thin Lizzy. Alas they took Phil to be cleaned that day. At least we got to walk and talk and i’ll never forget that day. This is one of his solo efforts and i believe he is one of the best artists of all time. The first track is deeply emotional.

References:

[1] A list of books on Stoicism -> click HERE.

[2] Genetic Programming (On the Programming of Computers by Means of Natural Selection), By Professor John R. Koza. There are multiple volumes i think four and i have all of this but this is a great place to start and the DEAP documentation. Just optimizing a transcendental functions is mind blowing what GP comes out with using arithmetic

Snake_Byte:[13] The Describe Function.

DALLE-2 Draws Describe

First i trust everyone is safe. Second i hope people are recovering somewhat from the SVB situation. We are at the end of a era, cycle or epoch; take your pick. Third i felt like picking a Python function that was simple in nature but very helpful.

The function is pandas.describe(). i’ve previously written about other introspection libraries like DABL however this is rather simple and in place. Actually i never had utilized it before. i was working on some other code as a hobby in the areas of transfer learning and was playing around with some data and decided to to use the breast cancer data form the sklearn library which is much like the iris data used for canonical modeling and comparison. Most machine learning is data cleansing and feature selection so lets start with something we know.

Breast cancer is the second most common cancer in women worldwide, with an estimated 2.3 million new cases in 2020. Early detection is key to improving survival rates, and machine learning algorithms can aid in diagnosing and treating breast cancer. In this blog, we will explore how to load and analyze the breast cancer dataset using the scikit-learn library in Python.

The breast cancer dataset is included in scikit-learn's datasets module, which contains a variety of well-known datasets for machine learning. The features describe the characteristics of the cell nuclei present in the image. We can load the dataset using the load_breast_cancer function, which returns a dictionary-like object containing the data and metadata about the dataset.

It has been surmised that machine learning is mostly data exploration and data cleaning.

from sklearn.datasets import load_breast_cancer
import pandas as pd

#Load the breast cancer dataset
data = load_breast_cancer()

The data object returned by load_breast_cancer contains the feature data and the target variable. The feature data contains measurements of 30 different features, such as radius, texture, and symmetry, extracted from digitized images of fine needle aspirate (FNA) of breast mass. The target variable is binary, with a value of 0 indicating a benign tumor and a value of 1 indicating a malignant tumor.

We can convert the feature data and target variable into a pandas dataframe using the DataFrame constructor from the pandas library. We also add a column to the dataframe containing the target variable.

#Convert the data to a pandas dataframe
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = pd.Series(data.target)

Finally, we can use the describe method of the pandas dataframe to get a summary of the dataset. The describe method returns a table containing the count, mean, standard deviation, minimum, and maximum values for each feature, as well as the count, mean, standard deviation, minimum, and maximum values for the target variable.

#Use the describe() method to get a summary of the dataset
print(df.describe())

The output of the describe method is as follows:

mean radius  mean texture  ...  worst symmetry      target
count   569.000000    569.000000  ...      569.000000  569.000000
mean     14.127292     19.289649  ...        0.290076    0.627417
std       3.524049      4.301036  ...        0.061867    0.483918
min       6.981000      9.710000  ...        0.156500    0.000000
25%      11.700000     16.170000  ...        0.250400    0.000000
50%      13.370000     18.840000  ...        0.282200    1.000000
75%      15.780000     21.800000  ...        0.317900    1.000000
max      28.110000     39.280000  ...        0.663800    1.000000

[8 rows x 31 columns]

From the summary statistics, we can see that the mean values of the features vary widely, with the mean radius ranging from 6.981 to 28.11 and the mean texture ranging from 9.71 to 39.28. We can also see that the target variable is roughly balanced, with 62.7% of the tumors being malignant.

Pretty nice utility.

Then again in looking at this data one would think we could get to first principles engineering and root causes and make it go away? This directly affects motherhood which i still believe is the hardest job in humanity. Makes you wonder where all the money goes?

Until then,

#iwishyouwater <- Free Diver Steph who is also a mom hunting pelagics on #onebreath

Muzak To Blog By Peter Gabriel’s “Peter Gabriels 3: Melt (remastered). He is coming out with a new album. Games Without Frontiers and Intruder are timeless. i applied long ago to work at Real World Studios and received the nicest rejection letter.