Share: Harry Potter and the Methods of

Somehow Harry had understood that, even before anyone else had warned him he’d understood. Before he’d read about Vladimir Lenin or the history of the French Revolution, he’d known. It might have been his earliest science fiction books warning him about people with good intentions, or maybe Harry had just seen the logic for himself. Somehow he’d known from the very beginning, that if he stepped outside his ethics whenever there was a reason, the end result wouldn’t be good.

A final image came to him, then: Lily Potter standing in front of her baby’s crib and measuring the intervals between outcomes: the final outcome if she stayed and tried to curse her enemy (dead Lily, dead Harry), the final outcome if she walked away (live Lily, dead Harry), weighing the expected utilities, and making the only sensible choice.

She would’ve been Harry’s mother if she had.

“But human beings can’t live like that,” the boy’s lips whispered to the empty classroom. “Human beings can’t live like that.

measure theory and cog. psych.

Measure theory defines three attributes for some variable to be considered a measure*.

  • 1. Non-negativity:
    It’s the idea that a value should not go to negative when measured (by whatever means/equipment in the real world.
  • 2.Null empty set:
    It’s the idea that the measure becomes zero for a null set.
  • 3.Countable additivity:
    This one basically means if there are ‘n’ sets with measures ‘X1, X2, …, Xn’ then the measure of the Union of all the ‘n’ sets is less than or equal to sum of ‘X1, X2, … , Xn’

* — I think it can be extrapolated/extended to measure of any geometric properties, but not beyond that. Very tellingly, it is used widely in a field called real analysis. After all, in electrical engineering we have all sorts complex, negative, fractional numbers. I picked up these definitons from Fractal Geometry book rather than the wikipedia links provided.
ps: There’s a more generalized definition of measure, that might fit these too here.
** — If you think about these are all just a set of rules for determining if a given set belongs/satisfies the properties of a set of numbers, but that’s beside the point here.

As much as i have been a fan of cognitive psychology, so far, i am now beginnning to wonder, which and how many of these concepts like executive control,,etc.. have been shown to obey these laws. I haven’t done a thorough survey or research, but deeply suspect there hasn’t been any published attempts in these directions. I would like to see some, but i think it may not be easy to pick a property that’s easy enough to deal with.

Also, i begin to wonder how many of these apply or scale to organizational psychology? or committee-centered decision-making policies. Again i suspect there’s been very little attempts to scale/correlate cog,psych concepts into organizational/behavioural psychology, never mind cross-checking with relevant math area’s base assumptions.

Share: Harry Potter and the Methods of

You’d already read about Philip Tetlock’s experiments on people asked to trade off a sacred value against a secular one, like a hospital administrator who has to choose between spending a million dollars on a liver to save a five-year-old, and spending the million dollars to buy other hospital equipment or pay physician salaries. And the subjects in the experiment became indignant and wanted to punish the hospital administrator for even thinking about the choice. Do you remember reading about that, Harry Potter? Do you remember thinking how very stupid that was, since if hospital equipment and doctor salaries didn’t also save lives, there would be no point in having hospitals or doctors? Should the hospital administrator have paid a billion pounds for that liver, even if it meant the hospital going bankrupt the next day?

“Shut up!” the boy whispered.

Every time you spend money in order to save a life with some probability, you establish a lower bound on the monetary value of a life. Every time you refuse to spend money to save a life with some probability, you establish an upper bound on the monetary value of life. If your upper bounds and lower bounds are inconsistent, it means you could move money from one place to another, and save more lives at the same cost. So if you want to use a bounded amount of money to save as many lives as possible, your choices must be consistent with some monetary value assigned to a human life; if not then you could reshuffle the same money and do better. How very sad, how very hollow the indignation, of those who refuse to say that money and life can ever be compared, when all they’re doing is forbidding the strategy that saves the most people, for the sake of pretentious moral grandstanding…

You knew that, and you still said what you did to Dumbledore.

You deliberately tried to hurt Dumbledore’s feelings.

He’s never tried to hurt you, Harry Potter, not once.

Harry’s head dropped into his hands.

Why had Harry said what he’d said, to a sad old ancient wizard who’d fought hard and endured more than anyone should ever have to endure? Even if the old wizard was wrong, did he deserve to be hurt for it, after all that had happened to him? Why was there a part of him that seemed to get angry at the old wizard beyond reason, lashing out at him harder than Harry had ever hit anyone, without thought of moderation once the rage had been raised, only to quiet as soon as Harry left his presence?

Is it because you know Dumbledore won’t fight back? That no matter what you say to him, however unfair, he’ll never use his own power against you, he’ll never treat you the way you treat him? Is this the way you treat people when you know they won’t hit back? James Potter’s bullying genes, manifesting at last?

Harry closed his eyes.

Like the Sorting Hat speaking inside his head –

What is the real reason for your anger?

What do you fear?

A whirlwind of images seemed to flash through Harry’s mind, then, the past Dumbledore weeping into his hands; the present form of the old wizard, standing tall and terrible; a vision of Hermione screaming in her chains, in the metal chair, as Harry abandoned her to the Dementors; and an imagination of a woman with long white hair (had she looked like her husband?) falling amid the flames of her bedroom, as a wand was held upon her and orange light reflected from half-moon glasses.

Albus Dumbledore had seemed to think that Harry would be better at that sort of thing than him.

And Harry knew that he probably would be. He knew the math, after all.

But it was understood, somehow it was understood, that utilitarian ethicists didn’t actually rob banks so they could give the money to the poor. The end result of throwing away all ethical constraint wouldn’t actually be sunshine and roses and happiness for all. The prescription of consequentialism was to take the action that led to the best net consequences, not actions that had one positive consequence and wrecked everything else along the way. Expected utility maximizers were allowed to take common sense into account, when they were calculating their expectations.

Somehow Harry had understood that, even before anyone else had warned him he’d understood. Before he’d read about Vladimir Lenin or the history of the French Revolution, he’d known. It might have been his earliest science fiction books warning him about people with good intentions, or maybe Harry had just seen the logic for himself. Somehow he’d known from the very beginning, that if he stepped outside his ethics whenever there was a reason, the end result wouldn’t be good.

A final image came to him, then: Lily Potter standing in front of her baby’s crib and measuring the intervals between outcomes: the final outcome if she stayed and tried to curse her enemy (dead Lily, dead Harry), the final outcome if she walked away (live Lily, dead Harry), weighing the expected utilities, and making the only sensible choice.

She would’ve been Harry’s mother if she had.

“But human beings can’t live like that,” the boy’s lips whispered to the empty classroom. “Human bei

Share: Harry Potter and the Methods of

Wow, said Ravenclaw. You just told an outright lie. Not only that, I think you actually believed it for the seconds it took to say it. That’s kinda scary.

  —–scariest thing I ever knew.

Share: Brisingr

You are capable of such a feat?

I am, but I do not know if I will be able to summon the magic I will need when I am standing before Isidar Mithrim. My ability to cast spells is not subject to my own desires. At times, it is as if I have gained a new sense and I can feel the pulse of energy within my own flesh, and by directing it with my will, I can reshape the world as I wish. The rest of my life, however, I can no more cast a spell than a fish can fly. If I could mend Isidar Mithrim, though, it would go a long way toward earning us the goodwill of all the dwarves, not just a select few who have the breadth of knowledge to appreciate the importance of their cooperation with us.

(Moon+ Reader Pro v2.6.5, Brisingr)

IP protocol — RFC study notes.

Here’s the original. (Recommended for the studious).

Scope limits:

<blockquote>
There are no mechanisms to augment end-to-end data
reliability, flow control, sequencing, or other services commonly
found in host-to-host protocols.
</blockquote>

Basic Functions:
1. Addressing:
a, Routing: Based on the addresses carried in the header, the datagrams are sent to destinations.
Which path they take is decided by routing.

2. Fragmentation:
The IP layer/module fragments the given data to it into datagrams for transmission through “small packet networks”.

Each Internet Datagram is an independant entity.
4 Mechanisms:
1. Type of Service:
Quality of service, as codified into parameter values defined by the layers above, and implemented/honoured by the gateways, to choose the transmission parameters.
2. Time to live:
Self-destruct time-limit for each datagram. Cool like self-destruct messages in Spy movies(mission impossible)
3. Options:
Used for control functions/commands
4. Header Checksum:
Like any other checksum, check to make sure the data transmitted is correct.

Addressing:
Addresses vs Names vs Routes:
address == Fixed length four octets
octet — eight bits.
Address starts with
1. Network Number
2. local address/rest field
# TODO: an example would help here.
types of local address:
a, highest order bit is zero, next 7 bits the network, last 24 the local address
b, high order two bits 10, next 14 bits the network, last 16 the local address
c, high order 3 bits 110, next 21 bits are the network, and last 8 the local address
Address Formats:
<blockquote>
Address Formats:

High Order Bits Format Class
————— ——————————- —–
0 7 bits of net, 24 bits of host a
10 14 bits of net, 16 bits of host b
110 21 bits of net, 8 bits of host c
111 escape to extended addressing mode
</blockquote>
Fragmentation:
— Used when a packet originates in a local net of higher packet size than the target local net
— packets can be flagged to never fragmented(but dropped if the case above happens)
— fragments have
identification field
offset field
more-fragments flag
Also have the same header as the original IP packet.

Gateways:
Forward datagrams between networks
<blockquote>
+——————————-+
| Internet Protocol & ICMP & GGP|
+——————————-+
| |
+—————+ +—————+
| Local Net | | Local Net |
+—————+ +—————+

Gateway Protocols
</blockquote>
Internet Header format:
<blockquote>
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Example Internet Datagram Header
</blockquote>

version: 4 bits
IHL : 4 bits, length of the header in 32 bit words
Type of Service: 8 bits
So the choices boil down to low-delay, high-reliability and high-thoroughput.
<blockquote>
Bits 0-2: Precedence.
Bit 3: 0 = Normal Delay, 1 = Low Delay.
Bits 4: 0 = Normal Throughput, 1 = High Throughput.
Bits 5: 0 = Normal Relibility, 1 = High Relibility.
Bit 6-7: Reserved for Future Use.
</blockquote>

Total Length: 16 bits
— length of the datagram measured in octets, Max 65535 octets.
— hosts are recommended to send > 576 octets.(576 heuristically arrive number, probably higher nowadays??)
Identification: 16 bits
— identification for fragmentation and re-assembling.
Flags: 3 bits
<blockquote>
Bit 0: reserved, must be zero
Bit 1: (DF) 0 = May Fragment, 1 = Don’t Fragment.
Bit 2: (MF) 0 = Last Fragment, 1 = More Fragments.

0 1 2
+—+—+—+
| | D | M |
| 0 | F | F |
+—+—+—+
</blockquote>

Fragment Offset: 13 bits
Time to live: 8 bits
Protocol: 8 bits
— Next level protocol used
Header Checksum: 16 bits
<blockquote>
The checksum field is the 16 bit one’s complement of the one’s
complement sum of all 16 bit words in the header. For purposes of
computing the checksum, the value of the checksum field is zero.
</blockquote>

Source Address: 32 bits
Destination Address: 32 bits
Options: variable
— transmission of options is optional.
2 formats:
a, Single octet of option-type
b, option-type octet + option-length octet + option-data octets
option-type octet:
1 bit — copied flag( whether to copy this option to each of the fragments)
2 bits — option class
option-classes:
<blockquote>
0 = control
1 = reserved for future use
2 = debugging and measurement
3 = reserved for future use
</blockquote>
5 bits — option number
Defined internet options.
<blockquote>
CLASS NUMBER LENGTH DESCRIPTION
—– —— —— ———–
0 0 – End of Option list. This option occupies only
1 octet; it has no length octet.
0 1 – No Operation. This option occupies only 1
octet; it has no length octet.
0 2 11 Security. Used to carry Security,
Compartmentation, User Group (TCC), and
Handling Restriction Codes compatible with DOD
requirements.
0 3 var. Loose Source Routing. Used to route the
internet datagram based on information
supplied by the source.
0 9 var. Strict Source Routing. Used to route the
internet datagram based on information
supplied by the source.
0 7 var. Record Route. Used to trace the route an
internet datagram takes.
0 8 4 Stream ID. Used to carry the stream
identifier.
2 4 var. Internet Timestamp.
</blockquote>

Each of these options then have more specifications about what they mean, and how they should work. That goes on for a couple of pages.
There are a couple more pages discussing some implementation requirements and some examples but this is as far a i go.

Urlshortener in python

I attempted this(url shortener) project as a kind of a dare. Over a lunch and beer one day, atul casually commented that a url shortener,

would be a ten minute work for someone like you and a blog about it would make a nice fit for my site.

I was not sure it’s a 10 minute work, but sounded like a small fun project for weekend attempts.

It took more than half a day, for me to be content(not happy, but just content) with the resulting work.

Nevertheless, it was time well spent. Here’s the link to the actual project.<a href=”https://github.com/emofeedback/urlshortener”>

 

Few clarifications about some choices(should i call it software engineering??):

  1. Redis because it’s extremely efficient, stays in RAM, and has some unconfirmed reports of being used to power china’s internal twitter clone.
  2. Used 5 chars, because, well the internet is big, and thought it’s a good number to cover most unique urls.(especially, when combined with the 78 chars allowed for url, i.e: 5^78) Thanks to a colleague’s suggestion for the idea, i was thinking about hashing/random before his suggestion. (Note to self: Fucking stop believing “outsourced magic is better” shit.)

3.A hash map of shortened url-> original url and original url -> shortened url was kinda against my idea. I still keep thinking this is too much memory, we should find a different way. I think if I take away the use-case of already shortened url, being submitted for new shortening, should return, I can eliminate the original url -> shortened url hash map.

  1. To check if a new original url has already been shortened, the hyperloglog comes to the rescue. Just pass it through the HLL algorithm and see if it returns True and False.
  2. From the UI point, well i just put up a minimal html form to take a original url and return a json.
  3. Yet to do, add a proper fabric script to setup virtualenv, python packages, redis install and nginx config and restart nginx.

You can see it live here.