Wednesday, July 31, 2013

Mapping changes over time

A fellow courserian mapped the decline of Monarch butterflies and it had several elements:
  1. An external data source (in this case: Flickr) with geocoding
    1. Photos are geotagged
  2. A time line
    1. 2008 to 2013
  3. Good visualization 
    • a heat map was used
  4. A basemap
    • Imagery was used I believe
If I'm running a hospital network and I have information such as aggregate patient location, I would be interested in seeing where patients are coming from i.e.

  1. An internal data source with geocoding
    • patients are located say via postal code
  2. A timeline
    • last 5 years
  3. Good visualization
    • a choropleth, or graduated circles
    • or a heat map
  4. A basemap 
    • Either imagery or split by postal code or natural subdistrict

Monday, July 29, 2013

Beyond Model Thinking

 Next steps beyond model thinking
  • Figure out entropy 
  • Checkout - http://www.complexityexplorer.org/

Saturday, July 27, 2013

Networks

Networks

Lectures cover:
  • Logic
    • what rules or organizations use to form connections?
    • how it forms
  • Structure
    • what are the measures to compare networks?
    • measures
  • Function
    • what properties emerges from the structure?
    • what it does

Network Structure

  • A set of nodes and edges
    • edges can be undirected or directed
  • Degree
    • how many edges each node has on average
    • node
      • number of edges attached to a node
    • network
      • average degree of all nodes
      • = 2 x Edges / Nodes
    • neighbours of a node
      • all other nodes connected by an edge to the node
    • Theorem
      • The average degree of neighbours of nodes will be at least as large as the average degree of the network
      • i.e. Most people's friends are more popular than they are!
  • Path Length
    • definition
      • Minimal number of edges that must be traversed to go from node A to node B
    • Average Path Length
      • Average path length between all pairs of nodes in a network
    • how far it is from each node to another node
  • Connectedness
    • whether the entire graph is connected to itself
    • definition
      • A graph is connected if you can get from one node to any other
  • Clustering Coefficient
    • how tightly clustered are the edges
    • definition
      • percentage of triples of nodes that have edges between all three nodes
  • What each measure tells us
    • Degree
      • Density of connections
      • Social Capital
        • A proxy for social capital
      • Speed of Diffusion 
        • How quickly information spreads
    • Path Length
      • # Flights Needed
      • Social Distance
      • Likelihood of information spreading
        • unlikely to spread if path length is long
    • Connectedness
      • Markov Process - an essential precondition
      • Terrorist Group Capabilities
        • Connected groups are more capable
      • Internet/Power Failure
      • Information Isolation
        • Disconnected people may not learn things
    • Clustering Coefficient
      • Redundancy/Robustness
        • If there is a break, the network still works
      • Social Capital
      • Innovation adoption (triangles)
        • How likely an innovation is likely adopted
  • Picture = 1000 words

Network Logic

  • Random attachment
    • Connection procedure
      • N nodes
      • P probability two nodes connected
    • Contextual Tipping Point
      • For large N, the network almost always becomes connected when P > 1/(N-1)
  • Small Worlds
    • People have some percentage of "local" or "clique" friends and some percentage of random friends
    • As people have more random friends, there's less clustering an shorter average path length
  • Preferential Attachment
    • Connection procedure:
      • Node Arrives
      • Probability connects to an existing node is proportional to the node's degree
    • The degree distribution always results in a long tail
      • A lot of nodes only have degree 1
      • A handful of nodes with very high degree
    • Results
      • The exact network we get is path dependent
      • The equilibrium degree distribution is not path dependent
        • Always a long tail degree distribution

Network Function

  • Micro decisions/processes when forming networks aggregates in emergent network properties
  • Six Degrees
    • Stanley Milgram & Duncan Watts
    • Random Clique Network
      • Formation Rules: Each person has
        • C clique friends
        • R random friends
      • K-Neighbour
        • All nodes that are of path length K to a node but not of any shorter path length
      • Strength of weak ties

Path Dependence

Path Dependence

Lectures cover:
  • What is Path Dependence?
  • Construct Urn Models to understand
    • different types of path dependence
    • what causes path dependence
    • difference between path dependent outcomes and path dependent equilibria
  • Examples of Urn Models
    • Polya Process, Balancing Process,
  • Path dependencies is logically different from increasing returns
  • Path dependencies are caused by externalities i.e. interdependencies between choices/decisions
    • externalities with negative effects are more likely to be path dependent
  • Compare path dependence and Markov Processes, Tipping Points and Chaos
  • Key lessons - my own reflection of what this lecture means
Real-world examples:
  • QWERTY typewriter keyboard
    • increasing returns / virtuous cycle
      • the more QWERTYs lead to more QWERTYs
  • Technology
    • AC vs DC
    • Gasoline vs Electric Cars
  • Common Law
    • Influence of Precedent
  • Institutional Choices
    • Defined benefits
  • Economic Success
    • Ann Arbor vs Jackson
  • Manifest Destiny of America
  • Railroads 
 

Path Dependence

  • Path Dependent
    • Outcome probabilities depend upon the sequence of path outcomes.
      • Doesn't necessarily determine, merely affects the probabilities
    • What happens now depends on what happened along the path to get here
  • Phat Dependent
    • Outcome probabilities depend upon past outcomes outcomes but not their order
      • Polya process is Phat

Urn Models

  • Basic Urn Model
    • Urn contains balls of various colors
    • The outcome equals the color of the ball selected
  • Bernoulli Model
    • Fixed number of balls in the urn
    • U = {B blue, R red}     ; U stands for Urn is a set of B blue and R red
    • Process: Select ball and return to the urn
    • P(red) = R/(B+R)
    • Outcomes independent
  • Polya Process
    • U = {1 Blue, 1 Red}
    • Process: 
      • Select and return
      • Add a new ball that is the same color as the ball selected
    • Probabilities will change over time
    • Result
      • Any probability of red balls is an equilibrium and equally likely
      • Any history of B blue and R red balls is equally likely
        • Seeing just the set in the outcome doesn't tell you anything about the order (a Phat process) because any order is equally likely
    • Example:
      • Fashion: People buy leopard prints because there are more leopard prints
      • Technology: People buy iPhones because they see iPhones
  • Balancing Process
    • U = {1 Blue, 1 Red}
    • Process:
      • Select and return
      • Add a new ball that is the opposite color as the ball selected
    • Result
      • The balancing process converges to equal percentages of the two colors of balls
    •  Examples
      • Need to keep constituencies happy
        • Selection of site for political conventions - northern or southern state
        • Selection of site by Olympic committee - Asia, Europe, North America or South America
  • Sway Process
    •  U = {1 Blue, 1 Red}
    • Process
      • Select and return 
      • In period t, add a ball of the same color as the selected ball and add 2^(t-s) - 2(t-s-1) of color chosen in each period s < t
    • As you go back in time,the older events take on exponentially more weight over time
    • Early movers have a bigger effect
  • Distinguish between:
    • Path Dependent Outcomes
      • color of ball in a given period depends on the path
    • Path Dependent Equilibrium
      • percentage of red balls in long run depends on the path
  • Outcomes and equilibrium
    • Polya process: 
      • Path-dependent outcomes
      • Path-dependent equilibria
    • Balancing process: 
      • Path dependent outcomes
      • Equilibria independent of path
  • Examples of path-independent equilibria
    • Manifest Destiny - America will stretch from sea to shining sea
    • Railroads - Once railroads were invented, they will build themselves
    • Mobile - Once invented, mobiles is the future

Path Dependence and Chaos

  • Why is the difference between Path Dependence and Phat Dependence important
  • Markov processes
    • finite states
    • fixed transition probabilities
    • can get to any other state
    • not simple cycle
    • markov converges to a unique stochastic equilibrium
  • Chaos
    • Extreme Sensitivity to Initial Conditions (ESTIC)
    • If initial points x and x' differ by even a tiny amount after many iterations of the outcome function, they differ by arbitraty amounts.
  • Tent Map (an example of chaotic)
    • x in (0,1)
    • F(x) = 2x   if X <0.5,
    •         = 2 - 2x if X > 0.5
  • Tent Map is not path dependent
    • Nothing happens along the way/path will change the end
    • is deterministic
  • Path dependence means what happens along the way has an impact on the outcome
Types of outcomes
  • Independent
    • Outcome doesn't depend on starting point or what happens along the way
  • Chaotic
    • Outcome depends on initial conditions
  • Path dependent
    • Outcome probabilities depend upon sequence of past outcomes
  • Phat dependent 
    • Outcome probabilities depend upon past outcomes but not their order
History is path dependent. The future is being written today.
  • History/future is not independent i.e. what's happening now is happening regardless of what happened in the past. Independence means no structure.
  • History/future is not chaotic i.e. initial conditions matter but it isn't the only thing that matter. Once we write the Constitution, the rest plays out deterministically
  • History/future is path dependent not phat dependent because early events have a larger importance.

Path Dependence and Increasing Returns

  • Increasing Returns
    • More produces more
    • Positive feedback / Virtuous cycles
    • The more I have of something, the more I want the same thing 
    • The the more other people do something, the more that other people will do it
  • Example:
    • The more people get QWERTY typewriters, the more people will get QWERTY typewriters
  • Is increasing returns equivalent to path dependent equilibrium? No
    • Increasing returns without path dependent equilibrium
      • Example:
        • Gas / Electric
        • Always goes to equilibrium at Gas even though there is increasing returns
    • Path dependent equilibrium without increasing returns
      • Example
      • Symbiots
  • Path Dependencies comes from a different process - Externalities
    • Externalities:
      • interdependence between choices can create path dependence
    • Decisions create externalities
    • Externalities that big projects create path dependence
      • Choosing Project A first results in choosing Project C next
      • Choosing Project B first results in choosing Project D next
    • Yi J's decision to migrate to Australia affects parents & Dai J

Path Dependence or Tipping Point

  • Path Dependent Equilibrium
    • percentage of red balls in the long run depends on the path
  • Tipping points
    • direct tips
  • Comparison
    • Tipping points
      • a single instance in time where the long term equilibrium
      • a singular event that tips the event abruptly
      • diversity index - count of equilibria
        • diversity index (uncertainly) is reduced abruptly
      • entropy - how much information in the system
    • Path Dependent Equilibrium
      • accumulative effect of moving along the path
      • diversity index reduces gradually
        • unlike tipping point where diversity index (uncertainly) is reduced abruptly

Key Lessons

  • Externalities are the reason choices we make in the past will affect choices we make in the future
  • Pay more attention to choices with externalities e.g.
    • Where you choose to live
    • What line of work you choose to do
    • What language you choose to learn
  • Where possible make decisions where externalities are all positive 
    • including future externalities
    • this will reduce path dependencies i.e. keep your options open
  • History matters when it changes transition probabilities
    • Make decisions that increase transition probabilities to states you desire - to goal states
  • Pay attention to externalities when making decision especially negative externalities
    • Keep your options open

Friday, July 26, 2013

The Power of Complements

The Power of Complements

In this week's lecture:
  • Examples and definition of complementary products
  • The economic definition for complementary products
  • Cross-price elasticity of complementary products
  • How substitute goods can also be surprising complements
  • Interesting strategies in markets with complementary products
    • Supporting the supplier of a complementary product
    • Produce the complements - Advantages and disadvantages
  • Strategies for firms that produce the complements
    • Cross subsidize complementary products
    • Bundle complementary products
    • Increase Lock-In
  • How complementarity can help achieve cooperation among firms who might otherwise compete
    • Competitors as Complementors
    • How Strategic Partnerships foster coordination between firms
      • Shared decision making
      • Organisation Integration
      • Economic Integration

Complementary Products

Examples of complementary products:
  • Computers and Software
  • Skis & Skiing Sticks
  • Smartphones & Apps
 

Economic Definition

The utility increase when the products are used together.
  • Two products A and B
  • These are complements if B increases users' utility from A, and vice versa
  • U(A+B) > U(A) + U(B)

Cross-Price Elasticity

  • Two products A and B
  • These are complements if the demand for B increases when the price of A drops, and vice versa
  • This phenomenon is referred to as negative cross price elasticity
  • Cross price elasticity is how the price of one product depend on the price of another products

Surprising Complements

  • Substitute good can also have complementary effects
  • A price cut of the substitute good decreases market share but increases the size of the market, resulting in a positive net effect
  • Example: Cloth shops in the same mall
    • Shop A's price cut makes the whole mall more attractive
    • Shop B's sales increase due to the additional customers


Supporting the Supplier

  • Enable the supplier in ways that increase sales of complement e.g.:
    • Better quality of complement
    • Higher sales of complement
  • Example: Apple
    • Gave laptops to students writing software for Mac OS
    • More compatible software titles made Apple's laptops more attractive
  • Example: Game console manufacturer 3DO
    • Problem
      • Console manufacturers sold consoles for high prices to make profits
      • This attracted a limited number of customers only
      • Neither optimal for console manufacturers not for game publishers
    • Solution
      • Publishers paid a fee of 3 dollars to 3DO for every game copy sold
      • 3DO could sell consoles much cheaper and attract more customers
      • This way, publishers could sell more copies and increase profits

Producing Complements

  • It may make sense to produce the complement yourself
  • Example
    • Sony produces game console and video games
    • Hewlett Packard manufactures printers and printing ink
  • Contra
    • Market for complements may simply be unattractive
    • Complement may require competencies the firm lacks (production, R&D, management, ...)
    • Prospective customers might be put off by a firm's dominant position
  • Pro
    • Better tailoring of complement to own product
    • Quality control for complement
    • Internalization of the positive effects (externalities) of the complement on own product
      • Cross-Subsidies
      • Bundling
      • Increasing Lock-in

Cross Subsidies

  • Idea
    • Product A is sold at small margins (even loss) to increase sales of Product B (high margins)
  • Advantage
    • Increase profits through intelligent pricing
  • Risks
    • Consumers do not buy product B at all
    • Consumers buy product B from another manufacturer
  • Examples
    • Razors and razor blades
    • Printers and printer cartridges
    • Mobile phones & operator contracts

Bundling

  • Idea
    • Firm sells product A and complement B combined as a package
  • Advantage
    • Little or no competition in market for A
    • Decreased competition in market for B
  • Risks
    • Potential buyers of "A only" or "B only" are lost
    • Bundling becomes standard and advantages of unbundling are overlooked
      • e.g. How to differentiate and how to set prices
  • Examples
    • Game console and games 
      • e.g. Wii bundle with console, game, steering wheel
    • Operating system and web browser
      • Flight and baggage handling

Increasing Lock-In

  • Idea
    • Users have switching costs when switching from A to a substitute
    • The more complements (B, C, ...) to A they buy, the higher the switching cost
  • Advantage
    • Higher switching costs imply a higher value of the customer to the firm
    • You can charge customers higher prices
  • Examples
    • Microsoft Office and MS Windows
    • Games and video consoles

Competitors as Competitors

  • In certain situations, firms may be
    • Competitors in one part of the market
    • Complementors in another part of the market
  • In such a constellation, they may not compete that harshly
  • Example: Music Players & Music Content
    • Sony and Apple
    • Competitors
      • Both sell portable music players
    • Complementors
      • Sony Music provides music content for Apple's iPod / iPhone
      • Apple's iTunes store is important sales platform for Sony's music content
  • Example: Mobile Phone Calls
    • Vodafone and T-Mobile
    • Competitors
      • Both sell mobile phone contracts
    • Complementors
      • Their networks are interlinked
      • Customers join Vodafone because they know that they can also call T-Mobile customers , and vice versa.
      • Parts of Vodafone's / T-Mobile's revenues come from these cross-network calls

Strategic Partnerships

  • Drivers of Strategic Partnerships
    • Producers of complementary goods depend on each other
    • Helping each other and coordinating each other's behaviour maximizes the positive effects of complementarity
    • In many cases, integration into one single company not feasible or not desired by involved firms
    • Forming a strategic partnership is a powerful way of institutionalizing coordination and formalising interests
  • Definition of Strategic Partnerships
    • Relationships between firms
    • Typical characteristics
      • Shared decision making
      • Organizational linkages & coordination mechanisms(organisational integration)
      • Joint equity ownership (economic integration)
  • Organisational Integration
    • Teams across firms
    • Established reporting and decision routines across firms
    • Heavy exchange of information
  • Economic Integration
    • Direct cross ownership of equity
    • Firm A holds X% of Firm B's assets and vice versa
    • Setting up a new legal entity (joint venture)
    • Benefits
      • Alignment of interests
      • Retention of control and exclusivity
      • Feasibility of inter-organisational coordination
  • Complementarity and Strategic Partnerships
    • If firms produce complementary products, already high incentives to work together cooperatively
    • Less need for economic integration to align interests

Beyond Creative Programming Course

Next steps after Creative Programming Course:
  1. Develop Mandelbrot Surfer
  2. Read the Nature of Code
  3. Develop Shoot the Apple Game
  4. Develop a site like http://funprogramming.org/ (they key being graduated exercises)
  5. Checkout Processing.js on Windows 8

Social Sharing Programmatically

Sharing on Social media
  • Tumblr: http://stackoverflow.com/questions/6169603/tumblr-sharer-url-override
A good source of information on Tumblr
  • http://www.cherrybam.com/tumblr-tutorials.php

Thursday, July 25, 2013

Request Features for Mandelbrot Surfer

Mandelbrot Surfer

Mandelbrot Surfer lets you explore the Mandelbrot Set and discover wonderful fractal images share them with your friends.

New Planned Features

  1. "Record" button -- allows you to record the images as you explore and "Play" button to playback.
  2. "Random Explore" mode -- randomly move in and out of various spots making a nice screen saver.
  3. Toggle sound/music -- goes well with random explore mode.
  4. Share your favourite images with your friends on Facebook / Twitter. (Done for Twitter)
  5. Add other features you'd like to see in comments below.

Wednesday, July 24, 2013

How to mix Javascript and Processing JS

Since Processing code gets converted to JavaScript and run like any other function, all Processing code has access to the global object. This means that if you create a variable or function in a global script block, they are automatically accessible to Processing

See http://processingjs.org/articles/jsQuickStart.html#mixingjsandprocessing

Mandelbrot Surfer

Mandelbrot Surfer

Mandelbrot Surfer lets users explore the Mandelbrot Set and discover wonderful fractal images. Give it a try - you may discover some graphical gems! See image below for an example.

Functionality

  1. Zoom in and out of the image by pressing on the zoom buttons
  2. Change the colors by pressing on the color flower button
  3. Center the image at point by pressing on the point of interest

Potential features 

Let me know which one you like to see first!
  1. "Record" button -- allows you to record the images as you explore and "Play" button to playback.
  2. "Random Explore" mode -- randomly move in and out of various spots making a nice screen saver.
  3. Toggle sound/music -- goes well with random explore mode.
  4. Share a gem -- Share your favourite images on Facebook/Twitter with your friends.
  5. What other features would you like to have?
Sample images from Mandelbrot Surfer:


Saturday, July 20, 2013

Lyapunov Functions, Externalities and Langton's Lambda

Externalities

An externality in an exchange market is an action by one party that materially affects the happiness of someone who is not directly a party to the action.

Externalities make systems churn - less likely to reach equilibrium. Examples include:
  1. Arms Trading
    • Participants are happy but other countries are unhappy (externality)
  2. Political Coalitions
    • When Party A merges Party B, Party C may be upsed
  3. Mergers
    • When two firms merge, other firms are less profitable, less secure
  4. Alliances
    • When two countries make alliances, other countries are less happy, feeling less secure 
 Systems with externalities affect the Lyapunov Function of other parties which changes their behaviour which in turn may change our behaviour and it generally leads to churn.

Chris Langton's Lambda Parameter

  1. Systems where behaviour isn't  influenced by others tend to go to equilibrium
  2. Systems where behaviour and actions are influenced by others then to be complex

Lyapunov Functions in Exchange Markets

Exchange Markets

  1. People bring stuff - some bring fish, some bring vegetables, some bring money
  2. People exchange stuff (trade)

Assumptions

  1. Each person brings a wagon of stuff
  2. People trade with others but only if each gets an increase in happiness by some amt K 

Lyapunov Function

  • Lyapunov Function
    • Sum of total happiness
  • Maximum
    • There is a maximum happiness - when everyone gets what they want
  • Each move increases value of Lyapunov Function
    • Each trade increases total happiness

Four states of any system

The four states

  • Equilibrium
  • Cycle
  • Random
  • Complex

Equilibrium State

  • Lyapunov Function: If a Lyapunov Function can be constructed for a system, the system will go to equilibrium 
  • Markov Process: If it's a Markov Process, it will reach stochastic equilibrium

Cooperation

Why do companies cooperate?

  • Sometimes competition is not in the companies' best interests
    • i.e in a Prisoner's Dilemma
  • Sometimes companies need each other

What are the mechanisms to achieve cooperation between individual profit maximizers?

  • Repeated games
  • Commitment

Friday, July 19, 2013

The Instaspam Week

Capabilities to develop

  1. Accessing the camera on mobile phones
  2. Access Facebook API from within Processing
  3. Use App GUI interface 
  4. Understand PHP and Javascript integration challenges

Gist of the Instaspam design

  1. Take a picture: Provide a button to capture images from files or cameras
    1. Add a Button to the sketch
    2. Link the selectFile() function in insta.js to the button
  2. Manipulate the image: Provide more buttons to manipulate the image
  3. Push image to Facebook: Provide a button to push an image to Facebook in a 2-step process
    1. Upload image in Processing canvas to a file in the cloud (using PHP or something similar)
    2. Push uploaded file to Facebook

Create a Facebook App for Integration

  1. Signup as a facebook developer
  2. Go to https://developers.facebook.com/apps
  3. Create a new app
    • You need own a web site (a place you can upload images)
  4. Get Facebook appId and store into insta.js
  5. Save the channel.php file on your webspace
Challenges
  1. Image manipulation on mobile phones can be slow for large images
 Image Effects
  • Applying tint filter. Tints are useful for:
    • turning a black and white photograph into an old style sepia image
    • making all of the images in your app have a consistent color scheme
  • Apply an overlay. Overlays are useful for:
    • adding a picture frame to your image
    • creating a mist or fog effect
  • Use Buttons:
    • Button b = new Button("name",x,y,w,h);
    • b.setImage(img_active); 
    • b.setImage(img_inactive); 
    • b.display();   // in draw()
    • b.mouseReleased();   // in mouseReleased()
  • Use RadioButtons
  • Use showGUI variable to display buttons only if showGUI is true
    • increases screen space
Image Processing
  • insta.js - allows Processing to access cameras on mobile phones
    • edit index.html
      • <body onload="setupFileListener()">
      • <script src="insta.js"></script>
      • <input type="file" name="file" id="file"/>
    • assign the selectFile() function to a button
      • the function will capture from the camera


Notes

  • alpha = opacity (255: opaque, 0: transparent)

How to publish Processing sketches on iOS app store

Steps to release apps on iOS app store

  1.  get an iOS developer account
  2. use Phonegap to make your JavaScript-based processing sketches into full iOS apps

Beyond Creative Programming

Next Steps

  1. Study Oli Roberts Network Graph to figure out how it works

Notable Works

Notable works


Running SSH on Windows

Setting up SSH on Windows for GitHub

  1. Create a ".ssh" folder in your home directory.
  2. Use Puttygen.exe to create ssh-rsa keys.
  3. Save the public key as %HOME%/.ssh/id_rsa.pub
  4. Save the private key as %HOME%/.ssh/id_rsa
  5. Edit the id_rsa.pub file by removing the comment and replacing with "ssh-rsa". Make sure it is one single line. It should look like:
    • ssh-rsa AAABSLDFEISELslghkjsesoi ...... yourname@email.com
  6. Login to GitHub and add the contents of id_rsa.pub as one of the security keys.

See this site on instructions on how to use Puttygen.exe to create keys.

Thursday, July 18, 2013

Why use Twitter Bootstrap

Use Tools

  1. Use Chrome's User-Agent Switcher to spoof your user agent
    • Make the spoof permanent
  2. Use Chrome's Resolution Test to quickly switch resolution of browser
    • Add iPhone resolutions using options
  3.  Use Twitter Bootstrap and CSS to quickly style a website to look good on mobile
    1. See documentation on examples and components

Beyond Machine Learning

Next steps:

  1. Competitive Data Mining with R and Python (Video 19:30)
  2. Checkout ML toolkit tutorials here.

List of Courses

Courses In-Progress

  1. Startup Engineering
  2. Model Thinking 
  3. Introduction to Finance
  4. Maps and the Geospatial Revolution 
  5. Competitive Strategy 
  6. Creative Programming for Digital Media & Mobile Apps 
  7. Introduction to Systematic Program Design - Part 1

Courses Completed

  1. Machine Learning
  2. An Introduction to Operations Management 
  3. Introduction to Data Science

Lyapunov Functions - Scary Russian Function Not!

What's a Lyapunov function

The existence of a Lyapunov function for a model or system means that the system will hit equilibrium.

The elements of such a system include:
  1. A maximum
  2. A Lyapunov function
  3. A property such that if something moves, it will always increase by k

How do cities self-organize such that queues are reasonable?

Answer: A Lyapunov function exists that explains how the city moves to equilibrium.

Applications of Lyapunov function

List of applications
  1. Self-organizing cities
  2. Exchange Economies
  3. Arms trading

Online GIS tools


Closed source:

Open source

Wednesday, July 17, 2013

Why/How to do Market Sizing, Product Tier and Product Pricing

Why do market sizing?

The only thing that matters is the market:
In a great market -- a market with lots of real potential customers -- the market pulls product out of the startup. ~Marc Andreessen

How to do market sizing?


Top-down estimation
Bottom-up estimation

Product Tier and Pricing

  1. Establish a market before building a minimum viable product
  2. Develop a simple landing page
    • Use Launchrock service
    • Use photos from iStockphoto
    • Use icons from iconfinder
    • Use some basic SEO
  3. Determine product tiers
    1. Read Kickstarter product tiers
    2. Read Kickstarter trends
    3. Use the product tier selection process
    4.  
  4. Review what Joel Spolsky has to say
 

The Idea Maze and Execution Mindset

The idea state machine

Think of the idea state machine above as a recipe that tells you what to do next.

How to develop a good idea?

  1. Develop a bird's eye view of the idea maze
    • understand all the permutations of the idea and the branching of the decision tree
    • gaming things out to the end of each scenario
  2. Develop an obsession with the market / the idea maze
  3. Study historical players that failed or succeeded in the maze
  4. Think deeply about others who have gone before you and failed or succeeded 
  5. Explain how you are different or you will navigate it better

The Execution Mindset

The execution mindset is in two parts:
  1. do the next thing on the todo list
  2. rewrite the list in response to progress
The list is essentially the plan - stay focused on what needs to happen and be flexible to "rewrite" the list in response to progress.

 References

  • Startup Engineering Lecture 5

Startup Ideas

Startup Ideas

Context-aware applications - like Google Glass.
A personal collection of recipes, templates, models, examples and where to learn that are accessible:
  1. Frequently Used Recipes, Templates, Practices
  2. Financial models tells us what kind of information to collect
  3. Code recipes or process recipes tells us what to do next
  4. Templates gives us a quick structure
  5. Model thinking models tells us what information to collect, which models to use
  6. Examples to illustrate how 
  7. Value - Productivity, better decision
  8. Eventually available on Google Glass
Theoretical Underpinnings: Knowledge is constructed.

Tuesday, July 16, 2013

Three Steps to creating a truly valuable tech company


There are three steps to creating a truly valuable tech company. 
  1. First, you want to find, create, or discover a new market. 
  2. Second, you monopolize that market
    •  through some combination of brand, scale cost advantages, network effects, or proprietary technology
  3. Then you figure out how to expand that monopoly over time. 
Reference:

Beyond Startup Engineering

Next Steps:
  1. Review awesome essays in Peter Thiel's CS183: Startup Course.
  2. Review the pmarca guide to startups
  3. Follow the pmarca blog
Technical
  1. Get a Javascript workout
  2. Get examples of node.js | jquery.js
  3. To to Startup School 

Beyond Systematic Program Design

Next steps beyond Systematic Program Design include:
  1. How to Design Programs, HtDP
  2. Structure and Interpretation of Computer Programs, SICP
  3. Concepts, Techniques, and Models of Programming , CTM

References:


On Systematic Program Design


Key lessons from this course include:
  1. Recipes are extremely useful
  2. Templates are extremely useful
  3. Knowing what needs to be done NOW is extremely valuable
    • It increases productivity tremendously
    • Recipes and templates are what makes this possible 
  4. Data design drives function design drives implementation
  5. Being systematic comes from using good recipes and templates
Key programming practices:
  1. Understand the information domain clearly
    1. Draw diagrams
    2. Write out examples
  2. Map the information domain to data domain
  3. Use check-expects / unit tests
  4. Use wishes to track work outstanding
Key tools:
  1. Recipes
  2. Templates



Data Definition for Tree Structures Using Mutual Recursion

A tree of arbitrary width and depth is defined using mutual recursion.
The figure below shows the mutual reference in the data definition and the corresponding function template.
Also contrast a tree with a list. A tree has arbitrary width and depth which a list has arbitrary length.

Decomposing Functions

When to decompose functions?

  1. Function composition:  A function should be split into a function composition when it performs two or more distinct and complete operations on the consumed data.
    • define arrange-images as a function composition of sort-images and layout-images helper functions.
  2. Operating on a list: When an expression must operate on a list -- and go arbitrarily far into that list -- then it should call a helper function to do that.
    • use the insert-images helper function so that the (first loi) expression can operate on the (rest loi) list, going arbitrarily far into that list as needed.
  3. Domain knowledge shift: When the body of a function must shift to a new knowledge domain, it should call a helper function to do the work in the new domain.
    • use the (larger? img1 img2) helper function when shifting from the domain knowledge of inserting images to domain knowledge of determining size of images.

Monday, July 15, 2013

Two Crucial Considerations for a Startup

Crucial Considerations

Two Crucial Considerations for a Startup:
1. Market Size
2. Time to Market

Market Size

Look at the market leaders for an estimate of market size.

Time to Market

A faster time to market beats all other considerations, other than market size.
Because of the effect of compounding.

Sunday, July 14, 2013

Cash Flows: Important Principles

Estimate all cash flows on an incremental basis

Create a cash flow timeline, A, for the firm without the project.
Create a cash flow timeline, B, for the firm with the project.
The project value is the incremental cash flows generated i.e. cash flows of B-A.

Do not forget the importance of year 0 and the last year of the chosen timeline for the project

In year 0, Capital Expenditures and Working Capital will be incurred.
Working Capital typically includes Cash, Inventory, AR and AP
At the end of the project, there's terminal value or sale of inventory.

Account Issues are Important

Depreciation is the main issue because it's made up - And similar non-cash items.
Capital: a) Capex and b) Working Capital - Think about changes.

Do not mix financing with operations

Stay on the asset side. Value is generated on the asset side.
When you are doing project analysis, don't worry about financing for two reasons:
  1. Money is generated by your ideas, not by financing
  2. When you are discounting your cash flow, you are taking financing into account
  3. Your ideas generate cash flows and financing just divides up the cash flows

Include effects of inflation/deflation

When projecting prices, take into account inflation or deflation.
Inflation is always in the discount rate, r.

Do not compare projects with unequal lives


Cash Flows from Project/Operations

Cash Flows from Project/Operations

  Revenues
- Costs of Goods Sold
- Selling, General & Admin. costs
- Depreciation
--------------------------------------
= Operating Profits
- Cash Taxes on Operating Profit
--------------------------------------
= Net Operating Profits After Tax
+ Depreciation
- Capital Expenditures
- Increases in Working Capital
--------------------------------------
= Cash Flows from Operations

Depreciation: Think of depreciation as the main non-cash item that has tax implications.
Working Capital = Cash + Inventory + Acct Receivable - Acct Payable

The dangers of using IRR


Value creation is most important when it impacts a lot of people and when it lasts a long time. And IRR has a bias for small, low-impact and short-term projects.

 IRR has a short-term bias

Be careful when using IRR. Do not compare IRR of one project with another project because they are internal rates.

All value is relative.
Instead of comparing IRR percentages to each other, compare the IRR percentages to a benchmark - the cost of capital outside.

IRR calculations favors projects with earlier cash flows - IRR has a short-term bias.
IRR is myopic in that it favours shorter term returns.

Be wary when IRR is used as the decision-making criteria - it indicates a myopic point of view.

Example Calculation

Consider Projects A and Project B:
  • Project A Cash flows: [ -2000, 400, 2400 ]  -  IRR = 20%
  • Project B Cash flows: [ -2000, 2000, 625 ]  -  IRR = 25%
Try computing the NPV of the two projects for discount rate of 5%, 11% and 20%.
Also, try drawing the graph of NPV vs r for the two projects.

IRR has a small-investment bias

Consider Project A and Project B:
  • Project A Cash flows: [ -5000, 7500 ]  -  IRR = 50%
  • Project B Cash flows: [ -50,000, 62500 ]  -  IRR = 25%

What is the Internal Rate of Return (IRR)

What is IRR

The Internal Rate of Return (IRR) is the rate of return you earn on your project.

The Internal Rate of Return (IRR) is the return such that NPV is zero.
An investment is worthwhile if IRR is greater than R, the next best competing alternative.

The rate of return is internal because it is the rate of return specific to the project. All that is needed is the cash flows for that project. Compared it to NPV, which requires cash flows and the discount rate, r.

Decision Making using IRR

IRR by itself doesn't mean anything.
IRR needs to be compared to r.
When IRR > r, then the idea/project is worth pursuing because NPV will be positive.

Saturday, July 13, 2013

What is the NPV of an idea?

The Net Present Value of an idea is the value created by the idea.

Interest rate, R, in Net Present Value

Where does the interest rate, r, used in computing net present value come from?
  • r comes from the next best use of your investment, or other people's investment on a similar project
  • r does not belong to your project
  • r is that return from investing in say a competitor

Simple and Continuously Compounded Returns

Time Value of Money

  • Future Value
  • Present Value
  • Compound Annual Return
  • Investment Horizon
  • Continuous Compounding

Effective Annual Rate

  • Effective Annual Rate
  • Effective Continuous Compounding Annual Rate

Asset Return Calculations

  • Simple Returns
  • Multi-period Returns
  • Simple k-month Return

Portfolio returns

  • A portfolio of investment assets
  • Define a portfolio by how much wealth (weight) is invested in each asset
  • Rate of return on a portfolio
    • A weighted average of the simple returns of individual assets
    • Sum of weights add up to 1

Adjusting for Dividends

  • Total Return = Capital Gain Return + Dividend yield (gross)

Adjusting for Inflation

  • Deflate the nominal price by an index of the general price level 
  • Compute returns in the usual way using the deflated prices
  • Real Rate of Return =

Tips

Develop an intuition of the reasonable orders of magnitudes of  rates of return on different investments.
e.g. what is reasonable for a 1-month investment for Microsoft?
What is a typical rate of return in a year
What is a typical rate of return in a month

Ideas for Startup Engineering Project

Retirement Calculator

A calculator of how much one needs to save using the principles of Finance.
Additional ideas include:
  1. Saving Reminders, 
  2. Integration with precommitment websites
  3. Gamification ideas

In Finance, always look forward

An interesting mindset of Finance is to always look forward - time travel if you have to.

A specific application is when calculating the amount owed at a point in time.
Instead of computing the entire loan amortization table to answer the question, it is easier to simply "time travel" to the point-in-time of interest and look forward to see how many payments are outstanding and do an PV calculation.

Simple Future Value and Present Value

Simple Future Value

FV = PV * (1 + r)^n

Simple Present Value

PV = FV / (1 + r)^n

In Finance, the term "Discounted ..." means present value

The meaning of "Discounted ..." in Finance simply refers to the present value of something.

The reasoning goes like this.
A dollar today is worth more than a dollar tomorrow.
A dollar tomorrow is worth less than a dollar today.
A dollar tomorrow is discounted (thus worth less) to get its present value.

For example, discounted cash flow simply means the present value of all the future cash flows.

Friday, July 12, 2013

Represent Real-World Finance Problems with Timelines

 Represent problems on the timeline with periods 0, 1, 2 ... to n.
Understand what happens during each period to get a sense of what happens at period n.

An Introduction to Introduction To Finance

Introduction

I like the introduction of Dr Kaul Introduction to Finance course:
Finance is the study of value.
The notion of value is tightly linked to the notion of better. Higher value = better.

What can I expect to learn?

A framework and the tools to value almost anything. I also expect to learn a value-based perspective.

How can I expect to be better?

I'll be able to make value-based decision making.

Some quotes:

I will not use a formula unless I can explain it in words... force yourself, to first say it in words before using the formula because I think the formula reflects what we are thinking, not the other way around. And that's one of the problems of Finance and Technical areas, that we somehow think, that, just because there's Math, there's a definitive answer. 

All answers are wrong. There's a bunch of assumptions, that we make in valuing things and it's your assumptions and way of thinking, that's the value part, not the final answer. Anybody can crank through Excel and come up with an answer, it doesn't mean much.


Tuesday, July 9, 2013

AngryBoids - Implementation Workflow

Implementation Workflow

  1. Import required libraries
    1. import jbox2d libraries for Java & Android
    2. for javascript, include the following files in directory
      1. Box2D.js
      2. CollisionDetector.s
      3. Maxim.js
      4. physics.js
  2. Setup physics objects - physics
    1. Setup the start point
    2. Setup the collision detector
  3. Setup audio
  4. Setup graphics
    1. Setup custom rendering function where all drawing is done by physics engine
    2. Layout all the objects
    3. Map complex Graphics shapes to simple Physics objects e.g. boid maps to circle
  5. Setup gameplay score
  6. In the draw():
    1. Update the game score
  7. In mouseDragged();
    1. Set position of objects
  8. In mouseReleased():
    1. Apply impulse to objects
  9. Implement the customRenderer
  10. Implement the collision call back
    1. Check collisions with walls
  11. Elements to be added
    1. Gameplay mechanics
    2. Scoring mechanism
    3. Good artwork
    4. Good audio

Integrating audio and physics

Implementation
  1. Setup One sound for every object
    1. This allows simultaneous sounds for all objects
  2. Setup arrays for similar objects
  3. Setup the appropriate looping for each object
  4. Load all the files e.g. droid, wall and crates
  5. Develop code that triggers each sound

One sound for every object

Maxim maxim;
AudioPlayer droidSound, wallSound;
AudioPlayer[] crateSounds;

Use arrays  for similar objects

crates = new Body[7];
crates[0] = physics.createRect(300, height-crateSize, 300+crateSize, height);

Sound Logic Pseudo-code

test for each object type
  cue player
  set speed of sound based on impulse
  play wall sound



Game Audio - Preparing and playing sound


Game Audio Workflow

  1. Make sound effects
    1. Record sound effects
    2. Trim sound effects and export selection
    3. Save into folder named "fx"
  2. Import data into sketch
    1. Copy to sketch's "data" folder
  3. Code the sound triggering function
    1. See code below
    2. Name the AudioPlayers to remind us of the sound
    3. Code up mousePressed() to quickly test the sound
  4. Parameterize the playback to make it dynamic
    1. So that they are not the same sounds every time they are played
    2. See playSound()


AudioPlayer ping1;
AudioPlayer ping2;
AudioPlayer rumble;

void setup() {
  maxim = new Maxim(this);
  ping1 = maxim.loadFile("ping1.wav");
  ping2 = maxim.loadFile("ping2.wav");
  rumble = maxim.loadFile("rumble.wav");
  ping1.setLooping(false);
  ping2.setLooping(false);
  rumble.setLooping(false);
}

void mousePressed() {
  ping1.play();
  ping2.play();
  rumble.play();
}

void playSound(int sound) {
  if (sound == 1){
    ping1.speed(random(0.1, 2));
    ping1.play();
  }
}

Game Engine - Forces

Gravity

Gravity is automatically built into the world.
Gravity is a vertically downward vector.

Impulse

Impulse is force applied at a moment in time.

Vec2 impulse = new Vec2(2,4);   // 2-right, 4-down
box.applyImpulse(impulse, box.getWorldCenter());

Designing the Catapult Implementation

Impulse

I = C(catapult - ball)

Vec2 impulse = new Vec2();
impulse.set(catapultPos);
impulse = impulse.sub(boid.getWorldCenter());
impulse = impulse.mul(200);

 Collisions are handled by the physics engine.
  • The key knowledge is to know when a collision happened

Collision handler function

void collision(Body b1, Body b2, float impulse) {
  // collision response goes here
}

Physics and Graphics Objects

Physics and Graphics Objects

Physics Objects

Physics objects are made up:
  • Simple Shape
  • Position
  • Angle
  • Mass 

Set up Physics World

physics = new Physics(this, width, height);
physics.setDensity(1.0);
physics.setDensity(0.0);  // Objects won't be affected by physics and they will not move

Creating Physics Objects

Body box = physics.createRect(top-left-X, top-left-Y, bottom-right-X, bottom-right-Y);
Body ball = physics.createCircle(center-X, center-Y, radius);

Graphics Objects

Graphics objects are composed of:
  • Complex Shape
  • Colors
  • Images

Mapping Physics to Graphics

The most important thing is link physics to graphics i.e get position and rotation of physics bodies and apply that.

Vec2 pos = physics.worldToScreen(body.getWorldCenter()); // get object's position
float angle = physics.getAngle(boid);

pushMatrix();
  translate(pos.x, pos.y);
  rotate(-radians(angle));
  image(ballImage, 0, 0, ballSize, ballSize);
popMatrix();

Scaling Units

One meter in physics = one pixel in graphics


Sequential Games, Backward Induction and Credible Threats

1-6 Sequential Games I - Game Setting

Sequential games where firms make decisions one after another are represented as game trees.

Game trees are built up as follows:
  1. First decision starts the game
  2. Every decision point represents a node
  3. From there, the decisions of subsequent players branch out accordingly
A revised working definition of strategy: strategy is a player's plan of actions in a game, given any possible circumstances.

Sequential games can be applied to the problem of price setting.

1-7 Sequential Games II - Backward Induction

Backward Induction is:
  • Simplification of a sequential game
  • Eliminate actions at the final node and work one's way backwards
  • Eliminate actions that would not maximize an individual's profit at that point
  • A rational player always tries to maximize their own profits
  • You can rely on a rational rival never choosing these actions
Backward induction allows us to find the best strategy for the first mover.

1-8 Sequential Games III - Credible Threats

Motivating question: How to distinguish between a credible threat and cheap talk?

Apply backward induction to determine if a threat is credible.
A public commitment (e.g. Lufthansa committing to a penalty) can also change the payoffs in such a way as to make a threat credible.

Commitment strategies is one way to change your payoffs to make your threat credible.


Simultaneous Games, Dominant and Dominated Strategies, Nash Equilibrium, Prisoner's Dilemma

1-2 Simultaneous Games I - Game Setting

A working definition of a strategy is a player's plan of actions in a game.
Simultaneous games as represented in a matrix structure.
The elements of a simultaneous games matrix are:
  • Players e.g. Sensodyne, Colgate
  • Actions e.g. Advertise, Don't Advertise
  • Rules e.g. Simultaneous decisions
  • Payoffs e.g.80% of market if advertise

1-3 Simultaneous Games II - Eliminating Dominated Strategies


A dominant strategy is a strategy that always does better than any other strategy regardless of what the other firm does.
  • A rational player always chooses the dominant strategy. 
  • We can anticipate that our rival will also choose the dominant strategy
A dominated strategy is a strategy that never does better than another one.
  • A rational player would never opt for this strategy. 
  • More importantly, you can rely on a rational rival never playing a dominated strategy
To solve this game, eliminate dominated strategies iteratively to eventually find the optimal strategy for each player.

1-4 Simultaneous Games III - Nash Equilibrium

A Nash Equilibirum is a combination of strategies such that any player that deviates from that equilibrium will have a worse payoff.
A good question to ask is: Does any player have an incentive to change their strategy?

Questions:

  1. Is a Nash Equilibrium the same as a dominant strategy?
  2. Can a Nash Equilibrium contain dominated strategies?
  3. Will every Nash Equilibrium contain dominant strategies?
  4. Will every game will have a Nash Equilibrium?
  5. Can a game have more than one Nash Equilibrium?

1-5 Simultaneous Games IV - Prisoner's Dilemma

The Prisoner's Dilemma is a special form of Nash Equilibrium such that:
  • there exists a combination of strategies with higher joint payoffs 
  • but it is unlikely to be chosen because each player chooses a dominant strategy 
  • and players gravitate to the lower-paying Nash Equilibrium


Monday, July 8, 2013

Publishing a Processing Javascript project

 I needed to publish the Javascript version of a Processing project but ran into some issues.

 Publishing to firexis.com

First I tried to publish to my own website but it didn't work.

Issue: IIS ignores files with unknown extensions such as .pde.
Resolution: Add MIME Types as below and it now works
  • Extension: .pde
  • Content Type: text/plain 
See the published project here.

Publishing to Google Drive

A simpler way, if you have a Google account is to publish it on Google Drive.
See the published project here.

Reference

Sunday, July 7, 2013

Markov Convergence Theorem

Assumptions for Convergence

A1: Finite states
A2: Fixed transition probabilities
A3: Can eventually get from any one state to any other
A4: Not a simple cycle (not automatic state changes)

Given A1-A4, a Markov process converges to an equilibrium distribution which is unique.

Implications

  • The initial state doesn't matter
  • History doesn't matter
  • Interventions doesn't matter
    • Is this the systemic structural property that prevents diets from succeeding?

Things to Remember

  • It could take a long time to reach the equilibrium
  • The point of intervention is by changing A2, by changing the transition probabilities
  • Changing state: temporary; Changing transition probabilities: permanent

How to use Models

How to use models

1. Start with a simple model (e.g. alert/bored model for Markov processes)
2. Understand the mechanics of the simple model
3. Understand how the simple model scales with more dimensions (e.g. 3 states instead of 2)
4. Apply the model to real problems with more dimensions (e.g. democratization problem)
5. Use real data and get a deeper understanding of how the model works
6. See if counter-intuitive results emerge

Reference:

  • Lecture 10.3 Markov Model of Democratization

Seeing Through the Lens of Markov Processes

"That's a Markov process"
What would it be like if we see the world through the lens of Markov processes?

What's a Markov process?

Two mild conditions:
  1. Finite set of states
  2. Stable transition probabilities
  3. Members can move from one state to another
Under those two conditions, the Markov Convergence Theorem says that there will be statistical equilibrium such that the number of members in each state remains the same even though there is churn.

How to determine the Markov Equilibrium?

Build the Markov Transition Matrix and solve for the equilibrium.

A Notion of "Better"

A notion of better

Faster, cheaper, better.How do we determine when a method/procedure/solution is "better"?
It is relatively easy to measure faster, cheaper but it's harder to measure better.

This is not simple idle thinking but it does lead to some life changing behaviours.

Less is better

Two concrete examples of better: Everything and Launchy (use version 1.25)
Everything is a tool that locates files and folders by name. It is an essential tool for me, yet a close friend of mine does not use it.
Launchy is another tool I use - as a calculator and a launcher. I probably use it 100 times a day, yet my close friend does not use it - even after I've demonstrated what it does.

I conclude that everyone has a different notion of better.

By using launchy, I've replaced the need to use the mouse to click the Start > Program > Folder > Shortcut with some quick key presses. A task that took 5 seconds now takes 0.5 seconds - an order of magnitude improvement. That's better.
But to get to that, it required some initial investment - setting up the launchy, understanding how it works and what it does and how to get the most out of it. But it is worth it.

Condensed is better

Proverbs and wise sayings are condensed wisdom of the ages. A few carefully selected words are better than a length essay.
There is value is condensing an entire topic into a few words. It may be that we need to first read the entire topic but the condensed words will quickly remind us of what is important.

Two quotes are relevant here:
He is the most useful teacher who condenses the most knowledge into short sentences, that are easily remembered and applied ~Samuel Johnson
The writer helps us the most who gives us the most knowledge, and takes from us the least time ~Sidney Smith

Visual is better

In a lecture on Nash Equilibrium, a textual description of the procedure to find the Nash Equilibrium was presented. Later in the discussion forum, two students described visual versions of the procedure which many of us found simpler and more intuitive.

Another takeaway from this will be simple is better and comprehensible is better.

The big idea

Minimal, condensed visuals are better.

Saturday, July 6, 2013

Setup Samba

On the Server

1. Edit /etc/samba/smb.conf
[sharename]
    comment = Share
    path = /path/to/shared_path
    writable = yes 


2. Restart samba server
sudo service smbd restart

Reference:

Change the origin of git repo

If the origin already exists, you can point to another repo as follows:
  git remote set-url origin git@github.com:username/repo.git 

If you've initialized a local repo and want to push to github, do the following:
  git remote add origin git@github.com:hoekit/vimrc.git
  git pull origin master
  git push --set-upstream origin master

Monday, July 1, 2013

A Musical Life - Project Submission for "Creative Programming for Digital Media & Mobile Apps"

A Musical Life

A Colorful Life blends the graphical elements of SonicPainter and John Conway's Game of Life ((http://en.wikipedia.org/wiki/Conway's_Game_of_Life)) to produce a fun and intriguing form of entertainment.

User interaction is rather intuitive:
  1. Users "give life" to cells by dragging the mouse over them.
  2. Once the mouse is released, the Game of Life plays on automatically
  3. The speed of the game can be changed by moving the mouse left (slower) and right (faster).
Video below shows a sample session of A Musical Life.
[Update: Go to http://www.firexis.com/processing/a_musical_life/ for an interactive version without the music - for some reason Javascript version kills the audio.]



Next on todo list is to publish the Javascript version so users can interact with it. -- Done!
Get the code from https://github.com/hoekit/a-musical-life.