Example #1
0
def read():
    dataset_folder = "dataset/"
    class_labels = {"Neutral": 0, "Angry": 2, "Happy": 3, "sad": 1}
    for i, directory in enumerate(class_labels):
        print("started reading folders", directory)
        os.chdir(directory)
        for filename in os.listdir('.'):
            fs, signal = read_wav(filename)
            signal = enframe(signal, 10, 1)
            mfcc = speechpy.feature.mfcc(signal, fs, num_cepstral=mfcc_len)
            x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(
                dataset_folder, class_labels)
            print(type(fs))
    return numpy.array(x_train), numpy.array(x_test), numpy(y_train), numpy(
        y_test)
Example #2
0
 def _uf(x,
         y,
         numpy=getattr(_numpy, ufunc),
         math=getattr(_math, ufunc),
         mathtypes=(float, int, int)):
     if type(x) in mathtypes and type(y) in mathtypes: return math(x, y)
     return numpy(x, y)
Example #3
0
case = pylon.Case.load("../data/case6ww.pkl")
case.generators[0].p_cost = (0.0, 16.0, 200.0)
case.generators[1].p_cost = (0.0, 2.0, 200.0)
case.generators[2].p_cost = (0.0, 32.0, 200.0)
case.buses[3].p_demand = 120.0
case.buses[4].p_demand = 120.0
case.buses[5].p_demand = 120.0
#plotGenCost(case.generators)

# Assume initial demand is peak demand (for sensor limits) and save it.
Pd0 = [b.p_demand for b in case.buses if b.type == pylon.PQ]

# Define a 24-hour load profile with hourly values.
p1h = numpy([
    0.52, 0.54, 0.52, 0.50, 0.52, 0.57, 0.60, 0.71, 0.89, 0.85, 0.88, 0.94,
    0.90, 0.88, 0.88, 0.82, 0.80, 0.78, 0.76, 0.68, 0.68, 0.68, 0.65, 0.58
])
#p1h = p1h[6:-6]
p1h = p1h[:12]
nf = len(p1h)

# Create a case environment specifying the load profile.
env = pyreto.CaseEnvironment(case, p1h)

# Create an episodic cost minimisation task.
task = pyreto.MinimiseCostTask(env)

# Create a network for approximating the agent's policy function that maps
# system demand to generator set-points..
nb = len([bus for bus in case.buses if bus.type == pylon.PQ])
ng = len([g for g in case.online_generators if g.bus.type != pylon.REFERENCE])
Example #4
0
"""
Converts a tile set from bmp to png for use with the Mac OS X frontend.

Usage
    python osx_bmp2png.py input_file output_file [options]

Options
--tcoord hcoord vcoord
    Reads the color to be treated as transparent for non-terrain tiles
    from the position (hcoord, vcoord) in the tile set.  Both coordinates
    are non-negative integers indexed from zero.  Is overridden by
    --transparent if that option is set.  When not set, the default is to
    read the color to be treated as transparent from (0,0).

--terrain lx1 ly1 ux1 uy1 ...
    Sets bounding boxes for parts of the tile set that are to be treated
    as completely opaque (i.e. as background terrain).  Each bound box is
    given by the coordinates for the lower corner, (lx,ly), and upper
    corner, (ux,uy), with ux > lx and uy > ly.  If not set, the default
    is to use two bounding boxes, (0,0) to (496,16) and (192,192) to
    (224,208), which are the terrain tiles in Michrochasm's tile set.

--transparent red green blue
    Sets the color, as RGB values between 0 and 255, which will be treated
    as completely transparent for non-terrain tiles.  If not set, uses
    --tcoord or its default to get the color.

Example
This is the conversion that was used to ready Microchasm's tile set for
the OS X front end:
Example #5
0
def _dot(x,y = (float,float)):
    numpy = getattr(_numpy,'dot')
    cv = getattr(_cvisual,'dot')
    if type(x) is vector and type(y) is vector: return cv(x,y)
    return numpy(x,y) # arrays rather than Visual vectors
Example #6
0
 def _uf(x,y,
         numpy = getattr(_numpy,ufunc),
         math = getattr(_math,ufunc),
         mathtypes = (float,int,int)):
     if type(x) in mathtypes and type(y) in mathtypes: return math(x,y)
     return numpy(x,y)
Example #7
0
######################################### NumPy #########################################
D:\Python34\plugins\numpy>python -m pip install --upgrade pip #升级pip
D:\Python34\plugins\numpy>pip install numpy-1.11.2+mkl-cp34-cp34m-win32.whl #安装numpy
D:\Python34\plugins\numpy>pip list #查看pip已安装的所有插件
	beautifulsoup4 (4.4.1)
	Django (1.8.6)
	numpy (1.11.2+mkl)
	objgraph (2.0.1)
	Pillow (3.0.0)
	pip (8.1.2)
	PyMySQL (0.6.7)
	queuelib (1.4.2)
	requests (2.8.1)
	setuptools (12.0.5)
	six (1.10.0)
	Twisted (15.4.0)
	w3lib (1.13.0)
	xdot (0.6)
	zope.interface (4.1.3)

>>> from numpy import * #将NumPy函数库中的所有模块引入当前命名空间

>>> random.rand(4,4) #构造一个4*4的随机数组
array([[ 0.9368179 ,  0.62638508,  0.74678506,  0.70292932],
       [ 0.49555878,  0.39984118,  0.39787973,  0.13399774],
       [ 0.501687  ,  0.86518164,  0.03717644,  0.95208253],
       [ 0.92678119,  0.04159648,  0.83192088,  0.0128645 ]])
	   
>>> randMat = mat(random.rand(4,4)) #将数组转化为矩阵
>>> randMat.I
matrix([[ 3.61826706, -0.50301544, -0.19119953, -0.40370259],
Example #8
0
case = pylon.Case.load("../data/case6ww.pkl")
case.generators[0].p_cost = (0.0, 16.0, 200.0)
case.generators[1].p_cost = (0.0, 2.0, 200.0)
case.generators[2].p_cost = (0.0, 32.0, 200.0)
case.buses[3].p_demand = 120.0
case.buses[4].p_demand = 120.0
case.buses[5].p_demand = 120.0
#plotGenCost(case.generators)

# Assume initial demand is peak demand (for sensor limits) and save it.
Pd0 = [b.p_demand for b in case.buses if b.type == pylon.PQ]

# Define a 24-hour load profile with hourly values.
p1h = numpy([0.52, 0.54, 0.52, 0.50, 0.52, 0.57, 0.60, 0.71, 0.89, 0.85, 0.88,
             0.94, 0.90, 0.88, 0.88, 0.82, 0.80, 0.78, 0.76, 0.68, 0.68, 0.68,
             0.65, 0.58])
#p1h = p1h[6:-6]
p1h = p1h[:12]
nf = len(p1h)

# Create a case environment specifying the load profile.
env = pyreto.CaseEnvironment(case, p1h)

# Create an episodic cost minimisation task.
task = pyreto.MinimiseCostTask(env)

# Create a network for approximating the agent's policy function that maps
# system demand to generator set-points..
nb = len([bus for bus in case.buses if bus.type == pylon.PQ])
ng = len([g for g in case.online_generators if g.bus.type != pylon.REFERENCE])
'''
Calculate and display the dimensions of a protein.


This is a first version, please use at your own risk!

REQUIREMENTS

numpy (http://numpy.scipy.org) that should be built into the newers versions of Pymol

'''

from __future__ import print_function

__author__  = 'Pablo Guardado Calvo'
__version__ = '0.1'
__email__   = 'pablo.guardado (at) gmail.com'
__date__    = '13/08/2015'

###########################################################################################################################################################
# USAGE
#
# The idea behing this script is to calculate an aproximate minimal bounding box to extract the cell dimensions of a protein. To calculate the minimal bounding
# is not trivial and usually the Axis Aligned Bounding Box (AABB) does not show up the real dimensions of the protein. This script calculates the inertia tensor
# of the object, extract the eigenvalues and use them to rotate the molecule (using as rotation matrix the transpose of the eigenvalues matrix). The result is that
# the molecule is oriented with the inertia axis aligned with the cartesian axis. A new Bounding Box is calculated that is called Inertia Axis Aligned Bounding Box
#(IABB), whose volume is always lower than AABB volume, and in many cases will correspond with the lowest volume. Of course, maybe it exists another Bounding Box
# with a lower volume (the minimal Bounding Box).
#
# As always with these type of things, you have to use at your own risk. I did not try all the possible combinations, but if you find a bug, do
Example #10
0
# - - coding: utf- 8 - -
import numpy
from mpi4py import MPI
a = numpy([1, 2, 3])
if MPI.COMM_WORLD.rank == 0:
    MPI.COMM_WORLD.Send(a, dest=1)
#  Comm.Send(buf, dest = 0, tag = 0)
#    Comm (MPI comm) – communicator we wish to query
#    buf (choice) – data to send
#    dest (integer) – rank of destination
#    tag (integer) – message tag

else:
    MPI.COMM_WORLD.Recv(a, source=0)

# Comm.Recv(buf, source = 0, tag = 0, Status status = None)
#    Comm (MPI comm) – communicator we wish to query
#    buf (choice) – initial address of receive buffer (choose receipt location)
#    source (integer) – rank of source
#    tag (integer) – message tag
#    status (Status) – status of object

#On a Recv you do not always need to specify the source. Instead, you can allow the calling process to accept a message from any process that happend to be sending to the receiving process. This is done by setting source to a predefined MPI constant, source=ANY_SOURCE (note that you would first need to import this with from mpi4py.MPI import ANY_SOURCE or use the syntax source=MPI.ANY_SOURCE).
Example #11
0
        # Display logs per epoch step
        if (epoch + 1) % display_step == 0:
            c = sess.run(cost, feed_dict={X: train_X, Y: train_Y})
            print("Epoch:", '%04d' % (epoch+1), "cost=", "{:.9f}".format(c), \
                "W=", sess.run(W), "b=", sess.run(b))

    print("Optimization Finished!")
    training_cost = sess.run(cost, feed_dict={X: train_X, Y: train_Y})
    print("Training cost=", training_cost, "W=", sess.run(W), "b=",
          sess.run(b), '\n')

    # Graphic display
    plt.plot(train_X, train_Y, 'ro', label='Original data')
    plt.plot(train_X, sess.run(W) * train_X + sess.run(b), label='Fitted line')
    plt.legend()
    plt.show()

    # Testing example, as requested (Issue #2)
    test_X = numpy([6.83, 4.668, 8.9, 7.91, 5.7, 8.7, 3.1, 2.1])
    test_Y = numpy([1.84, 2.273, 3.2, 2.831, 2.92, 3.24, 1.35, 1.03])

    print("Testing... (Mean square loss Comparison)")
    testing_cost = sess.run(tf.reduce_sum(tf.pow(pred - Y, 2)) /
                            (2 * test_X.shape[0]),
                            feed_dict={
                                X: test_X,
                                Y: test_Y
                            })  # same function as cost above
    print("Testing cost=", testing_cost)
    print("Absolute mean square loss difference:",
          abs(training_cost - testing_cost))
Example #12
0
n_list_2 = [
    2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 23, 25, 29, 32, 36, 40,
    45, 51, 57, 64, 72, 81, 91, 102, 114, 128, 144, 161, 181, 203, 228, 256,
    287, 323, 362, 406, 456, 512, 575, 645, 724, 813, 912, 1024, 1149, 1290,
    1448, 1625, 1825, 2048, 2299, 2580, 2896, 3251, 3649, 4096
]
rep = 100
rt_2 = [[], []]

# In[148]:

for n in n_list_2:

    start = time.time()
    x, w = quad.calc_lagu_para(n, numpy(n), numpy(n))
    for r in range(rep):
        y = f_exp(x)
        i_lagu = y.dot(w)
    end = time.time()
    rt_2[0].append((i_lagu, (end - start) / rep, x.size))

    start = time.time()
    x, w = quad.calc_lege_para(n, 0.0, x_high, numpy(n), numpy(n))
    for r in range(rep):
        y = f(x)
        i_lege = y.dot(w)
    end = time.time()
    rt_2[1].append((i_lege, (end - start) / rep, x.size))

    print("n = {} finished".format(n))
Example #13
0
def main():
    seq()
    numpy()
Example #14
0
def main():
   numpy()
   bioseq()
Example #15
0
def _dot(x, y, mathtypes=(float, int, int)):
    numpy = getattr(_numpy, "dot")
    cv = getattr(_cvisual, "dot")
    if type(x) is vector and type(y) is vector:
        return cv(x, y)
    return numpy(x, y)  # arrays rather than Visual vectors