Example #1
0
    mu_0 = [0, 0, 0], 
    kappa = 0.01, 
    mu = [-3, 0, 3], 
    tau = [
        np.array([[1]]),
        np.array([[1]]),
        np.array([[1]])
    ]
)
D = Poisson(
    mu = [5,15,20], 
    alpha=[1, 1, 1],
    beta=[0.0001, 0.0001, 0.0001],
    support_step = 20
)
pi = Initial(K=3,beta=0.001)

m = EDHMM(A,O,D,pi)

T = 500

X,Y,Dseq = m.sim(T)
U = [0 for y in Y]

max_durations = range(5,max(Dseq)+5)

pb.figure(figsize=(8,2))

for sample in range(5):
    print sample
    L = []
Example #2
0
if __name__ == '__main__':

    proxies = u.proxies()
    random.shuffle(proxies)

    with open('sites.json') as sitemaps_json:
        start = time.time()
        print("Attempting to initialize sitemap data...")
        sitemaps = json.load(sitemaps_json)
        sitemaps_length = len(sitemaps['sitemaps'])
        print(str(sitemaps_length) + " sitemap(s) detected.")
        data = [0 for x in range(sitemaps_length)]

    for i in range(sitemaps_length):
        try:
            data[i] = Initial(sitemaps['sitemaps'][i], proxies[i]).sendSites()
            print(u.getDatetime(), i,
                  'Initialized {}'.format(sitemaps['sitemaps'][i]['sitemap']),
                  len(data[i]))
            # print(data[i])
        except Exception as e:
            print(e)
    print("Sitemap data initialized.")
    print(time.time() - start)

    try:

        for i in range(sitemaps_length):
            Process(target=ShopifyMonitor(data[i],
                                          sitemaps['sitemaps'][i]).run,
                    name=sitemaps['sitemaps'][i]['name']).start()
Example #3
0
    def load(self, space: Space, space_name, adjoint):

        if not adjoint:
            displacement = Initial(
                space_name,
                "primal_displacement",
                space.function_space_split[0],
            )
            velocity = Initial(space_name, "primal_velocity",
                               space.function_space_split[1])

        else:
            displacement_adjoint = Initial(
                space_name,
                "adjoint_displacement",
                space.function_space_split[0],
            )
            velocity_adjoint = Initial(space_name, "adjoint_velocity",
                                       space.function_space_split[1])

        counter = 0
        macrotimestep = self.head
        global_size = self.size
        for n in range(global_size):

            microtimestep = macrotimestep.head
            local_size = macrotimestep.size
            for m in range(local_size):

                if not adjoint:
                    microtimestep.functions[
                        "primal_displacement"] = displacement.load(counter)
                    microtimestep.functions["primal_velocity"] = velocity.load(
                        counter)

                else:
                    microtimestep.functions[
                        "adjoint_displacement"] = displacement_adjoint.load(
                            counter)
                    microtimestep.functions[
                        "adjoint_velocity"] = velocity_adjoint.load(counter)
                if microtimestep.after is not None:

                    counter += 1

                microtimestep = microtimestep.after

            macrotimestep = macrotimestep.after
Example #4
0
from initial import Initial

import tty
import sys
import termios

# indices_list_row = []
# indices_list_column = []

game = Initial()
''' back is the instance of the class Background in background.py file'''

if __name__ == '__main__':
    game.run()

#     game.welcome_msg()
#     ''' Calling welcome_msg() function of the class Background on the instance 'back' '''

#     game.make_numpygrid()
#     ''' Calling make_numpygrid() function of the class Background on the instance 'back' to make the 2d grid for the background'''

#     back.fit_in_objects()
# while True:
#     orig_settings = termios.tcgetattr(sys.stdin)

#     tty.setcbreak(sys.stdin)
#     x = 0
#     x = sys.stdin.read(1)[0]
#     if x == chr(97): # ESC
#         print("You pressed", x)
#     elif x == chr(100):
Example #5
0
def time_stepping(
    functional_fluid_initial,
    functional_solid_initial,
    bilinear_form_fluid,
    functional_fluid,
    bilinear_form_solid,
    functional_solid,
    fluid: Space,
    solid: Space,
    interface: Space,
    param: Parameters,
    decoupling,
    fluid_timeline: TimeLine,
    solid_timeline: TimeLine,
    adjoint,
):

    # Initialize function objects
    if adjoint:

        displacement_name = "adjoint_displacement"
        velocity_name = "adjoint_velocity"

    else:

        displacement_name = "primal_displacement"
        velocity_name = "primal_velocity"

    displacement_fluid = Initial(
        "fluid", displacement_name, fluid.function_space_split[0]
    )
    velocity_fluid = Initial(
        "fluid", velocity_name, fluid.function_space_split[1]
    )
    displacement_solid = Initial(
        "solid", displacement_name, solid.function_space_split[0]
    )
    velocity_solid = Initial(
        "solid", velocity_name, solid.function_space_split[1]
    )

    # Save initial values for the primal problem
    if not adjoint:

        displacement_fluid.save(Function(fluid.function_space_split[0]))
        velocity_fluid.save(Function(fluid.function_space_split[1]))
        displacement_solid.save(Function(solid.function_space_split[0]))
        velocity_solid.save(Function(solid.function_space_split[1]))

    # Define time pointers
    if adjoint:

        fluid_macrotimestep = fluid_timeline.tail
        solid_macrotimestep = solid_timeline.tail

    else:

        fluid_macrotimestep = fluid_timeline.head
        solid_macrotimestep = solid_timeline.head

    # Create time loop
    size = fluid_timeline.size
    first_time_step = True
    counter = 0
    for n in range(size):

        if adjoint:

            print(f"Current macro time-step {size - counter}")

        else:

            print(f"Current macro time-step {counter + 1}")

        # Perform decoupling
        decoupling(
            displacement_fluid,
            velocity_fluid,
            displacement_solid,
            velocity_solid,
            functional_fluid_initial,
            functional_solid_initial,
            bilinear_form_fluid,
            functional_fluid,
            bilinear_form_solid,
            functional_solid,
            first_time_step,
            fluid,
            solid,
            interface,
            param,
            fluid_macrotimestep,
            solid_macrotimestep,
            adjoint,
        )

        # Perform final iteration and save solutions
        solve_problem(
            displacement_fluid,
            velocity_fluid,
            displacement_solid,
            velocity_solid,
            fluid,
            solid,
            solid_to_fluid,
            functional_fluid_initial,
            bilinear_form_fluid,
            functional_fluid,
            first_time_step,
            param,
            fluid_macrotimestep,
            adjoint,
            save=True,
        )
        solve_problem(
            displacement_solid,
            velocity_solid,
            displacement_fluid,
            velocity_fluid,
            solid,
            fluid,
            fluid_to_solid,
            functional_solid_initial,
            bilinear_form_solid,
            functional_solid,
            first_time_step,
            param,
            solid_macrotimestep,
            adjoint,
            save=True,
        )

        first_time_step = False

        # Update solution
        displacement_fluid.old.assign(displacement_fluid.new)
        velocity_fluid.old.assign(velocity_fluid.new)
        displacement_solid.old.assign(displacement_solid.new)
        velocity_solid.old.assign(velocity_solid.new)

        # Update boundary conditions
        displacement_fluid.interface_old.assign(
            displacement_fluid.interface_new
        )
        velocity_fluid.interface_old.assign(velocity_fluid.interface_new)
        velocity_solid.interface_old.assign(velocity_solid.interface_new)

        # Advance timeline
        if adjoint:

            fluid_macrotimestep = fluid_macrotimestep.before
            solid_macrotimestep = solid_macrotimestep.before

        else:

            fluid_macrotimestep = fluid_macrotimestep.after
            solid_macrotimestep = solid_macrotimestep.after
        counter += 1

    # Save initial values for the adjoint problem
    if adjoint:

        displacement_fluid.save(Function(fluid.function_space_split[0]))
        velocity_fluid.save(Function(fluid.function_space_split[1]))
        displacement_solid.save(Function(solid.function_space_split[0]))
        velocity_solid.save(Function(solid.function_space_split[1]))

    # Check convergence
    [print(linear_systems) for linear_systems in displacement_fluid.iterations]
    failed = 0
    for i in range(len(displacement_fluid.iterations)):
        failed += min(0, displacement_fluid.iterations[i])
    if failed < 0:
        print('The decoupling method failed at some point')

    return