Example #1
0
'''
This file tests to make sure conversion from numpy -> uqtkarray does
not change the row-major (C contiguous) format of the original numpy array

Also, when converting form uqtkarray-> numpy we want to make sure that the
resulting numpy array is *only* row major (C contiguous)

'''

# create numpy matrix and show flags
a_np = np.array([[0, 2.00], [0.1, 1], [1, 5.0]])
print("flags for a_np to show whether C or F contiguous")
print(a_np.flags)

# get a uqtk array from a numpy array (memory is copied, not shared)
a_uqtk = numpy2uqtk(a_np)
print(
    "\nflags for original numpy array to make sure it hasn't changed to F continguous after converting"
)
# verify that the original numpy array is only C contiguous
assert a_np.flags['F_CONTIGUOUS'] == False
assert a_np.flags['C_CONTIGUOUS'] == True

print("\nConvert uqtk array back to numpy array and make sure C contiguous")
b_np = uqtk2numpy(a_uqtk)
# test to make sure new numpy array is *only* C contiguous (row - major)
assert b_np.flags['F_CONTIGUOUS'] == False
assert b_np.flags['C_CONTIGUOUS'] == True

# test for the dot product
print(
Example #2
0
		self.__errbars_uqtk = uqtkarray.dblArray1D() # error bars for each weight
		self.__nextbasis_uqtk = uqtkarray.dblArray1D() # if adaptive
		self.__alpha_uqtk = uqtkarray.dblArray1D() # prior hyperparameter (1/gamma)
		self.__lambda_p = uqtktools.new_doublep()

		uqtktools.doublep_assign(self.__lambda_p,l_init)

		self.__compiled = True

	def leastsq(self,X,y):
		'''
		perform simple least squares based on the original
		pc order.
		'''
		# convert input to uqtk arrays
		self.__X_uqtk = numpy2uqtk(X)
		self.__y_uqtk = numpy2uqtk(y)

		# get vandermonde matrix w.r.t. original pc basis
		self.__V_uqtk = uqtkarray.dblArray2D()
		self.__pcmodel0 = uqtkpce.PCSet("NISPnoq",self.__mindex0_uqtk,self.pctype,0.0,1.0) # initiate
		self.__pcmodel0.EvalBasisAtCustPts(self.__X_uqtk,self.__V_uqtk)
		self.Vandermonde = uqtk2numpy(self.__V_uqtk)
		self.__sol = np.linalg.lstsq(self.Vandermonde,y)
		return self.__sol[0], self.__sol[1]

	def fit0(self,X,y,tol=1e-8,sigsq=None,upit=0):
		'''
		Train bcs model coefficients with X and y data
		X         :    2d numpy of inputs/ feature data
		y         :     1d numpy array of labels/ outputs
Example #3
0
# set 2d array to numpy array
# make sure to pass asfortranarray
y_np = random.randn(m,n)
y.setnpdblArray(asfortranarray(y_np))

for i in range(m):
	for j in range(n):
		assert y[i,j] == y_np[i,j]

''' alternative using uqtk2numpy and numpy2uqtk '''

# test conversion from 1d numpy array to 1d uqtk array
nn = 10
x1 = random.rand(nn)
y1 = numpy2uqtk(x1)
z1 = uqtk2numpy(y1)
for i in range(nn):
	assert x1[i] == y1[i]

# test conversion from 1d uqtk array to numpy
for i in range(nn):
	assert z1[i] == x1[i]

# test for conversion from 2d numpy to 2d uqtk
nn = 10
mm = 5
X1 = random.rand(mm,nn)
Y1 = numpy2uqtk(X1)
Z1 = uqtk2numpy(Y1)
for i in range(mm):