Exemple #1
0
def forward(nn_np, data):
    """
    Given a dictionary representing a feed forward neural net and an input data matrix compute the network's output and store it within the dictionary
    :param nn: neural network dictionary
    :param data: a numpy n by m matrix where m in the number of input units in nn
    :return: the output layer activations
    """
    nn = af.array(nn_np.ctypes.data, nn_np.shape, nn_np.dtype.char)
    nn['activations'] = [data]
    nn['zs'] = []
    for w, s, b in map(None, nn['weights'], nn['nonlin'], nn['biases']):
        z = af.dot(w, af.transpose(nn['activations'][-1])) + b
        nn['zs'].append(af.transpose(z))
        nn['activations'].append(s[0](af.transpose(z)))
    return nn['activations'][-1]
#!/usr/bin/python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################

import arrayfire as af
import array as host

a = af.array([1, 2, 3])
af.display(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

a = af.array(host.array('i', [4, 5, 6]))
af.display(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

a = af.array(host.array('l', [7, 8, 9] * 3), (3, 3))
af.display(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
Exemple #3
0
#!/usr/bin/python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af
from arrayfire import parallel_range
import array as host

a = af.randu(5, 5)
af.display(a)
b = af.array(a)
af.display(b)

c = a.copy()
af.display(c)
af.display(a[0, 0])
af.display(a[0])
af.display(a[:])
af.display(a[:, :])
af.display(a[0:3, ])
af.display(a[-2:-1, -1])
af.display(a[0:5])
af.display(a[0:5:2])

idx = af.array(host.array('i', [0, 3, 2]))
af.display(idx)
#!/usr/bin/python
import arrayfire as af
import array as host

a = af.array([1, 2, 3])
af.print_array(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())


a = af.array(host.array('d', [4, 5, 6]))
af.print_array(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

a = af.array(host.array('l', [7, 8, 9] * 4), (2, 5))
af.print_array(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())
#!/usr/bin/python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af
from arrayfire import parallel_range
import array as host

a = af.randu(5, 5)
af.display(a)
b = af.array(a)
af.display(b)

c = a.copy()
af.display(c)
af.display(a[0,0])
af.display(a[0])
af.display(a[:])
af.display(a[:,:])
af.display(a[0:3,])
af.display(a[-2:-1,-1])
af.display(a[0:5])
af.display(a[0:5:2])

idx = af.array(host.array('i', [0, 3, 2]))
af.display(idx)
#!/usr/bin/python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################

import arrayfire as af
import array as host

a = af.array([1, 2, 3])
af.display(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())


a = af.array(host.array("i", [4, 5, 6]))
af.display(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

a = af.array(host.array("l", [7, 8, 9] * 3), (3, 3))
af.display(a)
print(a.elements(), a.type(), a.dims(), a.numdims())