Exemple #1
0
def main():
    '''
    dataset_used = "german"
    for i in range(3):
        if i == 0:
            arr = dataset_used + " " + "[1, 0, 0]"
        if i == 1:
            continue
        if i == 2:
            arr = dataset_used + " " + "[0, 0, 1]"
        protected_attribute_used = attribute[i]
        for l in range(5):
            for m in range(4):
                for n in range(4):
                    dataset_orig, privileged_groups, unprivileged_groups, optim_options = LoadData(dataset_used, protected_attribute_used)                
                    algorithm_used = arr + " " + "[" + " " + str(l) + " " + str(m) + " " + str(n) + "]"
                    #dataset_original = copy.deepcopy(dataset_orig)
                    feature = comb_algorithm(l, m, n, dataset_orig, privileged_groups, unprivileged_groups, optim_options)
                    result = str(algorithm_used + feature)
                    print(result)
                    with open('comb_algor_german544.txt', 'a') as f:
                        f.write(result)
                        f.write("\n")
                        f.close()
    '''
    dataset_used = "german"
    # if i == 0 and j == 2:
    protected_attribute_used = "sex"
    dataset_orig, privileged_groups, unprivileged_groups, optim_options = LoadData(
        dataset_used, protected_attribute_used)

    l = 2
    m = 0
    n = 1
    feature = comb_algorithm(l, m, n, dataset_orig, privileged_groups,
                             unprivileged_groups, optim_options)
    print(l, m, n)
    print(feature)
Exemple #2
0
def get_2d_array(index,chi0s,R_avg0s):


    data_path = "../../2019-08-02/R_avg0_vs_chi0_scans"

    loadfilepath = data_path + "/data_formatted"

    datfile = data_path + "/data_formatted/input.dat"

    scan = {}


    loadsuf=["sigma_R0","R_eq","volFrac_0","beta","chi_0"]
    savesuf=["sigma_R0","R_eq","volFrac_0","beta"]

    thearray = np.zeros([len(chi0s),len(R_avg0s)],float)

    for i,chi0 in enumerate(chi0s):

        scan['chi_0'] = str(chi0)

        ld = LoadData(name=f"scanning",scan=scan,loadfilepath=loadfilepath,
                      loadsuf=loadsuf,savesuf=savesuf,
                      datfile=datfile)

        row = ld.data[:,index]
        
        if index != 4 and index != -1:

            Nrow = ld.data[:,4].astype(int)

            row[np.where(Nrow <= 1)] = np.nan
        
        thearray[i,:] = row
        

    return thearray,ld
Exemple #3
0
        self.saver = tf.train.Saver()
        model_path = os.path.join(backup_path, 'model.ckpt')
        assert (os.path.exists(model_path + '.index'))
        self.saver.restore(self.sess, model_path)
        print('Successfully read model from %s' % (model_path))
        #在测试集上计算准确率
        accuracy_list = []
        test_images = dataloader[0]
        test_labels = dataloader[1]
        #test_images = dataloader.data_augmenttation(dataloader.test_images, flip = False, crop = True, crop_shape = (24, 24, 3), whiten = True, noise = False)
        #test_labels = dataloader.test_labels
        for i in range(0, data.n_test, batch_size):
            batch_images = test_images[i:i + batch_size]
            batch_labels = test_labels[i:i + batch_size]
            [avg_accuracy] = self.sess.run(fetches=[self.accuracy],
                                           feed_dict={
                                               self.images: batch_images,
                                               self.labels: batch_labels,
                                               self.keep_prob: 1.0
                                           })
            accuracy_list.append(avg_accuracy)
        print('test precision: %.4f' % (100 * numpy.mean(accuracy_list)) + '%')
        self.sess.close()


cnn = ConvNet()
data = LoadData()
#data = Corpus()
cnn.train(([data.train_images, data.train_labels
            ], [data.valid_images, data.valid_labels]), 'model3/')
cnn.test([data.test_images, data.test_labels], 'model3/')
Exemple #4
0

        for j,sigma in enumerate(sigmas):

            scan['sigma_R0'] = str(sigma)
        
            rp = ReadParams(scan=scan,datfile=datfile)

            ts = rp.list_of_t_vals()

            Ns = np.empty([len(ts)],float)


            for i_t,t in enumerate(ts):

                ld = LoadData(name=f"radius_{i_t}",scan=scan,savesuf=savesuf,
                              loadfilepath=loadfilepath,datfile=datfile)
                
                Rs = ld.data[:,1]

                Ns[i_t] = Rs.size

            axarr.flat[i].plot(ts,Ns,markers[j],color=colors[j],
                               label=rf"$\sigma=\num{{{sigma:.0e}}}$")            



    
            axarr.flat[i].set_title(rf"$<\,R\,>(t=0)={R_avg0:.1f}$")
            axarr.flat[i].set_yscale('log')

        axarr.flat[i].set_xlabel(r"$t$")
        scan['chi_0'] = chi_0(R_avg0)

        for j, sigma in enumerate(sigmas):

            scan['sigma_R0'] = str(sigma)

            rp = ReadParams(scan=scan)

            ts = rp.list_of_t_vals()

            Ns = np.empty([len(ts)], float)

            for i_t, t in enumerate(ts):

                ld = LoadData(name=f"radius_{i_t}", scan=scan, savesuf=savesuf)

                Rs = ld.data[:, 1]

                Ns[i_t] = Rs.size

            axarr.flat[i].plot(ts,
                               Ns,
                               markers[j],
                               color=colors[j],
                               label=rf"$\sigma=\num{{{sigma:.0e}}}$")

            axarr.flat[i].set_title(rf"$<\,R\,>(t=0)={R_avg0:.1f}$")

        axarr.flat[i].set_xlabel(r"$t$")
        axarr.flat[i].set_ylabel(r"$N(t)$")
        for j, sigma in enumerate(sigmas):

            scan['sigma_R0'] = str(sigma)

            rp = ReadParams(scan=scan, datfile=datfile)

            ts = rp.list_of_t_vals()

            R_avgts = np.empty([len(ts)], float)
            sigma_Rts = np.empty([len(ts)], float)

            chi_spaced = np.empty([len(ts)], float)

            ldchi = LoadData(scan=scan,
                             savesuf=savesuf,
                             loadfilepath=loadfilepath,
                             datfile=datfile)

            t_smalls = ldchi.data[:, 0]
            chis = ldchi.data[:, 1]

            for i_t, t in enumerate(ts):

                ld = LoadData(name=f"radius_{i_t}",
                              scan=scan,
                              savesuf=savesuf,
                              loadfilepath=loadfilepath,
                              datfile=datfile)

                Rs = ld.data[:, 1]
            scan['sigma_R0'] = str(sigma)

            rp = ReadParams(scan=scan, datfile=datfile)

            ts = rp.list_of_t_vals()

            print(len(ts))

            fig, axarr = plt.subplots(3, len(ts) // 3)

            fig.set_size_inches(width, height)

            for i_t, t in enumerate(ts):

                ld = LoadData(name=f"radius_{i_t}",
                              scan=scan,
                              loadfilepath=loadfilepath,
                              datfile=datfile)

                Rs = ld.data[:, 1]

                axarr.flat[i_t].hist(Rs, density=True, stacked=True)

                axarr.flat[i_t].set_xlabel(r"$<R>(t)$")
                axarr.flat[i_t].set_xlim(0, 20)
                axarr.flat[i_t].set_ylim(0, 1)
                axarr.flat[i_t].text(3, 0.5, rf"$t=\num{{{t:.1e}}}$")

            fig.suptitle(rf"$<\,R\,>(t=0)={R_avg0:.1f}$" + ", " +
                         rf"$\sigma(t=0)=\num{{{sigma:.0e}}}$")

            fig.subplots_adjust(bottom=0.08, top=0.95, left=0.08, right=0.95)
Exemple #8
0
def main():

    dataset_used = "adult"
    for i in range(2):
        if i == 0:
            arr = dataset_used + " " + "[1, 0, 0]"
        if i == 1:
            arr = dataset_used + " " + "[0, 1, 0]"
        protected_attribute_used = attribute[i]
        for l in range(5):
            for m in range(4):
                for n in range(4):
                    dataset_orig, privileged_groups, unprivileged_groups, optim_options = LoadData(
                        dataset_used, protected_attribute_used)
                    algorithm_used = arr + " " + "[" + " " + str(
                        l) + " " + str(m) + " " + str(n) + "]"
                    #dataset_original = copy.deepcopy(dataset_orig)
                    feature = comb_algorithm(l, m, n, dataset_orig,
                                             privileged_groups,
                                             unprivileged_groups,
                                             optim_options)
                    result = str(algorithm_used + feature)
                    print(result)
                    with open('comb_algor_adult544.txt', 'a') as f:
                        f.write(result)
                        f.write("\n")
                        f.close()
    '''
Exemple #9
0
#%%
# Imports
from loaddata import LoadData
import matplotlib.pyplot as plt
%matplotlib qt
import mglearn
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet, LogisticRegression
from sklearn.svm import LinearSVC
from sklearn.datasets import make_blobs
import numpy as np
import pandas as pd

#%%
# Loading data
ld = LoadData()

#%%
# Linear model for wave data
X, y = ld.load_wave(n_samples=60)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
lr = LinearRegression().fit(X_train, y_train)
print(f'Train score: {lr.score(X_train,y_train)}')
print(f'Test score: {lr.score(X_test,y_test)}')

# %%
# Linear model on Boston Housing data
X, y = ld.load_boston()
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
lr = LinearRegression().fit(X_train, y_train)
print(f'Train score: {lr.score(X_train,y_train)}')
Exemple #10
0
def main():

    dataset_used = "german"
    protected_attribute_used = "sex"
    arr = dataset_used + " " + "[1, 0, 0]"
    data = np.zeros((80, 8))
    i = 0

    for l in range(5):
        for m in range(4):
            for n in range(4):
                dataset_orig, privileged_groups, unprivileged_groups, optim_options = LoadData(
                    dataset_used, protected_attribute_used)
                algorithm_used = arr + " " + "[" + " " + str(l) + " " + str(
                    m) + " " + str(n) + "]"
                while (True):
                    feature, feature_str = comb_algorithm(
                        l, m, n, dataset_orig, privileged_groups,
                        unprivileged_groups, optim_options)
                    if feature[1] == 0.5:
                        print(feature)
                        continue
                    else:
                        break
                        print(feature)
                data[i] = feature
                i = i + 1
                result = str(algorithm_used + feature_str)
                print(result)
                with open('german_sex_forAcc.txt', 'a') as f:
                    f.write(result)
                    f.write("\n")
                    f.close()
    '''
Exemple #11
0
# countries_oi = ["Italy", "Spain", "England", "France", "Netherlands", "Belgium", "Germany", "Switzerland", "Austria",
# "Hungary", "Czech Republic", "Slovakia", "Slovenia", "Poland", "Romania", "Bulgaria", "Macedonia", "Bosnia",
# "Croatia", "Serbia", "Montenegro", "Albania"]  # Everything
# countries_oi = ["Netherlands","Germany","France","Belgium","Swiss German","England","Scotland","Ireland","Switzerland"]

# countries_oi_west

print("Welcome back, friend.")

while True:
    inp = input(
        ("\nWhat do you want to do? \n(1) Extract data \n(2) Analyze Data"
         "\n(8) Save/Load data \n(0) Exit \n"))
    if inp == 1:
        min_len = input("What is the minimum block length? (in cM)?\n")
        data = LoadData(pop_path, ibd_list_path, coordinates_path, min_len,
                        countries_oi)
        analysis = MLE_analyse(data, all_chrom=True)

    elif inp == 2:
        while True:
            inp1 = input((
                "\n(1) Regress spec. block sharing \n(2) Regress min. block sharing \n(3) Bin-Plot"
                "\n(4) MLE estimation"
                "\n(0) Exit \n"))
            if inp1 == 1:
                min_len = input("What is the minimum block length? (in cM)?\n")
                max_len = input("What is the maximum block length? (in cM)?\n")
                analysis.plot_ibd_spec(min_len=min_len, max_len=max_len)
            elif inp1 == 2:
                min_len = input("What is the minimum block length? (in cM)?\n")
                analysis.plot_ibd_min(min_len, 150)
    scan = {}

    lines = [":", "-.", "--", "-", ":"]

    for i, R_avg0 in enumerate(R_avg0s):

        scan['R_avg0'] = str(R_avg0)

        scan['chi_0'] = chi_0(R_avg0)

        for j, sigma in enumerate(sigmas):

            scan['sigma_R0'] = str(sigma)

            ld = LoadData(scan=scan, savesuf=savesuf)

            ts = ld.data[:, 0]

            chis = ld.data[:, 1]

            axarr.flat[i].set_title(rf"$<\,R\,>(t=0)={R_avg0:.1f}$")
            axarr.flat[i].plot(ts,
                               chis,
                               '-',
                               color=colors[j],
                               linestyle=lines[j],
                               lw=4,
                               label=rf"$\sigma(t=0)=\num{{{sigma:.0e}}}$")

        axarr.flat[i].set_xlabel(r"$t$")
Exemple #13
0
    scan = {}

    lines = [":","-.","--","-",":"]

    for i,R_avg0 in enumerate(R_avg0s):

        scan['R_avg0'] = str(R_avg0)

        scan['chi_0'] = chi_0(R_avg0)

        for j,sigma in enumerate(sigmas):

            scan['sigma_R0'] = str(sigma)
        
            ld = LoadData(scan = scan,savesuf=savesuf,datfile=datfile,loadfilepath=loadfilepath)

            ts = ld.data[:,0]

            chis = ld.data[:,1]

            axarr.flat[i].set_title(rf"$<\,R\,>(t=0)={R_avg0:.1f}$")
            axarr.flat[i].plot(ts,chis,'-',color=colors[j],linestyle=lines[j],
                               lw=4,
                               label=rf"$\sigma(t=0)=\num{{{sigma:.0e}}}$")

        axarr.flat[i].set_xlabel(r"$t$")
        axarr.flat[i].set_ylabel(r"$\chi(t)$")

    axarr.flat[i].legend(frameon=False,handlelength=5)
12   |rho (g/m ** 3)          |1307.75            |Airtight
13   |wv (m/s)                |1.03               |Wind speed
14   |max. wv (m/s)           |1.75               |Maximum wind speed
15   |wd (deg)                |152.3              |Wind direction in degrees
16   |rain (mm)               |0.0                |Amount of the rainfall
17   |raining (s)             |0.0                |Duration of the rainfall
18   |SWDR (W/m ** 2)         |0.0                |Global radiation
19   |PAR (mu_mol/m**2/s)     |0.0                |Photosynthetically active radiation
20   |max. PAR (mu_mol/m**2/s)|0.0                |Maximum photosynthetically active radiation
21   |Tlog (degC)             |36.93              |Internal temperature of the data logger
22   |CO2 (ppm)               |434.1              |CO2 concentration of the outside air
"""

import os
import pandas as pd
import matplotlib.pyplot as plt
from loaddata import LoadData
from parsedata import ParseData

data_dir = 'data/'

data = LoadData.load(data_dir=data_dir)

parser = ParseData()

train_data, test_data = parser.parse(data=data)




Exemple #15
0
'''
Developer: vkyprmr
Filename: trees.py
Created on: 2020-09-04 at 16:45:27
'''
'''
Modified by: vkyprmr
Last modified on: 2020-09-04 at 16:45:28
'''

#%%
# Imports
from loaddata import LoadData
ld = LoadData()
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
%matplotlib qt
from sklearn.tree import export_graphviz
import graphviz
import numpy as np
import pandas as pd

#%%
# Breast cancer data
X, y, fn, tn = ld.load_cancer()
X_train, X_test, y_train, y_test = train_test_split(
X, y, stratify=y, random_state=42)
tree = DecisionTreeClassifier(random_state=0)
tree.fit(X_train, y_train)
print(f"Accuracy on training set: {tree.score(X_train, y_train)}")