def otherFinancialDetails():
    design.design()
    df, start_date = getCompanyData()

    df = df.sort_values(by=['Date'], ascending=[True])
    df.set_index('Date', inplace=True)
    df = df.resample('D').ffill().reset_index()

    closecost = df['Close']
    opencost = df['Open']
    value = input(
        "\n1. Moving Average\n2. Weighted Moving average\n3. MACD(Moving Average Conversion Diversion)\n4. Coefficient of Variation\n5. Go Back To previous Menu\n6. Exit\n\n"
    )
    if (value == "1"):
        moving_average(closecost)
    elif (value == "2"):
        weighted_moving_average(closecost)
    elif (value == "3"):
        macd(closecost)
    elif (value == "4"):
        cv(closecost)
    elif (value == "5"):
        financeMenu()
    elif (value == "6"):
        print("\n************** THANK YOU **************")
        sys.exit()
    else:
        print("\nWrong Choice !!! Please retry")
        otherFinancialDetails()

    otherFinancialDetails()
def getMenuDetails():
    design.design()
    print("Please select from the below menu option :\n")
    value = input("1. More Details of the Company\n2. Exit\n\n")
    if value == "1":
        selectMenu()
    elif value == "2":
        print("\n************** THANK YOU **************")
        sys.exit()
    else:
        print("Wrong Choice!!!! Please retry")
        getMenuDetails()
def roi(regr, date_test, currentcost):
    design.design()
    investment = float(
        input("\nPlease Enter the Amount You want to invest: $"))
    shares = (investment / currentcost)
    investment_period = input(
        "Enter till when you want to invest in the format MM/DD/YYYY :")
    value = datecal(investment_period)
    futureval = (prediction(regr, date_test, number=indx[0] + value))
    roi = (shares * futureval)
    print("\nCurrent Stock Price: $", currentcost)
    print("\nFuture Stock Price: $", futureval)
    print("\nRoi is: $", roi)
    print("\nProfit is: $", (roi - investment))
def selectMenu():
    design.design()
    value = input("1. Financial Details\n2. Prediction Model\n3. Exit\n\n")
    design.design()
    if value == "1":
        financial_indicators.main()
    elif value == "2":
        prediction.flow()
    elif value == "3":
        print("\n************** THANK YOU **************")
        sys.exit()
    else:
        print("Wrong Choice!!! Please retry")
        selectMenu()
def moving_average(closecost):
    design.design()
    try:
        n = int(
            input("\nEnter the value of n for calculating moving average: "))
    except:
        print("\nWrong Entry Please Try Again")
        otherFinancialDetails()

    value = pd.rolling_mean(closecost, n)
    ax = value.plot()
    plt.xlabel('Days')
    plt.ylabel('Stock Price')
    plt.suptitle('Moving Average')
    plt.show()
Example #6
0
    def execute(niters):

        #assign new random seed
        if parallelize: np.random.seed()

        naccept = 0
        samples = np.zeros((D, niters + 1))
        while True:
            d = design.design(size=(ado.N_categories,
                                    ado.N_features))  #first design is random
            u = ado.global_utility(d)
            if not u == 0: break
        accepted_u = []
        accepted_d = []

        iterator = range(niters)
        if ado.logging: iterator = tqdm.tqdm(iterator)

        for i in iterator:
            # j = J(i+1)
            d_i = proposal_distribution(d)  #random walk
            u_i = ado.global_utility(d_i)
            rho = min(1, u_i / u)  #**j consider sim. annealing
            if np.random.uniform() < rho:
                naccept += 1  #number accepted
                d = d_i
                u = u_i
                accepted_d.append(d)
                accepted_u.append(u)
        ado.log('\t### MCMC acceptance rate: %.2f ###' %
                float(1.0 * naccept / niters))
        idx_best_d = np.nanargmax(accepted_u)
        return accepted_d[idx_best_d], accepted_u[idx_best_d]
Example #7
0
    def execute(niters):

        #assign new random seed
        if parallelize: np.random.seed()

        xt = np.empty((niters, n_particles), dtype=np.object)
        ut = np.zeros((niters, n_particles))
        wt = np.zeros((niters, n_particles))
        wt[0, :] = np.ones(n_particles) / n_particles

        for i in np.arange(n_particles):
            while True:
                xt[0, i] = design.design(
                    size=(ado.N_categories,
                          ado.N_features))  #first design is random
                ut[0, i] = ado.global_utility(xt[0, i])
                if not ut[0, i] == 0: break

        iterator = np.arange(start=1, stop=niters)
        # if ado.logging: iterator = tqdm.tqdm(iterator)

        #smc
        for t in iterator:
            xt_ = np.empty(n_particles, dtype=np.object)
            ut_ = np.zeros(n_particles)
            wt_ = np.zeros(n_particles)

            #time update
            for i in np.arange(n_particles):
                xt_[i] = proposal_distribution(xt[t - 1, i])  #random walk
                #measurement update
                ut_[i] = ado.global_utility(xt_[i])
                wt_[i] = wt[t - 1, i] * ut_[i]

            #resample
            idx = np.random.choice(a=n_particles,
                                   size=n_particles,
                                   p=wt_ / np.sum(wt_))
            xt[t, :] = xt_[idx]
            ut[t, :] = ut_[idx]
            wt[t, :] = np.ones(n_particles) / n_particles

        print(np.max(ut))

        # #mcmc
        # for i in iterator:
        # 	# j = J(i+1)
        # 	d_i = proposal_distribution(d) #random walk
        # 	u_i = ado.global_utility(d_i)
        # 	rho = min(1, u_i / u) #**j consider sim. annealing
        # 	if np.random.uniform() < rho:
        # 		naccept += 1 #number accepted
        # 		d = d_i
        # 		u = u_i
        # 		accepted_d.append(d)
        # 		accepted_u.append(u)

        ado.log('\t### SMC sampling finished! ###')
        idx_best_d = np.nanargmax(ut)
        return xt.flatten()[idx_best_d], ut.flatten()[idx_best_d]
Example #8
0
	def evaluate_N_random(n):
		np.random.seed()
		#randomly generate and evaluate #'n_iterations' designs:
		randomDesigns = [design.design(size=(ado.N_categories, 
			ado.N_features), alpha=alpha) for i in np.arange(n)]

		U = [ado.global_utility(d) for d in randomDesigns]
		
		try:
			idx_best_d = np.nanargmax(U)
		except Exception:
			d = design.design(size=(ado.N_categories, 
				ado.N_features), alpha=alpha)
			return d, ado.global_utility(d)
		else:
			idx_best_d = np.nanargmax(U)
			return randomDesigns[idx_best_d], U[idx_best_d]
Example #9
0
def optimize(ado, **kwargs):
	N_designs = kwargs.get('n_designs', 100)
	ado.results.d_evaluated.append(N_designs)
	alpha = kwargs.get('alpha', 1.0)
	parallelize = kwargs.get('parallelize', False)
	if parallelize: N_threads = kwargs.get('N_threads', 4)

	def evaluate_N_random(n):
		np.random.seed()
		#randomly generate and evaluate #'n_iterations' designs:
		randomDesigns = [design.design(size=(ado.N_categories, 
			ado.N_features), alpha=alpha) for i in np.arange(n)]

		U = [ado.global_utility(d) for d in randomDesigns]
		
		try:
			idx_best_d = np.nanargmax(U)
		except Exception:
			d = design.design(size=(ado.N_categories, 
				ado.N_features), alpha=alpha)
			return d, ado.global_utility(d)
		else:
			idx_best_d = np.nanargmax(U)
			return randomDesigns[idx_best_d], U[idx_best_d]

	class MultiProcess(Process):
		def __init__(self, n):
			Process.__init__(self)
			self.n = n
			self.queueD = Queue()
			self.queueU = Queue()	

		def run(self):
			d, u = evaluate_N_random(self.n)
			self.queueD.put(d)
			self.queueU.put(u)

	if parallelize:
		split_N = np.array([int(N_designs / N_threads)] * N_threads)
		split_N[0] += N_designs - np.sum(split_N)
		jobs = [MultiProcess(n) for n in split_N]
		for job in jobs: job.start()
		for job in jobs: job.join()
		#find best design among jobs!!
		D = [job.queueD.get() for job in jobs]
		U = [job.queueU.get() for job in jobs]
		
		try:
			idx_best_d = np.nanargmax(U)
		except Exception:
			d = design.design(size=(ado.N_categories, 
				ado.N_features), alpha=alpha)
			return d, ado.global_utility(d)
		else:
			idx_best_d = np.nanargmax(U)
			return D[idx_best_d], U[idx_best_d]
	else:
		return evaluate_N_random(N_designs)
Example #10
0
def optimize(ado, **kwargs):
	alpha = kwargs.get('alpha', 1.0)
	ado.results.d_evaluated.append(1)
	while(True):
		d = design.design(size=(ado.N_categories, ado.N_features), alpha=alpha)
		u = ado.global_utility(d)
		if not math.isnan(u):
			break
	return d, u
def financeMenu():
    plt.clf()  # To close all the opened graphs from memory
    design.design()
    print("\nPlease select from the below options to see finance details : \n")
    value = input(
        "1. Basic Financial Details\n2. Other Financial Details \n3. Go back to previous menu\n4. Exit\n\n"
    )
    if (value == "1"):
        basicFinancialDetails()
    elif (value == "2"):
        otherFinancialDetails()
    elif (value == "3"):
        company_details.selectMenu()
    elif (value == "4"):
        print("\n************** THANK YOU **************")
        sys.exit()
    else:
        print("\nWrong Choice!!! Please retry")
        financeMenu()
Example #12
0
    def proposal_distribution(d, sigma=sigma):
        new_prior = np.absolute(
            np.add(d.prior, np.random.normal(0, sigma, size=d.prior.shape)))
        new_prior /= np.sum(new_prior)

        while True:
            new_lk = np.add(
                d.likelihoods,
                np.random.normal(0, sigma, size=d.likelihoods.shape))
            new_lk = norm_probabilities(new_lk)
            if np.argwhere(np.sum(new_lk, axis=1) % 3 == 0).size == 0: break
        return design.design(pr=new_prior[:-1], lk=new_lk)
def basicFinancialDetails():
    design.design()
    value = input(
        "\n1. Last 1 Year\n2. Last 6 Months\n3. Last 3 Months\n4. Go back to previous menu\n5. Exit\n\n"
    )
    design.design()
    df, start_date = getCompanyData()
    if value == "1":
        end_date = start_date - dateutil.relativedelta.relativedelta(months=12)

    elif value == "2":
        end_date = start_date - dateutil.relativedelta.relativedelta(months=6)

    elif value == "3":
        end_date = start_date - dateutil.relativedelta.relativedelta(months=3)

    elif value == "4":
        financeMenu()

    elif value == "5":
        print("\n************** THANK YOU **************")
        sys.exit()
    else:
        print("\nWrong Choice !!! Please retry")
        basicFinancialDetails()

    if value == "1" or value == "2" or value == "3":
        print("Trading at ", df['Open'][1], "as of ", df['Date'][1])
        design.design()
        mask = (df['Date'] > end_date) & (df['Date'] < start_date)
        df = df.loc[mask]
        financialDetails = df.describe()
        print(financialDetails)

    basicFinancialDetails()
    def utility(x_init):
        x = np.copy(x_init)
        penalty = 0
        for i, p in enumerate(x):  #penalize when
            x[i] = min(1.0, x[i])  #out of bounds
            x[i] = max(0.0, x[i])
            penalty += abs(x[i] - x_init[i])

        prior = x[:ado.N_categories - 1]
        prior_sum = np.sum(prior)
        if (prior_sum - 1.0) > 0.0:
            for i, _ in enumerate(prior):
                x[i] /= prior_sum
            penalty += abs(prior_sum - 1.0)

        likelihood = x[ado.N_categories - 1:]
        d = design.design(pr=prior,
                          lk=np.reshape(likelihood,
                                        (ado.N_features, ado.N_categories)))
        utility = ado.global_utility(d) - 1000 * penalty
        return d, utility
Example #15
0
    def run_step_simulation(self,
                            prior=None,
                            custom_design=None,
                            response=None,
                            last_step=0):
        """ Run simulations/DO only for one time step, allows for custom design, prior, and response. """
        subPath = ''  #'data/'

        self.max_steps = last_step + 1
        self.step = last_step
        self.stepwise = True

        # CUSTOM PRIOR
        if prior != None:  #TODO: check if prior matches !!!
            print "Loading prior from file!!!"
            self.prior = np.load(subPath + prior)
            self.priorName = 'custom'

        # CUSTOM DESIGN
        if custom_design != None:
            print "Loading design from file (using pre-specified environment)!!!"
            self.method = 'pre'
            d = np.load(subPath + custom_design)
            size = list(d.shape)[::-1]
            size[1] = int(np.log2(size[1]))
            self.N_categories, self.N_features = size
            joint = d.flatten()
            self.step_design = design.design(joint=joint, size=size)

        # CUSTOM RESPONSE
        if response != None:
            print "Response pre-specified"
            self.set_response = response
            self.simulation = False

        return self.execute()
Example #16
0
    def runTest(self):
        config_file = "{}/tests/configs/config".format(
            os.getenv("OPENRAM_HOME"))
        globals.init_openram(config_file)
        import wire
        import tech
        import design

        layer_stacks = [tech.poly_stack] + tech.beol_stacks

        for reverse in [False, True]:
            for stack in layer_stacks:
                if reverse:
                    layer_stack = stack[::-1]
                else:
                    layer_stack = stack

                # Just make a conservative spacing. Make it wire pitch instead?
                min_space = 2 * (
                    tech.drc["minwidth_{}".format(layer_stack[0])] +
                    tech.drc["minwidth_{}".format(layer_stack[2])])

                position_list = [[0, 0], [0, 3 * min_space],
                                 [1 * min_space, 3 * min_space],
                                 [4 * min_space, 3 * min_space],
                                 [4 * min_space, 0], [7 * min_space, 0],
                                 [7 * min_space, 4 * min_space],
                                 [-1 * min_space, 4 * min_space],
                                 [-1 * min_space, 0]]
                position_list = [[x - min_space, y - min_space]
                                 for x, y in position_list]
                w = design.design("wire_test_{}".format("_".join(layer_stack)))
                wire.wire(w, layer_stack, position_list)
                self.local_drc_check(w)

        globals.end_openram()
Example #17
0
    def runTest(self):
        globals.init_AMC("config_20_{0}".format(OPTS.tech_name))
        global calibre
        import calibre
        OPTS.check_lvsdrc = False

        import wire
        import tech
        import design

        min_space = 2 * (tech.drc["minwidth_poly"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("poly", "contact", "metal1")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x - min_space, y - min_space]
                         for x, y in old_position_list]
        w = design.design("wire_test1")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_poly"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("metal1", "contact", "poly")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x + min_space, y + min_space]
                         for x, y in old_position_list]
        w = design.design("wire_test2")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("metal1", "via1", "metal2")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]
        w = design.design("wire_test3")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("metal2", "via1", "metal1")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]
        w = design.design("wire_test4")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal3"])
        layer_stack = ("metal2", "via2", "metal3")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]
        position_list.reverse()
        w = design.design("wire_test5")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal3"])
        layer_stack = ("metal3", "via2", "metal2")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]
        position_list.reverse()
        w = design.design("wire_test6")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        # return it back to it's normal state
        OPTS.check_lvsdrc = True
        globals.end_AMC()
Example #18
0
    def runTest(self):
        config_file = "{}/tests/configs/config".format(
            os.getenv("OPENRAM_HOME"))
        globals.init_openram(config_file)
        import wire_path
        import tech
        import design

        min_space = 2 * tech.drc["minwidth_m1"]
        layer_stack = ("m1")
        # checks if we can retrace a path
        position_list = [[0, 0], [0, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [0, 3 * min_space],
                         [0, 6 * min_space]]
        w = design.design("path_test0")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_m1"]
        layer_stack = ("m1")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x + min_space, y + min_space]
                         for x, y in old_position_list]
        w = design.design("path_test1")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_m2"]
        layer_stack = ("m2")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x - min_space, y - min_space]
                         for x, y in old_position_list]
        w = design.design("path_test2")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_m3"]
        layer_stack = ("m3")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]
        # run on the reverse list
        position_list.reverse()
        w = design.design("path_test3")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        globals.end_openram()
Example #19
0
def webhook():
    global reqContext
    print(request.get_json(silent=True, force=True))
    reqContext = request.get_json(silent=True, force=True)
    print("webhook---->" + reqContext.get("result").get("action"))

    if reqContext.get("result").get("action") == "input.welcome.edwin":
        return welcome()
    elif reqContext.get("result").get("action") == "showpopularcategories":
        return showpopularcategories()
    elif reqContext.get("result").get("action") == "professionalcourses":
        return professional_courses.professionalcourses()
    elif reqContext.get("result").get("action") == "professionalcertificates":
        return professional_courses.professionalcertificates()
    elif reqContext.get("result").get("action") == "careeradvancement":
        return professional_courses.careeradvancement()
    elif reqContext.get("result").get("action") == "micromastersprograms":
        return professional_courses.micromastersprograms()
    elif reqContext.get("result").get("action") == "advancedskillsetcourses":
        return professional_courses.advancedskillsetcourses()
    elif reqContext.get("result").get("action") == "popularcourses":
        return popular_course.popularcourselist()
    elif reqContext.get("result").get("action") == "computerscience":
        return computer_science.computerscience()
    elif reqContext.get("result").get("action") == "data_and_statistics":
        return data_and_statistics.data_and_statistics()
    elif reqContext.get("result").get("action") == "business_management":
        return business_management.business_management()
    elif reqContext.get("result").get("action") == "language":
        return language.language()
    elif reqContext.get("result").get("action") == "economics_and_finance":
        return economics_and_finance.economics_and_finance()
    elif reqContext.get("result").get("action") == "engineering":
        return engineering.engineering()
    elif reqContext.get("result").get("action") == "humanities":
        return humanities.humanities()
    elif reqContext.get("result").get("action") == "life_sciences":
        return life_sciences.life_sciences()
    elif reqContext.get("result").get("action") == "science_courses":
        return science_courses.science_courses()
    elif reqContext.get("result").get("action") == "chemistry":
        return chemistry.chemistry()
    elif reqContext.get("result").get("action") == "electronics":
        return electronics.electronics()
    elif reqContext.get("result").get("action") == "environmental_studies":
        return environmental_studies.environmental_studies()
    elif reqContext.get("result").get("action") == "mathematics":
        return mathematics.mathematics()
    elif reqContext.get("result").get("action") == "medicine":
        return medicine.medicine()
    elif reqContext.get("result").get("action") == "physics":
        return physics.physics()
    elif reqContext.get("result").get("action") == "social_science":
        return social_science.social_science()
    elif reqContext.get("result").get("action") == "energy_and_earth_science":
        return energy_and_earth_science.energy_and_earth_science()
    elif reqContext.get("result").get("action") == "art_courses":
        return art_courses.art_courses()
    elif reqContext.get("result").get("action") == "architecture":
        return architecture.architecture()
    elif reqContext.get("result").get("action") == "art_and_culture":
        return art_and_culture.art_and_culture()
    elif reqContext.get("result").get("action") == "communication":
        return communication.communication()
    elif reqContext.get("result").get("action") == "design":
        return design.design()
    elif reqContext.get("result").get("action") == "food_and_nutrition":
        return food_and_nutrition.food_and_nutrition()
    elif reqContext.get("result").get("action") == "health_and_safety":
        return health_and_safety.health_and_safety()
    elif reqContext.get("result").get("action") == "history":
        return history.history()
    elif reqContext.get("result").get("action") == "music":
        return music.music()
    elif reqContext.get("result").get("action") == "law":
        return law.law()
    elif reqContext.get("result").get("action") == "BacktoWelcomeContent":
        return showpopularcategories()
    elif reqContext.get("result").get("action") == "BackToProfessionalCourses":
        return professional_courses.professionalcourses()
    else:
        print("Good Bye")
Example #20
0
from design import design
from box import print_msg_box
from birthmonth import month_of_birth
from todaymonth import today_month
from dayoftheYear import day_year
import time

exit_press = True
design()
# Loop our program using While loop...
while exit_press:
    print_msg_box(msg="""Follow this order: Month Date Year
Example: October 20 2000""")
    birth_month, birth_date, birth_year = [
        str(x) for x in input("Enter Birthday: ").split()
    ]
    recent_month, recent_date, recent_year = [
        str(x) for x in input("Enter Today's date: ").split()
    ]

    birth_month = birth_month.capitalize()
    recent_month = recent_month.capitalize()

    print("Processing...")
    time.sleep(2)
    # Check if our birth date and recent date is in range of calendars date.
    if int(birth_date) > 31:
        print_msg_box(msg="Invalid Birth date", title="Process Failed!")
        exit()
    elif int(recent_date) > 31:
        print_msg_box(msg="Invalid Today's date", title="Process Failed!")
Example #21
0
    def runTest(self):
        globals.init_AMC("config_20_{0}".format(OPTS.tech_name))
        global calibre
        import calibre
        OPTS.check_lvsdrc = False

        import path
        import tech
        import design

        min_space = 2 * tech.drc["minwidth_metal1"]
        layer = ("metal1")
        # checks if we can retrace a path
        position_list = [[0, 0], [0, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [0, 3 * min_space],
                         [0, 6 * min_space]]
        w = design.design("path_test0")
        path.path(w, layer, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_metal1"]
        layer = ("metal1")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x + min_space, y + min_space]
                         for x, y in old_position_list]
        w = design.design("path_test1")
        path.path(w, layer, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_metal2"]
        layer = ("metal2")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x - min_space, y - min_space]
                         for x, y in old_position_list]
        w = design.design("path_test2")
        path.path(w, layer, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_metal3"]
        layer = ("metal3")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]

        # run on the reverse list
        position_list.reverse()
        w = design.design("path_test3")
        path.path(w, layer, position_list)
        self.local_drc_check(w)

        # return it back to it's normal state
        OPTS.check_lvsdrc = True
        globals.end_AMC()
Example #22
0
    def runTest(self):
        globals.init_openram("config_{0}".format(OPTS.tech_name))
        import wire_path
        import tech
        import design

        min_space = 2 * tech.drc["minwidth_metal1"]
        layer_stack = ("metal1")
        # checks if we can retrace a path
        position_list = [[0, 0], [0, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [0, 3 * min_space],
                         [0, 6 * min_space]]
        w = design.design("path_test0")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_metal1"]
        layer_stack = ("metal1")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x + min_space, y + min_space]
                         for x, y in old_position_list]
        w = design.design("path_test1")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_metal2"]
        layer_stack = ("metal2")
        old_position_list = [[0, 0], [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0], [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list = [[x - min_space, y - min_space]
                         for x, y in old_position_list]
        w = design.design("path_test2")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * tech.drc["minwidth_metal3"]
        layer_stack = ("metal3")
        position_list = [[0, 0], [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space], [4 * min_space, 0],
                         [7 * min_space, 0], [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space], [-1 * min_space, 0]]
        # run on the reverse list
        position_list.reverse()
        w = design.design("path_test3")
        wire_path.wire_path(w, layer_stack, position_list)
        self.local_drc_check(w)

        globals.end_openram()
Example #23
0
    def runTest(self):
        config_file = "{}/tests/configs/config".format(os.getenv("OPENRAM_HOME"))
        globals.init_openram(config_file)
        import wire
        import tech
        import design
        
        min_space = 2 * (tech.drc["minwidth_poly"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("poly", "contact", "metal1")
        old_position_list = [[0, 0],
                             [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0],
                             [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list  = [[x-min_space, y-min_space] for x,y in old_position_list]        
        w = design.design("wire_test1")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_poly"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("metal1", "contact", "poly")
        old_position_list = [[0, 0],
                             [0, 3 * min_space],
                             [1 * min_space, 3 * min_space],
                             [4 * min_space, 3 * min_space],
                             [4 * min_space, 0],
                             [7 * min_space, 0],
                             [7 * min_space, 4 * min_space],
                             [-1 * min_space, 4 * min_space],
                             [-1 * min_space, 0]]
        position_list  = [[x+min_space, y+min_space] for x,y in old_position_list]
        w = design.design("wire_test2")        
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("metal1", "via1", "metal2")
        position_list = [[0, 0],
                         [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 0],
                         [7 * min_space, 0],
                         [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space],
                         [-1 * min_space, 0]]
        w = design.design("wire_test3")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)


        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal1"])
        layer_stack = ("metal2", "via1", "metal1")
        position_list = [[0, 0],
                         [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 0],
                         [7 * min_space, 0],
                         [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space],
                         [-1 * min_space, 0]]
        w = design.design("wire_test4")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal3"])
        layer_stack = ("metal2", "via2", "metal3")
        position_list = [[0, 0],
                         [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 0],
                         [7 * min_space, 0],
                         [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space],
                         [-1 * min_space, 0]]
        position_list.reverse()
        w = design.design("wire_test5")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        min_space = 2 * (tech.drc["minwidth_metal2"] +
                         tech.drc["minwidth_metal3"])
        layer_stack = ("metal3", "via2", "metal2")
        position_list = [[0, 0],
                         [0, 3 * min_space],
                         [1 * min_space, 3 * min_space],
                         [4 * min_space, 3 * min_space],
                         [4 * min_space, 0],
                         [7 * min_space, 0],
                         [7 * min_space, 4 * min_space],
                         [-1 * min_space, 4 * min_space],
                         [-1 * min_space, 0]]
        position_list.reverse()
        w = design.design("wire_test6")
        wire.wire(w, layer_stack, position_list)
        self.local_drc_check(w)

        globals.end_openram()
Example #24
0
def optimize(ado, **kwargs):

    D = (ado.N_features + 1) * ado.N_categories - 1
    n_designs = kwargs.get('n_designs', 100)
    n_iterations = kwargs.get('n_iterations', 100)
    n_particles = int(kwargs.get('n_iterations', n_designs / n_iterations))
    parallelize = kwargs.get('parallelize', False)
    sigma = kwargs.get('sigma', 0.3)
    alpha = kwargs.get('sigma', 1.0)
    ado.results.d_evaluated.append(n_designs)
    if parallelize: N_threads = kwargs.get('N_threads', 4)

    def norm_probabilities(array):
        for index, _ in np.ndenumerate(array):
            array[index] = min(1.0, array[index])
            array[index] = max(0.0, array[index])
        return array

    def proposal_distribution(d, sigma=sigma):
        new_prior = np.absolute(
            np.add(d.prior, np.random.normal(0, sigma, size=d.prior.shape)))
        new_prior /= np.sum(new_prior)

        while True:
            new_lk = np.add(
                d.likelihoods,
                np.random.normal(0, sigma, size=d.likelihoods.shape))
            new_lk = norm_probabilities(new_lk)
            if np.argwhere(np.sum(new_lk, axis=1) % 3 == 0).size == 0: break
        return design.design(pr=new_prior[:-1], lk=new_lk)

    def execute(niters):

        #assign new random seed
        if parallelize: np.random.seed()

        xt = np.empty((niters, n_particles), dtype=np.object)
        ut = np.zeros((niters, n_particles))
        wt = np.zeros((niters, n_particles))
        wt[0, :] = np.ones(n_particles) / n_particles

        for i in np.arange(n_particles):
            while True:
                xt[0, i] = design.design(
                    size=(ado.N_categories,
                          ado.N_features))  #first design is random
                ut[0, i] = ado.global_utility(xt[0, i])
                if not ut[0, i] == 0: break

        iterator = np.arange(start=1, stop=niters)
        # if ado.logging: iterator = tqdm.tqdm(iterator)

        #smc
        for t in iterator:
            xt_ = np.empty(n_particles, dtype=np.object)
            ut_ = np.zeros(n_particles)
            wt_ = np.zeros(n_particles)

            #time update
            for i in np.arange(n_particles):
                xt_[i] = proposal_distribution(xt[t - 1, i])  #random walk
                #measurement update
                ut_[i] = ado.global_utility(xt_[i])
                wt_[i] = wt[t - 1, i] * ut_[i]

            #resample
            idx = np.random.choice(a=n_particles,
                                   size=n_particles,
                                   p=wt_ / np.sum(wt_))
            xt[t, :] = xt_[idx]
            ut[t, :] = ut_[idx]
            wt[t, :] = np.ones(n_particles) / n_particles

        print(np.max(ut))

        # #mcmc
        # for i in iterator:
        # 	# j = J(i+1)
        # 	d_i = proposal_distribution(d) #random walk
        # 	u_i = ado.global_utility(d_i)
        # 	rho = min(1, u_i / u) #**j consider sim. annealing
        # 	if np.random.uniform() < rho:
        # 		naccept += 1 #number accepted
        # 		d = d_i
        # 		u = u_i
        # 		accepted_d.append(d)
        # 		accepted_u.append(u)

        ado.log('\t### SMC sampling finished! ###')
        idx_best_d = np.nanargmax(ut)
        return xt.flatten()[idx_best_d], ut.flatten()[idx_best_d]

    execute(n_iterations)

    d = design.design(size=(ado.N_categories, ado.N_features), alpha=alpha)
    return d, ado.global_utility(d)
def flow():
    design.design()
    data = pd.read_csv("file.csv", delimiter=",", na_values=['-'])
    date = data['Date']
    date = pd.to_datetime(date)

    data['Date'] = pd.to_datetime(data['Date'])
    data = data.sort_values(by=['Date'], ascending=[True])
    data.set_index('Date', inplace=True)
    data = data.resample('D').ffill().reset_index()

    data1 = data.drop_duplicates(subset=['Volume', 'Open', 'Close'],
                                 inplace=True)
    date1 = data['Date']
    opencost = data['Open']
    closecost = data['Close']

    timeGraph(opencost, date1, legend='Open Cost Trend')
    timeGraph(closecost, date1, legend='Close Cost Trend')
    test = np.array(range(val[0]))

    test = test.reshape(val[0], 1)

    indx.append(data.index[-1])

    opencost = (opencost[np.isfinite(opencost)])
    opencost = opencost[0:val[0]]
    opencost_pr = opencost.values.reshape(val[0],
                                          1)  # RESHAPPING TO SAME SHAPE

    global i
    global size
    if (i) == 1:
        try:
            size = float(
                input(
                    "\nPlease enter Percentage of training size between (1 - 99): "
                ))
        except:
            print("\n Wrong Entry! Try again")
            flow()

        if size not in range(1, 100):
            print("\nSorry Invalid Value please enter size between 0 to 100")
            flow()
        else:
            i += 1

    #TRAINING AND TESTING
    date_train, date_test, opencost_pr_train, opencost_pr_test = train_test_split(
        test, opencost_pr, random_state=1, train_size=(size) / 100)

    regr = linear_model.LinearRegression()

    regr.fit(date_train, opencost_pr_train)

    answer = input(
        "\n1. Check Cost Trend\n2. Regression Graph\n3. Predictor\n4. Calculate returns\n5. Go Back to previous menu\n6. Exit\n\n"
    ).upper()
    if answer == "1":
        plt.suptitle('Cost Trend')
        plt.show()

    elif answer == "2":
        plt.close()
        plt.scatter(test, opencost_pr, color='green')
        plt.plot(date_test, regr.predict(date_test), color='blue', linewidth=3)
        plt.xlabel('Months')
        plt.ylabel('Stock Price')
        plt.suptitle('Linear Regression')
        plt.xticks(())
        plt.yticks(())
        plt.show()

    elif answer == "3":

        design.design()
        date = enterdate()
        try:
            no_of_days = datecal(date)
        except:
            print("\nSorry Wrong Input Try Again")
            flow()
        value = (indx[0] + no_of_days)
        predict = prediction(regr, date_test, number=value)
        prediction_Model = regr.predict(date_test)

        if predict < 0:
            print("\n\nCompany Not Listed At that time")

        else:
            print("\nPredicted value at %s for selected company is $%f" %
                  (date, predict))
            # FOR R**2 value
            print("\nR Squared Value is : ",
                  metrics.r2_score(opencost_pr_test, prediction_Model))
            # Mean Square value
            print("\nMean Squared error Value is : ",
                  np.sqrt(((prediction_Model - opencost_pr_test)**2).mean()))

    elif answer == "4":
        try:
            roi(regr, date_test, closecost.iloc[-1])
        except:
            print("\n Oops Wrong Data Entry Retry")

    elif answer == "5":
        company_details.selectMenu()
    elif answer == "6":
        quitting()

    else:
        if input("Wrong Input! Press Any Key To Try Again or press 0 to exit: "
                 ) == "0":
            print("\n************** THANK YOU **************")
            sys.exit()

    flow()
Example #26
0
def optimize(ado, **kwargs):
    D = (ado.N_features + 1) * ado.N_categories - 1
    niters = kwargs.get('n_designs', 100)
    parallelize = kwargs.get('parallelize', True)
    sigma = kwargs.get('sigma', 0.4)
    alpha = kwargs.get('sigma', 1.0)
    ado.results.d_evaluated.append(niters)
    if parallelize: N_threads = kwargs.get('N_threads', 4)

    class MultiProcess(Process):
        def __init__(self, iterations):
            Process.__init__(self)
            self.iters = iterations
            self.queueD = Queue()
            self.queueU = Queue()

        def run(self):
            d, u = execute(niters=self.iters)
            self.queueD.put(d)
            self.queueU.put(u)

    def J(t):
        return int(t * 0.04) + 1

    def norm_probabilities(array):
        for index, _ in np.ndenumerate(array):
            array[index] = min(1.0, array[index])
            array[index] = max(0.0, array[index])
        return array

    def proposal_distribution(d, sigma=sigma):
        new_prior = np.absolute(
            np.add(d.prior, np.random.normal(0, sigma, size=d.prior.shape)))
        new_prior /= np.sum(new_prior)

        while True:
            new_lk = np.add(
                d.likelihoods,
                np.random.normal(0, sigma, size=d.likelihoods.shape))
            new_lk = norm_probabilities(new_lk)
            if np.argwhere(np.sum(new_lk, axis=1) % 3 == 0).size == 0: break
        return design.design(pr=new_prior[:-1], lk=new_lk)

    def execute(niters):

        #assign new random seed
        if parallelize: np.random.seed()

        naccept = 0
        samples = np.zeros((D, niters + 1))
        while True:
            d = design.design(size=(ado.N_categories,
                                    ado.N_features))  #first design is random
            u = ado.global_utility(d)
            if not u == 0: break
        accepted_u = []
        accepted_d = []

        iterator = range(niters)
        if ado.logging: iterator = tqdm.tqdm(iterator)

        for i in iterator:
            # j = J(i+1)
            d_i = proposal_distribution(d)  #random walk
            u_i = ado.global_utility(d_i)
            rho = min(1, u_i / u)  #**j consider sim. annealing
            if np.random.uniform() < rho:
                naccept += 1  #number accepted
                d = d_i
                u = u_i
                accepted_d.append(d)
                accepted_u.append(u)
        ado.log('\t### MCMC acceptance rate: %.2f ###' %
                float(1.0 * naccept / niters))
        idx_best_d = np.nanargmax(accepted_u)
        return accepted_d[idx_best_d], accepted_u[idx_best_d]

    if parallelize:
        iters = int(niters / N_threads)
        jobs = [MultiProcess(iterations=iters) for i in np.arange(N_threads)]
        for job in jobs:
            job.start()
        for job in jobs:
            job.join()
        D = [job.queueD.get() for job in jobs]
        U = [job.queueU.get() for job in jobs]

        try:
            idx_best_d = np.nanargmax(U)
        except Exception:
            d = design.design(size=(ado.N_categories, ado.N_features),
                              alpha=alpha)
            return d, ado.global_utility(d)
        else:
            return D[idx_best_d], U[idx_best_d]
    else:
        return execute(niters)
Example #27
0
def getinfo(x):
    companies = (companylist[(companylist == x).any(1)].stack())

    if len(companies) == 0:  # HANDLING ERROR
        print("Company Not Found :   *Please enter exact name or symbol* \n")
        value = input(
            "If you want to try more please enter Y or enter N to go back to previous menu: "
        )
        if value.upper() == "Y":
            getdetails("2")
        elif value.upper() == "N":
            design.design()
            mainmenu()
        else:
            print("\nWrong Choice !!!!!! Please retry")
            getdetails("2")

    elif len(companies) > 8:
        print(
            "\n Oops it does'nt look like a correct symbol - Looking For Anyone of these?"
        )
        design.design()
        print(companies[0:], "\n")
        design.design()
        if input(
                "\nif not in the list? Hit 0 to try again OR any key to continue: "
        ) == "0":
            main()
        else:
            np
        confirm = input("confirm the Company Symbol by entering : ").upper(
        )  #Upper to handle case sensitive execpts
        design.design()
        try:
            x = (np.where(companylist.Symbol == confirm))
            p = int(x[0])
            print(companylist.iloc[p][0:7])
            val = input(
                "To visit company's Nasdaq site press Y or to continue press any other key: "
            )
            if (val.upper() == "Y"):
                webbrowser.open(
                    companylist[7])  # To open the company link for more info
            company_details.getFile(confirm)
            main()
        except:
            print("\nInvalid Entry Try Again")
            getdetails("2")

    else:
        design.design()
        print((companies[0:7]), "\n")  #For memory quote in companies[8]
        val = input(
            "To visit company's Nasdaq site press Y or to continue press any other key: "
        ).upper()
        if (val == "Y"):
            print("opening url")
            webbrowser.open(
                companies[7])  # To open the company link for more info
        pih = 'PIH'
        if (x == pih):
            company_details.main(x)
        else:
            company_details.main(companies[0])
        design.design()