本文整理汇总了Python中apgl.util.PathDefaults.PathDefaults.getTempDir方法的典型用法代码示例。如果您正苦于以下问题:Python PathDefaults.getTempDir方法的具体用法?Python PathDefaults.getTempDir怎么用?Python PathDefaults.getTempDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.util.PathDefaults.PathDefaults
的用法示例。
在下文中一共展示了PathDefaults.getTempDir方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLoadParams
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testLoadParams(self):
try:
lmbda = 0.01
alterRegressor = PrimalRidgeRegression(lmbda)
egoRegressor = PrimalRidgeRegression(lmbda)
predictor = EgoEdgeLabelPredictor(alterRegressor, egoRegressor)
params = [0.1, 0.2]
paramFuncs = [egoRegressor.setLambda, alterRegressor.setLambda]
fileName = PathDefaults.getTempDir() + "tempParams.pkl"
predictor.saveParams(params, paramFuncs, fileName)
params2 = predictor.loadParams(fileName)
self.assertTrue(params2[0][0] == "apgl.predictors.PrimalRidgeRegression")
self.assertTrue(params2[0][1] == "setLambda")
self.assertTrue(params2[0][2] == 0.1)
self.assertTrue(params2[1][0] == "apgl.predictors.PrimalRidgeRegression")
self.assertTrue(params2[1][1] == "setLambda")
self.assertTrue(params2[1][2] == 0.2)
except IOError as e:
logging.warn(e)
示例2: testEstimate
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testEstimate(self):
#Lets set up a simple model based on normal dist
abcParams = ABCParameters()
epsilonArray = numpy.array([0.5, 0.2, 0.1])
posteriorSampleSize = 20
#Lets get an empirical estimate of Sprime
model = NormalModel(abcMetrics)
model.setMu(theta[0])
model.setSigma(theta[1])
Sprime = abcMetrics.summary(model.simulate())
logging.debug(("Real summary statistic: " + str(Sprime)))
thetaDir = PathDefaults.getTempDir()
abcSMC = ABCSMC(epsilonArray, createNormalModel, abcParams, thetaDir)
abcSMC.maxRuns = 100000
abcSMC.setPosteriorSampleSize(posteriorSampleSize)
thetasArray = abcSMC.run()
thetasArray = numpy.array(thetasArray)
meanTheta = numpy.mean(thetasArray, 0)
logging.debug((thetasArray.shape))
logging.debug(thetasArray)
logging.debug(meanTheta)
print(thetasArray.shape[0], posteriorSampleSize)
#Note only mean needs to be similar
self.assertTrue(thetasArray.shape[0] >= posteriorSampleSize)
self.assertEquals(thetasArray.shape[1], 2)
self.assertTrue(numpy.linalg.norm(theta[0] - meanTheta[0]) < 0.2)
示例3: testReadFromMatFile
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testReadFromMatFile(self):
numExamples = 10
dir = PathDefaults.getTempDir()
fileName = dir + "examplesList1"
X = rand(numExamples, 10)
ml = ExamplesList(numExamples)
ml.addDataField("X", X)
ml.writeToMatFile(fileName)
ml2 = ExamplesList.readFromMatFile(fileName)
self.assertTrue(ml == ml2)
Y = rand(numExamples, 20)
ml.addDataField("Y", Y)
ml.writeToMatFile(fileName)
ml2 = ExamplesList.readFromMatFile(fileName)
self.assertTrue(ml == ml2)
Z = rand(numExamples, 50)
ml.addDataField("Z", Z)
ml.writeToMatFile(fileName)
ml2 = ExamplesList.readFromMatFile(fileName)
self.assertTrue(ml == ml2)
示例4: testSaveParams
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testSaveParams(self):
try:
lmbda = 0.01
alterRegressor = PrimalRidgeRegression(lmbda)
egoRegressor = PrimalRidgeRegression(lmbda)
predictor = EgoEdgeLabelPredictor(alterRegressor, egoRegressor)
params = [0.1, 0.2]
paramFuncs = [egoRegressor.setLambda, alterRegressor.setLambda]
fileName = PathDefaults.getTempDir() + "tempParams.pkl"
predictor.saveParams(params, paramFuncs, fileName)
except IOError as e:
logging.warn(e)
示例5: testSaveLoad
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testSaveLoad(self):
try:
vList = VertexList(self.numVertices, self.numFeatures)
vList.setVertex(0, numpy.array([1, 2, 3]))
vList.setVertex(1, numpy.array([4, 5, 6]))
vList.setVertex(2, numpy.array([7, 8, 9]))
tempDir = PathDefaults.getTempDir()
fileName = tempDir + "vList"
vList.save(fileName)
vList2 = VertexList.load(fileName)
self.assertTrue((vList.getVertices() == vList2.getVertices()).all())
except IOError as e:
logging.warn(e)
pass
示例6: testWriteToMatFile
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testWriteToMatFile(self):
numExamples = 100
X = rand(numExamples, 10)
ml = ExamplesList(numExamples)
dir = PathDefaults.getTempDir()
fileName = dir + "examplesList1"
#Try writing with no examples
self.assertRaises(ValueError, ml.writeToMatFile, fileName)
#Now, add a data field and try writing
ml.addDataField("X", X)
ml.writeToMatFile(fileName)
ml.addDataField("Y", X)
ml.writeToMatFile(fileName)
示例7: testSaveLoad
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def testSaveLoad(self):
try:
vList = GeneralVertexList(self.numVertices)
vList.setVertex(0, "abc")
vList.setVertex(1, 12)
vList.setVertex(2, "num")
tempDir = PathDefaults.getTempDir()
fileName = tempDir + "vList"
vList.save(fileName)
vList2 = GeneralVertexList.load(fileName)
for i in range(self.numVertices):
self.assertEquals(vList.getVertex(i), vList2.getVertex(i))
except IOError as e:
logging.warn(e)
pass
示例8: profile
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def profile(command, globalVars, localVars, numStats=30):
"""
Just profile the given command with the global and local variables
and print out the cumulative and function times.
"""
try:
import pstats
import cProfile
except ImportError:
raise ImportError("profile() requires pstats and cProfile")
tempDirectory = PathDefaults.getTempDir()
profileFileName = tempDirectory + "profile.cprof"
logging.info("Starting to profile ...")
cProfile.runctx(command, globalVars, localVars, profileFileName)
logging.info("Done")
stats = pstats.Stats(profileFileName)
stats.strip_dirs().sort_stats("cumulative").print_stats(numStats)
stats.strip_dirs().sort_stats("time").print_stats(numStats)
示例9: setUp
# 需要导入模块: from apgl.util.PathDefaults import PathDefaults [as 别名]
# 或者: from apgl.util.PathDefaults.PathDefaults import getTempDir [as 别名]
def setUp(self):
tempDir = PathDefaults.getTempDir()
self.fileName = tempDir + "abc"