## Some special functions

ANSI C99 and POSIX compliant compilers include functions tgamma and lgamma for computing the gamma function and its natural logarithm respectively. Visual Studio 2008, however, does not support these standards.

Found this fact during the last few weeks, so decided to explore these exotic mathematical functions which microsoft decided not to include in the visual studio 2008.

Gamma function computes the the gamma function,$\Gamma(x)$. The gamma function is a shifted version of the ordinary factorial, satisfying $\Gamma(n) = (n-1)!$ for integers $n > 0$. More generally, it is defined by
$\Gamma(x) = \int_0^{\infty} t^{x-1} e^{-t}\, dt$

for any real or complex $x$ with $\Re(x) > 0$ and for $\Re(x) < 0$ by analytic continuation.

LogGamma function computes the principal branch of the log-gamma function, $\ln \Gamma(z).$ Unlike $\ln(\Gamma(z))$, which has infinitely many complex branch cuts, the principal log-gamma function only has a single branch cut along the negative half-axis. The principal branch continuously matches the asymptotic Stirling expansion

$\ln \Gamma(z) \sim \frac{\ln(2 \pi)}{2} + \left(z-\frac{1}{2}\right) \ln(z) - z + O(z^{-1}).$

The real parts of both functions agree, but their imaginary parts generally differ by $2 n \pi$ for some $n \in \mathbb{Z}$.

They coincide for $z \in \mathbb{R}, z 0$.

Computationally, it is advantageous to use loggamma() instead of gamma() for extremely large arguments.

Error Functions

Computes the error function, $\mathrm{erf}(x)$. The error function is the normalized antiderivative of the Gaussian function $\exp(-t^2)$. More precisely,

$\mathrm{erf}(x) = \frac{2}{\sqrt \pi} \int_0^x \exp(-t^2) \,dt$

Scipy provides ton of special functions. The error functions, the gamma functions are part of them. All of them are found in the scipy.special module

So lets see how they look like.


import scipy.special as sp
import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(-4.5,6,6601)

# gamma function
g=sp.gamma(x)

# plot
f, ax = plt.subplots(figsize=(10,5))
ax.plot(x,g)
ax.grid(True)




# loggamma function

g=sp.gammaln(x)

#plot
f, ax = plt.subplots(figsize=(10,5))
ax.plot(x,g)
ax.grid(True)




# erf function

g=sp.erf(x)

# plot
f, ax = plt.subplots(figsize=(10,5))
ax.plot(x,g)
ax.grid(True)



## Quotes

Here are some quotes and text collected over last few months from books, blogs and online articles I have read ….

• The true measure of a man is how he treats someone who can do him absolutely no good. – Samuel Johnson
• Gossip represents a widespread, efficient, and low-cost form of punishment. – Matthew Feinberg, Joey Cheng, and Robb Willer
• You couldn’t squeeze a dime between what they already know and what they will never learn. -Philip Wylie
• I did not succeed in life by intelligence. I succeeded because I have a long attention span. – Charlie Munger
• Vision to see, courage to buy and patience to hold. – Tom Phelps on Investing
• We do not know what a thought is, yet we’re thinking them all the time. – Ani Tenzin Palmo
• If you take care of important things, the urgent things don’t show up as often. The opposite is never true. -Seth Godin
• The news we consume changes us. Not just the news manufactured by CNN, but the news manufactured by our boss, our investors, our customers. -SG
• The school education will help you earn a living, but self-education will make you a fortune – Anon
• You can do real work or go to meetings but you cannot do both. – Peter Drucker
• For the things we have to learn before we can do them, we learn by doing them. – Aristotle
• The more basic knowledge you have, the less new knowledge you have to get. – Charlie Munger
• Where is the knowledge we have lost in information? -T. S. Eliot
• Steamers which have the longest routes seek deepest waters. -CHARLES FRANKLIN THWING
• The dyer’s hand is not subdued to its materials; it is strengthened through materials for service. -CHARLES FRANKLIN THWING
• Thinking is a practical art. It cannot be taught. It is learned by doing. -CHARLES FRANKLIN THWING
• If a man will begin with certainties, he shall end in doubts; but if he will be content to begin with doubts, he shall end in certainties. – F. Bacon
• Games are won by players who focus on the field, not the ones looking at the scoreboard. – Warren Buffet
• It is the mark of an educated mind to be able to entertain a thought without accepting it. – Aristotle
• A doctor can bury his mistakes but an architect can only advise his clients to plant vines. -Frank Lloyd Wright
• I will prepare and someday my chance will come.- Abraham Lincoln
• Worldly wisdom teaches that it is better for reputation to fail conventionally than to succeed unconventionally. –Keynes
• I think it’s very important to have a feedback loop, where you’re constantly thinking about what you’ve done and how you could be doing it better – Elon Musk
• The rabbit runs faster than the fox, because the rabbit is running for his life while the fox is only running for his dinner. – R. Dawkins
• The behaviour you see is usually the result of incentives you don’t see. –Farnam Street
• Most geniuses-especially those who lead others-prosper not by deconstructing intricate complexities but by exploiting unrecognized simplicities. – Andy Benoit
• If you want to go fast, go alone. If you want to go far, go together. – old saying
• Ship before you’re ready, because you will never be ready. –Seth Godin
• Better place yourself or your wares where they can be seen. Then lay off. Give interest, curiosity, and natural friendliness, a chance to work. – Carl Franklin Braun
• Focus on things that will last – Endeavour
• Call me old-fashioned, but sometimes the optimal place for your light is hiding directly under a bushel – SAM HINKIE
•  Give me six hours to chop down a tree and I will spend the first four sharpening the axe. – Abraham Lincoln
• Whenever possible, I think cross pollinating ideas from other contexts is far, far better than attempting to solve our problems in basketball as if no one has ever faced anything similar. -SAM HINKIE
• You should take the approach that you’re wrong. Your goal is to be less wrong.- Tesla’s Elon Musk
• To develop truly contrarian views will require a never-ending thirst for better, more diverse inputs – SAM HINKIE
• So if we want to think like a scientist more often in life, those are the three key objectives—to be humbler about what we know, more confident about what’s possible, and less afraid of things that don’t matter. – Tim Urban
• A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die. -Max Planck

## Quick Gantt Chart with Matplotlib

The problem: You need a quick Gantt chart for a quick proposal report and you dint have any project planner software installed.

Solution:

While there are many different ways, you only have access to python, well Here’s a simple Gantt chart plotter with just matplotlib.

Not for rigorous use but a good substitute to make quick Gantt plot for quick report.

## Gravity doesn’t care

Woke up to this beautiful anecdote, can’t resist posting it here.

Stanford Professor Robert Burgelman once dropped his pen onto the floor in a lecture. He muttered as he stooped to pick it up, “I hate gravity.”

Then, as he walked to the blackboard to continue his line of thought, he added, “But do you know what? Gravity doesn’t care! It will always pull things down, and I may as well plan on it.”

## Biplot  in Python revisited.

Mark sent a recent email complaining  the previous biplot code not working. Though I was not able to replicate his errors,but from the error message figured the error was due to the PCA numbers supplied.

That reminded me of the simplification task that I intended to do on the previous version to make it work like it works in matlab.

No dependency on PCA data structure, send to variables, scores and coefficient and plot the biplot.

## How to choose a book vs how to google?

From the book Curious by Ian Leslie. Like the analogy of browsing a bookstore vs booking a train ticket.

Economist John Maynard Keynes once offered advice on how to conduct oneself in a bookstore: “A bookshop is not like a railway booking-office which one approaches knowing what one wants. One should enter it vaguely, almost in a dream, and allow what is there freely to attract and influence the eye. To walk the rounds of the bookshops, dipping in as curiosity dictates, should be an afternoon’s entertainment.”

This is far different from the advice you’d give someone on how to use Google, which, in Keynes’s terms, is more like a railway booking office—a place to visit when you know your destination.

## It’s there to serve you, not to guide you

My colleague is a hard core trader. He intellectually understands the Gardner mentality to investing but doesn’t believes in it.
Most of his investing is based on momentum and he trades on news.

With the recent crush his trades like many have decreased and he is daily looking at the market movement trying to guess if it will rebound or see a new lower bottom.

Today as we were discussing markets, got reminded of the following Berkshire letter of 1987 about market.

From: 1987 letter
Ben Graham, my friend and teacher, long ago described the mental attitude toward market fluctuations that I believe to be most conducive to investment success. He said that you should imagine market quotations as coming from a remarkably accommodating fellow named Mr. Market who is your partner in a private business. Without fail, Mr. Market appears daily and names a price at which he will either buy your interest or sell you his.

Even though the business that the two of you own may have economic characteristics that are stable, Mr. Market’s quotations will be anything but. For, sad to say, the poor fellow has incurable emotional problems. At times he feels euphoric and can see only the favorable factors affecting the business. When in that mood, he names a very high buy-sell price because he fears that you will snap up his interest and rob him of imminent gains.

At other times he is depressed and can see nothing but trouble ahead for both the business and the world. On these occasions he will name a very low price, since he is terrified that you will unload your interest on him.

Mr. Market has another endearing characteristic: He doesn’t mind being ignored. If his quotation is uninteresting to you today, he will be back with a new one tomorrow. Transactions are strictly at your option. Under these conditions, the more manic-depressive his behavior, the better for you.

But, like Cinderella at the ball, you must heed one warning or everything will turn into pumpkins and mice: Mr. Market is there to serve you, not to guide you. It is his pocketbook, not his wisdom, that you will find useful. If he shows up some day in a particularly foolish mood, you are free to either ignore him or to take advantage of him, but it will be disastrous if you fall under his influence. Indeed, if you aren’t certain that you understand and can value your business far better than Mr. Market, you don’t belong in the game. As they say in poker, “If you’ve been in the game 30 minutes and you don’t know who the patsy is, you’re the patsy.”

Ben’s Mr. Market allegory may seem out-of-date in today’s investment world, in which most professionals and academicians talk of efficient markets, dynamic hedging and betas. Their interest in such matters is understandable, since techniques shrouded in mystery clearly have value to the purveyor of investment advice. After all, what witch doctor has ever achieved fame and fortune by simply advising “Take two aspirins”?

The value of market esoterica to the consumer of investment advice is a different story. In my opinion, investment success will not be produced by arcane formulae, computer programs or signals flashed by the price behavior of stocks and markets. Rather an investor will succeed by coupling good business judgment with an ability to insulate his thoughts and behavior from the super-contagious emotions that swirl about the marketplace. In my own efforts to stay insulated, I have found it highly useful to keep Ben’s Mr. Market concept firmly in mind.

Following Ben’s teachings, Charlie and I let our marketable equities tell us by their operating results – not by their daily, or even yearly, price quotations – whether our investments are successful. The market may ignore business success for a while, but eventually will confirm it. As Ben said: “In the short run, the market is a voting machine but in the long run it is a weighing machine.” The speed at which a business’s success is recognized, furthermore, is not that important as long as the company’s intrinsic value is increasing at a satisfactory rate. In fact, delayed recognition can be an advantage: It may give us the chance to buy more of a good thing at a bargain price.