コード例 #1
0
def open_and_process_audio(audio_file, frame, overlap):
    GS.clear_directory('../test_audio_frames')

    audio = AudioSegment.from_wav(audio_file)
    length = int(math.ceil(len(audio) / 1000))

    write_out_audio(audio, length, frame, overlap)
コード例 #2
0
ファイル: asserts.py プロジェクト: AdaCore/gps
def __show_error(msg, quiet=False):
    """
    Display the error message on stdout, and possibly add the backtrace.
    :param bool quiet: whether to show a traceback
    """
    global exit_status
    exit_status = FAILURE

    if not quiet:
        msg += '\n'
        for s in inspect.stack():
            msg += '\n  at %s:%s:%s' % (s[1], s[2], s[3])
        msg += '\n in directory ' + GS.pwd()

    GS.Logger('TESTSUITE').log(msg)
コード例 #3
0
ファイル: GSTests.py プロジェクト: kristianeschenburg/Graphs
    def test_sex_size(self):
        """
        Test whether male/female arrays are the matching sizes.
        """

        m = np.asarray([0, 1])
        w = np.asarray([0, 1, 2])

        mp = np.asarray([[1, 0], [1, 0]])
        wp = np.asarray([[0, 1], [0, 1]])

        m2 = np.asarray([0, 1])
        w2 = np.asarray([1, 2])

        self.assertRaises(GS.GaleShapley(m, w, mp, wp))
        self.assertRaises(GS.GaleShapley(w, m, mp, wp))
        self.assertRaises(GS.GaleShapley(m2, w2, mp, wp))
コード例 #4
0
ファイル: GSTests.py プロジェクト: kristianeschenburg/Graphs
    def test_misalignments(self):
        """
        Test misalignments -- when preference matches do not exist.
        """

        m = np.asarray([0, 1])
        w = np.asarray([0, 1])

        mp = np.asarray([[1, 0], [1, 0]])
        wp = np.asarray([[1, 0], [1, 0]])

        G = GS.GaleShapley(m, w, mp, wp)
        G.marry()

        expected = {0: 0, 1: 1}

        self.assertTrue(G.husband == expected)
コード例 #5
0
ファイル: GSTests.py プロジェクト: kristianeschenburg/Graphs
    def test_simple_reordered(self):
        """
        A simple 2x2 case, where men's preferences are the same as the women's.
        """

        m = np.asarray([1, 0])
        w = np.asarray([0, 1])

        mp = np.asarray([[0, 1], [1, 0]])
        wp = np.asarray([[0, 1], [1, 0]])

        G = GS.GaleShapley(m, w, mp, wp)
        G.marry()

        expected = {0: 0, 1: 1}

        self.assertTrue(G.husband == expected)
        self.assertTrue(G.wife == expected)
コード例 #6
0
ファイル: GSTests.py プロジェクト: kristianeschenburg/Graphs
    def test_ties(self):
        """
        Test a case where men prefer the same woman.
        """

        m = np.asarray([0, 1, 2])
        w = np.asarray([0, 1, 2])

        mp = np.asarray([[0, 1, 2], [0, 1, 2], [0, 1, 2]])

        wp = np.asarray([[0, 1, 2], [0, 1, 2], [0, 1, 2]])

        G = GS.GaleShapley(m, w, mp, wp)
        G.marry()

        husbands = {0: 0, 1: 1, 2: 2}
        wives = {0: 0, 1: 1, 2: 2}

        self.assertTrue(G.husband == husbands)
        self.assertTrue(G.wife == wives)
コード例 #7
0
ファイル: GSTests.py プロジェクト: kristianeschenburg/Graphs
    def test_shifts(self):
        """
        Test shifted case, where men each prefer the next in line.
        """

        m = np.asarray([0, 1, 2, 3])
        w = np.asarray([0, 1, 2, 3])

        mp = np.asarray([[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 1],
                         [3, 0, 1, 2]])

        wp = np.asarray([[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3],
                         [0, 1, 2, 3]])

        G = GS.GaleShapley(m, w, mp, wp)
        G.marry()

        husbands = {0: 0, 1: 1, 2: 2, 3: 3}
        wives = {0: 0, 1: 1, 2: 2, 3: 3}

        self.assertTrue(G.husband == husbands)
        self.assertTrue(G.wife == wives)
コード例 #8
0
ファイル: asserts.py プロジェクト: spanners/GNATstudio
def clang_assert(left, right, msg='Error in test script', quiet=False):
    """
    Special assert procedure for clang tests, that will log a few things
    relevant to the error happening, namely errors and include paths for
    libclang
    """
    import compiler_paths
    from os import path

    if not gps_assert(left, right, msg, quiet):
        f = GS.EditorBuffer.get().file()
        logger = GS.Logger("TESTSUITE")
        logger.log("Clang assert failed")
        clang_tu = GS.Libclang.get_translation_unit(f)

        logger.log("Begin logging clang diagnostics")
        for i, d in enumerate(clang_tu.diagnostics):
            logger.log("    Diagnostic {}: {}".format(i, d))
        logger.log("End logging clang diagnostics")

        logger.log("Begin logging clang include paths")

        # Pass the testsuite logger to get_compiler_search_paths, so that we
        # also get all the logging
        paths = compiler_paths.get_compiler_search_paths(f.project().name(),
                                                         f.language(),
                                                         logger=logger,
                                                         use_cache=False)

        for p in paths:
            logger.log("    Path : {}".format(p))
            if not path.isdir(p):
                logger.log("    WARNING: This path is not valid (path.isdir)")
        logger.log("End logging clang include paths")
        return False
    return True
コード例 #9
0
def train_clf(frame, overlap, frame_factor, overlap_factor):
    GS.write_frames(frame, overlap)
    inputs, labels = feature_extractor_GS.extract(frame_factor, overlap_factor)
    clf = ExtraTreesClassifier(n_estimators=100, random_state=0)
    clf.fit(inputs, labels)
    return clf
コード例 #10
0
ファイル: SMD.py プロジェクト: manpan/game_theoretic_routing
    def solve_smd_game(self, importance):
        """
        Solves the bimatrix secure delivery message game.
        """

        self.nash_smd_plan = []
        self.nash_attack_distr = []
        self.aodv_plan = []

        if importance == 'Security Risk':
            costs_importance = self.costs_importance_vector[0]
        elif importance == 'Security Risk and Energy Consumption':
            costs_importance = self.costs_importance_vector[1]
        elif importance == 'Security Risk and QoS':
            costs_importance = self.costs_importance_vector[2]
        elif importance == 'Security Risk, Energy Consumption and QoS':
            costs_importance = self.costs_importance_vector[3]
        else:
            pass

        for route in range(self.no_routes):
            for msg in range(self.no_msgs):
                confusion = (1 - self.rout_confusion_matrices[route][msg][msg])
                if msg != self.no_msgs - 1:
                    damage_value = confusion * self.sec_damage * costs_importance[0]
                else:
                    damage_value = 0
                false_alarm_cost_value = confusion * self.false_alarm * costs_importance[1]
                energy_costs_value = self.rout_eng_costs[route] / self.max_energy_cost * costs_importance[2]
                qos_costs_value = self.rout_qos_cost[route] * costs_importance[3]
                self.def_matrix[route][msg] = - damage_value - false_alarm_cost_value \
                                              - energy_costs_value - qos_costs_value

        self.att_matrix = deepcopy(self.def_matrix)
        for route in range(len(self.att_matrix)):
            for msg in range(len(self.att_matrix[0])):
                    self.att_matrix[route][msg] = - self.att_matrix[route][msg]
        self.def_np_matrix = np.matrix(self.def_matrix)
        self.att_np_matrix = np.matrix(self.att_matrix)
 		
 		# Separate code must be used to solve the game
        game_sols = GS.all_ne(self.def_np_matrix, self.att_np_matrix, self.no_routes, self.no_msgs)

        defender = 0
        attacker = 1
        solution_id = 0
        bare_value = 0

        # Set the Nash defence distribution akin to Nash Message Delivery Plan
        for route in range(self.no_routes):
            print 'debugging:', game_sols[defender][solution_id][route][bare_value]
            self.nash_smd_plan.append(game_sols[defender][solution_id][route][bare_value])

        # Create the Nash attack distribution
        for msg in range(self.no_msgs):
            self.nash_attack_distr.append(game_sols[attacker][solution_id][msg][bare_value])

        # Create AODV routing plan
        for route in range(self.no_routes):
            if route != self.aodv_route_id:
                self.aodv_plan.append(0)
            else:
                self.aodv_plan.append(1)
コード例 #11
0
    def solve_smd_game(self, importance):
        """
        Solves the bimatrix secure delivery message game.
        """

        self.nash_smd_plan = []
        self.nash_attack_distr = []
        self.aodv_plan = []

        if importance == 'Security Risk':
            costs_importance = self.costs_importance_vector[0]
        elif importance == 'Security Risk and Energy Consumption':
            costs_importance = self.costs_importance_vector[1]
        elif importance == 'Security Risk and QoS':
            costs_importance = self.costs_importance_vector[2]
        elif importance == 'Security Risk, Energy Consumption and QoS':
            costs_importance = self.costs_importance_vector[3]
        else:
            pass

        for route in range(self.no_routes):
            for msg in range(self.no_msgs):
                confusion = (1 - self.rout_confusion_matrices[route][msg][msg])
                if msg != self.no_msgs - 1:
                    damage_value = confusion * self.sec_damage * costs_importance[
                        0]
                else:
                    damage_value = 0
                false_alarm_cost_value = confusion * self.false_alarm * costs_importance[
                    1]
                energy_costs_value = self.rout_eng_costs[
                    route] / self.max_energy_cost * costs_importance[2]
                qos_costs_value = self.rout_qos_cost[route] * costs_importance[
                    3]
                self.def_matrix[route][msg] = - damage_value - false_alarm_cost_value \
                                              - energy_costs_value - qos_costs_value

        self.att_matrix = deepcopy(self.def_matrix)
        for route in range(len(self.att_matrix)):
            for msg in range(len(self.att_matrix[0])):
                self.att_matrix[route][msg] = -self.att_matrix[route][msg]
        self.def_np_matrix = np.matrix(self.def_matrix)
        self.att_np_matrix = np.matrix(self.att_matrix)

        # Separate code must be used to solve the game
        game_sols = GS.all_ne(self.def_np_matrix, self.att_np_matrix,
                              self.no_routes, self.no_msgs)

        defender = 0
        attacker = 1
        solution_id = 0
        bare_value = 0

        # Set the Nash defence distribution akin to Nash Message Delivery Plan
        for route in range(self.no_routes):
            print 'debugging:', game_sols[defender][solution_id][route][
                bare_value]
            self.nash_smd_plan.append(
                game_sols[defender][solution_id][route][bare_value])

        # Create the Nash attack distribution
        for msg in range(self.no_msgs):
            self.nash_attack_distr.append(
                game_sols[attacker][solution_id][msg][bare_value])

        # Create AODV routing plan
        for route in range(self.no_routes):
            if route != self.aodv_route_id:
                self.aodv_plan.append(0)
            else:
                self.aodv_plan.append(1)
コード例 #12
0
# The Thomas-Fermi distribution
def nTF(x, y):
    mask = mu0 - Vinit(x, y) > 0.0
    return ((mu0 - Vinit(x, y)) / gN) * mask.astype(np.int)
    #return ((mu0-Vinit(x,y))/gN)*(abs(Vinit(x,y))<sqrt(2*mu0)).astype(np.int)


xgrid = -Lx + 2 * (Lx / Nx) * np.asfortranarray(arange(Nx))
ygrid = -Ly + 2 * (Ly / Ny) * np.asfortranarray(arange(Ny))
xmesh, ymesh = np.meshgrid(xgrid, ygrid)

###########################
# Ground state computation#
###########################

g_s = gs.GroundState(Vinit(xmesh, ymesh), nTF(xmesh, ymesh), gN, Omega, xmesh,
                     ymesh)
psi0 = g_s.psifinal
print('Number of steps=', g_s.nsteps)
print('Chemical potential =%.3f' % g_s.mufinal)
print('Healing length =%.3f' % (1 / sqrt(2 * g_s.mufinal)))


# Define phase to add on ground state wavefunction
def helix(th):
    dphi = 2 * pi * 1.0
    return dphi * (th / (2 * pi))


#########################
#  Real time evolution  #
#########################