...

Friday, May 15, 2015

Microeconomics 05

From the previous discussion, we can easily see that if unconstrained, consumers will simply buy an infinite amount of goods (by choosing the highest indifference curve).

However, due to a limited budget, we will have to choose the best combination that will maximize our budget and utility. This is called Constraint Maximization.

Budget Constraints

Typically, we can represent  a constraint as:


Where P is the number of pizzas, and Pp is the price of each pizza.

Suppose that a pizza costs $20, and a movie costs $10, and we have $100 to spend, then we will have a graph as such:


We will be drawing $100 = $20P + $10M. The slope of this line is -Pm/Pp.

The price ratio is -0.5, which is the Marginal Rate of Transformation (MRT). It is the rate at which we can transform pizzas into movies.

The Opportunity Cost of something is the value of foregone alternative. For example, if we forgo a pizza, then we are forgoing 2 movies. Or from the other perspective, a movie costs half a pizza. This is the Opportunity Cost of the situation. Opportunity costs only make sense if we have a limited budget.

Suppose that the price of pizza rose to $30. We will have the following graph now:


With the $100, we have things to choose from now. In other words, our Opportunity Set has become more restricted.

We can also have a restricted Opportunity Set if our budget drops. Keeping the price constant as the first example, we will have the following graph if we drop our budget to $80. In this case, the slope remains the same.


We want to find out what is the furthest indifference curve given a budget constraint. An example when we combine the indifference curves and the budget constraint looks like this.

(Note that the x-axis represents movies, while y-axis represents pizza).

We can afford anything under our budget line. Notice that there are three points on our budget line itself. Points A and C are equivalent, but because we want the farthest indifference line (due to Non-Satiation), point D is actually the best we can get.

The best indifference curve we can get is one where the budget constraint line is tangent to the curve. In order to perform utility maximization, we need to get these things to be tangent by ensuring that the MRS is equal to the MRT. By setting MRS equal to MRT, we are setting marginal benefits equal to marginal costs.

Deriving Marginal Utilities, MRS and MRT

The marginal at each point is the partial derivative of the functional utility with respect to the item we are interested in. For example, if we are interested in the marginal utility function of pizza then we differentiate sqrt(PM) with respect to P.

Points A and C are both undesirable. It is clear that the MRT for the entire budget line is -0.5. Let's work out the MRS for all the points:


An MRS of -2 means that we are willing to trade 2 pizzas for a movie. However, the market MRT of -0.5 only requires us to trade half a pizza for a movie.

There are times where we will end up with negative quantities when we solve for the optimum point. It may be that we are looking at a problem with a corner solution.

Remember that MRS is the rate the consumer is willing to trade the y-axis for the x-axis. On the other hand, MRT is the actual market value ratio between the y-axis and the x-axis.

Note that B, D and E both satisfies that MRT equals MRS, but we want the farthest indifference point that is still within our budget. That is the basic goal of utility maximization.

Microeconomics 04

Consumer Theory

In the previous lectures, we simply made use of given supply and demand curves. Now we are going to start looking at how the curves are made. We shall start by focusing on the demand curves in the study of consumer theory.

All consumer-related behavior in economics revolves around utility maximization. In order to do these, we need to take into account consumer preferences, budget constraints, and perform constraint optimization. In the most basic sense, we will look at the tradeoff between two goods and how the consumer will choose between them.

In summary, we will need to:
1) Make assumptions about preferences
2) Translate these assumptions into utility functions
3) Add budget constraints and perform maximization

In order to model preferences across goods, we will need to impose the following assumptions to make our modeling simpler:
1) Completeness - When we compare two bundles of goods, we would prefer one or the other but never equally. In other words, you can always make a choice between them.
2) Transitivity - If we prefer x to y, and y to z, then we will prefer x to z.
3) Non-Satiation - More is always better and we will never be satisfied. We will never turn down having more.

Indifference Curves

These curves are somewhat like preference maps. These are the graphical representation of people's preferences.

Suppose that your parents gave you some money and you want to decide between pizza or movies. We can have the following choices.


Assume that we are indifferent between two pizzas and one movie, and one pizza and two movies. Clearly we would prefer two pizzas and two movies better than either of them. An indifference curve is a curve which shows all combinations of assumptions that the consumer is indifferent. Example curves based on the above statements can be shown as such:


From the assumptions of consumers above, we have the following properties of indifference curves:
1) Due to the non-satiation assumption, consumers will prefer higher indifference curves.
2) Due to non-satiation, we can also say that indifference curves are always downward sloping. If it is upward sloping, then there can be a case where we are indifferent between 2 pizza and 2 movies and 1 pizza and 2 movies.
3) Indifference curves cannot cross. If the curves cross, there would be a case where we are indifferent between two choices even though one of it has more, which violates non-satiation.
4) Completeness also implies that we cannot have more than one indifference curves through a point.

Utility

Utility functions are just a mathematical representation of the preference maps. We simply need to maximize the utility function to see what the user would choose.

An example utility function can be U = sqrt(M*P). This is something that is empirical that we come up with and this is not the only utility function we can come up with. However, this is consistent with the indifference maps.

Marginal utility refers to the amount utility changes with each change of the unit. In other words, it is the (partial) derivative of the utility function.

An example of a diminishing marginal utility is shown below:


We can see that each additional movie improves the utility, but it increases at a diminishing rate. Marginal utility would usually be diminishing, but at different rates for different goods. However, marginal utility will always be positive due to non-satiation.

The Delta Marginal Utility graph can show us the actual contributions of each pizza.


Marginal Rate of Substitution

The MRS links the utility to the preference map. The MRS is the slope of the indifference curve, which is dP/dM. It is the rate at which we are willing to trade off the y-axis for the x-axis. For example, it is how many pizzas we are willing to trade off to get another movie. It purely comes from the preferences.

We will refer to the following diagram and attempt to compute the MRS for each segment.


From the first segment to the second, we have an MRS of -2, because we are willing to give up 2 movies for 1 pizzas. However, the MRS of the second to the third segment is -0.5. This is because when we have 4 pizzas, the last pizza has a very low marginal utility. However its, marginal utility is increasing the lower number of pizzas we have.

In general, we have:


Marginal utility is a negative function of quantity. The lower quantity we have, the higher the marginal utility, which is why we flip the X and Y axis.

Thursday, May 14, 2015

Microeconomics 03

Elasticity

The magnitude of change we can expect from a supply or demand shock is determined by shape of the two curves.

The elasticity of the curves can determine how much the quantity or price changes upon a shock.

A perfectly inelastic demand curve is shown below.


When there are no substitutes for a particular product, for example body parts for a transplant, then the demand curve for that product will be inelastic. When there is a supply shock, the quantity doesn't change - only the price changes.

On the other hand, we have a perfectly elastic demand curve below.


A very substitutable product will be elastic. A possible example of an elastic good is toilet paper, where we'll simply switch to another brand if a particular brand becomes expensive. Once the price increases, the quantity sold will drop drastically.

Elasticity can be expressed as:


If the quantity falls by 2% for every 1% increase in price, then we have E = -2. Therefore, an inelastic good will have E = 0, and a perfectly elastic good will have E = -infinity. E will typically be between 0 and -infinity.

Suppose now that a producer sells Q goods at price P, they will make revenue R = PQ. The change in revenue with respect to price, would be:


From this formula, if we are a producer, we should only raise prices when E is between 0 and -1.

Estimating Elasticities

Theoretical economics can show us the direction of change, but empirical economics is what we use to show us the absolute values of change. However, the most difficult part of empirical economics is causation vs correlation.

Take the example in the previous article, we saw that the price of pork rose when the price of beef rose.



If we wanted to calculate E here, we might try to plug in the numbers in the formulae. Since both the price and quantity increased in this case, we may say that we have a positive elasticity - higher price led to higher quantity. However, this is one of the most dangerous mistakes we can make. In this case, the increase in demand is actually what's causing the price to increase, and not the other round. We can only use this formula to find the amount of change in quantity per percentage change in price. Since quantity is driving the price in this case, and not the other round, we cannot apply the elasticity formula.

What we are measuring here is actually the elasticity of the supply.

However, when we change the supply as in the following diagram, we can actually get the correct answer.


What we want is to be able to measure the slope of the demand curve. By shifting the supply curve, keeping the demand curve unchanged, we can measure the elasticity.

Taxation Example

Suppose that we have vendors selling 100 million units of a particular type of product for $10 each. The government comes along and imposes a tax on the vendors, asking for $1 per unit. This increase in price effectively shifts the supply curve up. In order to make the same amount, the producers would have to charge $11 for each unit. However, this causes the equilibrium to drop to 97 million units, at $10.5 per unit.



In this case, we can clearly see that the equilibrium points have traveled on the demand curve, so we can calculate the elasticity using the formula.

Since we see that the elasticity is -0.6, this means that we can continue raising prices further to increase profits.

Of course, we are assuming elasticity is constant. However, since elasticity is a curve for straight demand lines, we are actually just measuring the LOCAL elasticity around that price change.

It can be seen that the amount of money the government earns is the final equilibrium quantity multiplied by the amount of tax. This can be represented by the shaded region. We can clearly see that the amount of money the government makes depends on the elasticity of demand.

If demand is perfectly inelastic, then the amount the government makes is simply Q * tax per unit. If the product demand is elastic, then the government will make a lot less money as the price needs to be fixed.

Wednesday, May 13, 2015

Microeconomics 02

Introduction to Supply and Demand

The twin engines of economics are Supply and Demand. Demand refers to how much people wants something, and Supply refers to how much something is available. Adam Smith first came up with the Supply and Demand model, and when describing his model, he came up with the Water and Diamond paradox.

Water and Diamond Paradox

We can clearly see that water is much more essential to life than diamond, yet diamonds are worth so much more than water. The problem here is that even though there is great demand for water, the supply is much higher than the demand, hence its low price. On the other hand, even though there is much less demand for diamond than water, its supply is much lower than the demand, hence the high price.

Supply and Demand Equilibrium

We can visualize supply and demand on a graph. An example of a supply and demand curve is shown below.

Generic Supply and Demand Graph

The blue line represents the demand curve. The demand curve represents the consumers' willingness to pay for a certain good. As the price increases, the quantity the consumer obtains is likely to decrease.

On the other hand, the red line represents the supply curve. The supply curve represents the willingness of a producer to supply a good. As the price rises, the producers would be more willing to produce more.

When the two lines meet, we have a Supply and Demand Equilibrium. This is where both the suppliers and consumers will be happy.

Equilibrium Shift

Suppose that the graph represents the supply of chicken. Suppose that the supply of pork goes down due to a disease, leading to an increase in pork prices. Since pork and chicken are substitutes for each other, we can expect the demand for chicken to increase.

Increase in Demand

As the demand increases, the demand curve shifts upwards (or outwards). With the supply being fixed, this would mean that suppliers can start charging more as consumers are now more willing to pay for it.

On the other hand, if the supply for pork decreases with the demand being fixed, we can also end up with a higher price as shown in the following graph.

Decrease in Supply

Although prices increased in both cases, the quantity sold differs between them. In order to determine if it's a supply or demand shift, we need to be told the price, as well as the quantity.

Constraints

In certain countries, there is the concept of minimum wage. We can analyze employment using the Supply and Demand model as well.

Constraint with Excess Supply

In this case, the suppliers would the citizens (as they provide man-hours), while the consumers are the firms. In a country without minimum wage, we would expect the equilibrium to follow the supply and demand curves.

However, suppose that we add the constraint of minimum wage. When there is minimum wage, we would be in a state of disequilibrium. Due to the minimum wage, workers would be more willing to work. However, due to the higher costs, firms will be less willing to hire. This would lead to an excess in supply i.e. unemployment.

Notice that the new equilibrium e2 is actually on the demand curve instead of the supply curve. This is because even though there are more workers willing to work, the firms are the ones deciding how many they want to hire.

If, however, suppose that the minimum wage is below the equilibrium wage. In this case, the wages will actually stabilize at the equilibrium e1 instead of at the minimum wage.

In the above example, we talked about excess supply. There can also be a case where we have excess demand. Suppose that we try to model the Supply and Demand curves for oil.

Excess Demand

Initially, we are at the equilibrium point e1. Suppose that there is a worldwide shortage of oil. If the supply for oil decreases, prices are expected to increase. Shifting the supply curve upwards (to indicate the decrease of supply), we will end up at point e2. However, if the government decides to put a cap on the maximum price for gas (limiting it to the original price), the suppliers will now be unwilling to supply as much as before. We now end up with the equilibrium on the supply curve at e3.

Market Efficiency

In general, equilibrium points always results in the highest efficiency in the market. Constraints, therefore, lead to inefficiencies. The efficiency loss in the wage scenario is that even though workers are willing to work at a lower wage, they are now unemployed because of the minimum wage. Another example is where suppliers would be willing to supply more gas (and consumers will be willing to purchase them) but the gas price cap results in the shortage of gas.

A perfectly competitive market refers to a market where producers offer their goods to a wide range of consumers who bid up the price until the highest bidder gets it. An example of a perfectly competitive market is eBay auctions.

Without constraints, i.e. in a perfectly competitive market, the mechanism used for allocation is price. When prices are allowed to swing unconstrained, we will end up at the natural equilibrium. Looking at the gas example, price is no longer the allocation mechanism due to the constraint which leads to gas shortage. People will have to queue up for gas no matter how much money they are willing to pay. When price is not used as the allocation mechanism, there will be more inefficient mechanisms like the queue mechanism.

There is always a trade-off between efficiency and equity. Even though the market is most efficient at the equilibrium, but it may not be completely fair. For example, without a minimum wage, there are people who could be exploited. When equity comes into play, things become very complicated. For example, in order to shift the supply curve downwards, the government can provide subsidies to the oil companies. However, this would mean that people will be taxed more heavily on the other end.

Summary

In summary, the market is always going to attempt to reach equilibrium whenever they can. Whenever a constraint causes a disequilibrium, the component that is lacking (either supply or demand) will determine where the new equilibrium will be. Equilibrium points are points of highest market efficiency, and constraints, in general, lead to inefficiencies. However, inefficiency may not necessarily be bad as it leads to equity.

Tuesday, May 12, 2015

Microeconomics 01

The study of microeconomics involves constrained optimization in face of scarcity. We build models on how consumers and producers behave in order to study their relationships. However, unlike engineering models, these models are never precise, and can only capture the main insights and never the minute details.

The main constraint faced by consumers is their limited budget, which we will optimize through utility maximization. We want to maximize their utility subject to a budget constraint. Firms on the other hand focus on maximizing profits subject to both consumer demands and input costs.

In Microeconomics, prices play three fundamental roles:
1) What goods and services should be produced?
2) How do we produce these goods and services?
3) Who will make use of these goods and services?

The above three question can be summarized into the term "allocation". As consumers and firms interact in the marketplace, these questions will lead to a set of prices which best satisfies both the consumers and producers.

If we want to create a product, we need to analyze the consumer's reception towards it. Next, we will need to look at all the input costs to see if we will be able to set a price that allows us to profit, while making it affordable to the target market.

When dealing with economics, we have to face both the theoretical and empirical sides. Theoretical economics involves building models to explain the world, while empirical economics involves testing those models to judge its accuracy. That would mean that, of course, models built in theoretical economics should be testable.

Economics can also be positive or normative. Positive describes what the world are, and normative describes what the world should be.

We can almost model any kind of decision. An example model for a decision-making process for buying a new vs used product can be:
1) What are your personal preferences?
2) Are you risk-averse or risk-loving?
3) Is your budget limited or unlimited?

By comparing the price of the new and used product, we weigh that difference in price with the above questions to result in an optimization problem.

Even though we do not really go through these thought processes, but we behave AS IF we have solved these optimization problems. This is known as Milton Friedman's "As If" principle.

Wednesday, July 24, 2013

Physics 01

Introduction to Dimensions

Physics is concerned about the very small, and the very large. In order to represent our observations, we need to know about units. The SI unit for length is the metre (m), time - seconds (s) and mass - kilograms (kg). The L (length), T (time) and M (mass) are fundamental units which all other quantities in physics can be derived.

[ Speed ] = [ L ] / [ T]

The dimension of Speed, is the dimension of Length, divided by the dimension of Time.

[ Volume ] = [ L ]3

The dimension of Volume, is the dimension of Length to the power of 3.

[ Density ] = [ M ] / [ Volume ] = [ M ] / [ L ]<sup>3</sup>

[ Acceleration ] = [ L ] / [ T ]2

All other quantities can be derived from these 3 fundamentals.

Uncertainty

Any measurement, without any knowledge of its uncertainty, is completely meaningless. The uncertainty is the known error margin. Take for example, two measurements taken are:

25.0cm
24.5cm

Whether it is true that the subject in the first measurement is longer than the second one, or is there a possibility that they might be equal, depends on the error margin or the uncertainty of a measurement. If the uncertainty is +-0.1, we can almost guarantee that the first subject is longer than the second. However, if the uncertainty is +-1cm, we may have to take more measurements.

We can find the uncertainty of our measurements through control tests.

Galileo Proportions Problem

When it comes to measurements in systems, we also need to look at how certain measurements scale with each other. Let's look at an example posed by Galileo Galilei.

Suppose that we have an animal of size S. It has legs with a femur bone of length L. The femur bone has a thickness of D.

It is safe to say that an animal has a femur bone that is proportionate (∝) to its size:
S ∝ L

In this case, it is also safe to say that the mass of an animal is proportional to its size to the power of 3:
M ∝ S3

Therefore:
M ∝ L3

Now notice that in order to support its weight, according to Galileo, its femur bone's cross section must be proportionate to the mass:
M ∝ D2

We can then derive this proportionality:
D ∝ S3/2

Then he raised a comparison between an elephant and a mouse. An elephant is about 100 times the size of the mouse, so its femur bone would be 100 times longer, which is true. This proportionality suggests that an elephant's femur cross section would also be 1000 times thicker than the mouse, which turned out to be false. The elephant's femur, is only 100 times thicker, which scientists concluded to be nature's protection against buckling.

Derivation of Dimensions

Let us look at how we can derive the dimensions of units. Recall the following formula:

F = ma

[ Force ] = [M] * [ Acceleration ]

[ Acceleration ] = [ Velocity ] / [ T ]

[Velocity ] = [ L ] / [ T ]

Therefore:

[ Acceleration ] = [ L ] / [ T ]2

[ Force ] = [ M ] [ L ] / [ T ]2

Now let's look at Momentum. Momentum is described as:

p = mv

[ Momentum ] = [ M ] * [ Velocity ]

Therefore:

[ Momentum ] = [ M ] * [ L ] / [ T ]

How about Pressure? Pressure is described as Force per unit Area:

[ Pressure ] = [ Force ] / [ Area ]

[ Force ] = [ M ] [ L ] / [ T ]2

[ Area ] = [ L ]2

Therefore:

[ Pressure ] = [ M ] / [ L ] [ T ]2

Finally, Kinetic Energy is defined as:

1/2*mv2

This gives us:

[ Kinetic Energy ] = 1/2 [ M ] [ L ]2 / [ T ]2

From here, we can derive Work, which is the application of Force for a certain Distance:

[ Work ] = [ M ] [ L ]2 / [ T ]2

We can also derive Power, which is the supply of Energy (which is equal to Work) over Time:

[ Power ] = [ M ] [ L ]2 / [ T ]3

Period of Pendulum Problem

Let us now create a function that can tell us the period of a pendulum (time it takes for a full oscillation).

Suppose that we have the following information:
l = Length of Pendulum (L)
m = Mass of Bob (M)
g = Gravitational Acceleration (L/T2)
θ = Angular Amplitude (L)
C = Constant

Our final solution would be in the form:
[T] = C [L]p [M]q [L]r [LT-2]s

From here, we can conclude that q is zero because it doesn't appear on the left at all. We can also conclude that s must be -0.5 because T on the left is to the power of 1 only. Since L doesn't appear on the left, then L should be eliminated as well.

The total power of L in this equation is currently p+r+s. In order for L to have the power of 0, we must have:
p+r+s = 0
p+r = -s
p+r = 0.5

Now, in order to find out exactly what p and r is, we'll need to go through experimentation to find out if Angular Amplitude plays a part in the equation. If we mess around with a pendulum, you'll soon discover that the Angular Amplitude does not affect the oscillation at all. Therefore, p = 0.5, r = 0.

Our final expression would be:
[T] = C [L]0.5 [LT-2]-0.5
T = C(l/g)0.5

If we scale the length by x, the function would react as:
T(scaled) = C(xl/g)0.5
T(scaled) = (x)0.5C(xl/g)0.5
T(scaled) = (x)0.5T

This is the furthest we can go without experimentation.

Wednesday, June 26, 2013

Computer Science 17

Noise, in photography, is the inability of your camera's sensor to accurately sample and reproduce a pixel from a given exposure. However, the fact that your picture is still discernible is due to the high Signal-to-Noise Ratio.

Signal-to-Noise Ratio is a measurement of how much of a given piece of information is correct, and how much of it is simply noise. For a typical picture, the SNR is actually extremely high, which means that most of the information is correct.

Noise, like most physical phenomena, is Normally Distributed. In case of a picture, for each pixel, the accuracy of the color representation is normally distributed between 3 axes, the Red, Green and Blue, with the Mean of the distribution being the most accurate color representation of the pixel that a camera can produce. If the color inaccuracy exceeds a certain threshold, we will call it "Noise".

If we measure the Noise of a single image, we measure the number of correctly produced pixels, versus the pixels that are incorrectly produced. We must, of course, define what Noise means in an image. In our example, we'll say that pixels of colors that are below 80% accuracy would be considered Noise. If for every 100 pixels there exists 1 pixel of Noise, we would have the SNR of 100:1. This also means that 1% of total pixels are actually Noise.

In the context of an image, I'll refer to noise as Image Noise. Image Noise of an image is relatively stable. The percentage of pixels that are incorrectly produced for a given exposure is roughly constant and does not fluctuate greatly. When considering Image Noise, an exposure can be 100:1 SNR, the next exposure can be 105:1, and the following can be 95:1.

However, if we look at the noise of each pixel, we measure how far is the color away from the actual. For a 100:1 SNR image, 99% of the pixels are actually sufficiently correctly reproduced, while 1% strayed too far from the Mean.

In the context of individual pixels, I'll refer to the noise as Pixel Noise. Pixel Noise can fluctuate greatly. A pixel can have RGB SNR ranging from 100:1 , or 5:1, or even 1:1 accuracy. It is this fluctuation that causes Pixels to contribute to Image Noise.

In order to fix this, we use Image Averaging. If we average every single pixel across 100 exposures of the same angle, we would have a pixel that is 99% accurate to its actual color. By averaging, no pixels would be 100% accurate this way, but pixels that are below 80% accuracy would become extremely rare. The overall Noise is unchanged, but by evening and spreading out the Pixel Noise across all pixels, we effectively reduced the Image Noise of the image.

Let's go through an example of Image Averaging. You can do this with any series of images taken from the same angle. For our purpose, we'll use frames from a video. Here's the set of frames we have, downsized from 720p:



This is the full image of a single frame. Click to open it in a separate page to further inspect it:



After averaging, this is what we got:



Not bad for a zoomed video at 60x huh?

Let's look at another example, at 30x zoom with some contrasting colors:



Notice that you can also have images where the lighting change slightly. It would all even out perfectly.

(There's been some error with the image hosting. I'll host the images once the server is online)

Here's a single shot in full resolution:



And here's the shot after averaging the pixels across 10 shots:



As you can see, the focal blur is better represented and so on.

This concludes this article. I may write another article on how we can do the averaging, especially across hundreds of images.
<