def demo_aspect_extraction(): 
	"""
	Demo the aspect extraction functionality on one restaurant
	"""

	from main import read_data, get_reviews_for_business, extract_aspects

	TEST_BIZ_ID = 's1dex3Z3QoqiK7V-zXUgAw'

	print "Reading data..."
	df = read_data()
	print "Done."

	BIZ_NAME = str(df[df.business_id==TEST_BIZ_ID]['name'].iloc[0])


	print "Getting reviews for %s (ID = %s)" % (BIZ_NAME, TEST_BIZ_ID)
	reviews = get_reviews_for_business(TEST_BIZ_ID, df)
	print "Done."

	print "Extracting aspects..."
	aspects = extract_aspects(reviews)
	print "Done."

	print "==========="
	print "Aspects for %s:" % BIZ_NAME
	for i,aspect in enumerate(aspects):
		print str(i) + ". " + aspect
Exemplo n.º 2
0
def motion():
    data = main.read_data('odometry.dat')
    
    noise = scipy.array([0.005, 0.01, 0.005])

    # how many particles
    numParticles = 100

    # initialize the particles array
    particles = [{'weight':1./numParticles,
                 'pose':scipy.zeros((3,)),
                 'history':[]} for x in range(numParticles)]

    
    #for i = 1:numParticles
    #  particles(i).weight = 1. / numParticles;
    #  particles(i).pose = zeros(3,1);
    #  particles(i).history = cell();
    #end

    # Perform filter update for each odometry-observation read from the
    # data file.
    for t in xrange(len(data['odometry'])):# = 1:size(data.timestep, 2)
        #for t = 1:50
        print('timestep = %d\n', t)

        # Perform the prediction step of the particle filter
        particles = motion.prediction_step(particles, data['odometry'][t], noise)

        # Generate visualization plots of the current state of the filter
        main.plot_state(particles, t)
def demo_aspect_extraction():
    """
	Demo the aspect extraction functionality on one restaurant
	"""

    from main import read_data, get_reviews_for_business, extract_aspects

    TEST_BIZ_ID = 's1dex3Z3QoqiK7V-zXUgAw'

    print "Reading data..."
    df = read_data()
    print "Done."

    BIZ_NAME = str(df[df.business_id == TEST_BIZ_ID]['name'].iloc[0])

    print "Getting reviews for %s (ID = %s)" % (BIZ_NAME, TEST_BIZ_ID)
    reviews = get_reviews_for_business(TEST_BIZ_ID, df)
    print "Done."

    print "Extracting aspects..."
    aspects = extract_aspects(reviews)
    print "Done."

    print "==========="
    print "Aspects for %s:" % BIZ_NAME
    for i, aspect in enumerate(aspects):
        print str(i) + ". " + aspect
Exemplo n.º 4
0
    def test_read_data(self):
        data = main.read_data('./data.out')
        self.assertFalse(data)

        data = main.read_data('./test/data.in')
        self.assertEqual(len(data), 2)

        city1 = data[0].cities
        optimal1 = data[0].optimal

        city2 = data[1].cities
        optimal2 = data[1].optimal
        
        self.assertEqual(len(city1), 4)
        self.assertEqual(optimal1, 14.0)
        self.assertEqual(len(city2), 10)
        self.assertEqual(optimal2, 35.06889373058871)
Exemplo n.º 5
0
def load_time_series_ucr(data_name):
    max_item = -1 # nb d'items lus au plus par classe
    file_path = '../data/ucr/'
    file_name = data_name + '/' + data_name + '_TRAIN'
    data = main.read_data(file_path + file_name, max_item)
    assign = np.array( [int(d[0]) for d in data ] )
    data = [d[1:] for d in data]
    data = [np.array(d) for d in data]
    data = [np.reshape(d,(len(d),1)) for d in data]
    data = np.array(data)
    return data, assign
Exemplo n.º 6
0
def load_time_series_modis_GX():
    max_item = 20 # nb d'items lus au plus par classe
    file_path = '../data/modis_GX/'
    file_names = ['classe_bati.txt',
                  'classe_bois.txt',
                  'classe_cultures.txt',
                  'classe_eau.txt',
                  'classe_prairies.txt']
    data = np.array([ np.array([np.reshape(np.array(d),(len(d),1))
                                for d in main.read_data(file_path + file_name, max_item)])
                      for file_name in file_names])
    assign = np.concatenate( [i*np.ones(len(list(data[i]))) for i in range(len(data))] )
    data = np.concatenate(data)
    return data, assign
Exemplo n.º 7
0
def academicinfluence(path):
    print('Calculating Academic Influence...')
    noaf = read_data(path)
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', 1200)
    # pd.set_option('display.max_colwidth', 400)
    # print(noaf)
    noaf = noaf.apply(lambda x: x.replace(0, 1))
    noaf['Academic Influence'] = noaf['Cites/Paper'] * (np.log(noaf['Highly Cited Papers'] * noaf['Hot Papers']) / np.log(100))
    # print(noaf.sort_values(by='Academic Influence', ascending=False))
    af = noaf
    af.rename(columns={'Country': 'Nation'}, inplace=True)
    print(af)
    return af
Exemplo n.º 8
0
    def test_create_new_solution(self):
        data = main.read_data('./test/data.in')
        cities = data[1].cities
        solution = [0, 1, 7, 9, 5, 4, 8, 6, 2, 3]
        
        i, j = 3, 7
        # inverse_solution = main.inverse_solution(solution, i, j)
        insert_solution = main.insert_solution(solution, i, j)
        # swap_solution = main.swap_solution(solution, i, j)

        """enable line code if want to see the evalation value"""
        # evaluation_inverse = main.evaluate_solution(cities, inverse_solution)
        # evaluation_insert = main.evaluate_solution(cities, insert_solution)
        # evaluation_swap = main.evaluate_solution(cities, swap_solution)

        new_solution = main.create_new_solution(cities, solution, i, j)
        
        # for i=3, j=7, the best solution is insert
        self.assertEqual(new_solution, insert_solution)
Exemplo n.º 9
0
def topsis_data(file):
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', 1200)
    td = read_data(file)
    nations = td['Nation']
    td = td.set_index('Nation')
    td['C1'] = td['C1'] / (td['C1'] + 1)
    td['C2'] = td['C2'] / (td['C2'] + 1)
    td = td.dropna(axis=1)
    tarr = td.values

    # redirection
    tarr[:, 2] = topsis_redirection('m', tarr[:, 2], 0.5)           # C1
    tarr[:, 3] = topsis_redirection('m', tarr[:, 3], 0.5)           # C2
    tarr[:, 4] = topsis_redirection('r', tarr[:, 4], 60, 50)        # D1
    tarr[:, 6] = topsis_redirection('m', tarr[:, 6], 30)            # E3
    tarr[:, 8] = topsis_redirection('r', tarr[:, 8], 75, 65)        # F2

    return tarr, nations
Exemplo n.º 10
0
def main():
    # Reads in transcript data and analyzes it for collocation data
    parser = argparse.ArgumentParser(
        description='Trains and gives information for a '
        'collocation-based model.')
    parser.add_argument('transcript_file',
                        help='File containing the collated '
                        'utterance information.')
    args = vars(parser.parse_args())
    transcript_file = args['transcript_file']
    if not os.path.isfile(transcript_file):
        raise RuntimeError('The given file does not exist!')
    data = read_data(transcript_file)

    for sen in data:
        train_classifier(sen)

    print_common_features('GOOD_END', 'last_word', 10)
    print_common_features('BAD_END', 'last_word', 10)

    decision_list = create_decision_lists(collocation_dict['GOOD_END'],
                                          collocation_dict['BAD_END'])
    calculate_best_collocation(decision_list, 10)
Exemplo n.º 11
0
def main():
    a_it, x_it, y_it, z_it = read_data()
    a_it = a_it[:, :, [0, 1]]
    # a_it[:, :, 2] = (a_it[:, :, 2] - 1987) / 8
    x_it = (x_it - 18)
    T = 23
    n_batch = a_it.shape[0]

    data = np.load('param1-10000-2.npz')
    delta = data['delta']
    rho = data['rho']

    delta = np.vstack(delta).mean(axis=0)
    rho = np.vstack(rho).mean(axis=0)

    mu = np.sum(delta[np.newaxis, :, :] * z_it[:, np.newaxis, np.newaxis, :],
                axis=3)

    qs = []

    for i in range(T):
        logits = np.sum(a_it[:, i, np.newaxis, np.newaxis, :] *
                        rho[np.newaxis, :, np.newaxis, :],
                        axis=3) + mu
        q = softmax(np.concatenate(
            [logits, np.zeros_like(logits[:, :, 0, np.newaxis])], axis=2),
                    axis=2).mean(axis=0)
        # q = np.stack([
        #     sigmoid(logits[:, :, 0]),
        #     sigmoid(logits[:, :, 1]) -
        #     sigmoid(logits[:, :, 0]),
        #     1 - sigmoid(logits[:, :, 1])
        # ], axis=2).mean(axis=0)
        qs.append(q)

    q_mean = np.mean(qs, axis=0)
    print(q_mean)
Exemplo n.º 12
0
def unesco(path, nations, academic):
    for year in range(2006, 2020):
        year = str(year)
        file = path + year + '.csv'
        udf = read_data(file)
        udf['Teachers in higher education, both sexes (number)'] \
            = udf['Teachers in post-secondary non-tertiary education, both sexes (number)'] \
              + udf['Teachers in tertiary education programmes, both sexes (number)']
        udf['Enrolment in higher education, both sexes (number)'] \
            = udf['Enrolment in post-secondary non-tertiary education, both sexes (number)'] \
              + udf['Enrolment in tertiary education, all programmes, both sexes (number)']
        udf['Teacher-to-Student ratio in higher education (number per 100 students)'] = udf[
            'Teachers in higher education, both sexes (number)'] / udf[
                'Enrolment in higher education, both sexes (number)'] * 100
        # print(udf[['Unnamed: 0', 'Teacher-to-Student ratio in higher education (number per 100 students)']])
        udf['School age population, higher education, both sexes (number)'] \
            = udf['School age population, post-secondary non-tertiary education, both sexes (number)'] \
              + udf['School age population, tertiary education, both sexes (number)']
        udf['Enrolment to school age population ratio in higher education, both sexes (%)'] = udf[
            'Enrolment in higher education, both sexes (number)'] / udf[
                'School age population, higher education, both sexes (number)']
        # print(udf[['Unnamed: 0', 'Enrolment to school age population ratio in higher education, both sexes (%)']])
        udf['Enrolment in higher education, all programmes, gender parity index (GPI)'] \
            = (udf['Enrolment in tertiary education, all programmes, female (number)']
               / udf['Enrolment in tertiary education, all programmes, male (number)'])
        udf['All staff compensation as a percentage of total expenditure in higher public institutions (%)'] \
            = (udf['All staff compensation as a percentage of total expenditure in post-secondary non-tertiary public institutions (%)'] + udf['All staff compensation as a percentage of total expenditure in tertiary public institutions (%)']) / 2
        # print(udf[['Unnamed: 0', 'Enrolment in higher education, all programmes, gender parity index (GPI)']])
        cols = [
            'Nation',
            'Enrolment to school age population ratio in higher education, both sexes (%)',
            'Number of tertiary education institutions per thousand population (number per thousand population)',
            'Teacher-to-Student ratio in higher education (number per 100 students)',
            'Mean tuition of public institution on tertiary education as a percentage of average family consumption (%)',
            'Enrolment in higher education, all programmes, gender parity index (GPI)',
            'Gross graduation ratio from first degree programmes (ISCED 6 and 7) in tertiary education, gender parity index (GPI)',
            'Differences of distribution in higher education (score)',
            'Gross graduation ratio from first degree programmes (ISCED 6 and 7) in tertiary education, both sexes (%)',
            'Suitability between higher education and employment market (score)',
            'Net flow ratio of internationally mobile students (inbound - outbound), both sexes (%)',
            'Academic Influence (score)',
            'Percentage of graduates from Science, Technology, Engineering and Mathematics programmes in tertiary education, both sexes (%)',
            'Government expenditure on tertiary education as a percentage of GDP (%)',
            'All staff compensation as a percentage of total expenditure in higher public institutions (%)'
        ]
        cols = [
            'Nation', 'A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'C3', 'D1', 'D2',
            'E1', 'E2', 'E3', 'F1', 'F2'
        ]
        udf = udf[[
            'Unnamed: 0',
            'Enrolment to school age population ratio in higher education, both sexes (%)',
            'Teacher-to-Student ratio in higher education (number per 100 students)',
            'Enrolment in higher education, all programmes, gender parity index (GPI)',
            'Gross graduation ratio from first degree programmes (ISCED 6 and 7) in tertiary education, gender parity index (GPI)',
            'Gross graduation ratio from first degree programmes (ISCED 6 and 7) in tertiary education, both sexes (%)',
            'Net flow ratio of internationally mobile students (inbound - outbound), both sexes (%)',
            'Percentage of graduates from Science, Technology, Engineering and Mathematics programmes in tertiary education, both sexes (%)',
            'Government expenditure on tertiary education as a percentage of GDP (%)',
            'All staff compensation as a percentage of total expenditure in higher public institutions (%)'
        ]]
        # print(udf)
        udf.rename(columns={'Unnamed: 0': 'Nation'}, inplace=True)
        # cols.extend(list(udf.columns)[1:])
        # print(pd.value_counts(list(udf.columns)[0:]).sort_index())
        nudf = pd.DataFrame(columns=cols)
        for na in nations:
            na = str(na)
            rn = udf.query('Nation =="' + na + '"')
            af = academic.query('Nation =="' + na + '"')
            if not rn.empty:
                rn = list(rn.iloc[0])
                af = list(af.iloc[0])[1]
                nudf = nudf.append(
                    {
                        'Nation': na,
                        'A1': rn[1],
                        'B1': rn[2],
                        'C1': rn[3],
                        'C2': rn[4],
                        'D1': rn[5],
                        'E1': rn[6],
                        'E2': af,
                        'E3': rn[7],
                        'F1': rn[8],
                        'F2': rn[9]
                    },
                    ignore_index=True)
                # nudf = nudf.append({
                #     'Nation': na,
                #     'Enrolment to school age population ratio in higher education, both sexes (%)': rn[1],
                #     # 'Number of tertiary education institutions per thousand population (number per thousand population)',
                #     'Teacher-to-Student ratio in higher education (number per 100 students)': rn[2],
                #     # 'Mean tuition of public institution on tertiary education as a percentage of average family consumption (%)',
                #     'Enrolment in higher education, all programmes, gender parity index (GPI)': rn[3],
                #     'Gross graduation ratio from first degree programmes (ISCED 6 and 7) in tertiary education, gender parity index (GPI)': rn[4],
                #     'Gross graduation ratio from first degree programmes (ISCED 6 and 7) in tertiary education, both sexes (%)': rn[5],
                #     'Net flow ratio of internationally mobile students (inbound - outbound), both sexes (%)': rn[6],
                #     'Academic Influence (score)': af,
                #     'Percentage of graduates from Science, Technology, Engineering and Mathematics programmes in tertiary education, both sexes (%)': rn[7],
                #     'Government expenditure on tertiary education as a percentage of GDP (%)': rn[8],
                #     'All staff compensation as a percentage of total expenditure in higher public institutions (%)': rn[9]}, ignore_index=True)
        print(year)
        print(nudf)
        exec(
            'nudf.to_csv(\'./data/all/{}_nake_all.csv\', encoding="utf-8-sig", header=True, index=False)'
            .format(year))
Exemplo n.º 13
0
from main import read_data
import pandas as pd
import numpy as np
from plot import show
import matplotlib.pyplot as plt

if __name__ == '__main__':
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', 1200)
    # pd.set_option('display.max_colwidth', 400)
    ndf = read_data('./data/allfill/2019_fill_all.csv')
    mdf = read_data('./data/meanfill/2019_meannation_all.csv')
    mdf.dropna(axis=1, inplace=True)
    mdf = mdf.append(mdf.query('Nation == "Poland"'), ignore_index=True)
    mdf.iloc[124, 0] = 'Poland - New Data'
    print(mdf)
    mdf.set_index('Nation', inplace=True)

    print(mdf.at['Poland', 'B1'], mdf.at['Poland', 'C1'],
          mdf.at['Poland', 'E2'], mdf.at['Poland', 'F1'])
    # mdf = mdf.append(mdf.loc['Poland'])
    # print(mdf)
    mdf.at['Poland - New Data', 'B1'] = 10
    mdf.at['Poland - New Data', 'C1'] = 1.1
    mdf.at['Poland - New Data', 'E2'] = 17
    mdf.at['Poland - New Data', 'F1'] = 1.6

    mdf['C1'] = mdf['C1'] / (mdf['C1'] + 1)
    mdf['C2'] = mdf['C2'] / (mdf['C2'] + 1)
Exemplo n.º 14
0
# This is the main extended Kalman filter SLAM loop. This script calls all the required
# functions in the correct order.
#
# You can disable the plotting or change the number of steps the filter
# runs for to ease the debugging. You should however not change the order
# or calls of any of the other lines, as it might break the framework.
#
# If you are unsure about the input and return values of functions you
# should read their documentation which tells you the expected dimensions.

# Read world data, i.e. landmarks. The true landmark positions are not given to the robot
landmarks = read_world('../world.dat')
# load landmarks;
# Read sensor readings, i.e. odometry and range-bearing sensor
data = read_data('../sensor_data.dat')
#load data

infty = 1000.
# Get the number of landmarks in the map
n = len(landmarks['id'])  #size(landmarks,2) this must be changed

# observedLandmarks is a vector that keeps track of which landmarks have been observed so far.
# observedLandmarks(i) will be true if the landmark with id = i has been observed at some point by the robot
observedLandmarks = scipy.zeros((1, N)).astype(bool)  #repmat(false,1,N);

# Initialize belief:
# mu: 2N+3x1 vector representing the mean of the normal distribution
# The first 3 components of mu correspond to the pose of the robot,
# and the landmark poses (xi, yi) are stacked in ascending id order.
# sigma: (2N+3)x(2N+3) covariance matrix of the normal distribution
Exemplo n.º 15
0
import pickle

# with open('../data/training_df.pkl', 'rb') as f:  # load数据集
#     df = pickle.load(f)
# with open(r'../data/selected_feat_names.pkl', 'rb') as f:  # 特征和标签的key
#     selected_feat_names = pickle.load(f)
# print("data loaded")

# y = df["attack_type"].values  # 标签,y值
# X = df[selected_feat_names].values  # 所有特征值

import main as m

data_file = "data/201504_data.csv"
print('reading training and testing data...')
train_x, train_y, test_x, test_y = m.read_data(data_file)

rfc = RandomForestClassifier(n_jobs=-1)  # 随机森林分类器

parameters = {
    'min_samples_leaf': range(1, 3),
    'n_estimators': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
    'criterion': ("gini", "entropy")
}

# scorer = cbs.scorer(show=True)

if __name__ == '__main__':
    gscv = GridSearchCV(rfc,
                        parameters,
                        scoring="accuracy",
Exemplo n.º 16
0
from main import read_data
from argparser import parse_args
from data import GraphDataset
import networkx as nx
import pickle
import os
path = '/mnt/nfs/work1/mccallum/dswarupogguv/x.pkl'
args = parse_args()
if os.path.exists(path):
    with open(path, 'rb') as f:
        nx_g = pickle.load(f)
else:
    drugs, protiens, relations, ddi, ppi, dpi = read_data(args)
    dataset = GraphDataset(drugs, protiens, relations, ddi, ppi, dpi)

    with open(path, 'wb') as f:
        pickle.dump(dataset.nx_g, f)
        nx_g = dataset.nx_g
print('loaded')
paths = list(nx.all_simple_paths(nx_g, (2, 'drug'), (1, 'drug'), cutoff=4))
print('here')
print(len(paths))
#for path in paths:
#    print(path)
with open('path.pkl', 'wb') as f:
    pickle.dump(paths, f)
Exemplo n.º 17
0
import pandas as pd
import matplotlib.pyplot as plt


def show(df):
    df.plot()
    # plt.title('Normal TOPSIS apply to 6 selected nations (Non-Normalization)')
    # plt.title('TOPSIS with EWM apply to 6 selected nations (Non-Normalization)')
    plt.title('TOPSIS with EWM apply to All nations (Non-Normalization)')
    num1, num2, num3, num4 = 3, 0, 3, 0
    plt.legend(bbox_to_anchor=(num1, num2), loc=num3, borderaxespad=num4)
    plt.show()


if __name__ == '__main__':
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', 1200)
    # pd.set_option('display.max_colwidth', 400)
    nt1 = read_data('./result/csv_zscore/normal_topsis_nake.csv')
    # print(nt1)
    nt1.set_index('Nation', inplace=True)
    # print(nt1)
    nt1T = nt1.T
    nt1T.reset_index()
    nt1T['MEAN'] = nt1T.apply(lambda x: x.mean(), axis=1)
    # nt1T.columns = nt1T[:, 1]
    print(nt1T)
    # show(nt1T[['Germany', 'Poland', 'Ethiopia', 'Switzerland', 'Romania', 'MEAN']])
    show(nt1T)
Exemplo n.º 18
0
 def test_evaluate_solution(self):
     data = main.read_data('./test/data.in')
     evaluation = main.evaluate_solution(data[0].cities, [0,1,2,3])
     self.assertEqual(evaluation, data[0].optimal)
Exemplo n.º 19
0
    if args.model == 'cnn':
        print("Fitting CNN\n")
        model = cnn()
    elif args.model == 'paper':
        print("Fitting CNN model from paper\n")
        sys.exit()
    else:
        sys.exit("Model not found!\n")

    if args.dry:
        print('Model: {}'.format(args.model))
        print('Epoch: {}'.format(args.epochs))
        model.summary()
        sys.exit()

    X, y = read_data()
    X = StandardScaler().fit_transform(X)
    # X = X.reshape((-1, 3, 512, 1))
    y = y.reshape((-1, 1))
    y = OneHotEncoder(sparse=False).fit_transform(y)

    # sparse=True: (0, 1)
    # sparse=True: [ 0.  1.  0.]
    # y = to_categorical(y) # this return [ 0.  0.  1.  0.] for some reasons

    if not args.valid:
        model.fit(X, y, verbose=True, epochs=args.epochs)
    else:
        X_train, X_val, y_train, y_val = train_test_split(
            X, y, test_size=args.valid, shuffle=True)
Exemplo n.º 20
0
# Autor: Michał Wójcik

import numpy as np
import random
from sklearn import tree

from main import parse_args, read_data
from validation import k_fold_cross_validation


class CartTree(tree.DecisionTreeClassifier):
    def eval(self, X: np.ndarray, y: np.ndarray) -> float:
        """Returns error on given examples"""
        preds = self.predict(X)
        errors = preds != y

        return errors.sum() / len(errors)


if __name__ == '__main__':
    random.seed(42)
    np.random.seed(42)

    dataset = parse_args()
    X, y = read_data(dataset)

    model = CartTree()
    accuracy = k_fold_cross_validation(model, 1, 5, X, y)
    print(f'Total accuracy: {100 * accuracy:.3f}%')
Exemplo n.º 21
0
 def test_read_data(self):
     data = main.read_data("./Lyrics")
     self.assertEqual(len(data["characterizations"]), 1001)
Exemplo n.º 22
0
    # # nation selection
    # latest = read_data('./data/allfill/2019_fill_all.csv')
    # # print(latest[['Nation', 'A1', 'B1', 'C1', 'C2', 'D1', 'E1', 'E2', 'E3', 'F1', 'F2']])
    # nlatest = latest[['Nation', 'A1', 'B1', 'C1', 'C2', 'D1', 'E1', 'E2', 'E3', 'F1', 'F2']]
    # nlatest = (nlatest.dropna(axis=0, thresh=5)).reset_index(drop = True)
    # newnations = list(nlatest['Nation'])
    # print(newnations)
    #
    # for year in range(2006, 2020):
    #     year = str(year)
    #     old = read_data('./data/allfill/' + year + '_fill_all.csv')
    #     new = pd.DataFrame(columns=old.columns)
    #     for nn in newnations:
    #         if not old.query('Nation == "' + nn + '"').empty:
    #             # print(old.query('Nation == "' + nn + '"'))
    #             new = new.append(old.query('Nation == "' + nn + '"'), ignore_index=True)
    #     print(new)
    #     new.to_csv('./data/nationall/' + year + '_nation_all.csv', encoding="utf-8-sig", header=True, index=False)

    # data fill by mean
    for year in range(2006, 2020):
        year = str(year)
        datas = read_data('./data/nationall/' + year + '_nation_all.csv')
        for column in list(datas.columns[datas.isnull().sum() > 0]):
            mean_val = datas[column].mean()
            datas[column].fillna(mean_val, inplace=True)
        print(datas)
        datas.to_csv('./data/meanfill/' + year + '_meannation_all.csv',
                     encoding="utf-8-sig",
                     header=True,
                     index=False)
Exemplo n.º 23
0
#You can disable the plotting or change the number of steps the filter
# runs for to ease the debugging. You should however not change the order
# or calls of any of the other lines, as it might break the framework.
#
# If you are unsure about the input and return values of functions you
# should read their documentation which tells you the expected dimensions.
#

#location of data sources
world_loc = '../world.dat'
data_loc = '../sensor_data.dat'

# Read world data, i.e. landmarks.
landmarks = read_world(world_loc)
# Read sensor readings, i.e. odometry and range-bearing sensor
data = read_data(data_loc)

# Initialize belief
# x: 3x1 vector representing the robot pose [x; y; theta]
x = scipy.zeros((3, ))

# Iterate over odometry commands and update the robot pose
# according to the motion model
for t in xrange(len(data['sensor'])):
    #distinctly python2.7

    # Update the pose of the robot based on the motion model
    #x = motion_command(x, data.timestep(t).odometry);
    x = motion_command(x, data['odometry'][t])

    #Generate visualization plots of the current state
Exemplo n.º 24
0
 def test_generate_2_random_index(self):
     data = main.read_data('./test/data.in')
     i, j = main.generate_2_random_index(data[0].cities)
     self.assertTrue(i < len(data[0].cities))
     self.assertTrue(j < len(data[0].cities))
Exemplo n.º 25
0
 def test_create_initial_temp(self):
     data = main.read_data('./test/data.in')
     cities = data[1].cities
     temp_list = main.create_initial_temp(cities, 30, initial_acc_probability=0.7)
     self.assertEqual(len(temp_list), 31)
Exemplo n.º 26
0
# This is the main FastSLAM loop. This script calls all the required
# functions in the correct order.
#
# You can disable the plotting or change the number of steps the filter
# runs for to ease the debugging. You should however not change the order
# or calls of any of the other lines, as it might break the framework.
#
# If you are unsure about the input and return values of functions you
# should read their documentation which tells you the expected dimensions.
# Read world data, i.e. landmarks. The true landmark positions are not given
# to the robot

landmarks = main.read_world('../world.dat')
# Read sensor readings, i.e. odometry and range-bearing sensor
data = main.read_data('../sensor_data.dat')

# Get the number of landmarks in the map
N = len(landmarks['id'])

noise = scipy.array([0.005, 0.01, 0.005])

# how many particles
numParticles = 100

# THIS IS VERY MATLABED I NEED TO REDO THIS AGAIN
# initialize the particles dict
particles = [{
    'weight':
    1. / numParticles,
    'pose':