本文整理汇总了Python中math.ceil函数的典型用法代码示例。如果您正苦于以下问题:Python ceil函数的具体用法?Python ceil怎么用?Python ceil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ceil函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: is_converged
def is_converged(hartree_parameters, structure, return_values=False):
filename = s_name(structure) + ".conv_res"
to_return = {}
try:
f = open(filename, mode='r')
conv_res = ast.literal_eval(f.read())
f.close()
converged = True if True in conv_res['control'].values() else False
except (IOError, OSError, ValueError):
if return_values:
print('Inputfile ', filename, ' not found, the convergence calculation did not finish properly' \
' or was not parsed ...')
converged = False
return converged
if return_values and converged:
if hartree_parameters:
try:
conv_res['values']['ecut'] = 4 * math.ceil(conv_res['values']['ecut'] * eV_to_Ha / 4)
except (KeyError, ArithmeticError, FloatingPointError, SyntaxError):
pass
try:
conv_res['values']['ecuteps'] = 4 * math.ceil(conv_res['values']['ecuteps'] * eV_to_Ha / 4)
except (KeyError, ArithmeticError, FloatingPointError, SyntaxError):
pass
for k in conv_res['values'].keys():
if conv_res['values'][k] != 0 and conv_res['values'][k] != np.inf:
to_return.update({k: conv_res['values'][k]})
return to_return
else:
return converged
开发者ID:rousseab,项目名称:pymatgen,代码行数:30,代码来源:helpers.py
示例2: sharkeventkinshnavaw
def sharkeventkinshnavaw(self, a_ship, a_screen):
randnum = random.randint(1, 10)
if randnum < 10:
self.mess = "What were you thinking? The king shark sees all in the seas, nothing escapes it's sight"
self.mess += "What would you order your crew to do? The shark is still attacking."
messobj = StrObj.render(self.mess[0:33], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 5))
messobj = StrObj.render(self.mess[33:68], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 25))
messobj = StrObj.render(self.mess[69:87], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 45))
messobj = StrObj.render(self.mess[87:113], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 65))
messobj = StrObj.render(self.mess[113:143], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 85))
messobj = StrObj.render(self.mess[144:], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 105))
randnum = random.randint(0, 9)
a_ship.ShipHp -= int(math.ceil(randnum * .55))
a_ship.CrewHp -= int(math.ceil(randnum * .45))
self.MenuOp.initshkinafternavawf(170)
self.MenuOp.drawmen(a_screen, 0)
else:
self.mess = "Impossible! The king shark did not see us! The fates must be asleep."
messobj = StrObj.render(self.mess[0:35], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 5))
messobj = StrObj.render(self.mess[35:], 1, (0, 0, 0))
a_screen.blit(messobj, (self.xpos, 25))
开发者ID:mliming,项目名称:Tide-Glory,代码行数:28,代码来源:MyEvents.py
示例3: _download
def _download(url):
"""
Do a wget: Download the file specified in url to the cwd.
Return the filename.
"""
filename = os.path.split(url)[1]
req = requests.get(url, stream=True, headers={'User-Agent': 'PyBOMBS'})
filesize = float(req.headers['content-length'])
filesize_dl = 0
with open(filename, "wb") as f:
for buff in req.iter_content(chunk_size=8192):
if buff:
f.write(buff)
filesize_dl += len(buff)
# TODO wrap this into an output processor or at least
# standardize the progress bars we use
status = r"%05d kB / %05d kB (%03d%%)" % (
int(math.ceil(filesize_dl/1000.)),
int(math.ceil(filesize/1000.)),
int(math.ceil(filesize_dl*100.)/filesize)
)
status += chr(8)*(len(status)+1)
sys.stdout.write(status)
sys.stdout.write("\n")
return filename
开发者ID:n-west,项目名称:pybombs2,代码行数:25,代码来源:wget.py
示例4: SetValue
def SetValue(self, value):
""" Sets the FloatSpin value. """
if not self._textctrl or not self.InRange(value):
return
if self._snapticks and self._increment != 0.0:
finite, snap_value = self.IsFinite(value)
if not finite: # FIXME What To Do About A Failure?
if (snap_value - floor(snap_value) < ceil(snap_value) - snap_value):
value = self._defaultvalue + floor(snap_value)*self._increment
else:
value = self._defaultvalue + ceil(snap_value)*self._increment
strs = ("%100." + str(self._digits) + self._textformat[1])%value
strs = strs.strip()
strs = self.ReplaceDoubleZero(strs)
if value != self._value or strs != self._textctrl.GetValue():
self._textctrl.SetValue(strs)
self._textctrl.DiscardEdits()
self._value = value
开发者ID:AceZOfZSpades,项目名称:RankPanda,代码行数:26,代码来源:floatspin.py
示例5: __init__
def __init__(self, n, n_iter=3, train_size=.5, test_size=None,
random_state=None, n_bootstraps=None):
self.n = n
if n_bootstraps is not None: # pragma: no cover
warnings.warn("n_bootstraps was renamed to n_iter and will "
"be removed in 0.16.", DeprecationWarning)
n_iter = n_bootstraps
self.n_iter = n_iter
if (isinstance(train_size, numbers.Real) and train_size >= 0.0
and train_size <= 1.0):
self.train_size = int(ceil(train_size * n))
elif isinstance(train_size, numbers.Integral):
self.train_size = train_size
else:
raise ValueError("Invalid value for train_size: %r" %
train_size)
if self.train_size > n:
raise ValueError("train_size=%d should not be larger than n=%d" %
(self.train_size, n))
if isinstance(test_size, numbers.Real) and 0.0 <= test_size <= 1.0:
self.test_size = int(ceil(test_size * n))
elif isinstance(test_size, numbers.Integral):
self.test_size = test_size
elif test_size is None:
self.test_size = self.n - self.train_size
else:
raise ValueError("Invalid value for test_size: %r" % test_size)
if self.test_size > n:
raise ValueError("test_size=%d should not be larger than n=%d" %
(self.test_size, n))
self.random_state = random_state
开发者ID:abouaziz,项目名称:scikit-learn,代码行数:33,代码来源:cross_validation.py
示例6: NNI
def NNI(dir):
All = os.listdir(dir)
NumL = [int(I[0:-4]) for I in All]
n = len(All)
if n < 32:
Ext = [int(math.ceil(x*32./n)) for x in NumL]
for i in range(n):
os.rename(os.path.join(dir, All[i]), os.path.join(dir,'__' + str(Ext[i]) + '.png'))
for i in range(n):
os.rename(os.path.join(dir, '__' + str(Ext[i]) + '.png'), os.path.join(dir, str(Ext[i]) + '.png'))
Dif = list(set(range(1,33)).difference(set(Ext)))
Dif.sort()
Ext.sort()
for i in Dif:
item = [x>i for x in Ext].index(True)
obj = Ext[item]
os.system('cp '+os.path.join(dir,str(obj)+'.png')+' '+os.path.join(dir,str(i)+'.png'))
elif n > 32:
Ext = [int(math.ceil(x*n/32.)) for x in range(1,33)]
m = len(Ext)
Dif = list(set(NumL).difference(set(Ext)))
Dif.sort()
Ext.sort()
for i in Dif:
os.remove(os.path.join(dir, str(i) + '.png'))
for i in range(m):
os.rename(os.path.join(dir, str(Ext[i]) + '.png'),os.path.join(dir, '__'+str(i+1) + '.png'))
for i in range(m):
os.rename(os.path.join(dir, '__'+str(i+1) + '.png'),os.path.join(dir, str(i+1) + '.png'))
开发者ID:waxida,项目名称:one-shot-learning-gesture-recognition,代码行数:29,代码来源:online_test_lxj.py
示例7: setAppearance
def setAppearance(self):
"""
A setter for the appearance of the tower.
"""
self.towerDiv = avg.DivNode(size=util.towerDivSize, pos=(self.pos.x - util.towerDivSize[0]//2, self.pos.y-util.towerDivSize[1]//2))
#sets the explosion radius
self.towerCircle = avg.CircleNode(fillopacity=0.3, strokewidth=0, fillcolor=self.team.color, r=self.towerDiv.size.x//2, pos=(self.towerDiv.size.x//2,self.towerDiv.size.y//2), parent=self.towerDiv)
#sets the fancy snow balls
for i in xrange(5):
radius = self.towerDiv.size[0]//10
xPos = random.randint(0 + math.floor(radius), math.ceil(self.towerDiv.size.x - radius))
yPos = random.randint(0 + math.floor(radius), math.ceil(self.towerDiv.size.y - radius))
snowball = avg.CircleNode(fillopacity=0.5, strokewidth=0, filltexhref=os.path.join(getMediaDir(__file__, "resources"), "snowflakes.png"), r=radius, pos=(xPos,yPos), parent=self.towerDiv)
self.snowballAnim(xPos,yPos,snowball)
self.tower = avg.RectNode(fillopacity=1, strokewidth=0, size=util.towerSize, pos=(self.pos.x - util.towerSize[0] // 2, self.pos.y - util.towerSize[1] // 2))
if self.team.name == "Team2":
self.tower.filltexhref = os.path.join(getMediaDir(__file__, "resources"), "iceball.png")
else:
self.tower.filltexhref = os.path.join(getMediaDir(__file__, "resources"), "iceball.png")
开发者ID:libavg,项目名称:mtc-geneatd,代码行数:29,代码来源:iceTower.py
示例8: testFloor
def testFloor(self):
self.assertRaises(TypeError, math.floor)
# These types will be int in py3k.
self.assertEquals(float, type(math.floor(1)))
self.assertEquals(float, type(math.floor(1L)))
self.assertEquals(float, type(math.floor(1.0)))
self.ftest('floor(0.5)', math.floor(0.5), 0)
self.ftest('floor(1.0)', math.floor(1.0), 1)
self.ftest('floor(1.5)', math.floor(1.5), 1)
self.ftest('floor(-0.5)', math.floor(-0.5), -1)
self.ftest('floor(-1.0)', math.floor(-1.0), -1)
self.ftest('floor(-1.5)', math.floor(-1.5), -2)
# pow() relies on floor() to check for integers
# This fails on some platforms - so check it here
self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
self.assertEquals(math.ceil(INF), INF)
self.assertEquals(math.ceil(NINF), NINF)
self.assert_(math.isnan(math.floor(NAN)))
class TestFloor(object):
def __float__(self):
return 42.3
class TestNoFloor(object):
pass
self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
self.assertRaises(TypeError, math.floor, TestNoFloor())
t = TestNoFloor()
t.__floor__ = lambda *args: args
self.assertRaises(TypeError, math.floor, t)
self.assertRaises(TypeError, math.floor, t, 0)
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:32,代码来源:test_math.py
示例9: readEgg
def readEgg(self,filename):
""" reads the egg file and stores the info"""
egg = EggData()
egg.read(filename)
for char in getAllEggGroup(egg):
name = str(char.getName())
image = Image()
image.name = name
self.images[name] = image
pos = char.getComponentVec3(0)
for p in getAllType(char,EggPolygon):
if p.getNumVertices() > 2:
v = p.getVertex(2)
vpos = v.getPos3()-pos
image.x = pos.getX()
image.y = pos.getZ()
image.w = vpos.getX()
image.h = vpos.getZ()
for l in getAllType(char,EggPoint):
extend = l.getVertex(0).getPos3()-pos
image.extend = math.ceil(extend.getX()),math.ceil(extend.getZ())
开发者ID:tlarhices,项目名称:planet,代码行数:26,代码来源:eggatlas.py
示例10: gaussian_smear
def gaussian_smear(self, r):
"""
Applies an isotropic Gaussian smear of width (standard deviation) r to the potential field. This is necessary to
avoid finding paths through narrow minima or nodes that may exist in the field (although any potential or
charge distribution generated from GGA should be relatively smooth anyway). The smearing obeys periodic
boundary conditions at the edges of the cell.
:param r - Smearing width in cartesian coordinates, in the same units as the structure lattice vectors
"""
# Since scaling factor in fractional coords is not isotropic, have to have different radii in 3 directions
a_lat = self.__s.lattice.a
b_lat = self.__s.lattice.b
c_lat = self.__s.lattice.c
# Conversion factors for discretization of v
v_dim = self.__v.shape
r_frac = (r / a_lat, r / b_lat, r / c_lat)
r_disc = (int(math.ceil(r_frac[0] * v_dim[0])), int(math.ceil(r_frac[1] * v_dim[1])),
int(math.ceil(r_frac[2] * v_dim[2])))
# Apply smearing
# Gaussian filter
gauss_dist = np.zeros((r_disc[0] * 4 + 1, r_disc[1] * 4 + 1, r_disc[2] * 4 + 1))
for g_a in np.arange(-2.0 * r_disc[0], 2.0 * r_disc[0] + 1, 1.0):
for g_b in np.arange(-2.0 * r_disc[1], 2.0 * r_disc[1] + 1, 1.0):
for g_c in np.arange(-2.0 * r_disc[2], 2.0 * r_disc[2] + 1, 1.0):
g = np.array([g_a / v_dim[0], g_b / v_dim[1], g_c / v_dim[2]]).T
gauss_dist[int(g_a + r_disc[0])][int(g_b + r_disc[1])][int(g_c + r_disc[2])] = la.norm(np.dot(self.__s.lattice.matrix, g))/r
gauss = scipy.stats.norm.pdf(gauss_dist)
gauss = gauss/np.sum(gauss, dtype=float)
padded_v = np.pad(self.__v, ((r_disc[0], r_disc[0]), (r_disc[1], r_disc[1]), (r_disc[2], r_disc[2])), mode='wrap')
smeared_v = scipy.signal.convolve(padded_v, gauss, mode='valid')
self.__v = smeared_v
开发者ID:ZhewenSong,项目名称:USIT,代码行数:33,代码来源:daniil_pathfinder.py
示例11: __setAccountsAttrs
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime = 0):
disableTTHeader = ''
disableTTBody = ''
isNavigationEnabled = True
if self.prbDispatcher:
isNavigationEnabled = not self.prbDispatcher.getFunctionalState().isNavigationDisabled()
if isPremiumAccount:
if not premiumExpiryTime > 0:
raise AssertionError
deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime)))
if deltaInSeconds > time_utils.ONE_DAY:
timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY)
timeMetric = i18n.makeString('#menu:header/account/premium/days')
else:
timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR)
timeMetric = i18n.makeString('#menu:header/account/premium/hours')
buyPremiumLabel = i18n.makeString('#menu:headerButtons/doLabel/premium')
premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', {'timeMetric': timeMetric,
'timeLeft': timeLeft})
canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR
else:
canUpdatePremium = True
premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label')
buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy')
if not canUpdatePremium:
disableTTHeader = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_HEADER)
disableTTBody = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_BODY, number=time_utils.ONE_YEAR / time_utils.ONE_DAY)
self.as_doDisableHeaderButtonS(self.BUTTONS.PREM, canUpdatePremium and isNavigationEnabled)
hasPersonalDiscount = len(g_itemsCache.items.shop.personalPremiumPacketsDiscounts) > 0
tooltip = canUpdatePremium or {'header': disableTTHeader,
'body': disableTTBody}
else:
tooltip = TOOLTIPS.HEADER_PREMIUM_EXTEND if isPremiumAccount else TOOLTIPS.HEADER_PREMIUM_BUY
self.as_setPremiumParamsS(isPremiumAccount, premiumBtnLbl, buyPremiumLabel, canUpdatePremium, disableTTHeader, disableTTBody, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
开发者ID:webiumsk,项目名称:WOT-0.9.15-CT,代码行数:34,代码来源:lobbyheader.py
示例12: _max_min
def _max_min(self):
"""
Calculate minimum and maximum for the axis adding some padding.
There are always a maximum of ten units for the length of the axis.
"""
value = length = self._max - self._min
sign = value/value
zoom = less_than_one(value) or 1
value = value * zoom
ab = abs(value)
value = math.ceil(ab * 1.1) * sign
# calculate tick
l = math.log10(abs(value))
exp = int(l)
mant = l - exp
unit = math.ceil(math.ceil(10**mant) * 10**(exp-1))
# recalculate max
value = math.ceil(value / unit) * unit
unit = unit / zoom
if value / unit > 9:
# no more that 10 ticks
unit *= 2
self.unit = unit
scale = value / length
mini = math.floor(self._min * scale) / zoom
maxi = math.ceil(self._max * scale) / zoom
return mini, maxi
开发者ID:Jian-Zhan,项目名称:customarrayformatter,代码行数:30,代码来源:chart.py
示例13: getCtInfo
def getCtInfo(id):
infos = {'description':'','ip':[],'hostname':'','ram':0}
infos['vmStatus'] = VE_STOPPED
#infos['ips'] = getCtIp(id)
f = open(VPS_CONF_DIR+'/'+id+'.conf')
for line in f:
line = re.sub('#.*','',line).strip()
if line != '':
m = re.search('([A-Z_]*)="(.*)"', line)
key = m.group(1)
value = m.group(2).replace('\\"','"')
if key == 'HOSTNAME':
infos['hostname'] = value
elif key == 'DESCRIPTION':
infos['description'] = unescape(value)
elif key == 'PRIVVMPAGES':
privvmpages = int(ceil(int(value.split(':')[0])/256.0))
elif key == 'LOCKEDPAGES':
infos['ram'] = int(ceil(int(value.split(':')[0])/256.0))
elif key == 'IP_ADDRESS':
infos['ip'] = re.sub('\s+',' ',value).strip().split(' ')
infos['swap'] = privvmpages - infos['ram']
return infos
开发者ID:binRick,项目名称:openvz-cluster,代码行数:26,代码来源:vzinfo.py
示例14: generate_shifts_2d
def generate_shifts_2d(width, height, n_samples, with_hot=False):
x_shifts = gpu_rng.gen_uniform((n_samples,), np.float32) * (width - 0.01)
x_shifts = x_shifts.astype(np.uint32)
y_shifts = gpu_rng.gen_uniform((n_samples,), np.float32) * (height - 0.01)
y_shifts = y_shifts.astype(np.uint32)
if with_hot:
shifts_hot = gp.empty((width * height, n_samples), np.float32)
threads_per_block = 32
n_blocks = int(math.ceil(n_samples / threads_per_block))
gpu_shift_to_hot_2d(x_shifts, y_shifts, shifts_hot,
np.uint32(shifts_hot.strides[0]/4),
np.uint32(shifts_hot.strides[1]/4),
np.uint32(width), np.uint32(height), np.uint32(n_samples),
block=(threads_per_block, 1, 1), grid=(n_blocks, 1))
return x_shifts, y_shifts, shifts_hot
else:
shifts = gp.empty((2, n_samples), np.float32)
threads_per_block = 32
n_blocks = int(math.ceil(n_samples / threads_per_block))
gpu_vstack(y_shifts, x_shifts, shifts,
np.uint32(shifts.strides[0]/4), np.uint32(shifts.strides[1]/4),
np.uint32(n_samples),
block=(threads_per_block, 1, 1), grid=(n_blocks, 1))
return x_shifts, y_shifts, shifts
开发者ID:surban,项目名称:ml,代码行数:26,代码来源:shift_gpu.py
示例15: format
def format(self, value, form, length=32):
""" Format a number based on a format character and length
"""
# get current gdb radix setting
radix = int(re.search("\d+", gdb.execute("show output-radix", True, True)).group(0))
# override it if asked to
if form == 'x' or form == 'a':
radix = 16
elif form == 'o':
radix = 8
elif form == 'b' or form == 't':
radix = 2
# format the output
if radix == 16:
# For addresses, probably best in hex too
l = int(math.ceil(length/4.0))
return "0x"+"{:X}".format(value).zfill(l)
if radix == 8:
l = int(math.ceil(length/3.0))
return "0"+"{:o}".format(value).zfill(l)
if radix == 2:
return "0b"+"{:b}".format(value).zfill(length)
# Default: Just return in decimal
return str(value)
开发者ID:molejar,项目名称:PyCortexMDebug,代码行数:26,代码来源:svd_gdb.py
示例16: add_header_and_rotate_timeline
def add_header_and_rotate_timeline(target, height, operations_height):
header_root = os.path.join(settings.BASE_DIR, 'base', 'static', 'doc', 'header.pdf')
result_root = os.path.join(settings.BASE_DIR, 'media', 'report.pdf')
pdf_target = PyPDF2.PdfFileReader(open(target, 'rb'))
pdf_header = PyPDF2.PdfFileReader(open(header_root, 'rb'))
pdf_writer = PyPDF2.PdfFileWriter()
total_pages = int(math.ceil(height / PIXELS_X_PAGE))
total_pages_x_rows = int(math.ceil(operations_height / ROWS_X_PAGE))
for page_num in range(pdf_target.getNumPages()):
pdf_target.getPage(page_num).mergePage(pdf_header.getPage(0))
if pdf_target.getNumPages() - 1 == 4 + total_pages_x_rows + total_pages:
total_pages -= 1
for page_num in range(pdf_target.getNumPages()):
page = pdf_target.getPage(page_num)
if (page_num >= (4 + total_pages_x_rows)) \
and (page_num <= (4 + total_pages_x_rows + total_pages)):
page.rotateClockwise(-90)
pdf_writer.addPage(page)
result = open(result_root, 'wb')
pdf_writer.write(result)
result.close()
开发者ID:ifreddyrondon,项目名称:atm-analytics,代码行数:26,代码来源:utils.py
示例17: getDurationString
def getDurationString(delta, showDays=True, showHours=True, showMinutes=True, showSeconds=False):
string = [""]
def appendDuration(num, singular, plural, showZero=False):
if (num < 0 or num > 1):
string[0] += "%d %s " % (num, plural)
elif (num == 1):
string[0] += "%d %s " % (num, singular)
elif(showZero):
string[0] += "%d %s " % (num, plural)
if (showDays):
appendDuration(delta.days, "day", "days")
if (showHours):
appendDuration(int(math.ceil(delta.seconds / 3600)), "hour", "hours")
if (showMinutes):
appendDuration(int(math.ceil((delta.seconds % 3600) / 60)), "minute", "minutes", showZero=True)
if (showSeconds):
appendDuration(delta.seconds % 60, "second", "seconds")
return string[0][:-1]
开发者ID:schme,项目名称:ChronalRobot,代码行数:25,代码来源:handmade_stream.py
示例18: attack
def attack(self, player, enemy):
player_accuracy = (ceil(player.attack_current / 2.0) + player.proficiency_current) - (ceil(enemy.defense_current / 2.0) + enemy.proficiency_current)
if player_accuracy < -10:
player_accuracy = -10
elif player_accuracy > 10:
player_accuracy = 10
player_accuracy = int(player_accuracy * 5) + 85 + randint(0, 5)
enemy_accuracy = (ceil(enemy.attack_current / 2.0) + enemy.proficiency_current) - (ceil(player.defense_current / 2.0) + player.proficiency_current)
if enemy_accuracy < -10:
enemy_accuracy = -10
elif enemy_accuracy > 10:
enemy_accuracy = 10
enemy_accuracy = int(enemy_accuracy * 5) + 85 + randint(0, 5)
player_damage = 0
enemy_damage = 0
state = "miss"
if randint(0, 100) <= player_accuracy:
player_damage = player.attack_current - int(enemy.defense_current * 0.65)
if player_damage < 0:
player_damage = 0
state = enemy.take_damage(player_damage)
if state == "alive" or state == "miss":
if randint(0, 100) <= enemy_accuracy:
enemy_damage = enemy.attack_current - int(player.defense_current * 0.65)
if enemy_damage < 0:
enemy_damage = 0
player.take_damage(enemy_damage)
return ("You attack, dealing {0} damage and taking {1} damage".format(player_damage, enemy_damage), curses.color_pair(2))
elif state == "miss":
return ("You miss and take {0}".format(enemy_damage), curses.color_pair(2))
elif state == "dead":
return ("You attack, dealing {0} damage".format(player_damage), curses.color_pair(2))
else:
raise ValueError("Unit is not alive or dead")
开发者ID:qrogers,项目名称:pyscape,代码行数:34,代码来源:combat_handler.py
示例19: plot_cost
def plot_cost(self):
if self.show_cost not in self.train_outputs[0][0]:
raise ShowNetError("Cost function with name '%s' not defined by given convnet." % self.show_cost)
train_errors = [o[0][self.show_cost][self.cost_idx] for o in self.train_outputs]
test_errors = [o[0][self.show_cost][self.cost_idx] for o in self.test_outputs]
numbatches = len(self.train_batch_range)
test_errors = numpy.row_stack(test_errors)
test_errors = numpy.tile(test_errors, (1, self.testing_freq))
test_errors = list(test_errors.flatten())
test_errors += [test_errors[-1]] * max(0,len(train_errors) - len(test_errors))
test_errors = test_errors[:len(train_errors)]
numepochs = len(train_errors) / float(numbatches)
pl.figure(1)
x = range(0, len(train_errors))
pl.plot(x, train_errors, 'k-', label='Training set')
pl.plot(x, test_errors, 'r-', label='Test set')
pl.legend()
ticklocs = range(numbatches, len(train_errors) - len(train_errors) % numbatches + 1, numbatches)
epoch_label_gran = int(ceil(numepochs / 20.)) # aim for about 20 labels
epoch_label_gran = int(ceil(float(epoch_label_gran) / 10) * 10) # but round to nearest 10
ticklabels = map(lambda x: str((x[1] / numbatches)) if x[0] % epoch_label_gran == epoch_label_gran-1 else '', enumerate(ticklocs))
pl.xticks(ticklocs, ticklabels)
pl.xlabel('Epoch')
# pl.ylabel(self.show_cost)
pl.title(self.show_cost)
开发者ID:01bui,项目名称:cuda-convnet,代码行数:28,代码来源:shownet.py
示例20: handle
def handle(self, *args, **options):
"""
Основной метод - точка входа
"""
query = Q()
urls = [
'allmychanges.com',
'stackoverflow.com',
]
for entry in urls:
query = query | Q(link__contains=entry)
items = Item.objects.exclude(query).order_by('?')
items_cnt = items.count()
train_size = math.ceil(items_cnt * (options['percent'] / 100))
# test_size = items_cnt - train_size
train_part_size = math.ceil(train_size / options['cnt_parts'])
train_set = items[:train_size]
test_set = items[train_size:]
for part in range(options['cnt_parts']):
name = 'data_{0}_{1}.json'.format(train_part_size, part)
queryset = train_set[part * train_part_size: (part + 1) * train_part_size]
create_dataset(queryset, name)
with open(os.path.join(settings.DATASET_FOLDER, 'test_set_ids.txt'), 'w') as fio:
fio.writelines(['%s\n' % x for x in test_set.values_list('id', flat=True)])
开发者ID:ivlevdenis,项目名称:pythondigest,代码行数:32,代码来源:create_dataset.py
注:本文中的math.ceil函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论