Exemplo n.º 1
0
n = 2
# Set the number of points used in the sufficient summary plot
k = 1000
# Compute ex0act solution for M randomly selected points
M = 1000

# Select function
#For c_index =  0,1,2,3
x0 = 2*np.random.rand(M,m)-1
f = np.zeros(M)
df = np.zeros((M,m)) 
c_index = 0 #matrix number
comp_flag = 1 #0 for MC, 1 for LGW quadtrature
for i in range(0,M):
    sample = x0[i,:].reshape(m)
    [out, gradout] = borehole.fun(sample)
    f[i] = out
    df[i,:] = gradout.T
    
    
sub = active_subspaces.subspaces.Subspaces()
sub.compute(df ,f ,x0,borehole.fun, c_index, comp_flag, 5, 200)
#sub.compute(df)
W = sub.eigenvectors
evals = sub.eigenvalues.reshape((m,1))
np.savez('C0_LGQ_data',m=m,n=n,M=M,f=f,x0=x0,evals=evals,W=W,comp_flag=comp_flag,sub_br=sub.sub_br,e_br=sub.e_br)


# Rewrite the active/inactive subspace variables to be n-dimensional
W1 = W[:,:n]
W2 = W[:,n:]
Exemplo n.º 2
0
import matplotlib.pyplot as plt
import borehole
# Set the number of parameter (m) 
m = 8
# Set the dimension of the active subspace (n)
n = 2
# Set the number of points per dimension for Gauss Legendre Quadrature
k = 6
# Compute ex0act solution for M randomly selected points
M = 100000
x0 = 2*np.random.rand(M,m)-1
f = np.zeros(M)
df = np.zeros((M,m))
for i in range(0,M):
    sample = x0[i,:].reshape(m)
    [out, gradout] = borehole.fun(sample)
    f[i] = out
    df[i,:] = gradout.T
    
#Gauss Legendre Quadrature of the C matrix
xx = (np.ones(m)*k).astype(np.int64).tolist()  
[x,w] = active_subspaces.utils.quadrature.gauss_legendre(xx)
C = np.zeros((m,m))
N = np.size(w)
for i in range(0,N):
    [Out,Gradout] = borehole.fun(x[i,:])
    C = C + np.outer(Gradout,Gradout)*w[i]
# Eigenvalue decomposition    
[evals,WW] = np.linalg.eig(C)
# Ordering eigenvalues in decending order
order = np.argsort(evals)
Exemplo n.º 3
0
# checking derivatives with first-order finite differences
import borehole
import numpy as np      
h = 1e-6;
m = 8;
for k in range(0,20):
    x0 = 2*np.random.rand(1,m)-1
    x0 = x0.reshape(m)
    [f0,df] = borehole.fun(x0)
    df_fd = np.zeros(m)
    for i in range(0,m):
        e = np.zeros(m)
        e[i] = 1
        [step,dif] = borehole.fun(x0+h*e)
        df_fd[i] = (step-f0)/h
    print("borehole: Norm of fd error:",np.linalg.norm(df-df_fd))