Saturday, January 13, 2024

Can you give the example of an odd integrand and prove that it is odd?

Example of an odd integrand and it's proof.

Certainly! Let's consider the function f ( x ) = x 3 f(x) = x^3 . We'll integrate this function over a symmetric interval, say [ a , a ] [-a, a] , and then show that the result is zero, proving that f ( x ) f(x) is an odd function.

The integral is given by:

a a x 3 d x \int_{-a}^{a} x^3 \,dx

To evaluate this integral, we'll use the properties of odd functions. An odd function f ( x ) f(x) satisfies f ( x ) = f ( x ) f(-x) = -f(x) . Let's evaluate f ( x ) f(-x) for f ( x ) = x 3 f(x) = x^3 :

f ( x ) = ( x ) 3 = x 3 f(-x) = (-x)^3 = -x^3

Now, compare f ( x ) f(-x) with f ( x ) -f(x) :

f ( x ) = x 3 -f(x) = -x^3

As we can see, f ( x ) = f ( x ) f(-x) = -f(x) . This property holds for all values of x x .

Now, let's calculate the integral:

a a x 3 d x = 1 4 x 4 a a \int_{-a}^{a} x^3 \,dx = \frac{1}{4}x^4 \Big|_{-a}^{a}

= 1 4 ( a 4 ( a ) 4 ) = \frac{1}{4}(a^4 - (-a)^4)

= 1 4 ( a 4 a 4 ) = \frac{1}{4}(a^4 - a^4)

= 1 4 ( 0 ) = \frac{1}{4}(0)

= 0 = 0

The result is zero, which means that the integral of the odd function f ( x ) = x 3 f(x) = x^3 over the symmetric interval [ a , a ] [-a, a] is zero. This demonstrates that f ( x ) = x 3 f(x) = x^3 is an odd function.

Friday, January 12, 2024

Gaussian Integral: Integrate exp(-x^2) from -infinite to +infinite

Integrate exp(-x^2) from -infinite to +infinite

Note: this integral is also known as Gaussian integral.

The integral of ex2e^{-x^2} from -\infty to ++\infty is a well-known mathematical constant and is denoted by π\sqrt{\pi}. The integral is often expressed as:

ex2dx=π\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}

This result is commonly encountered in probability theory and statistics, especially in the context of the normal distribution. The integral doesn't have a simple elementary function representation and is typically solved using advanced mathematical techniques. The proof involves the use of polar coordinates and complex analysis.

Some of the mathematical results and properties we will use today:

Note (1):

I = Integral of f(x) w.r.t. dx
Then I^2 = Integral of f(x).f(y) w.r.t. dxdy

Note (2): Well known step:

When changing to polar coordinates from (x, y) to (r, theta):

# (dx dy) changes to (r dr dtheta) 

Note (3): Well known trigonometric property:

sq(sin(theta)) + sq(cos(theta)) = 1

Note (4):

(integral of e^(x)) = e^(x)

The result that folows from this is: (integral of e^(-x)) = -e^(-x)

Fig 1:
Fig 2:

Thursday, January 11, 2024

What this book (Why We Meditate) offers you (Chapter 1)

Translate this page:

Why We Meditate: The Science And Practice of Clarity and Compassion
CH 1: WHAT THIS BOOK OFFERS YOU

A word about the authors:

Who is Tsoknyi Rinpoche?

Tsoknyi Rinpoche is a Tibetan Buddhist teacher and the spiritual head of the Pundarika Foundation. He was born in 1966 in Nubri, Nepal, and is a renowned meditation master and author. Tsoknyi Rinpoche is part of the Nyingma school of Tibetan Buddhism, which is one of the oldest schools of Tibetan Buddhism.

Tsoknyi Rinpoche comes from a long line of meditation masters, and he received extensive training in both the Kagyu and Nyingma traditions. He is known for his accessible and humorous teaching style, making ancient Buddhist wisdom relevant and applicable to contemporary audiences.

Who is Daniel Goleman?

Daniel Goleman is an American psychologist and science journalist best known for his work on emotional intelligence. He was born on March 7, 1946, in Stockton, California. Goleman earned his PhD in psychology from Harvard University.

He gained widespread recognition with the publication of his book "Emotional Intelligence: Why It Can Matter More Than IQ" in 1995. In this influential book, Goleman explores the concept of emotional intelligence and argues that it is a crucial factor in personal and professional success. He contends that emotional intelligence, which includes skills like self-awareness, self-regulation, empathy, and interpersonal skills, plays a significant role in determining a person's effectiveness in various aspects of life.

Apart from his work on emotional intelligence, Goleman has written extensively on topics related to psychology, education, and leadership. Some of his other notable books include "Social Intelligence," "Working with Emotional Intelligence," and "Focus: The Hidden Driver of Excellence."

This book is for you:

(1) if you have been considering starting meditation and are not sure why you should or how to begin;

(2) if you are meditating but wonder why or what to do next to progress;

(3) or if you already are a convinced meditator and want to help someone you care about get going, by giving them this book.

Tags: Psychology,Buddhism,Book Summary,

Wednesday, January 10, 2024

Why Write about Emotional Upheaval? (Chapter 1)

Translate this page:





Emotional Writing: A Brief History

Figure 1. Yearly physician visits for illness among people who report not having had a childhood trauma (No Trauma), having had one or more traumas about which they confided (Trauma — Confide), or having had at least one significant childhood trauma that they had kept secret (Trauma — No Confide).

Figure 2. Yearly number of physician visits for illness in the three months after the experiment for participants in the emotional writing and control (non-emotional writing) conditions.

The No Writing data is based on students who did not participate in the experiment.

What Are the Effects of Writing?

Biological effects

The immune system.

The body’s immune system can function more or less effectively, depending on the person’s stress level.

Studies find that emotional writing is associated with general enhancement in immune function [1]

Medical markers of health.

Expressive writing finds usage in tracking general / overall health of the patient of any illness.

[1]: Koschwanez et al., 2013; Pennebaker, Kiecolt-Glasser & Glasser 1988; Lumley et al. 2011

Physiological indicators of stress

Somewhat surprisingly, while people write or talk about traumas, they often show immediate signs of reduced stress: lower muscle tension in their face, and drops in hand skin conductance (often used in lie detection to measure the stress of deception and also easily measured with readily available Biodot® skin thermometers). Immediately after writing about emotional topics, people have lower blood pressure and heart rates.

Psychological Effects

# Mood changes immediately after writing: Feeling sad is normal.

# Long-term mood changes.

Writing may make you sad for a brief time after writing, but the long-term effects are far more positive.

Behavioral Changes

# Performance at school or work:

Among beginning college students, expressive writing helps people adjust to their situation better.

# Working Memory

Working memory is the technical term for our general ability to think about complex tasks. If we are worrying about things — including emotional upheavals from the past — we have less working memory.

Expressive writing, we now know, frees working memory, allowing us to deal with more complicated issues in our lives (Klein & Boals 2001).

Students who did expressive writing about upcoming exams reported improved mood prior to their exams and improved performance (Dalton & Glenwick 2009; Frattaroli, Thomas, & Lyubomirsky 2011).

Dealing with our social lives.

Working with other people can sometimes be a daunting psychological task. The more emotional stress we are under, the more draining it is. Recent studies have suggested that expressive writing can enhance the quality of our social lives.

Writing Style

Some ways of writing appear to work better than others do. Recent studies by multiple labs are converging on some common guidelines. People tend to benefit most from expressive writing if they:

Openly acknowledge emotions.

Emotional experience is part of a trauma. The ability to feel and label both the negative and the positive feelings that occurred during and following the trauma is important.

Work to construct a coherent story.

Immediately after a trauma, things often seem out of control and disconnected. One goal of expressive writing is to begin to put things together again. One way of accomplishing this is to make a meaningful story of what happened and how it is affecting you. Many argue that the brain is a narrative organ and that story-making is hardwired into our very nature. Creating a narrative, including a coherent beginning, middle, and end, is a well-documented part of trauma treatment and holds much promise for benefits from writing about trauma.

Switch perspectives.

People who have experienced a trauma initially see it from one perspective — their own. Indeed, when individuals first write about a massive upheaval, they first describe what they saw, felt, and experienced. Recent studies indicate that people who benefit the most from writing have been able to see events through others’ eyes. Indeed, even writing about a personal event in the third person has proven beneficial (Andersson & Conley 2013; Campbell & Pennebaker 2003; Seih et al. 2011).

Find your voice.

A guiding principle of expressive writing is that you express yourself openly and honestly. People who write in a cold, detached manner and who quote Shakespeare, Aristotle, or Henry Ford may be fine historians and may even write a great editorial in the local newspaper. But impressive writing is not the point of expressive writing. People who benefit the most from writing are able to find a voice that reflects who they are.

Tags: Book Summary,Psychology,

Tuesday, January 9, 2024

Genomic Range Query: Find the minimal nucleotide from a range of sequence DNA (Medium Complexity)

Problem

A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has an impact factor, which is an integer. Nucleotides of types A, C, G and T have impact factors of 1, 2, 3 and 4, respectively. You are going to answer several queries of the form: What is the minimal impact factor of nucleotides contained in a particular part of the given DNA sequence?

The DNA sequence is given as a non-empty string S = S[0]S[1]...S[N-1] consisting of N characters. There are M queries, which are given in non-empty arrays P and Q, each consisting of M integers. The K-th query (0 ≤ K < M) requires you to find the minimal impact factor of nucleotides contained in the DNA sequence between positions P[K] and Q[K] (inclusive).

Write a function:

def solution(S, P, Q)

that, given a non-empty string S consisting of N characters and two non-empty arrays P and Q consisting of M integers, returns an array consisting of M integers specifying the consecutive answers to all queries.

Result array should be returned as an array of integers.

Write an efficient algorithm for the following assumptions:

N is an integer within the range [1..100,000];

M is an integer within the range [1..50,000];

each element of arrays P and Q is an integer within the range [0..N - 1];

P[K] ≤ Q[K], where 0 ≤ K < M;

string S consists only of upper-case English letters A, C, G, T.

Example

For example, consider string S = CAGCCTA and arrays P, Q such that:

P[0] = 2 Q[0] = 4

P[1] = 5 Q[1] = 5

P[2] = 0 Q[2] = 6

The answers to these M = 3 queries are as follows:

The part of the DNA between positions 2 and 4 contains nucleotides G and C (twice), whose impact factors are 3 and 2 respectively, so the answer is 2.

The part between positions 5 and 5 contains a single nucleotide T, whose impact factor is 4, so the answer is 4.

The part between positions 0 and 6 (the whole string) contains all nucleotides, in particular nucleotide A whose impact factor is 1, so the answer is 1.

The function should return the values [2, 4, 1], as explained above.

Brute Force Solution

def solution(S, P, Q):
    impact_factors = {
        'A': 1,
        'C': 2,
        'G': 3,
        'T': 4
    }

    X = [impact_factors[i] for i in S]

    # Implement your solution here
    rtn = []
    for i in range(len(P)):
        start = P[i]
        end = Q[i] + 1

        s = X[start:end]

        rtn.append(min(s))

    return rtn 

Detected time complexity:

O(N * M)

Smart Solution Using Prefix Sums (Part 1)

def solution(S, P, Q):
    N = len(S)
    M = len(P)

    impact_factors = {'A': 1, 'C': 2, 'G': 3, 'T': 4}

    # Calculate prefix sums for each nucleotide type
    prefix_sums = [[0] * (N + 1) for _ in range(4)]
    for i in range(1, N + 1):
        for j in range(4):
            prefix_sums[j][i] = prefix_sums[j][i - 1]
        prefix_sums[impact_factors[S[i - 1]] - 1][i] += 1
        print(i, S[i-1])
        print(prefix_sums)

    print(':1 ~ ~ ~ ~ ~ ~ ~ ~ ~')
    S = 'CAGCCTA'
    P = [2, 5, 0]
    Q = [4, 5, 6]
    print(solution(S, P, Q))  # Output: [2, 4, 1]

    print(':2 ~ ~ ~ ~ ~ ~ ~ ~ ~')
    print(solution('AGCT', [], []))

    print(':3 ~ ~ ~ ~ ~ ~ ~ ~ ~')
    print(solution('AACT', [], []))

This is a two part solution.

In the first part, we build prefix sum sequences for each nucleotide to track it’s occurrence.

Output (Part 1)

S = 'CAGCCTA'

:1 ~ ~ ~ ~ ~ ~ ~ ~ ~

1 C

[[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]

2 A

[[0, 0, 1, 0, 0, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]

3 G

[[0, 0, 1, 1, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]

4 C

[[0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 2, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]

5 C

[[0, 0, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 2, 3, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]

6 T

[[0, 0, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 2, 3, 3, 0], [0, 0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 1, 0]]

7 A

[[0, 0, 1, 1, 1, 1, 1, 2], [0, 1, 1, 1, 2, 3, 3, 3], [0, 0, 0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1]]

Output (Part 2)

For 'AGCT'

:2 ~ ~ ~ ~ ~ ~ ~ ~ ~

1 A

[[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

2 G

[[0, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]

3 C

[[0, 1, 1, 1, 0], [0, 0, 0, 1, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 0]]

4 T

[[0, 1, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 0, 1]]

For 'AACT'

:3 ~ ~ ~ ~ ~ ~ ~ ~ ~

1 A

[[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

2 A

[[0, 1, 2, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

3 C

[[0, 1, 2, 2, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

4 T

[[0, 1, 2, 2, 2], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]

Smart Solution Using Prefix Sums (Part 2)

def solution(S, P, Q):
    N = len(S)
    M = len(P)

    impact_factors = {'A': 1, 'C': 2, 'G': 3, 'T': 4}

    # Calculate prefix sums for each nucleotide type
    prefix_sums = [[0] * (N + 1) for _ in range(4)]
    for i in range(1, N + 1):
        for j in range(4):
            prefix_sums[j][i] = prefix_sums[j][i - 1]
        prefix_sums[impact_factors[S[i - 1]] - 1][i] += 1

    # Process queries
    result = []
    for k in range(M):
        start_position = P[k]
        end_position = Q[k] + 1

        for nucleotide_type in range(4):
            if prefix_sums[nucleotide_type][end_position] - prefix_sums[nucleotide_type][start_position] > 0:
                result.append(nucleotide_type + 1)
                break

    return result

    # Example usage:
    S = 'CAGCCTA'
    P = [2, 5, 0]
    Q = [4, 5, 6]
    print(solution(S, P, Q))  # Output: [2, 4, 1]

In the second part of the solution we determine from start to end if a low factor nucleotide is present or not.

Here, let seq_X be sequence from as in prefix_sums[nucleotide_type]

It takes the form:

seq_A: [0, 0, 1, 1, 1, 1, 1, 2],

seq_C: [0, 1, 1, 1, 2, 3, 3, 3],

seq_G: [0, 0, 0, 1, 1, 1, 1, 1],

seq_T: [0, 0, 0, 0, 0, 0, 1, 1]

For input sequence: CAGCCTA

Then from any of this seq, we determine whether if A is appearing between start and end using seq_A[end] - seq_A[start]

Or if C is appearing between start and end using:

seq_C[end] – seq_C[start]

Or if G is appearing between start and end using:

seq_G[end] – seq_G[start]

Or if T is appearing between start and end using:

seq_T[end] – seq_T[start]

If a nucleotide is found in this second part of the code, we record this nucleotide and break out.

Time Complexity

Detected time complexity:

O(N + M)

Tests

Correctness tests

extreme_sinlge

single character string

extreme_double

double character string

simple

simple tests

small_length_string

small length simple string

small_random

small random string, length = ~300

Performance tests

almost_all_same_letters

GGGGGG..??..GGGGGG..??..GGGGGG

large_random

large random string, length

extreme_large

all max ranges

Explanation of Code Using Bard

I'd be glad to explain the code you provided:

Here's a breakdown of the code's key steps:

  1. Initialization:

    • N stores the length of the DNA sequence S.
    • M stores the number of queries (the length of arrays P and Q).
    • impact_factors maps each nucleotide to its corresponding impact factor.
  2. Prefix Sums Calculation:

    • prefix_sums is a 2D array with 4 rows (one for each nucleotide type) and N+1 columns. It's used to store the counts of each nucleotide type up to each position in the DNA sequence.
    • The nested loops iterate through the DNA sequence and update prefix_sums accordingly:
      • The first loop iterates through each position in the sequence.
      • The second loop iterates through each nucleotide type.
      • For each position and nucleotide type, the code copies the count from the previous position and then increments the count if the current nucleotide matches the type.
  3. Query Processing:

    • result is an empty list to store the answers to the queries.
    • The outer loop iterates through each query, accessing its start and end positions from P and Q.
    • The inner loop iterates through each nucleotide type.
    • It checks if the count of the current nucleotide type within the query range (end_position - start_position) is greater than 0. If so, it means that nucleotide type is present within the range, and its impact factor is added to the result list. The loop then breaks because we've found the minimum impact factor for that query.
  4. Returning Results:

    • The function returns the result list containing the answers to all queries.

Example Usage:

  • The provided example demonstrates how to use the function with a sample DNA sequence S and query arrays P and Q.
  • The output [2, 4, 1] correctly represents the minimum impact factors for the specified query ranges in S.

Key Points:

  • The code efficiently calculates prefix sums to count the occurrences of each nucleotide type up to each position.
  • This precomputation allows for quick calculation of minimum impact factors within any query range, using simple subtractions of prefix sums.
  • The time complexity of the code is O(N + M), making it efficient for large DNA sequences and multiple queries.

Monday, January 8, 2024

Div Count (Problem on Prefix Sums)

Div Count Problem
Compute number of integers divisible by k in range [a..b].

Problem

Write a function:

def solution(A, B, K)

that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.:

{ i : A ≤ i ≤ B, i mod K = 0 }

For example, for A = 6, B = 11 and K = 2, your function should return 3, because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 and 10.

Write an efficient algorithm for the following assumptions:

# A and B are integers within the range [0..2,000,000,000];

# K is an integer within the range [1..2,000,000,000];

# A ≤ B

Code

from math import ceil, floor 

def solution(A, B, K):
    
    start = ceil(A/K)
    end = floor(B/K)
    return end - start + 1

Complexity

Detected time complexity:

O(1)

Tests

Correctness tests

simple

A = 11, B = 345, K = 17

minimal

A = B in {0,1}, K = 11

extreme_ifempty

A = 10, B = 10, K in {5,7,20}

extreme_endpoints

verify handling of range endpoints, multiple runs

Performance tests

big_values

A = 100, B=123M+, K=2

big_values2

A = 101, B = 123M+, K = 10K

big_values3

A = 0, B = MAXINT, K in {1,MAXINT}

big_values4

A, B, K in {1,MAXINT}

Passing Cars (Count the number of passing cars on the road) - Problem on Prefix Sums

Passing Cars
Count the number of passing cars on the road.
Problem on Prefix Sums

Problem

A non-empty array A consisting of N integers is given. The consecutive elements of array A represent consecutive cars on a road.

Array A contains only 0s and/or 1s:

0 represents a car traveling east,

1 represents a car traveling west.

The goal is to count passing cars. We say that a pair of cars (P, Q), where 0 ≤ P < Q < N, is passing when P is traveling to the east and Q is traveling to the west.

Write a function:

def solution(A)

that, given a non-empty array A of N integers, returns the number of pairs of passing cars.

The function should return −1 if the number of pairs of passing cars exceeds 1,000,000,000.

Write an efficient algorithm for the following assumptions:

N is an integer within the range [1..100,000];

each element of array A is an integer that can have one of the following values: 0, 1.

Example

For example, consider array A such that:

A[0] = 0

A[1] = 1

A[2] = 0

A[3] = 1

A[4] = 1

We have five pairs of passing cars: (0, 1), (0, 3), (0, 4), (2, 3), (2, 4).

For example, given:

the function should return 5, as explained above.

Hint

Code (I)

def solution(A):
    # In the question, it is given that 0 are travelling east. We assume it to be the direction of prefix sums.
    # So if we implement using prefix counts, we would have to count zeroes.

    # '1' is going to the west, that is having the direction of suffix sums.

    prefix_counts = [0] * (len(A) + 1)

    for i in range(len(A)):
        if A[i] == 0:
            prefix_counts[i+1] = prefix_counts[i] + 1
        else:
            prefix_counts[i+1] = prefix_counts[i] + 0

    passing_cars = 0 
    for i in range(len(A)):
        if A[i] == 1:
            passing_cars += prefix_counts[i+1]

    if passing_cars > 1000000000:
        passing_cars = -1

    return passing_cars

Code (II): Now Using Suffix Sums

def solution(A):
    # In the question, it is given that 0 are traveling east. We assume it to be the direction of prefix sums.

    # '1' is going to the west, that is having the direction of suffix sums.
    # So if we implement using suffix counts, we would have to count ones.

    suffix_counts = [0] * (len(A) + 1)

    for i in range(len(A) - 1, -1, -1):
        if A[i] == 1:
            suffix_counts[i] = suffix_counts[i+1] + 1
        else:
            suffix_counts[i] = suffix_counts[i+1] + 0

    passing_cars = 0 
    for i in range(len(A)):
        if A[i] == 0:
            passing_cars += suffix_counts[i]

    if passing_cars > 1000000000:
        passing_cars = -1

    return passing_cars

Time Complexity

Detected time complexity:

O(N)

Tests

Correctness tests

single element

double

two elements

simple

simple test

small_random

random, length = 100

small_random2

random, length = 1000

Performance tests

medium_random

random, length = ~10,000

large_random

random, length = ~100,000

large_big_answer

0..01..1, length = ~100,000

large_alternate

0101..01, length = ~100,000

large_extreme

large test with all 1s/0s, length = ~100,000

I am what I think I am (Chapter 1)

 In 1902, the sociologist Charles Horton Cooley wrote: “I am not what I think I am, and I am not what you think I am. I am what I think you think I am.”
Let that blow your mind for a moment.
Our identity is wrapped up in what others think of us—or, more accurately, what we think others think of us.
Not only is our self-image tied up in how we think others see us, but most of our efforts at self-improvement are really just us trying to meet that imagined ideal. If we think someone we admire sees wealth as success, then we chase wealth to impress that person. If we imagine that a friend is judging our looks, we tailor our appearance in response. In West Side Story, Maria meets a boy who's into her.
What's her very next song? “I Feel Pretty.”

~ ~ ~

When you try to live your most authentic life, some of your relationships will be put in jeopardy. Losing them is a risk worth bearing; finding a way to keep them in your life is a challenge worth taking on.

~ ~ ~

IS THIS DUST OR IS IT ME?

Gauranga Das offered me a beautiful metaphor to illustrate the external influences that obscure our true selves. We are in a storeroom, lined with unused books and boxes full of artifacts. Unlike the rest of the ashram, which is always tidy and well swept, this place is dusty and draped in cobwebs. The senior monk leads me up to a mirror and says, “What can you see?” Through the thick layer of dust, I can't even see my reflection. I say as much, and the monk nods. Then he wipes the arm of his robe across the glass. A cloud of dust puffs into my face, stinging my eyes and filling my throat. He says, “Your identity is a mirror covered with dust. When you first look in the mirror, the truth of who you are and what you value is obscured. Clearing it may not be pleasant, but only when that dust is gone can you see your true reflection.” This was a practical demonstration of the words of Chaitanya, a sixteenth- century Bengali Hindu saint. Chaitanya called this state of affairs ceto-darpaṇa- mārjanam, or clearance of the impure mirror of the mind. The foundation of virtually all monastic traditions is removing distractions that prevent us from focusing on what matters most—finding meaning in life by mastering physical and mental desires. Some traditions give up speaking, some give up sex, some give up worldly possessions, and some give up all three. In the ashram, we lived with just what we needed and nothing more. I experienced rsthand the enlightenment of letting go. When we are buried in nonessentials, we lose track of what is truly significant. I'm not asking you to give up any of these things, but I want to help you recognize and filter out the noise of external influences. This is how we clear the dust and see if those values truly reflect you. Guiding values are the principles that are most important to us and that we feel should guide us: who we want to be, how we treat ourselves and others. Values tend to be single-word concepts like freedom, equality, compassion, honesty. That might sound rather abstract and idealistic, but values are really practical. They're a kind of ethical GPS we can use to navigate through life. If you know your values, you have directions that point you toward the people and actions and habits that are best for you. Just as when we drive through a new area, we wander aimlessly without values; we take wrong turns, we get lost, we're trapped by indecision. Values make it easier for you to surround yourself with the right people, make tough career choices, use your time more wisely, and focus your attention where it matters. Without them we are swept away by distractions.

WHERE VALUES COME FROM

Our values don't come to us in our sleep. We don't think them through consciously. Rarely do we even put them into words. But they exist nonetheless. Everyone is born into a certain set of circumstances, and our values are defined by what we experience. Were we born into hardship or luxury? Where did we receive praise? Parents and caregivers are often our loudest fans and critics. Though we might rebel in our teenage years, we are generally compelled to please and imitate those authority gures. Looking back, think about how your time with your parents was spent. Playing, enjoying conversation, working on projects together? What did they tell you was most important, and did it match what mattered most to them? Who did they want you to be? What did they want you to accomplish? How did they expect you to behave? Did you absorb these ideals, and have they worked for you? From the start, our educations are another powerful influence. The subjects that are taught. The cultural angle from which they are taught. The way we are expected to learn. A fact-driven curriculum doesn't encourage creativity, a narrow cultural approach doesn't foster tolerance for people from different backgrounds and places, and there are few opportunities to immerse ourselves in our passions, even if we know them from an early age. This is not to say that school doesn't prepare us for life—and there are many different educational models out there, some of which are less restrictive—but it is worth taking a step back to consider whether the values you carried from school feel right to you.

TRY THIS: WHERE DID YOUR VALUES COME FROM?

It can be hard to perceive the effect these casual influences have on us. Values are abstract, elusive, and the world we live in constantly pushes blatant and subliminal suggestions as to what we should want, and how we should live, and how we form our ideas of who we are. Write down some of the values that shape your life. Next to each, write the origin. Put a checkmark next to each value that you truly share.
VALUE ORIGIN IS IT TRUE TO ME?
Kindness Parent
Appearance Media Not in the same way
Wealth Parent No
Good grades School Interfered with real learning
Knowledge School
Family Tradition Family: yes, but not traditional
When we tune out the opinions, expectations, and obligations of the world around us, we begin to hear ourselves. ~ ~ ~

AUDIT YOUR LIFE

No matter what you think your values are, your actions tell the real story. What we do with our spare time shows what we value. For instance, you might put spending time with your family at the top of your list of values, but if you spend all your free time playing golf, your actions don't match your values, and you need to do some self-examination. Time TRY THIS: AUDIT YOUR TIME Spend a week tracking how much time you devote to the following: family, friends, health, and self. (Note that we're leaving out sleeping, eating, and working. Work, in all its forms, can sprawl without boundaries. If this is the case for you, then set your own definition of when you are “officially” at work and make “extra work” one of your categories.) The areas where you spend the most time should match what you value the most. Say the amount of time that your job requires exceeds how important it is to you. That's a sign that you need to look very closely at that decision. You're deciding to spend time on something that doesn't feel important to you. What are the values behind that decision? Are your earnings from your job ultimately serving your values? Media When you did your audit, no doubt a significant amount of your time was spent reading or viewing media. Researchers estimate that, on average, each of us will spend more than eleven years of our lives looking at TV and social media! Perhaps your media choices feel casual, but time reflects values. Money Like time, you can look at the money you spend to see the values by which you live. Exclude necessities like home, dependents, car, bills, food, and debt. Now look at your discretionary spending. What was your biggest investment this month? Which discretionary areas are costing you the most? Does your spending correspond to what matters most to you? We often have an odd perspective on what's “worth it” that doesn't quite make sense if you look at all your expenditures at once. I was advising someone who complained that the family was overspending on afterschool classes for the kids… until she realized that she spent more on her shoes than on their music lessons. Seeing posts on social media that compared spending and our priorities got me thinking about how the ways we spend our time and money reveal what we value. A 60-minute TV show (“Flew by!”) A 60-minute lunch with family (“Will it ever end!”) Everyday coffee habit ($4/day, almost $1,500/year) (“Need it!”) Fresh healthy food choices (an extra 1.50/day, about $550/year) (“Not worth it!”) 15 minutes scrolling social media (“Me time!”) 15 minutes of meditation (“No time!”) It's all in how you see it. When you look at a month of expenses, think about whether discretionary purchases were long- or short-term investments—a great dinner out or a dance class? Were they for entertainment or enlightenment, for yourself or someone else? If you have a gym membership, but only went once this month and spent more on wine, you have some rethinking to do.

CURATE YOUR VALUES

TRY THIS: PAST VALUES Reflect on the three best and three worst choices you've ever made. Why did you make them? What have you learned? How would you have done it differently? TRY THIS: VALUE-DRIVEN DECISIONS For the next week, whenever you spend money on a nonnecessity or make a plan for how you will spend your free time, pause, and think: What is the value behind this choice? It only takes a second, a flash of consideration. Ideally, this momentary pause becomes instinctive, so that you are making conscious choices about what matters to you and how much energy you devote to it. TRY THIS: COMPANION AUDIT Over the course of a week, make a list of the people with whom you spend the most time. List the values that you share next to each person. Are you giving the most time to the people who align most closely with your values?

Sunday, January 7, 2024

Exercise 1.1 On Linear Equations for Regression - From Pattern Recognition and ML - By Christopher Bishop

Pre-read
Question
Solution from web
My Explanation
Tags: Technology,Machine Learning,Mathematical Foundations for Data Science,

Exercise 1.2 On Regularization in Linear Regression - Pattern Recognition and ML - By Christopher Bishop

Pre-read for exercise 1.1:
Pre-read for exercise 1.2:
Problem 1.2:
Solution for problem 1.2: Pg 1:
Pg 2:
Pg 3:
Pg 4:

Exercise 1.3 on 'sum rule and product rule of probability' (From the book Pattern Recognition and ML by Christopher Bishop)

Let's quiz you for the basic concepts of probability theory by considering a simple example. 
    
Imagine we have two boxes, one red and one blue, and in the red box we have 2 apples and 6 oranges, and in the blue box we have 3 apples and 1 orange.

This is illustrated in Figure 1.9. Now suppose we randomly pick one of the boxes and from that box we randomly select an item of fruit, and having observed which sort of fruit it is we replace it in the box from which it came. We could imagine repeating this process many times. 

Let us suppose that in so doing we pick the red box 40% of the time and we pick the blue box 60% of the time, and that when we remove an item of fruit from a box we are equally likely to select any of the pieces of fruit in the box.

In this example, the identity of the box that will be chosen is a random variable, which we shall denote by B. This random variable can take one of two possible values, namely r (corresponding to the red box) or b (corresponding to the blue box). Similarly, the identity of the fruit is also a random variable and will be denoted by F . It can take either of the values a (for apple) or o (for orange).

To begin with, we shall define the probability of an event to be the fraction of times that event occurs out of the total number of trials, in the limit that the total number of trials goes to infinity. Thus the probability of selecting the red box is 4/10 and the probability of selecting the blue box is 6/10. We write these probabilities as: 
p(B = r) = 4/10 and p(B = b) = 6/10. 

Note that, by definition, probabilities must lie in the interval [0, 1]. Also, if the events are mutually exclusive and if they include all possible outcomes (for instance, in this example the box must be either red or blue), then we see that the probabilities for those events must sum to one.

We can now ask questions such as: 
“what is the overall probability that the selection procedure will pick an apple?”, 

or 

“given that we have chosen an orange, what's the probability that the box we chose was the blue one?”

We can answer questions such as these, and indeed much more complex questions associated with
problems in pattern recognition, once we have equipped ourselves with the two elementary rules of probability, known as the sum rule and the product rule. 

Sum Rule and Product Rule

Here p(X, Y ) is a joint probability and is verbalized as “the probability of X and Y ”. Similarly, the quantity p(Y |X) is a conditional probability and is verbalized as “the probability of Y given X”, whereas the quantity p(X) is a marginal probability and is simply “the probability of X”. Let us now return to our example involving boxes of fruit. For the moment, we shall once again be explicit about distinguishing between the random variables and their instantiations. We have seen that the probabilities of selecting either the red or the blue boxes are given by p(B = r) = 4/10 p(B = b) = 6/10 respectively. Note that these satisfy p(B = r) + p(B = b) = 1. Now suppose that we pick a box at random, and it turns out to be the blue box. Then the probability of selecting an apple is just the fraction of apples in the blue box which is 3/4, and so p(F = a|B = b) = 3/4. In fact, we can write out all four conditional probabilities for the type of fruit, given the selected box p(F = a|B = r) = 1/4 p(F = o|B = r) = 3/4 p(F = a|B = b) = 3/4 p(F = o|B = b) = 1/4

Practice Exercise

Suppose that we have three coloured boxes r (red), b (blue), and g (green). Box r contains 3 apples, 4 oranges, and 3 limes, box b contains 1 apple, 1 orange, and 0 limes, and box g contains 3 apples, 3 oranges, and 4 limes. If a box is chosen at random with probabilities p(r) = 0.2, p(b) = 0.2, p(g) = 0.6, and a piece of fruit is removed from the box (with equal probability of selecting any of the items in the box), then what is the probability of selecting an apple? If we observe that the selected fruit is in fact an orange, what is the probability that it came from the green box?

Solution

Ref: ChatGPT