Example #1
0
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()
Example #2
0
def plotFrequency(series, sampRate):
    """ Plot a frequency to a graph """
    s = series / (2.**15)
    p, freqArray = _fastFourier(s, sampRate)
    np.plot(freqArray / 1000, 10 * pl.log10(p), color='k')
    np.xlabel('Frequency (kHz)')
    np.ylabel('Power (dB)')
    np.plt.show()
    return
Example #3
0
def simAll(drunkKinds, walkLengths, numTrials):
    styleChoice = styleIterator(('m-', 'b--', 'g-.'))
    for dClass in drunkKinds:
        curStyle = styleChoice.nextStyle()
        print('Starting simulation of', dClass.__name__)
        means = simDrunk(numTrials, dClass, walkLengths)
        numpy.plot(walkLengths, means, curStyle, label=dClass.__name__)
    numpy.title('Mean Distance from Origin (' + str(numTrials) + ' trials)')
    numpy.xlabel('Number of Steps')
    numpy.ylabel('Distance from Origin')
    numpy.legend(loc='best')
Example #4
0
def plotTone(series, sampRate):
    """ Plot a tone to a graph """
    # Convert sound array to floating point between -1 to 1
    snd = series / (2.**15)
    timeArray = pl.arange(0, snd.shape[0])
    timeArray = timeArray / sampRate
    timeArray = timeArray * 1000  # scales to milliseconds
    # Plot the tone graph
    np.plot(timeArray, snd, color='k')
    np.ylabel('Amplitude')
    np.xlabel('Time (ms)')
    np.plt.show()
    return
Example #5
0
def traceWalk(fieldKinds, numSteps):
    styleChoice = styleIterator(('b+', 'r^', 'ko'))
    for fClass in fieldKinds:
        d = UsualDrunk()
        f = fClass()
        f.addDrunk(d, Location(0, 0))
        locs = []
        for s in range(numSteps):
            f.moveDrunk(d)
            locs.append(f.getLoc(d))
        xVals, yVals = [], []
        for loc in locs:
            xVals.append(loc.getX())
            yVals.append(loc.getY())
        curStyle = styleChoice.nextStyle()
        numpy.plot(xVals, yVals, curStyle, label=fClass.__name__)
    numpy.title('Spots Visited on Walk (' + str(numSteps) + ' steps)')
    numpy.xlabel('Steps East/West of Origin')
    numpy.ylabel('Steps North/South of Origin')
    numpy.legend(loc='best')
Example #6
0
def plotLocs(drunkKinds, numSteps, numTrials):
    styleChoice = styleIterator(('k+', 'r^', 'mo'))
    for dClass in drunkKinds:
        locs = getFinalLocs(numSteps, numTrials, dClass)
        xVals, yVals = [], []
        for loc in locs:
            xVals.append(loc.getX())
            yVals.append(loc.getY())
        xVals = numpy.array(xVals)
        yVals = numpy.array(yVals)
        meanX = sum(abs(xVals)) / len(xVals)
        meanY = sum(abs(yVals)) / len(yVals)
        curStyle = styleChoice.nextStyle()
        numpy.plot(xVals, yVals, curStyle,
                      label = dClass.__name__ +\
                      ' mean abs dist = <'
                      + str(meanX) + ', ' + str(meanY) + '>')
    numpy.title('Location at End of Walks (' + str(numSteps) + ' steps)')
    numpy.ylim(-1000, 1000)
    numpy.xlim(-1000, 1000)
    numpy.xlabel('Steps East/West of Origin')
    numpy.ylabel('Steps North/South of Origin')
    numpy.legend(loc='lower center')
Example #7
0
# #plt.title('Accuracy for different Momentum for CNN')
# plt.ylabel('Error')
# #plt.ylabel('Accuracy')
# plt.xlabel('Momentum')
# plt.show()

# #For Batch Size
# plt.xticks([1 ,2, 3, 4, 5],['1','10','100','500','1000'])
# plt.plot([1 ,2, 3, 4, 5],[1.88155 ,1.25564 ,0.43665 ,1.11511 ,3.02981 ], 'bo', label='Training')
# plt.plot([1 ,2, 3, 4, 5],[1.88067 ,1.71583 ,0.63323 ,1.07845 ,2.84858 ], 'go', label='Validation')
# plt.axis([0, 5.5, 0.0, 3.2])
# plt.legend(loc=0)
# plt.title('Cross-Entropy for different batch sizes for CNN')
# #plt.title('Accuracy for different batch sizes for CNN')
# plt.ylabel('Error')
# #plt.ylabel('Accuracy')
# plt.xlabel('Batch Size')
# plt.show()

#For 3.3
plt.xticks([1, 2, 3], ['[2 16]', '[15 16]', '[30 16]'])
plt.plot([1, 2, 3], [0.28542, 0.74748, 0.28542], 'bo', label='Training')
plt.plot([1, 2, 3], [0.27924, 0.70883, 0.27924], 'go', label='Validation')
plt.axis([0.5, 3.5, 0, 0.8])
plt.legend(loc=0)
#plt.title('Cross-Entropy for different number of filters in the first layer of CNN')
plt.title('Accuracy for different number of filters in the first layer of CNN')
#plt.ylabel('Error')
plt.ylabel('Accuracy')
plt.xlabel('Number of Units')
plt.show()
Example #8
0
        means.append(vals / float(numDice))
    numpy.hist(means,
               numBins,
               color=color,
               label=legend,
               weights=[1 / len(means)] * len(means),
               hatch=style)
    return getMeanAndStd(means)


mean, std = plotMeans(1, 1000000, 19, '1 die', 'b', '')
print('Mean of rolling 1 die =', str(mean) + ',', 'Std =', std)
mean, std = plotMeans(50, 1000000, 19, 'Mean of 50 dice', 'r', '')
print('Mean of rolling 50 dice =', str(mean) + ',', 'Std =', std)
numpy.title('Rolling Continuous Dice')
numpy.xlabel('Value')
numpy.ylabel('Probability')
numpy.legend()

##Test CLT
# numTrials = 100000
# numSpins = 2000
# game = FairRoulette()

# means = []
# for i in range(numTrials):
#    means.append(findPocketReturn(game, 1, numSpins,
#                                  False)[0])

# numpy.hist(means, bins = 19,
#           weights = [1/len(means)]*len(means))
Example #9
0
def makeHist(data, title, xlabel, ylabel, bins=20):
    numpy.hist(data, bins=bins)
    numpy.title(title)
    numpy.xlabel(xlabel)
    numpy.ylabel(ylabel)
Example #10
0
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()
Example #11
0
            for count in np.mslice[1:C]:
                code_sent = Codewords(count, np.mslice[:]).T
                F = symbols_est(np.mslice[(sub_block - 1) * n + 1:sub_block * n], fr)
                H = fading_coeffs(np.mslice[(sub_block - 1) * n + 1:sub_block * n], fr)
                # Detect_output(count,1) =  sum(abs(F - code_sent.*H).^2); %if no equalization (only for OFDM)
                Detect_output(count, 1).lvalue = sum(abs(F - code_sent) ** np.elpow ** 2)
            # end
            # Determine Data_sent from minimum
            Minimum = min(Detect_output)
        # end
    # end
    # % Demapping
    Data_out_reshape = np.reshape(Data_out, np.mcat([]), 1)
    symbols_estimated = np.reshape(Codewords(Data_out_reshape, np.mslice[:]).T, np.mcat([]), Frames)
    OutputBinaryp = CodewordsIntoBits(symbols_estimated, M, n, k, g, Frames)
    OutputBinary = np.reshape(OutputBinaryp, 1, np.mcat([]))
    # % BER Calculation
    Nbre_error = np.length(np.find(np.reshape(InputBinaryS, 1, np.mcat([])) - OutputBinary != 0))  # Number of errors
    ber(j).lvalue = Nbre_error / (Frames * m)  # number of errors per number of total bit
# end SNR

# %% BER Plot
np.semilogy(EbNo_dB, ber, np.mstring('d-b'), np.mstring('linewidth'), 2)
np.hold(np.mstring('on'))
np.grid(np.mstring('on'))
np.hold(np.mstring('on'))
np.xlim(np.mcat([0, 25]))
np.ylim(np.mcat([1e-6, 1]))
np.xlabel(np.mstring('Eb/N0 in dB'))
np.ylabel(np.mstring('BER'))
Example #12
0
# In[44]: Soal1

import pandas as choi  #melakukan import pada library pandas sebagai arjun

laptop = {
    "Nama Laptop": ['Asus', 'ROG', 'Lenovo', 'Samsung']
}  #membuat varibel yang bernama laptop, dan mengisi dataframe nama2 laptop
x = Arjun.DataFrame(
    laptop
)  #variabel x membuat DataFrame dari library pandas dan akan memanggil variabel laptop.
print(' Arjun Punya Laptop ' + x)  #print hasil dari x

# In[44]: Soal2

import numpy as Arjun  #melakukan import numpy sebagai arjun

matrix_x = Arjun.eye(
    10)  #membuat matrix dengan numpy dengan menggunakan fungsi eye
matrix_x  #deklrasikan matrix_x yang telah dibuat

print(matrix_x)  #print matrix_x yang telah dibuat dengan 10x10

# In[44]: Soal3

import matplotlib.pyplot as Arjun  #import matploblib sebagai arjun

Arjun.plot([1, 1, 7, 4, 0, 2,
            1])  #memberikan nilai plot atau grafik pada arjun
Arjun.xlabel('Arjun Yuda Firwanda')  #memberikan label pada x
Arjun.ylabel('1174008')  #memberikan label pada y
Arjun.show()  #print hasil plot berbentuk grafik
from pylab import plot,show
x=[]
y=[]
for i in range(10):
    y.append(i*i)
    x.append(2*i)
plot(x,y)
show()

from numpy import linspace,xlabel, sin
x=linspace(0,10,100)
y=sin
plot(x,y)
xlabel("Radians")
show()
xlabel("Radians")a=open("test.data","w")
for i in range(len(x)):
    a.write("%.2f %.2f\n"%(x[i],y[i]))
a.close()

from numpy import loadtxt
a=loadtxt("test.dat",float)
print(a[:,0])
print(a[:,1])   
plot((a[:,0]),(a[:,1]))