Skip to content

Instantly share code, notes, and snippets.

View zyzyis's full-sized avatar

Si Yin zyzyis

  • AWS
  • Seattle
View GitHub Profile
@zyzyis
zyzyis / zshrc
Created August 19, 2015 08:17
zshrc
#!/bin/zsh
autoload -U colors && colors
autoload -U compinit && compinit
export PATH=/apollo/bin:$PATH
export PATH=/apollo/env/envImprovement/bin:$PATH
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
@zyzyis
zyzyis / FindMinimuminRotatedSortedArrayII.java
Last active August 29, 2015 14:08
FindMinimuminRotatedSortedArrayII.java
public class Solution {
public int findMin(int[] num) {
return findMin(num, 0, num.length);
}
private int findMin(int[] num, int start, int end) {
if (end - start <= 2)
return Math.min(num[start], num[end - 1]);
int medium = (start + end) / 2;
if (num[medium] > num[end - 1])
@zyzyis
zyzyis / FindMinimuminRotatedSortedArray.java
Last active August 29, 2015 14:08
FindMinimuminRotatedSortedArray.java
public class Solution {
public int findMin(int[] num) {
return findMin(num, 0, num.length);
}
private int findMin(int[] num, int start, int end) {
if (end - start <= 2)
return Math.min(num[start], num[end - 1]);
int medium = (start + end) / 2;
if (num[medium] > num[end - 1])
@zyzyis
zyzyis / MaximumProductSubarray.java
Created November 4, 2014 12:04
MaximumProductSubarray.java
public class Solution {
public int maxProduct(int[] A) {
if (A == null || A.length == 0)
return 0;
int high = A[0], low = A[0];
int result = A[0];
for (int i = 1; i < A.length; i ++) {
int tmp = Math.max(A[i] * low, Math.max(A[i], A[i] * high));
low = Math.min(A[i] * low, Math.min(A[i], A[i] * high));
high = tmp;
@zyzyis
zyzyis / objective.m
Last active August 29, 2015 14:07
objective.m
function y = objective(x)
global rho alpha eta beta delta W r smin smax fspace cr egrid P theta lbar Pw
beta = 0.92;
alpha = 2/3;
eta = 0.85; % decreasing returns
delta = 0.06;
Lbar = 1;
spliorder = 1;
Tinit = 50; % periods to initialize distribution of assets
T = 10; % periods to simulate allocations
%Nf = 50000; % # producers
Nf = 500;
randn('state', 100);
rand('state', 100);
Pcum = P*triu(ones(size(P))); % cumulative ergodic distributon
ppi = [0; cumsum(Perg)];
T = 1000; % periods we wait for weights to converge
K = 5001;
K = 1101;
agrid = nodeunif(K, smin(1), smax(1));
edges = [agrid(1); (agrid(2:end-1) + agrid(1:end-2))/2; agrid(end)];
state = gridmake(agrid, (1:1:k)');
N = size(state, 1);
n = 1/N*ones(N,1);
%%% Calibration for Vietnam Census Data 2000-2009 %%%
clear;
clc;
format short;
%theta = 0.265193716508201;
theta = 0.60;
rho = 0.411821223252127;
se = 1.866148709477601;
W = 0.967988540291824;
import random
import math
class Point:
def __init__(self, x, y):
this.x = x
this.y = y
def distance(