Thursday, August 26, 2021

Utilizing the bloody bandwidth

I grew up with dial-up internet. Abbu probably got internet connection at home first time circa 2002. Back then, "computer time" was limited to about one hour per day, "internet time" even more so. And this limited time on a line with 56 kbps download speed. Now let's do some elementary maths. Even if I spent that maximum of allotted computer time on the internet, what's the amount of data that would get me?
56*3600/(1024*8) which is around 25 megabytes 
Heh. An mp3 of a song was around 5 megabytes. So, if I wanted to listen to a song, I'd have to spend 20% of my total internet time dedicatedly towards that one goal. 

Then I eventually first got introduced to a broadband line, when Bhaiya was in his third year of university, about 7 years from that first introduction to internet. I also got introduced to torrents. And local servers. And the rush was amazing. I mean, I didn't have to wait a really long time to download a single piece of music any more. It also meant I could be multi-tasking. I could be reading up on the latest Naruto chapters, while a movie was downloading in the background. I could take breaks by watching HD videos that I'd find on the LAN. I was amazed as the high bandwidth I could get and thought that any time when the internet line is not being used to the maximum possible bandwidth is a "waste of internet". And I knowingly couldn't bring myself to waste this beautiful beautiful thing.

And that usage pattern continued, and weirdly enough leaked into other aspects of my behavior. And not particularly in a good way. I mean, when I was trying to "not waste" internet, it's not like I was using it to save the world or anything, right? So, in multi-tasking in real life, I basically took it to mean I shouldn't be taking a shit without browsing my phone. Such a waste of time. If there's an advertisement while watching a film, I should use that time glued to my phone. If I'm walking up to campus, I should be checking Facebook posts and listening to music (double multi-tasking, take that!). Time's a more important commodity than internet, and no time bandwidth can be wasted.

I only recently made the connection to this urge of utilizing the bloody bandwidth in all aspects of life and the really low attention span I have at this point. I mean, I never really learned to do multi-tasking properly. All I learned was to break down the time to small parts and do different things at the different times. I began to give value to trivial tasks and important tasks alike. I mean, focusing on a single important task is for chumps, I'm increasing bandwidth utilization! And if need came to focus for a longer amount of time on a single task, which might be important, it turns out I'm not equipped to do that. Surprise!

So, I've been trying a lot at recent times to let go of the bandwidth thoughts. I keep telling myself I don't need to utilize the bandwidth to do pointless tasks. Just because there are more posts in the wrestling forum doesn't mean I should be trying to spend my free time reading those. Just because there might be this new fancy tutorial video on YouTube which might give me a minute of excitement doesn't mean I need to watch it. And I'm trying to stop this silly practice of high utilization and trying to rather focus on doing on what I need to.

Tuesday, July 28, 2020

Coder's Block and the Birthday Problem


So, I've been going through something of a Coder's block, which is just a fancy way to say that I've been procrastinating too much instead of working. I get ideas, work on them with pen and paper, but when it comes to testing them, even very simplistic stuff is hard to write down. So, I thought maybe trying something very simplistic (like undergrad first year kind of simplistic) might help at least writing something. And maybe that would help with getting out of this fancy block.

When thinking of simple problems, the Birthday Problem came to mind, which asks-
What is the smallest n, such that in n randomly chosen people, the probability that a pair of them will have the same birthday is at least half?

Now, this problem can be solved analytically (and the solution's really neat as a counting problem). But I'm not really in a counting block, I'm in a coding block. So instead of solving this analytically, decided to do a Monte Carlo (MC) simulation for it. An MC simulation really comes down to generating different random numbers. So, for different values of n, we generate n random integers between 0 and 364 inclusive (why?) and see if any pair among the n are equal. We repeat this experiments a number of time for each n and count how many times, such an event has happened. And we treat the fraction of time this has happened as the prediction of the probability. (In actuality, to get a better prediction, we should repeat this experiment multiple times and take the means, but again, that's not the point of why I was doing this).
As it turns out, the number of people we need to get the probability above half --according to the results of our code, which is shown below-- is merely 23. This is the same as the analytically found result as well.
Now, this was a result that I used to find very intriguing back in high school. There are 365 days in a year after all. So, why can only 23 people give a probability of more than half that two of them share a birthday? Interestingly, this is easy to understand if we count the right thing. We are essentially looking at "pairs of people" than individuals for the Birthday Problem. And how many pairs of people are there with n peoples? n(n-1)/2. For 23 people, this is 253, a number much closer to 365. And suddenly the result does not seem so weird. This argument can naturally be extended to support the fact that soon the probability reaches almost 1. Any way, this 20-ish line code with a couple of for loops and ifs were easy enough. Let's just hope that doing simple exercises does help in getting back to actual coding that I "need" to do.

Thursday, November 21, 2019

Star Wars



They used to do the original trilogy reruns on Star Movies when I was a kid. Me and Bhaiya would go crazy about them. I don't even think I understood much beyond "hey cool light swords and aliens" around the first time, to be honest.

So probably I began "understanding" the Star Wars mythology and everything later on, between the release of Attack of the Clones and Revenge of the Sith. By RotS, I had become this proper SW "stan", as they say this days. Did I think Anakin was a worse protagonist than Luke? Yes. Did I hate Jar Jar Binks? Yes. But did I hate the prequel trilogy? No, not really. I mean, yeah I'll occasionally bash them for the weird plot points and shit but still, teenage me loved the hell out of those things.

Then, by the time the sequel trilogy came along, I was actually a grownup. I've had my time to create "higher" expectations from a eff-ing space opera. I got into the whole web interactions thing, where just watching a movie wasn't enough, dissecting it, "theorizing" about it, then getting mad when the theories didn't become true, then getting mad at other people for spewing nonsense.

Damn, being a SW fan has become complicated. Anyhow, as we near the end of the sequel trilogy, I feel like, this once I'd like to forget all the shit. I'd like to just go, watch the movie, and enjoy some good old space opera.

One last time.

Saturday, November 09, 2019

Break

I graduated from BUET in August 2015, it took about five and a half years. Towards the end, it got more exhausting than I could have imagined in the earlier days. No matter how good some of the times were, I couldn't wait to put it behind me.
I also felt I needed a well-deserved break. I remember telling my mother as early as March of that year, that after graduating I wish I got to go home and stay in Rajshahi for a few weeks, even months may be. That I would not feel bad or whatever if I don't immediately get a job. Bla bla bla.

As fate would have it, I got a rather tempting job offer as soon as graduating. Couldn't resist the allure, deserved break be damned, I joined. And while the first months in the job were possibly easier than whatever I went through in the final year of university, it was no vacation. Eventually, got involved in the job more, used to spend hours in the office at times, would bring work home even (to the irritation of my wife). I think I can safely say, to some extent I enjoyed the work. However much I enjoyed it though, the need for a break that I felt before, was coming back. And it had only gotten stronger during the wait. I used to joke all the time that I'd some day be brave enough to just call my boss and say "I quit, I want to sleep!". During my three years working there, the only long leave that I managed to take was for a two-week tour to Nepal. The tour itself was lovely. My wife and I saw snow for the first time, paraglided, ate different types of momo. Then I came back, rejoined office, and to my utter surprise, realized that I still wanted that goddamn break. That I still need to just lay back, and do abso-fucking-lutely nothing for a few days.

Anyway, again, as time would see, I would get another opportunity that would be great for me. An admission offer letter to graduate school, studying economics, computation and other shit. Again, being the sucker that I am for "good" opportunities, I took the offer. Before leaving for school though, spent even the last few days tying up ends at the job. So, if I had been subconsciously motivated about grad school from the hope that, I'd get some time between quitting the job and needing to leave, that hope was very much misplaced.

So still no break, and lo - I'm suddenly doing my PhD. I mean, I know why I'm here. I understand that with my curiosity, or ambitions or whatever else attributes I might possess, I was bound to end up here anyway.

But, still, I can't help thinking, if only I had managed to take that break, somewhere in the last five years, maybe, maybe today would be more tolerable.   

Monday, July 29, 2019

আপাত অপ্রাসঙ্গিক ব্যাপার-স্যাপার (Supposedly Irrelevant Factors)

(কয়েকদিন হল অর্থনীতিবিদ রিচার্ড থেলারের আংশিক জীবনী, আংশিক টেক্সটবুক ঘরানার বই Misbhevaing: The making of behavorial economics পড়া শুরু করেছি। অনেক জায়গায় বইটাকে Professional Memoir হিসেবে বর্ণনা করতে দেখেছি, যেটা অনেকাংশে ঠিক। প্রফেসর থেলার পিএইচডি থিসিসের সময় (১৯৭০) থেকে শুরু করে মোটামুটি ২০১০ এর দিক পর্যন্ত নিজের কাজের পিছনে মোটিভেশন, witty সব বাস্তবিক উদাহরণ, কলিগদের সাথে তার বিভিন্ন সময়ের interaction উঠে আসে। এর মধ্যেই আমরা দেখতে পাই কিভাবে ধীরে ধীরে আলাদা ফিল্ড হিসেবে Behavorial Economics দাঁড়া হয়ে ওঠে, যাকে বাংলায় আচরণগত অর্থনীতি বলতে দেখেছি এখানে সেখানে। বিহেভরিয়াল ইকোনমিক্সের ডেভেলপমেন্টে উল্লেখযোগ্য ভূমিকা রাখার কারণে রিচার্ড থেলার ২০১৭ সালে অর্থনীতিতে নোবেল পুরস্কার পান। এই বই বেরিয়েছে অবশ্য তারও বছর কয়েক আগে। বইটা পড়ার সময় বেশ কিছু আইডিয়া বেশ পছন্দ হয়, যার কারণে ঠিক করি নিজের মত করে নোট নিয়ে রাখব। সেই নোটগুলোরই প্রথমটা হচ্ছে এই পোস্ট।)

একটা আদর্শ অর্থনৈতিক দুনিয়ায় সব মানুষের একটা কমন বৈশিষ্ট্য থাকার কথা: rationality বা যৌক্তিকতা। অর্থনৈতিক তো বটেই, সব ডিসিশনই মানুষের নেওয়ার কথা যৌক্তিক ভাবে। যৌক্তিকতা মানে কি? নিজের কাজের কারণে মানুষের যেন সর্বোচ্চ লাভ বা সর্বনিম্ন ক্ষতি হয় সেইটা নিশ্চিত করা। এই জিনিসটার একটা গালভরা নাম আছে: utility maximization। কিন্তু কথা হল, মানুষ কিসে নিজের লাভ বা ক্ষতি মনে করে, এটাকে সবসময় টাকা-পয়সা (কিংবা অন্য কোন জিনিস যেটার লাভ-ক্ষতি পরিমাপ করা সহজ) দিয়ে ব্যখ্যা করা যায় কিনা এটা একটা বড় প্রশ্ন। 

প্রফেসর থেলার নিজের জীবন থেকে একটা উদাহরণ ব্যবহার করেন। উনি যখন প্রথম যখন শিক্ষকতা শুরু করেন, তার একটা পরীক্ষায় শিক্ষার্থীদের গড় মার্কস ছিল ৭০-এর আশেপাশে। উনি যেখানে পড়াতেন (University of Rochester, NY, USA), সেখানে মার্কসের সাথে গ্রেডের সম্পর্ক আমাদের দেশের মত এত জোরালো না। ৮০ মানে এ, ৭৫ মানে এ-, এরকম ধরাবাধা নিয়ম নাই আর কি। যেহেতু একেক প্রফেসরের পরীক্ষার ডিফিকাল্টির উপর ডিপেন্ড করে ৫০/১০০ মানে হয় খুব জঘন্য পরীক্ষা, অথবা মোটামুটি ভালো পরীক্ষা, যেকোনটা হতে পারে। উনিও সুন্দর মত বলে দিয়েছেন যে তোমাদের এই নাম্বারের দিকে তাকানোর দরকার নাই, আমি "curving" করে তারপরে গ্রেড দিব। তার পরেও উনি বেশ শোরগোল শুনেন ক্লাস থেকে। "ভাল পড়েও মাত্র ৭০ পেলাম, এ কেমন বিচার?" জাতীয় কথাবার্তা আর কি। পরীক্ষার মান সহজ করার ব্যাপারে অনীহা থাকায়, একটা অদ্ভুত কাজ করে বসলেন তিনি। পরের পরীক্ষা ১০০ মার্কসে না নিয়ে, নিলেন ১৩৭ এ। কেন? "এতে গড় মার্কস ৭০ এর দিকে না থেকে থাকে ৯৫ এর আশেপাশে। এক দুইজন ১০০+ মার্কসও পেয়ে যায়।" (এইটা ১৩৭ দিয়ে ভাগ না করে ১৪০ টাইপের কিছু দিয়ে ভাগ করলেও হত, কিন্তু একটা ১৩৭ দিয়ে মুখে মুখে ভাগ করে ফেলা একটু কঠিন, এটাও হয়তো একটা ভাল ব্যাপার)।
যেহেতু শুধু মার্কস না দেখে এখনও লোকজনের পাওয়া মার্কসের ডিস্ট্রিবিউশন দেখে গ্রেড দেওয়া হবে, এতে আসলে শিক্ষার্থীদের অবস্থার কোন হেরফের হবে না। তার মানে ইউটিলিটি বাড়ানোর দিক দিয়ে, তাদের কিছু যায় আসার কথা না, যেহেতু ইউটিলিটি দিন শেষে গ্রেডের উপরেই নির্ভরশীল, এই মার্কসের উপর না। কিন্তু অবাক করা ব্যাপার হল এই আপাত অপ্রাসঙ্গিক ব্যাপার (মোট মার্কস) পরিবর্তনের কারণে, জীবনে প্রফেসর থেলারকে তার গ্রেডিং নিয়ে আর কোন কমপ্লেইন শুনতে হয় নি। 

আরেকটা উদাহরণ দেখা যাক। এবার আর ক্লাসের ব্যাপার-স্যাপার না। ধরে নিন ফেসবুকে একটা ফুটফুটে বাচ্চার ছবি সহ একটা পোস্ট দেখলেন। ছয় বছর বয়সী ছেলেটার অপারেশনের জন্য কয়েক লক্ষ টাকা লাগবে। তাকে সাহায্য করার উপায় জানানো থাকলে, বিকাশ হোক, ব্যাংক একাউন্ট হোক, আশা করা যায়, মানুষ নিজের জায়গা থেকে একটা এমাউন্ট দান করে বাচ্চাটার অপারেশনের ব্যবস্থা করতে পারবে। এই একই মানুষগুলোকে যদি জানানো হয় যে ইনকাম ট্যাক্স আরেকটু বাড়ানো হলে দেশের হাসপাতালগুলোতে দরিদ্র শিশুদের চিকিৎসা ব্যবস্থার উন্নতি করা যাবে এবং বছরে অন্তত ১০০ জন শিশুর জীবন বাঁচবে, সেক্ষেত্রে হয়তো আর ওরকম আগ্রহ পাওয়া যাবে না। ট্যাক্সের টাকা কই যায়, হাসপাতালে দূর্নীতি হয় কিনা, এসব আপাতত হিসেবের বাইরে রাখি। এখানে মূলত যে পার্থক্যটা তা হল থমাস শেলিং এর মত identified life আর statistical life এর পার্থক্য। প্রথম ক্ষেত্রে, বাচ্চাটাকে আপনি দেখছেন, একটা পরিচয় জানছেন, এবং এটাই একটা বড় পার্থক্য গড়ে দেয়। মানুষ খুব কম ক্ষেত্রেই identified life এর ক্ষতি হোক এটা চায়। এখন যৌক্তিক চিন্তার দিক থেকে কিন্তু এ পার্থক্যটা থাকার কথা না। যদি আমার সরাসরি পরিচিত না হয়, একটা identified life আর statistical life বাঁচানো, দুইটার ক্ষেত্রেই আমার সমান আগ্রহ থাকা উচিৎ। দুর্ভাগ্যজনকভাবে তা থাকে না।

এই যে ফিক্সড ইউটিলিটির বাইরে চলে যাওয়ার মানুষের স্বভাব, এই জিনিসগুলোর কারণ হচ্ছে এসব আপাতদৃষ্টিতে অপ্রাসঙ্গিক ব্যাপার-স্যাপার। এগুলোকে irrational বলে অনেক ক্ষেত্রেই ইকোনমিক এনালিসিসের মধ্যে আনা হয় না। কিন্তু থেলার (এবং আরও অনেকে) আসলেই প্রমাণ করেন, যে এগুলোকে ব্যবহার করে আমরা ভালোমত মানুষের অর্থনৈতিক আচরণ ব্যখ্যা করতে পারব। মানুষের এই ব্যাপারগুলোকেও গাণিতিক মডেল ব্যবহার করে ইকোনমিক্সের মধ্যে আনাটাই এক দিক দিয়ে বলা যায় বিহেভরিয়াল ইকোনমিক্সের উদ্দেশ্য।

(চলবে)

Saturday, July 27, 2019

Random reposts - 3

I could not prevent myself from ranting about this.
The following thing has been floating around Facebook for a few days now.
1+4=5
2+5=12
3+6=21
5+8=???
Always it is accompanied by something like "I failed to solve this, so had to change profile pic".
NO.
I don't know what your answer is but very likely you did not fail. This is not a "properly" defined problem. In the very simplistic sense I could take the binary operator a + b to mean a*(b+1) and say the last thing is 45. The fact that 1+4=5 has nothing to do with that solution.
I could again say a+(a+3) actually means a^2+4a. That again is a perfectly valid solution. (In fact it gives the same value as before).
Now, the functions above are both quadratic terms. We can try cubic polynomials to define the problem. We can try any higher order polynomial that 
This is NOT some clever problem that tricks people. This is a very VERY poorly defined problem. That's it.
PS: I understand some of you just enjoy doing things like this in Facebook and enjoy changing their profile pictures to weird things and are happy to do weird trend-y stuff. I apologize if I seem like a killjoy. Just couldn't take so many people being in a "GOTCHA" mood over nothing.

PS: I had made this post in Facebook, where the context seemed clear to most people. However, probably adding a bit context here would be good. The actual text going around with the problem was "find the correct one". And the reply came as 1+4=5 is the only "correct" one according to regular arithmetic, the proper answer would be "1+4=5 is the correct one".
...
Stupid.
Yes.
I know.

Friday, May 24, 2019

Let's talk about democracy - Part 1

Growing up in a democracy, that had just before my birth got rid of dictatorship, and was in fact a relatively young country, probably by default I have always had the thought that democracy is "important" and "infallible".

So how does said democracy work? The thing we have now may be called representative democracy. We elect people to represent us and they build up the legislature and are in charge of running the country. This is different from something that used to be in days old, called "direct democracy". Now, ideally, many people would maintain that direct democracy, where each person would get a vote on all matters important, would be a great thing to have. Unfortunately with such a great population, it's not possible for most nations. And we can merely try to approximate that with our representative democracy.

But let's look at the claim of righteousness for direct democracy once, shall we? The problem with any election is that, there isn't really an observable "ground truth". We don't REALLY have a right/wrong. We have different people making choices of their own. Now, looking from a social welfare perspective, this choice can either be right or wrong. As simple as that. So, what happens if we think of each voter as a binary classifier? There can only be two alternatives for a voter, either she's right or she's wrong. And we can naively assume that for each voter, there is a probability p that she is in the right. Let's call p to represent her wisdom. Now, for this simplified setting, if the average wisdom of a population is lesser than fifty percent, it can be shown that the decision the majority of these people will lead to in case of direct democracy will be the wrong one. Just like that, our argument for direct democracy sort of goes out of the window. As long as the majority of people are "unwise", or rather the average wisdom is "low", the majority decision is likely to be wrong as well.

Here, representative democracy can play a really good role. Instead of being an approximation to direct democracy, it can surpass it. How? Bangladesh is broken down into 300 parliamentary seats, right? Where different blocks of people choose a representative who would make decisions for them. Now if, IF, we can make the assumption that each block of people would choose the wisest among them to represent them, then the average wisdom of the representatives go up. And it's more likely that their decisions would be better for social welfare. So even if most people aren't able to judge for themselves, what's best, if they can at least identify the persons who can, democracy still has a saving grace.

Now comes the fun part. This result relies on the hope that the people choose well. Then again we go back to the original problem. Do we choose well? Do the prospective representatives really want us to choose well? As long as the average wisdom is still low, the choice of representatives may go wrong as well. Particularly, if we don't choose the wisest amongs us, if we choose the corrupt, the greedy, we're probably messing up our chances for the social welfare wished for anyway.

[May or may not be continued]

PS: I have used the term "wisdom" very loosely throughout the writeup. Don't consider it to have anything to do with actual intelligence or anything.

References
1. https://papers.nips.cc/paper/7720-a-mathematical-model-for-optimal-decisions-in-a-representative-democracy.pdf
2. https://www.semanticscholar.org/paper/A-note-on-the-Condorcet-Jury-Theorem-with-voting-Fey/7c95005ffa20bf35e32331c003de3b8ed578fc2a