예제 #1
0
파일: lect8.py 프로젝트: asdhamidi/6.0002
def plotDiffs(sampleSizes, diffs, title, label, color = 'b'):
    numpy.plot(sampleSizes, diffs, label = label,
               color = color)
    numpy.xlabel('Sample Size')
    numpy.ylabel('% Difference in SD')
    numpy.title(title)
    numpy.legend()
예제 #2
0
def testFits(models, degrees, xVals, yVals, title):
    numpy.plot(xVals, yVals, 'o', label='Data')
    for i in range(len(models)):
        estYVals = numpy.polyval(models[i], xVals)
        error = rSquared(yVals, estYVals)
        numpy.plot(xVals, estYVals,
                   label = 'Fit of degree '\
                   + str(degrees[i])\
                   + ', R2 = ' + str(round(error, 5)))
    numpy.legend(loc='best')
    numpy.title(title)
예제 #3
0
def fitData1(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals * 9.81  #get force
    numpy.plot(xVals, yVals, 'bo', label='Measured points')
    labelPlot()
    model = numpy.polyfit(xVals, yVals, 1)
    estYVals = numpy.polyval(model, xVals)
    numpy.plot(xVals,
               estYVals,
               'r',
               label='Linear fit, k = ' + str(round(1 / model[0], 5)))
    numpy.legend(loc='best')
예제 #4
0
def fitData(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals * 9.81  #get force
    numpy.plot(xVals, yVals, 'bo', label='Measured points')
    labelPlot()
    a, b = numpy.polyfit(xVals, yVals, 1)
    estYVals = a * numpy.array(xVals) + b
    print('a =', a, 'b =', b)
    numpy.plot(xVals,
               estYVals,
               'r',
               label='Linear fit, k = ' + str(round(1 / a, 5)))
    numpy.legend(loc='best')
예제 #5
0
def fitData(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals*9.81 #get force
    numpy.plot(xVals, yVals, 'bo',
               label = 'Measured points')                 
    model = numpy.polyfit(xVals, yVals, 1)
    xVals = xVals + [2]
    yVals = yVals + []
    estYVals = numpy.polyval(model, xVals)
    numpy.plot(xVals, estYVals, 'r',
               label = 'Linear fit, r**2 = '
               + str(round(rSquared(yVals, estYVals), 5)))                
    model = numpy.polyfit(xVals, yVals, 2)
    estYVals = numpy.polyval(model, xVals)
    numpy.plot(xVals, estYVals, 'g--',
               label = 'Quadratic fit, r**2 = '
               + str(round(rSquared(yVals, estYVals), 5)))
    numpy.title('A Linear Spring')
    labelPlot()
    numpy.legend(loc = 'best')
예제 #6
0
def show_plot_compare_strategies(title, x_label, y_label):
    """
    Produces a plot comparing the two robot strategies in a 20x20 room with 80%
    minimum coverage.
    """
    num_robot_range = range(1, 11)
    times1 = []
    times2 = []
    for num_robots in num_robot_range:
        print("Plotting", num_robots, "robots...")
        times1.append(
            run_simulation(num_robots, 1.0, 1, 20, 20, 3, 0.8, 20,
                           StandardRobot))
        times2.append(
            run_simulation(num_robots, 1.0, 1, 20, 20, 3, 0.8, 20,
                           FaultyRobot))
    numpy.plot(num_robot_range, times1)
    numpy.plot(num_robot_range, times2)
    numpy.title(title)
    numpy.legend(('StandardRobot', 'FaultyRobot'))
    numpy.xlabel(x_label)
    numpy.ylabel(y_label)
    numpy.show()
예제 #7
0
def show_plot_room_shape(title, x_label, y_label):
    """
    Produces a plot showing dependence of cleaning time on room shape.
    """
    aspect_ratios = []
    times1 = []
    times2 = []
    for width in [10, 20, 25, 50]:
        height = 300 / width
        print("Plotting cleaning time for a room of width:", width,
              "by height:", height)
        aspect_ratios.append(float(width) / height)
        times1.append(
            run_simulation(2, 1.0, 1, width, height, 3, 0.8, 200,
                           StandardRobot))
        times2.append(
            run_simulation(2, 1.0, 1, width, height, 3, 0.8, 200, FaultyRobot))
    numpy.plot(aspect_ratios, times1)
    numpy.plot(aspect_ratios, times2)
    numpy.title(title)
    numpy.legend(('StandardRobot', 'FaultyRobot'))
    numpy.xlabel(x_label)
    numpy.ylabel(y_label)
    numpy.show()
예제 #8
0
def make_two_curve_plot(x_coords, y_coords1, y_coords2, y_name1, y_name2,
                        x_label, y_label, title):
    """
    Makes a plot with two curves on it, based on the x coordinates with each of
    the set of y coordinates provided.

    Args:
        x_coords (list of floats): the x coordinates to graph
        y_coords1 (list of floats): the first set of y coordinates to graph
        y_coords2 (list of floats): the second set of y-coordinates to graph
        y_name1 (str): name describing the first y-coordinates line
        y_name2 (str): name describing the second y-coordinates line
        x_label (str): label for the x-axis
        y_label (str): label for the y-axis
        title (str): the title of the graph
    """
    pl.figure()
    pl.plot(x_coords, y_coords1, label=y_name1)
    pl.plot(x_coords, y_coords2, label=y_name2)
    pl.legend()
    pl.xlabel(x_label)
    pl.ylabel(y_label)
    pl.title(title)
    pl.show()
예제 #9
0
파일: lect8.py 프로젝트: asdhamidi/6.0002
def showErrorBars(population, sizes, numTrials):
    xVals = []
    sizeMeans, sizeSDs = [], []
    for sampleSize in sizes:
        xVals.append(sampleSize)
        trialMeans = []
        for t in range(numTrials):
            sample = random.sample(population, sampleSize)
            popMean, sampleMean, popSD, sampleSD =\
               getMeansAndSDs(population, sample)
            trialMeans.append(sampleMean)
        sizeMeans.append(sum(trialMeans)/len(trialMeans))
        sizeSDs.append(numpy.std(trialMeans))
    print(sizeSDs)
    numpy.errorbar(xVals, sizeMeans,
                   yerr = 1.96*numpy.array(sizeSDs), fmt = 'o',
                   label = '95% Confidence Interval')
    numpy.title('Mean Temperature ('
                + str(numTrials) + ' trials)')
    numpy.xlabel('Sample Size')
    numpy.ylabel('Mean')
    numpy.axhline(y = popMean, color ='r', label = 'Population Mean')
    numpy.xlim(0, sizes[-1] + 10)
    numpy.legend()
예제 #10
0
파일: lect8.py 프로젝트: asdhamidi/6.0002
sems = []
sampleSDs = []
for size in sampleSizes:
   sems.append(sem(popSD, size))
   means = []
   for t in range(numTrials):
       sample = random.sample(population, size)
       means.append(sum(sample)/len(sample))
   sampleSDs.append(numpy.std(means))
numpy.plot(sampleSizes, sampleSDs,
          label = 'Std of ' + str(numTrials) + ' means')
numpy.plot(sampleSizes, sems, 'r--', label = 'SEM')
numpy.xlabel('Sample Size')
numpy.ylabel('Std and SEM')
numpy.title('SD for ' + str(numTrials) + ' Means and SEM')
numpy.legend()


def plotDistributions():
    uniform, normal, exp = [], [], []
    for i in range(100000):
        uniform.append(random.random())
        normal.append(random.gauss(0, 1))
        exp.append(random.expovariate(0.5))
    makeHist(uniform, 'Uniform', 'Value', 'Frequency')
    numpy.figure()
    makeHist(normal, 'Gaussian', 'Value', 'Frequency')
    numpy.figure()
    numpy.show()
    makeHist(exp, 'Exponential', 'Value', 'Frequency')