本文整理汇总了Python中pysgpp.DataVector.l2Norm方法的典型用法代码示例。如果您正苦于以下问题:Python DataVector.l2Norm方法的具体用法?Python DataVector.l2Norm怎么用?Python DataVector.l2Norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysgpp.DataVector
的用法示例。
在下文中一共展示了DataVector.l2Norm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: currentDiagHess
# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import l2Norm [as 别名]
def currentDiagHess(self, params):
#return np.ones(params.shape)
# if hasattr(self, 'H'):
# return self.H
# op_l2_dot = createOperationLTwoDotProduct(self.grid)
# self.H = np.empty((self.grid.getSize(), self.grid.getSize()))
# u = DataVector(self.grid.getSize())
# u.setAll(0.0)
# result = DataVector(self.grid.getSize())
# for grid_idx in xrange(self.grid.getSize()):
# u[grid_idx] = 1.0
# op_l2_dot.mult(u, result)
# self.H[grid_idx,:] = result.array()
# u[grid_idx] = 0.0
# self.H = np.diag(self.H).reshape(1,-1)
# return self.H
#import ipdb; ipdb.set_trace()
size = self._lastseen.shape[0]
data_matrix = DataMatrix(self._lastseen[:,:self.dim])
mult_eval = createOperationMultipleEval(self.grid, data_matrix);
params_DV = DataVector(self.grid.getSize())
params_DV.setAll(0.)
results_DV = DataVector(size)
self.H = np.zeros(self.grid.getSize())
for i in xrange(self.grid.getSize()):
params_DV[i] = 1.0
mult_eval.mult(params_DV, results_DV);
self.H[i] = results_DV.l2Norm()**2
params_DV[i] = 0.0
self.H = self.H.reshape(1,-1)/size
#import ipdb; ipdb.set_trace()
return self.H
示例2: computeErrors
# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import l2Norm [as 别名]
def computeErrors(jgrid, jalpha,
grid1, alpha1,
grid2, alpha2,
n=200):
"""
Compute some errors to estimate the quality of the
interpolation.
@param jgrid: Grid, new discretization
@param jalpha: DataVector, new surpluses
@param grid1: Grid, old discretization
@param alpha1: DataVector, old surpluses
@param grid2: Grid, old discretization
@param alpha2: DataVector, old surpluses
@return: tuple(<float>, <float>), maxdrift, l2norm
"""
jgs = jgrid.getStorage()
# create control samples
samples = DataMatrix(np.random.rand(n, jgs.dim()))
# evaluate the sparse grid functions
jnodalValues = evalSGFunctionMulti(jgrid, jalpha, samples)
# eval grids
nodalValues1 = evalSGFunctionMulti(grid1, alpha1, samples)
nodalValues2 = evalSGFunctionMulti(grid2, alpha2, samples)
# compute errors
p = DataVector(jgs.dim())
err = DataVector(n)
for i in xrange(n):
samples.getRow(i, p)
y = nodalValues1[i] * nodalValues2[i]
if abs(jnodalValues[i]) > 1e100:
err[i] = 0.0
else:
err[i] = abs(y - jnodalValues[i])
# get error statistics
# l2
l2norm = err.l2Norm()
# maxdrift
err.abs()
maxdrift = err.max()
return maxdrift, l2norm
示例3: loss_fun
# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import l2Norm [as 别名]
def loss_fun(self, params):
'''
Compute the value of regularized quadratic loss function in the current state
'''
if not hasattr(self, '_lastseen'):
return np.inf
else:
params_DV = DataVector(params)
residuals = []
for sample_idx in xrange(self.batch_size):
x = self._lastseen[sample_idx, :self.dim]
y = self._lastseen[sample_idx, self.dim]
x_DV = DataVector(x)
residual = self.grid.eval(params_DV, x_DV) - y
residuals.append(residual*residual)
regularizer = params_DV.l2Norm()
regularizer = self.l*regularizer*regularizer
return 0.5*np.mean(residuals) + regularizer
示例4: computeErrors
# 需要导入模块: from pysgpp import DataVector [as 别名]
# 或者: from pysgpp.DataVector import l2Norm [as 别名]
def computeErrors(jgrid, jalpha, grid, alpha, f, n=200):
"""
Compute some errors to estimate the quality of the
interpolation.
@param jgrid: Grid, new discretization
@param jalpha: DataVector, new surpluses
@param grid: Grid, old discretization
@param alpha: DataVector, old surpluses
@param f: function, to be interpolated
@param n: int, number of Monte Carlo estimates for error estimation
@return: tuple(<float>, <float>), maxdrift, l2norm
"""
jgs = jgrid.getStorage()
# create control samples
samples = DataMatrix(np.random.rand(n, jgs.dim()))
# evaluate the sparse grid functions
jnodalValues = evalSGFunctionMulti(jgrid, jalpha, samples)
nodalValues = evalSGFunctionMulti(grid, alpha, samples)
# compute errors
p = DataVector(jgs.dim())
err = DataVector(n)
for i in xrange(n):
samples.getRow(i, p)
y = f(p.array(), nodalValues[i])
err[i] = abs(y - jnodalValues[i])
# get error statistics
# l2
l2norm = err.l2Norm()
# maxdrift
err.abs()
maxdrift = err.max()
return maxdrift, l2norm