def setupDebug(self):
        node = BulletDebugNode("Debug")
        node.showWireframe(True)

        self.world.setDebugNode(node)

        np = self.render.attachNewNode(node)
        np.show()
def pngs_equal(a, b):
    if files_equal(a, b):
        print a, 'and', b, 'are perfectly equal'
        return True
    im_a = numpy.imread(a) * 255.0
    im_b = numpy.imread(b) * 255.0
    if im_a.shape != im_b.shape:
        print a, 'and', b, 'have different size:', im_a.shape, im_b.shape
        return False
    diff = im_b - im_a
    alpha = im_a.shape[-1] == 4
    if alpha:
        diff_alpha = diff[:, :, 3]

    equal = True
    print a, 'and', b, 'are different, analyzing whether it is just the undefined colors...'
    print 'Average difference (255=white): (R, G, B, A)'
    print numpy.mean(numpy.mean(diff, 0), 0)
    print 'Average difference with premultiplied alpha (255=white): (R, G, B, A)'
    diff = diff[:, :, 0:3]
    if alpha:
        diff *= numpy.imread(a)[:, :, 3:4]
    res = numpy.mean(numpy.mean(diff, 0), 0)
    print res
    if numpy.mean(res) > 0.01:
        # dithering should make this value nearly zero...
        equal = False
    print 'Maximum abs difference with premultiplied alpha (255=white): (R, G, B, A)'
    res = numpy.amax(numpy.amax(abs(diff), 0), 0)
    print res
    if max(abs(res)) > 1.1:
        # this error will be visible
        # - smaller errors are hidden by the weak alpha
        #   (but we should pay attention not to accumulate such errors at each load/save cycle...)
        equal = False

    if not equal:
        print 'Not equal enough!'
        if alpha:
            numpy.figure(1)
            numpy.title('Alpha')
            numpy.imshow(im_b[:, :, 3], interpolation='nearest')
            numpy.colorbar()
        numpy.figure(2)
        numpy.title('Green Error (multiplied with alpha)')
        numpy.imshow(diff[:, :, 1], interpolation='nearest')
        numpy.colorbar()
        if alpha:
            numpy.figure(3)
            numpy.title('Alpha Error')
            numpy.imshow(diff_alpha, interpolation='nearest')
            numpy.colorbar()
        numpy.show()

    return equal
Exemple #3
0
def pngs_equal(a, b):
    if files_equal(a, b):
        print a, 'and', b, 'are perfectly equal'
        return True
    im_a = numpy.imread(a)*255.0
    im_b = numpy.imread(b)*255.0
    if im_a.shape != im_b.shape:
        print a, 'and', b, 'have different size:', im_a.shape, im_b.shape
        return False
    diff = im_b - im_a
    alpha = im_a.shape[-1] == 4
    if alpha:
        diff_alpha = diff[:, :, 3]

    equal = True
    print a, 'and', b, 'are different, analyzing whether it is just the undefined colors...'
    print 'Average difference (255=white): (R, G, B, A)'
    print numpy.mean(numpy.mean(diff, 0), 0)
    print 'Average difference with premultiplied alpha (255=white): (R, G, B, A)'
    diff = diff[:, :, 0:3]
    if alpha:
        diff *= numpy.imread(a)[:, :, 3:4]
    res = numpy.mean(numpy.mean(diff, 0), 0)
    print res
    if numpy.mean(res) > 0.01:
        # dithering should make this value nearly zero...
        equal = False
    print 'Maximum abs difference with premultiplied alpha (255=white): (R, G, B, A)'
    res = numpy.amax(numpy.amax(abs(diff), 0), 0)
    print res
    if max(abs(res)) > 1.1:
        # this error will be visible
        # - smaller errors are hidden by the weak alpha
        #   (but we should pay attention not to accumulate such errors at each load/save cycle...)
        equal = False

    if not equal:
        print 'Not equal enough!'
        if alpha:
            numpy.figure(1)
            numpy.title('Alpha')
            numpy.imshow(im_b[:, :, 3], interpolation='nearest')
            numpy.colorbar()
        numpy.figure(2)
        numpy.title('Green Error (multiplied with alpha)')
        numpy.imshow(diff[:, :, 1], interpolation='nearest')
        numpy.colorbar()
        if alpha:
            numpy.figure(3)
            numpy.title('Alpha Error')
            numpy.imshow(diff_alpha, interpolation='nearest')
            numpy.colorbar()
        numpy.show()

    return equal
Exemple #4
0
def adaptIntPlot(f,a,b):
    """
    Adaptive (doubling partition) integration.
    Minimizes function evaluations at the expense of some tedious
    array minipulations.
    """
    maxiter = 20
    miniter = 5
    tolerance = 0.1
    maxnx = 2**maxiter
    minnx = 2**miniter
    x = 0.*N.zeros(maxnx)
    
    dx = (b-a)/2.#**minsteps
    nx = 2
    x[0] = a
    x[1] = a+dx
    integral = N.sum(f(x[1:2]))*dx # 1 so we don't include the first endpt
    dx /= 2.
    newintegral = integral/2. + N.sum(f(x[:nx]+dx))*dx
    for i in range(nx-1,-1,-1):
        x[2*i] = x[i]
        x[2*i+1] = x[i] + dx
    nx *= 2
    keepgoing = 1
    while keepgoing == 1:
        integral = newintegral
        dx /= 2.
        eff = f(x[:nx]+dx)
        N.plot(x[:nx]+dx,f(x[:nx]+dx))
        newintegral = integral/2. + N.sum(eff)*dx#N.sum(f(x[:nx]+dx))*dx
        print newintegral*nx/(nx-1)
        for i in range(nx-1,-1,-1):
            x[2*i] = x[i]
            x[2*i+1] = x[i] + dx
        nx *= 2
        keepgoing = 0
        if integral*newintegral > 0.:
            if ((N.fabs(N.log(integral*(nx/2)/(nx/2-1)/(newintegral*nx/(nx-1)))) >\
                 tolerance) and (nx < maxnx/2)) or (nx < minnx):
                keepgoing = 1
        elif integral*newintegral == 0.:
            print "Hmmm, we have a zero integral here.  Assuming convergence."
        else:
            keepgoing = 1
    
    N.show()
    print nx,
    if nx == maxnx/2:
        print 'No convergence in utils.adaptInt!'
    return newintegral*nx/(nx-1)
    def showRoomLayout(self,
                       showCeilings=True,
                       showWalls=True,
                       showFloors=True):

        for np in self.scene.scene.findAllMatches(
                '**/layouts/**/render-semantics/*c'):
            if showCeilings:
                np.show()
            else:
                np.hide()

        for np in self.scene.scene.findAllMatches(
                '**/layouts/**/render-semantics/*w'):
            if showWalls:
                np.show()
            else:
                np.hide()

        for np in self.scene.scene.findAllMatches(
                '**/layouts/**/render-semantics/*f'):
            if showFloors:
                np.show()
            else:
                np.hide()
Exemple #6
0
    def showRoomLayout(self, showCeilings=True, showWalls=True, showFloors=True):

        for np in self.scene.scene.findAllMatches('**/layouts/**/render/*c'):
            if showCeilings:
                np.show(self.cameraMask)
            else:
                np.hide(BitMask32.allOn())

        for np in self.scene.scene.findAllMatches('**/layouts/**/render/*w'):
            if showWalls:
                np.show(self.cameraMask)
            else:
                np.hide(BitMask32.allOn())

        for np in self.scene.scene.findAllMatches('**/layouts/**/render/*f'):
            if showFloors:
                np.show(self.cameraMask)
            else:
                np.hide(BitMask32.allOn())
Exemple #7
0
# 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()
Exemple #8
0
    factor1 = (1.0 / (sigma * ((2 * numpy.pi)**0.5)))
    factor2 = numpy.e**-(((x - mu)**2) / (2 * sigma**2))
    return factor1 * factor2


xVals, yVals = [], []
mu, sigma = 0, 2.5
x = -10
while x <= 10:
    xVals.append(x)
    yVals.append(gaussian(x, mu, sigma))
    x += 0.05
numpy.plot(xVals, yVals)
numpy.title('Normal Distribution, mu = ' + str(mu)\
           + ', sigma = ' + str(sigma))
numpy.show()

# import scipy.integrate

# def checkEmpirical(numTrials):
#   for t in range(numTrials):
#      mu = random.randint(-10, 10)
#      sigma = random.randint(1, 10)
#      print('For mu =', mu, 'and sigma =', sigma)
#      for numStd in (1, 1.96, 3):
#         area = scipy.integrate.quad(gaussian,
#                                     mu-numStd*sigma,
#                                     mu+numStd*sigma,
#                                     (mu, sigma))[0]
#         print(' Fraction within', numStd,
#               'std =', round(area, 4))
import csv
import numpy as ___
import _________ as plt
from mpl_toolkits.mplot3d import Axes3D

g = open("../galaxygas.csv","___")
gasfile = csv.reader(g)

x=[]
y=[]
z=[]
temp=[]
density =[]

for row in gasfile:
    x.append(_____(row[0]))
    y.append(float(row[1]))
    z.______(float(row[2]))
    temp.append(np.log10(float(row[3])))
    density.append(np.log10(float(row[4])))

g.close()

cm = plt.get_cmap("nipy_spectral")
fig = plt.figure()
ax = fig.__________(111,projection="3d")
image = ax.scatter(x,y,z,c=temp,vmin=3,vmax=7,s=10,cmap=cm)
bar = plt.colorbar(image)
bar.set_label("Log Gas Temperature (K)")
___.show()
Exemple #10
0
import numpy as np 
import matplotlib as mpl 

x = np.linspace(0, 1, 100)
y = np.sin(x)
np.plot(x, y)
np.show()
import csv
import numpy as ___
import _________ as plt
from mpl_toolkits.mplot3d import Axes3D

g = open("../galaxygas.csv", "___")
gasfile = csv.reader(g)

x = []
y = []
z = []
temp = []
density = []

for row in gasfile:
    x.append(_____(row[0]))
    y.append(float(row[1]))
    z.______(float(row[2]))
    temp.append(np.log10(float(row[3])))
    density.append(np.log10(float(row[4])))

g.close()

cm = plt.get_cmap("nipy_spectral")
fig = plt.figure()
ax = fig.__________(111, projection="3d")
image = ax.scatter(x, y, z, c=temp, vmin=3, vmax=7, s=10, cmap=cm)
bar = plt.colorbar(image)
bar.set_label("Log Gas Temperature (K)")
___.show()
Exemple #12
0
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
 def __mesh_colour_callback(self, dc: DynamicColour, np: NodePath) -> None:
     if dc.visible:
         np.show()
     else:
         np.hide()
     np.set_color(LVecBase4f(*dc()), 1)