示例#1
0
文件: logxs.py 项目: minlaxz/logxs
def printf(*argv):
    data, data_type, data_shape = [], [], []
    for arg in argv:
        try:
            data.append(arg)
            data_type.append(type(arg))
            data_shape.append(arg.shape)
        except AttributeError:
            data_shape.append(None)
        except Exception as e:
            print_danger(e)

    for i in range(len(data)):
        print_danger(data[i])
        if (data_shape[i] == () or data_shape[i] == None):
            p('{0}'.format(data_type[i]))
        else:
            p('{0} => shape: {1}'.format(data_type[i], data_shape[i]))
示例#2
0
def main(student_cnt: int = 2,
         stop_time: int = 2000,
         stop_percent: Optional[float] = None,
         display: bool = False):
    assert student_cnt >= 2 and student_cnt <= 10000
    students = [Student() for _ in range(student_cnt)]
    students[0].hear()

    if display:
        console.rule(f'cnt={student_cnt}, stop={stop_time}')

    def percent_heard():
        return sum([s.heard() for s in students]) / student_cnt

    time = 0
    while time < stop_time:
        shuffle(students)
        split = student_cnt // 2
        firsts = students[:split]
        seconds = students[split:]

        for i in range(len(firsts)):
            first = firsts[i]
            second = seconds[i]

            if first.able_to_tell() and second.able_to_tell():
                if randint(0, 1):
                    first.hear()
                if randint(0, 1):
                    second.hear()
            elif first.able_to_tell():
                first.tell(second)
            elif second.able_to_tell():
                second.tell(first)

        time += 1
        if stop_percent is not None:
            if percent_heard() >= stop_percent:
                break

        if display:
            p(time, percent_heard)

    return percent_heard(), time
示例#3
0
文件: logxs.py 项目: minlaxz/logxs
    def c(self, *argv):
        self.m_io.clear()
        self.t_io.clear()
        self.shape.clear()

        for arg in argv:
            try:
                self.m_io.append(arg)
                self.t_io.append(type(arg))
                self.shape.append(arg.shape)
            except AttributeError:
                self.shape.append(None)

            except Exception as e:
                p(e)

        if not self.debug:
            for i in range(len(self.m_io)):
                self.print_danger(self.m_io[i])
                if (self.shape[i]) == None:
                    p('{0}'.format(self.t_io[i]))
                else:
                    p('{0} => shape: {1}'.format(self.t_io[i], self.shape[i]))
        else:
            pass
def main(args: Namespace):
    trials = args.trials
    q_cnt = args.questions
    c_cnt = args.choices
    exams_shape = (trials, q_cnt)

    with console.status('Computing on GPU'):
        #! Create exams
        if args.answer_type == 'last':
            exams = cp.full(exams_shape, c_cnt - 1, dtype=NP_TYPE)
        elif args.answer_type == 'random':
            exams = cp.random.choice(c_cnt, exams_shape).astype(NP_TYPE)
        else:
            log("[bold red] Incorrect answer strategy!")
            exit(-1)

        #! Create attempts
        attempts = cp.random.choice(c_cnt, exams_shape).astype(NP_TYPE)

        grades = (exams == attempts)
        correct = grades.sum(axis=1).astype(NP_TYPE)
        scores = (correct / q_cnt) * 100

    # displayResults(exam, trial, graded)
    # log(f'Score = {score:0.2f}%')
    # log(locals())

    # Move to CPU and sync
    cp.cuda.Stream.null.synchronize()
    scores = scores.get()

    passing = (scores > 70).sum()
    trace = np.random.choice(scores, 10).round(2)
    simulation_result = (passing / len(scores))

    title('[bold purple]Results')
    p(f'[green]Scores (trace 10): [blue][{"] [".join(trace.astype(str))}]')
    p(f'[green]Percent of Successes (> 70%): [blue]{toPercent(simulation_result)}'
      )  # type: ignore
    p(f'[green]Average: [blue] {scores.mean()}')

    formula = '    (1 / c_cnt) ** np.ceil(q_cnt * 0.7)'
    formula_result = eval(formula)
    syntax = Syntax(formula, "python")
    error = (simulation_result - formula_result) / formula_result

    title('[bold yellow]Conclusion')
    p('Each question is independent, therefor:')
    p('    P(q1,q2,q3)\n    = P(q1)P(q2)P(q3)')
    p('Each question has the same probability of being answered correctly')
    p('    = P(q1)^N\n    where N is the number of questions')
    p('and in this case where success is > 70%...')
    p(syntax, f'    = {toPercent(formula_result)}')
    p('The simulation results support this conclusion:')
    p(f'Experimental Error = {toPercent(error)}')
    p(f'[green]Average: [blue] {scores.mean()}')

    formula = '    (1 / c_cnt) ** np.ceil(q_cnt * 0.7)'
    formula_result = eval(formula)
    syntax = Syntax(formula, "python")
    error = (simulation_result - formula_result) / formula_result

    title('[bold yellow]Conclusion')
    p('Each question is independent, therefor:')
    p('    P(q1,q2,q3)\n    = P(q1)P(q2)P(q3)')
    p('Each question has the same probability of being answered correctly')
    p('    = P(q1)^N\n    where N is the number of questions')
    p('and in this case where success is > 70%...')
    p(syntax, f'    = {toPercent(formula_result)}')
    p('The simulation results support this conclusion:')
    p(f'Experimental Error = {toPercent(error)}')


if __name__ == '__main__':
    args = setupArgParser()

    title('[bold cyan]Assumptions')
    p('- Interview has 3 questions instead of 20')
    p('- Success means a 70% or higher')
    p('  - That means 3/3 given the above assumption')

    title('[bold blue]Parameters')
    inspect(args, title='Simulation Params', docs=False)

    main(args)
示例#6
0
文件: logxs.py 项目: minlaxz/logxs
def print_danger(m):
    p('[italic red]{0}[/italic red]'.format(m))