# -*- coding: utf-8 -*-
"""
Created on Sat Jul  4 16:22:48 2020

@author: joost
"""

import pandas as pd
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt

# loading dataframes
n_list = [8,10,12,14,16]
frames = [load_csv("data_trim/data_trim_3-regular_unweighted_INT_"+str(n)+".csv") for n in n_list]
df = pd.concat(frames)
p_max = 8

# plot configuration
font = {'family' : 'normal',
        'size'   : 16}

plt.rc('font', **font)
plt.figure(figsize=(10,6))
ax = plt.subplot(111)
#colors = ['midnightblue', 'navy', 'darkblue', 'mediumblue', 'blue','dodgerblue', 'royalblue', 'cornflowerblue', 'red']


for c, p in enumerate(range(p_max,0,-1)):
    p_array = [np.mean(df[(df['p'] == p) & (df['n_nodes'] == n)]['Fp']/df[(df['p'] == p) & (df['n_nodes'] == n)]['Cmax']) for n in n_list]
    plt.plot(n_list, p_array, linestyle = 'solid', label = 'p = '+str(p), marker = 'o')
示例#2
0
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt

# # loading dataframes
# # ER 0.75
# n_list = [6,7,8,9,10,11,12,13,14,15]
# frames = [load_csv("data/data_ER-075_unweighted_INT_"+str(n)+".csv") for n in [12,13,14,15]]
# frames.append(load_csv("data/data_ER-075_unweighted_INT_4-12.csv"))
# df = pd.concat(frames)
# p_max = 8

# ER 0.50
n_list = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
frames = [
    load_csv("data/data_ER-050_unweighted_INT_11-14.csv"),
    load_csv("data/data_ER-050_unweighted_INT_15-16.csv"),
    load_csv("data/data_ER-050_unweighted_INT_6-10.csv")
]
df = pd.concat(frames)
p_max = 8

# plot configuration
font = {'family': 'normal', 'size': 16}

plt.rc('font', **font)
plt.figure(figsize=(10, 6))
ax = plt.subplot(111)
#colors = ['midnightblue', 'navy', 'darkblue', 'mediumblue', 'blue','dodgerblue', 'royalblue', 'cornflowerblue', 'red']

for c, p in enumerate(range(p_max, 0, -1)):
import pandas as pd
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt

# plot configuration
font = {'family': 'normal', 'size': 16}

plt.rc('font', **font)
plt.figure(figsize=(10, 6))

# loading dataframe
n = 15
filename = "data/data_ER-075_unweighted_INT_15.csv"
df = load_csv(filename)
# eine keer

p_max = 8  #int(np.max(df['p']))
seed_max = 10
N = seed_max

mean_n_evals = np.zeros(p_max)
mean_cum_n_evals = np.zeros(p_max)

attr = 'n_Fp_evals'

df_new = df[(df['n_nodes'] == n) & (df['seed'] < seed_max) &
            (df['p'] <= p_max)][attr].iloc()

# df.loc[df['p'] == 10][['gammas']] - Wybe
示例#4
0
Created on Thu Jul  2 22:22:51 2020

@author: joost
"""
import pandas as pd
from data_load import load_csv
import numpy as np
from pyquil_base import brute_force
from tqdm import tqdm
import networkx as nx
from GW import goemans_williamson as gw

# Comparing runtime of RI and INT

# unweighted
dfu1 = load_csv('data/data_3-regular_unweighted_INT_12.csv')
dfu2 = load_csv('data/data_3-regular_unweighted_INT_14.csv')
dfu3 = load_csv('data/data_3-regular_unweighted_INT_8-10-16.csv')

# weighted
dfw1 = load_csv('data/data_3-regular_weighted_INT_8-10-12.csv')
dfw2 = load_csv('data/data_3-regular_weighted_INT_14-16.csv')

# loading the data s.t. they are equivalent (same p, same N)
p_max = 8
seed_max = 20
# unweighted
u8 = dfu3.loc[lambda df: df['p'] <= p_max, :].loc[
    lambda df: df['seed'] < seed_max, :].loc[lambda df: df['n_nodes'] == 8, :]
u10 = dfu3.loc[lambda df: df['p'] <= p_max, :].loc[
    lambda df: df['seed'] < seed_max, :].loc[lambda df: df['n_nodes'] == 10, :]
from pyquil_interp_function import interp_pyquil
import pandas as pd
import networkx as nx
from data_load import load_csv
from GW import goemans_williamson

# creating dataframe without overwriting (so additing)
# if you start a new set of data, make sure you start with a fresh file
filename = 'data_2-regular.csv'
overwrite = False

if overwrite == True:
    output = pd.DataFrame()
else:
    output = load_csv(filename)

p_max = 10  # maxdepth
n_min, n_max = 3, 20
N = 1  # number of graphs per node number n
d = 2  # degree of regular graphs

for n in range(n_min, n_max + 1):
    for s in range(N):
        G = nx.cycle_graph(n)
        graph_type = str(d) + '-regular_' + str(n) + '-nodal'

        results = interp_pyquil(G, p_max)

        for i, results_i in results.items():
            results_i['graph_name'] = graph_type
from data_load import load_csv
import matplotlib.pyplot as plt

# plot configuration
font = {'family' : 'normal',
        'size'   : 16}

plt.rc('font', **font)
plt.figure(figsize=(10,6))

# loading dataframe
n = 16
pre = "data_trim/data_trim_3-regular_"
post =".csv"
filename = "unweighted_INT_"+str(n)
df = load_csv(pre+filename+post); # eine keer

# exponent or exponent of square root
SQR = True

p_max = int(np.max(df['p']))
N = len(set(df['seed']))

mean_runtime = np.zeros(p_max)
mean_cum_time = np.zeros(p_max)



# df.loc[df['p'] == 10][['gammas']] - Wybe
for i in range(0,len(df),p_max): 
    runtime = np.array([df['time'][i+j] for j in range(p_max)])
示例#7
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jul  1 13:13:02 2020

@author: joost
"""

from data_load import load_csv
import numpy as np
import networkx as nx
from pyquil_interp_function import brute_force
import matplotlib.pyplot as plt

folder = 'data/'
df_u3R = load_csv(folder+'data_3-regular_unweighted_INT_14.csv', True)
df_w3R = load_csv(folder+'data_3-regular_weighted_INT_14-16.csv', True)


# trimming data
last_graph = 200
u3R = df_u3R[df_u3R['n_nodes']==14][:last_graph].iloc()
w3R = df_w3R[df_w3R['n_nodes']==14][:last_graph].iloc()


p_max = 10
for df in [w3R]:
    plt.figure()
    r_sum = np.zeros(p_max)
    label = True
    for i in range(0,last_graph,p_max): 
        print("graph", i,"/",last_graph)
示例#8
0
文件: forest.py 项目: pinoden/titanic
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
from data_load import load_csv
from sklearn import preprocessing

test = load_csv('test')
train = load_csv('train')
# y = LabelBinarizer().fit_transform(y)
lb = preprocessing.LabelBinarizer()

train.Sex = lb.fit_transform(train.Sex)
# print(train.Sex)
# print(train.shape, train.head())

features = ['Pclass','Sex','SibSp','Parch','SibSp','Parch']
# Create target object and call it y
y = train.Survived
# Create X
X = train[features]
print(X.shape)
X = X.dropna()
print(X.shape)
# print('before',X.shape)
# print('after',X.shape)

# Split into validation and training data
train_X, val_X, train_y, val_y = train_test_split(X, y,test_size=0.1, random_state=1)
# print(val_y.loc[val_y == 0])
示例#9
0
# -*- coding: utf-8 -*-
"""
Created on Sat Jul  4 16:22:48 2020

@author: joost
"""

import pandas as pd
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt

# loading dataframes
n_list = [4,5,6,7,8,9,10,11,12]

df1 = load_csv("data/data_complete_unweighted_INT_4-12.csv")
df2 = pd.DataFrame() 

frames = [df1, df2]
df = pd.concat(frames)
p_max = 8
p_list = range(p_max,0,-1)

# plot configuration
font = {'family' : 'normal',
        'size'   : 16}

plt.rc('font', **font)
plt.figure(figsize=(10,6))
ax = plt.subplot(111)
示例#10
0
# -*- coding: utf-8 -*-
"""
Created on Sat Jul  4 16:22:48 2020

@author: joost
"""

import pandas as pd
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt

# loading dataframes
n_list = [8, 10, 12, 14, 16]

df = load_csv('data/data_3-regular_unweighted_RI_8-16.csv')

p_max = 8
p_list = range(p_max, 0, -1)

# plot configuration
font = {'size': 16}

plt.rc('font', **font)
plt.figure(figsize=(10, 6))
ax = plt.subplot(111)

for c, p in enumerate(p_list):
    r_array = np.array([
        np.mean(df[(df['p'] == p) & (df['n_nodes'] == n)]['Fp'] /
                df[(df['p'] == p) & (df['n_nodes'] == n)]['Cmax'])
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt

# plot configuration
font = {'family': 'normal', 'size': 16}

plt.rc('font', **font)
plt.figure(figsize=(10, 6))

# loading dataframe
n = 16
pre = "data_trim/data_trim_3-regular_"
post = ".csv"
filename = "unweighted_INT_" + str(n)
df = load_csv(pre + filename + post)
# eine keer

# exponent or exponent of square root
SQR = True

p_max = int(np.max(df['p']))
N = len(set(df['seed']))

mean_n_evals = np.zeros(p_max)
mean_cum_evals = np.zeros(p_max)

# df.loc[df['p'] == 10][['gammas']] - Wybe
for i in range(0, len(df), p_max):
    n_evals = np.array([df['n_Fp_evals'][i + j] for j in range(p_max)])
    cum_evals = np.array([
Created on Mon Jun 29 15:50:15 2020

@author: joost
"""

import pandas as pd
import numpy as np
from data_load import load_csv
import matplotlib.pyplot as plt
from math import ceil # this is easiest (and luckily turns out right in this case, in the future I'll add another column with C_max)
import matplotlib.pylab as pylab
from GW import goemans_williamson

# loading dataframe
filename = 'data/data_3-regular_unweighted_INT_12.csv'
df = load_csv(filename); # eine keer

p_max = 10
# plotting params
fontsize = 20 # 'x-large'
params = {'legend.fontsize': fontsize,
          'figure.figsize': (10, 8),
         'axes.labelsize': fontsize+4,
         'axes.titlesize':fontsize+4,
         'xtick.labelsize':fontsize-2,
         'ytick.labelsize':fontsize-2}
#pylab.rcParams.update(params)

# figure 1
plt.figure() 
for i in range(0,280,10):