This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import sys | |
# reference: https://en.wikipedia.org/wiki/Power_iteration | |
def power_method(M): | |
b = np.random.rand(M.shape[1]) | |
diff = np.linalg.norm(b) | |
while diff > 10 ** (-6): | |
b_new = np.dot(M, b) | |
b_norm = np.linalg.norm(b_new) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\*\shell\Edit with Sublime Text] | |
@="Edit with &Sublime Text" | |
"Icon"="C:\\Program Files\\Sublime Text 3\\sublime_text.exe,0" | |
"MuiVerb"="Edit with Sublime Text" | |
[HKEY_CLASSES_ROOT\*\shell\Edit with Sublime Text\command] | |
@="C:\\Program Files\\Sublime Text 3\\sublime_text.exe \"%1\"" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v = -5:0.5:5; | |
[x, y] = meshgrid(v); | |
z = x .* exp(x.^2 - y.^2) + y.*exp(-x.^2 + y.^2); | |
[px, py] = gradient(z); | |
figure | |
surf(x, y, z) | |
figure | |
contour(x, y, z); | |
hold on | |
quiver(x, y, px, py); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% demonstrate the linear convergence rate of gradient descent | |
stepsize = 0.05; | |
x = rand(2, 1); | |
f_diff = 1; | |
f = @(x) 1/2*(x(1)^2 + 10 * x(2)^2); | |
first_grad = @(x) [x(1); 10*x(2)]; | |
iter = 0; | |
fprintf('ITER \t F_VAL \t F_VAL_U \t F_DIFF \n'); | |
% fprintf('ITER \t\t F_VAL \t F_VAL_U \t F_DIFF \t F_GRAD \t F_GRAD_U \n'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear; | |
has_quadprog = exist( 'quadprog' ) == 2 | exist( 'quadprog' ) == 3; | |
has_linprog = exist( 'linprog' ) == 2 | exist( 'linprog' ) == 3; | |
rnstate = randn( 'state' ); randn( 'state', 1 ); | |
s_quiet = cvx_quiet(true); | |
s_pause = cvx_pause(false); | |
cvx_clear; echo on | |
b = [2; 0; 2; 0]; | |
cvx_begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Jul 28 15:28:15 2015 | |
""" | |
from sklearn.cluster import KMeans | |
import numpy as np | |
import pandas | |
dataset = np.array([1, 4, 5, 6, 9]) | |
km = KMeans(n_clusters=3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
""" | |
A deterministic model of farmer's problem: | |
""" | |
try: | |
from pyomo.core import * | |
from pyomo import * | |
from pyomo.opt import * | |
from pyomo.core.base import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _________________________________________________________________________ | |
# | |
# Pyomo: Python Optimization Modeling Objects | |
# Copyright (c) 2014 Sandia Corporation. | |
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, | |
# the U.S. Government retains certain rights in this software. | |
# This software is distributed under the BSD License. | |
# _________________________________________________________________________ | |
# | |
# Farmer: rent out version has a scalar root node var |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: webserver | |
webserver: webserver.o tcp.o request.o | |
gcc webserver.o tcp.o request.o -o webserver -g -lpthread | |
webserver.o: webserver.c | |
g cc -Wall -g -c webserver.c -o webserver.o | |
tcp.o: tcp.c tcp.h | |
gcc -Wall -g -c tcp.c -o tcp.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(raw_input()) | |
with open('outfile.txt', 'w') as outfile: | |
for test in range(N): | |
size = int(raw_input()) | |
v1 = sorted(map(int, raw_input().split(" ")), reverse=True) | |
v2 = sorted(map(int, raw_input().split(" "))) | |
pro = 0 | |
for i in range(size): | |
pro += v1[i] * v2[i] | |
outfile.write("Case #{}: ".format(test + 1) + str(pro) + "\n") |