Exemple #1
0
    def create_policy(self):
        costs_to_go = {}
        for s in range(self.depot.Q + 1):
            costs_to_go[self.depot.T + 1, s] = 0

        policy = {}
        for t in range(self.depot.T, 0, -1):

            demand = int(average(self.depot.demands[t]))
            for s in range(self.depot.Q + 1):

                min_ = float('inf')
                decision = None
                new_state = None
                for x in range(self.depot.Q - s + 1):
                    s_next = self.depot.transition(s + x, demand)
                    cost = self.depot.inmediate_cost(s, x, demand)
                    cost += costs_to_go[t + 1, s_next]

                    if cost < min_:
                        decision = x
                        min_ = cost

                policy[t, s] = decision
                costs_to_go[t, s] = min_
        return policy
def main():
    # this function is complete, DO NOT MODIFY IT
    # you may modify it while you program, but when you turn in for grading
    # it must be returned to EXACTLY this state
    
    # never use literals in your code. always make constants and use them instead
    # note these are capitalized to denote they are constants
    MINR = 10
    MAXR = 30
    MINARRAYSIZE = 1
    MAXARRAYSIZE = 10
    
    # this will make a random number from MINARRAYSIZE to MAXARRAYSIZE
    size = rnd.randint(MINARRAYSIZE, MAXARRAYSIZE)

    # this will create and initialize an array of size length
    # with random ints from MIN to MAX (inclusive)
    numbers = fn.make_array(size, MINR, MAXR)
    
    # show the array
    print("Array is size",size)
    print("All the numbers...")
    print(numbers)
    print()
    
    print("The minimum is:", fn.minimum(numbers))
    print("The maximum is:", fn.maximum(numbers))
    print("The total is:", fn.total(numbers))
    print("The average is:", fn.average(numbers))
    print()

    # this will reverse the array
    rnumbers = fn.reverse_array(numbers)

    # show the array
    print("All the numbers...")
    print(numbers)
    print(rnumbers)
    print()

    # the code here will not work until reverse_array() is complete
    # you may want to comment out these lines until you are ready for them
    print("The minimum is:", fn.minimum(rnumbers))
    print("The maximum is:", fn.maximum(rnumbers))
    print("The total is:", fn.total(rnumbers))
    print("The average is:", fn.average(rnumbers))
    print()
Exemple #3
0
        print(f"Average:            \n{functions.average(dataset)}")
        _modus = functions.modus(dataset)
        print(f"Modus:              \n{_modus[0]}: {_modus[1]} time(s)")
        print(f"Median:             \n{functions.median(sortedData)}")
        print(f"Standard deviaton:  \n{functions.standardDeviation(dataset)}")

        # Show histogram with confindence interval
        fig, ax = plt.subplots()

        binwidth = (max(dataset) - min(dataset)) / 40

        plt.hist(dataset,
                 bins=np.arange(min(dataset),
                                max(dataset) + binwidth, binwidth))

        avg = functions.average(dataset)
        plt.axvline(x=avg, color='red')

        for value in functions.confidenceInterval(dataset):
            plt.axvline(x=value, color='green', linestyle=':')

        plt.ylabel('Count')
        plt.xlabel('Value')
        plt.title(re.sub(r"(\w)([A-Z])", r"\1 \2", header).split('_')[0])
        plt.show()

        # Show graph with all data and trend line
        x, y, b = functions.linearRegression(dataset)
        fig, ax = plt.subplots()
        # plot points
        plt.scatter(x, y, color="m", marker="o", s=10)
 def test_average(self):
     self.assertEqual(average(2, 4), 3)
        print fname
        data, head = f.f_open(fname)
        epac_c = head.index('Epac1cAMP')
        epaccamps = data[:, epac_c]

        time = data[:, 0]
        dt = time[1] - time[0]
        #cs = (1-beta)*epac + epaccamps
        #ys = beta*epac+gamma*(epac+epaccamps)+cs*delta

        #r = cs/ys
        r = epaccamps

        n = 30

        r = f.average(r, n=n)

        time_ = np.linspace(time[0], time[-1], len(r)) / 1000. - 250

        new_dt = time_[1] - time_[0]
        base = r[150 / new_dt:250 / new_dt].mean()
        print new_dt
        res = (r - base) / base * 100
        if i < 4:
            ax2.plot(time_, res, label=labels[i], lw=1, color=colors[i])
        else:
            ax2.plot(time_, res, label=labels[i], lw=2, color=colors[i])

        # else:
        #     ax2.plot(time_,res,label='simplified model',lw=1)
    ax2.set_xlabel('time (s)', fontsize=10)