Beispiel #1
0
def histogram():
    args = parse.get_args_ds()
    if args == -1:
        return
    df = parse.read_file(args.fname_dataset)
    plot_hist(parse.normalize_df(df))
    my_histogram(parse.normalize_df(df))
Beispiel #2
0
def main(argv):
    arg_parser = argparse.ArgumentParser(prog="blast_sort",
            description="A program to look up blast numbers and associated DNA/Protein data from a data file, check it against a list of blasts you want to compare, and save the output of all of the finds in fasta formated files named after the blast number")
    arg_parser.add_argument('--blast_file', '-b',
            required=True,
            help="csv lookup for blast nos")
    arg_parser.add_argument('--data_files', '-d', nargs='+',
            required=True,
            help="data files to search")
    arg_parser.add_argument('--output_folder', '-o',
            required=True,
            help="where to save the results")
    arg_parser.add_argument('--verbose', '-v', action='store_true',
            required=False,
            default=False, help="print status and completion rate")
    if len(argv) == 1:
        argv.append('--help')
    args = arg_parser.parse_args(argv[1:])
    sys.stdout = os.fdopen(sys.stdout.fileno(), 'w',0)
    output_folder = path(args.output_folder)
    # check that the output folder exists
    if not output_folder.exists():
        output_folder.mkdir()
    if not output_folder.isdir():
        print "{0} already exists and is not a directory.  please choose a directory or a new name"
        sys.exit(status=1)
    blast_set = read_file(args.blast_file)
    for data_file in args.data_files:
        check_inclusion(blast_set, data_file, output_folder, args.verbose)
    if args.verbose:
        print "\n\nDONE! :)"
Beispiel #3
0
def main():
    args = parse.get_args_ds()
    if args == -1:
        return
    df = parse.read_file(args.fname_dataset)

    # Describe
    test_describe(df, dc.get_data(df))
Beispiel #4
0
def main():
    # Read CSV file with pandas
    args = parse.get_args_ds()
    if args == -1:
        return
    df = parse.read_file(args.fname_dataset)

    # Plot the normalized data for each feature
    my_scatter_plot(parse.normalize_df(df.copy()))
Beispiel #5
0
def main():
    args = parse.get_args_predict()
    if args == -1:
        exit(1)
    df = parse.normalize_df(
        parse.read_file(args.fname_dataset, check_hog=False))
    df1 = df.copy()[cst.feat_list]
    df1 = df1.replace(np.nan, 0.5)
    theta = load_thetas(args.fname_weights)
    y_pred = lt.predict(theta, df1, df1.shape[0])
    print_in_file(y_pred)
Beispiel #6
0
def main():
    # Read CSV file with pandas
    args = parse.get_args_ds()
    if args == -1:
        return
    df = parse.read_file(args.fname_dataset)

    # Normalize a copy of the dataframe
    df_norm = parse.normalize_df(df.copy())

    # Pair plot the normalized grades for each class and each house
    my_pair_plot(df_norm, get_classes(df_norm))
Beispiel #7
0
def main():
	args = parse.get_args_train()
	if args == -1:
		return
	df = parse.normalize_df(parse.read_file(args.fname_dataset))
	df1 = df.copy()[['Hogwarts House'] + cst.feat_list]
	df1 = df1.replace(np.nan, 0.5)
	rocky = Rocky(df1, tp=(59 if args.accuracy else 100))
	rocky.y = rocky.get_binary_house()
	rocky.gradient()
	save_thetas(rocky.theta, args.fname_weights)
	if args.accuracy:
		accuracy(rocky)
Beispiel #8
0
def test_read_file():
    filename = './datasets/C50test/AaronPressman/421829newsML.txt'
    data = parse.read_file(filename)
    assert data[0][:4] == 'U.S.'
Beispiel #9
0

def dpll_solve(sudo: Circuit) -> Solution:
    return dpll(sudo)


def pycosat_solve(circ: Circuit) -> Solution:
    variables = {t.variable for c in circ for t in c}
    to_sym = dict(zip(variables, range(1, len(variables) + 1)))
    from_sym = {v: k for k, v in to_sym.items()}

    sym = []
    for c in circ:
        sym.append([to_sym[t.variable] if t.sign else -1 * to_sym[t.variable]
            for t in c])

    sol = next(itersolve(sym), False)
    if sol:
        return True, {from_sym[abs(s)] : s > 0 for s in sol}
    return False, {}


if __name__ == "__main__":
    sudo = make_circ(read_file("./circuits/sudoku_circuit.txt"))

    sol = pycosat_solve(sudo)




Beispiel #10
0
    def command_handler(self, command="NA"):
        commands = [
            "help", "credits", "parse", "viewmem", "viewreg", "start", "next",
            "changereg", "changemem", "stop", "exit", "run", "dumpmem"
        ]
        args = command.split(' ')

        if args[0] in commands:
            if args[0] == "help":
                print(
                    "help\t\t\tView available commands\n" +
                    "credits\t\t\tView credits\n" +
                    "parse\t\t\tBegin parsing and syntax checking\n" +
                    "viewmem\t\t\tExport current memory to a text-file\n" +
                    "viewreg\t\t\tView the value of a given register\n" +
                    "start\t\t\tStarts the interpreter\n" +
                    "next\t\t\tIncrements the interpreter by one instruction\n"
                    + "changereg\t\tAlters a given register\n" +
                    "changemem\t\tAlters a section of memory\n" +
                    "stop\t\t\tStops the interpreter\n" +
                    "exit\t\t\tExits the simulator\n" +
                    "run\t\t\tExecutes the entire assembly file" +
                    "dumpmem\t\t\tExports the current memory to a txt file")
            elif args[0] == "credits":
                clear_console()
                print("----------Credits----------")
                print("Product of Bagel Bois 2019")
                print(
                    "Gary Fishell - Console and Interpreter Architecture Design"
                )
                print("Salim Aweys - Memory and Register management")
                print("Lauren DeLeon - Parser Design and Documentation")
                print(
                    "Kristian Bunda - Memory/Register Design and Assembler Directives management"
                )
                print(
                    "SIC and SICXE Instruction implementation - Collective effort"
                )
                print("---------------------------")

            elif args[0] == "parse":
                if len(args) != 2:
                    print("Usage: parse [filename]")
                    return

                while True:
                    print("SIC (0) or SIC/XE (1)", end=' ')
                    choice = input()

                    if (choice == '0'):
                        self.isExtended = False
                        break

                    elif (choice == '1'):
                        self.isExtended = True
                        break

                    else:
                        print("Invalid choice, try again")

                self.instruction_array = (read_file(args[1]))
                if self.instruction_array is None:
                    print("Parsing unsuccesful")
                    return

                self.memory = Memory(self.isExtended)
                self.registery = Registery(self.isExtended)

            elif args[0] == "viewmem":
                if len(args) != 2:
                    print("Usage: viewmem [address]")
                    return

                if self.memory == None:
                    print("Please parse a file before viewing memory")
                    return

                address = args[1]

                if len(address) == SIZE_OF_BYTE * 2:
                    memory = self.memory.get_memory(address)
                    if (memory == None):
                        print("Address out of bounds or invalid address")

                    else:
                        print(memory)

                else:
                    print("Please provide an address in the correct format")

            elif args[0] == "viewreg":
                if len(args) != 2:
                    print("Usage: viewreg [register]")
                    return

                if self.registery == None:
                    print("Please parse a file before viewing registery")
                    return

                reg_choice = args[1]
                if self.isExtended and reg_choice in VALID_OPTIONS_EXTENDED:
                    print(self.registery.get_register(reg_choice))

                elif not self.isExtended and reg_choice in VALID_OPTIONS_SIMPLE:
                    print(self.registery.get_register(reg_choice))

            elif args[0] == "start":
                self.interpreter = Interpreter(self.instruction_array,
                                               self.memory, self.registery,
                                               self.isExtended)
                self.interpreter.assign_address()

            elif args[0] == "next":
                self.interpreter.execute_next_instruction()

            elif args[0] == "run":
                while True:
                    done = self.interpreter.execute_next_instruction()
                    if done != None:
                        break

            elif args[0] == "dumpmem":
                if self.memory == None:
                    print("Please parse a file before viewing memory")

                else:
                    self.memory.show_mem()

            elif args[0] == "changereg":
                if len(args) != 3:
                    print("Usage: changereg [register] [value]")
                    return

                reg_choice = args[1]
                value = args[2]

                if (len(value) % 2 != 0 or len(value) > 6):
                    print("Please provide a valid value")
                    return

                if self.isExtended and reg_choice in VALID_OPTIONS_EXTENDED:
                    print("Adjusting register", reg_choice, "to", value)

                elif not self.isExtended and reg_choice in VALID_OPTIONS_SIMPLE:
                    if self.registery.set_register(reg_choice, value) == False:
                        print("Invalid value - Setting register failed")

                else:
                    print("Please provide a valid register")

            elif args[0] == "changemem":
                if len(args) != 3:
                    print("Usage: changemem [address] [bytevalue]")
                    return

                address = args[1]
                value = args[2]

                if (len(value) != SIZE_OF_BYTE):
                    print("Please provide a valid value")
                    return

                if self.memory.set_memory(address, value) == False:
                    print("Invalid value or address - Setting memory failed")

            elif args[0] == "stop":
                print("Stopping interpreter")

            elif args[0] == "exit":
                print("Bye :)")
                sys.exit()

        else:
            print("Invalid command")