In [1]:
import numpy as np
In [2]:
seed=np.array([[1.1,3.2],[2,2]])
In [3]:
seed
Out[3]:
array([[1.1, 3.2],
       [2. , 2. ]])
In [4]:
def extend_row_(row):
        DEBUG=False
        new_elem=np.array([np.sum([ i*np.sin(elem) for i,elem in enumerate(row) ])])
        if DEBUG: print(new_elem)
        if DEBUG: print(row)
        res=np.concatenate((row,new_elem))
        if DEBUG: print(res)
        return res
In [5]:
list(range(4))
Out[5]:
[0, 1, 2, 3]
In [6]:
map(lambda x: extend_row(x),seed)
Out[6]:
<map at 0x10f983d30>
In [7]:
extra_colum=list(map(lambda x: extend_row_(x),seed))
extra_colum
Out[7]:
[array([ 1.1       ,  3.2       , -0.05837414]),
 array([2.        , 2.        , 0.90929743])]
In [8]:
np.transpose(extra_colum)
Out[8]:
array([[ 1.1       ,  2.        ],
       [ 3.2       ,  2.        ],
       [-0.05837414,  0.90929743]])
In [9]:
extra_colum_row=list(map(lambda x: extend_row_(x),np.transpose(extra_colum) ))
extra_colum_row
Out[9]:
[array([1.1       , 2.        , 0.90929743]),
 array([3.2       , 2.        , 0.90929743]),
 array([-0.05837414,  0.90929743,  0.78907234])]
In [10]:
def fromNtoNplus1(seed):
    extra_colum=list(map(lambda x: extend_row_(x),seed))
    extra_colum_row=list(map(lambda x: extend_row_(x),np.transpose(extra_colum) ))
    return np.transpose(extra_colum_row)
In [11]:
def makeNxN(seed,N=6,DEBUG=False):
    '''
    N number of new dimensions to add to the seed matrix
    '''
    new=fromNtoNplus1(seed)
    if DEBUG: print(new)
    if DEBUG: print('N=',N)
    for i in range(N):
        if DEBUG: print('i=',i)
        if DEBUG: print('~~~~~~~~~~~~~~~~~')
        if DEBUG: print(new.shape)
        new=fromNtoNplus1(new)
        if DEBUG: print(new)
    return new
In [12]:
makeNxN(seed,N=2)
Out[12]:
array([[ 1.1       ,  3.2       , -0.05837414, -0.17505614, -0.69754639],
       [ 2.        ,  2.        ,  0.90929743,  2.48744211,  4.3128982 ],
       [ 0.90929743,  0.90929743,  0.78907234,  2.20847242,  4.61891667],
       [ 2.48744211,  2.48744211,  2.20847242,  2.21544819,  4.61337524],
       [ 4.3128982 ,  4.3128982 ,  4.61891667,  4.61337524, -5.89783489]])
In [13]:
def fofMatrix(matrix,*Rn,DEBUG=False):
    res=0
    for xS in enumerate(matrix):
        j=xS[0]
        for x in enumerate(xS):
            i=x[0]
            if DEBUG: print('element=',i,j)
            if i!=j and i<j:
                res+=Rn[i]*Rn[j]*matrix[i,j]
            if i==j:
                res+=Rn[i]*matrix[i,j]
    return res
In [14]:
seed
Out[14]:
array([[1.1, 3.2],
       [2. , 2. ]])
In [15]:
def generate(nP=10,nDim=3):
    return np.random.rand(nP,nDim)
In [16]:
fofMatrix(makeNxN(seed,N=2),*np.random.rand(5))
Out[16]:
8.092972871412497
In [17]:
fofMatrix(makeNxN(seed,N=2),*np.random.rand(5))
Out[17]:
7.672721030680512
In [18]:
fofMatrix(makeNxN(seed,N=2),*np.random.rand(15))
Out[18]:
1.905165210483766