How to use selectindex method in pyatom

Best Python code snippet using pyatom_python

cardMagic.py

Source:cardMagic.py Github

copy

Full Screen

1typ=02if typ==0:3 import first.father as father4 import first.Database as database5 import first.cardMoreServent as moreS6 import first.buff as buff7 import first.cardGround as ground8 import first.cardMoreServent9 import first.cardServent10else:11 import father as father12 import Database as database13 import cardMoreServent as moreS14 import buff15 import cardGround as ground16import random17import re18import copy19def selectCards(ty,storage,haveUsed=[]):20 arr=[]21 for i in storage:22 if i.typeCard==ty and not(i in haveUsed):23 arr.append(i)24 return (arr[random.randint(0,len(arr)-1)]) if len(arr)!=0 else False25class sweeping(father.magic):26 name='sweeping'27 narrate='对所有随从造成1点伤害'28 def __init__(self) -> None:29 super().__init__()30 self.cost=['w']31 def ability(self, MyMaster, Master, selectIndex=None):32 for i in MyMaster.cardGround:33 i.live-=134 for ii in Master.cardGround:35 ii.live-=136class NaturalSelect(father.magic):37 name='NaturalSelect'38 narrate='使你的随从+1+1'39 def __init__(self) -> None:40 super().__init__()41 self.cost=['g','g']42 self.buffNar=buff.NaturalSelect()43 def ability(self, MyMaster, Master, selectIndex=None):44 for i in MyMaster.cardGround:45 i.buff.append(self.buffNar)46class BigClever(father.magic):47 name='BigClever'48 narrate='抽两张牌'49 def __init__(self) -> None:50 super().__init__()51 self.allCost=352 def ability(self, MyMaster, Master, selectIndex=None):53 MyMaster.getCard(2)54class GodPower(father.magic):55 name='GodPower'56 narrate='杀死一个随从,自己恢复4点血量'57 selectMode='osa'58 def __init__(self) -> None:59 super().__init__()60 self.allCost=261 self.cost=['w','w']62 def ability(self, MyMaster, Master, selectIndex=None):63 selectIndex.live-=999964 MyMaster.live+=465class ancientTsunami(father.magic):66 name='ancientTsunami'67 narrate='消灭所有随从'68 69 def __init__(self) -> None:70 super().__init__()71 self.cost=['bl' for i in range(7)]72 def ability(self, MyMaster, Master, selectIndex=None):73 for i in MyMaster.cardGround.copy():74 i.dieth(MyMaster,Master)75 for ii in Master.cardGround.copy():76 ii.dieth(Master,MyMaster)77class Mecha(father.magic):78 name='Mecha'79 narrate='选择一个随从,使其 +5+5'80 selectMode='osm'81 def __init__(self) -> None:82 super().__init__()83 self.cost=['g' for i in range(3)]84 self.allCost=285 self.buffNar=buff.Mecha()86 def ability(self, MyMaster, Master, selectIndex=None):87 selectIndex.buff.append(self.buffNar)88class Healing(father.magic):89 name='Healing'90 narrate='选择一个角色,恢复4血'91 selectMode='oaa'92 def __init__(self) -> None:93 super().__init__()94 self.cost=['w' for i in range(2)]95 def ability(self, MyMaster, Master, selectIndex=None):96 selectIndex.live+=497class Cannon(father.magic):98 name='Cannon'99 narrate='选择一个角色,造成5点伤害'100 selectMode='oaa'101 def __init__(self) -> None:102 super().__init__()103 self.cost=['r' for i in range(3)]104 def ability(self, MyMaster, Master, selectIndex=None):105 selectIndex.live-=5106class FlameThrower(father.magic):107 name='FlameThrower'108 narrate='对所有敌方随从造成4点伤害'109 def __init__(self) -> None:110 super().__init__()111 self.cost=['bl' for i in range(4)]112 def ability(self, MyMaster, Master, selectIndex=None):113 for i in Master.cardGround:114 i.live-=4115class FireBall(father.magic):116 name='FireBall'117 narrate='对一个随从造成2点伤害,抽一张牌'118 selectMode='oaa'119 def __init__(self) -> None:120 super().__init__()121 self.cost=['r' for i in range(2)]122 def ability(self, MyMaster, Master, selectIndex=None):123 selectIndex.live-=2124 MyMaster.getCard(1)125class SoulExplosion(father.magic):126 name='SoulExplosion'127 narrate='选择一个随从,造成4点伤害,溢出的伤害传给自己'128 selectMode='osa'129 def __init__(self) -> None:130 super().__init__()131 self.cost=['bk' for i in range(2)]132 def ability(self, MyMaster, Master, selectIndex=None):133 selectIndex.live-=4134 if selectIndex.Rlive()<0:135 MyMaster.live+=selectIndex.Rlive()136class NaturalGift(father.magic):137 name='NaturalGift'138 narrate='获得5种地'139 def __init__(self) -> None:140 super().__init__()141 self.allCost=2142 def ability(self, MyMaster, Master, selectIndex=None):143 MyMaster.cardHand+=[ground.Forest(),ground.Flame(),ground.Dark(),ground.Light(),ground.Ocean()]144class Blasphemy(father.magic):145 name='Blasphemy'146 narrate='对所有随从造成1点伤害,如果有随从死亡,再次释放该法术'147 def __init__(self) -> None:148 super().__init__()149 self.allCost=1150 self.cost=['bk' for i in range(2)]151 def ability(self, MyMaster, Master, selectIndex=None):152 check=False153 for i in MyMaster.cardGround.copy():154 i.live-=1155 if i.Rlive()<=0:156 check=True157 i.dieth(MyMaster, Master)158 for ii in Master.cardGround.copy():159 ii.live-=1160 if ii.Rlive()<=0:161 check=True162 ii.dieth(MyMaster, Master)163 if check==True:164 self.ability(MyMaster, Master)165class SpellOverload(father.magic):166 167 name='SpellOverload'168 narrate='消耗所有地,每消耗一个地,召唤一个1-1的幽灵'169 def __init__(self) -> None:170 super().__init__()171 self.cost=['g']172 def ability(self, MyMaster, Master, selectIndex=None):173 for i in MyMaster.termGround:174 for ii in range(i):175 MyMaster.cardGround.append(moreS.Phantom())176 MyMaster.termGround=[0,0,0,0,0]177class StageAComeback(father.magic):178 name='StageAComeback'179 narrate='复活所有死过的随从'180 def __init__(self) -> None:181 super().__init__()182 self.cost=['bk' for i in range(9)]183 def ability(self, MyMaster, Master, selectIndex=None):184 r=re.compile(r"'.+'")185 cop=MyMaster.tomb.copy()186 random.shuffle(cop)187 for i in cop:188 print(type(i))189 servent=eval((r.findall(str(type(i)))[0]).replace("'",'')+'()')190 MyMaster.cardGround.append(servent)191class Greed(father.magic):192 name='Greed'193 narrate='抽一张牌,如果牌的法力大于4,扣1滴血再抽一张'194 def __init__(self) -> None:195 super().__init__()196 self.allCost=1197 self.cost=['bk']198 def ability(self, MyMaster, Master, selectIndex=None):199 get=MyMaster.getCard(1)200 if len(get)>0:201 getArr=get[0]202 if len(getArr.Rcost(MyMaster, Master))+getArr.allCost>4:203 self.ability(MyMaster, Master)204 MyMaster.live-=1205class Lifemanship(father.magic):206 name='Lifemanship'207 narrate='所有随从获得冲锋'208 def __init__(self) -> None:209 super().__init__()210 self.cost=['r' for i in range(3)]211 def ability(self, MyMaster, Master, selectIndex=None):212 for i in MyMaster.cardGround.copy():213 i.sleep=False214class SummonSandworm(father.magic):215 name='SummonSandworm'216 narrate='对敌方所有随从造成4点伤害,我方所有随从+2攻击力'217 def __init__(self) -> None:218 super().__init__()219 self.cost=['r' for i in range(4)]220 self.allCost=3221 self.buffNar=buff.SummonSandworm()222 def ability(self, MyMaster, Master, selectIndex=None):223 for i in Master.cardGround.copy():224 i.live-=4225 for ii in MyMaster.cardGround.copy():226 ii.buff.append(self.buffNar)227class Reinforce(father.magic):228 name='Reinforce'229 narrate='从牌库里召唤2个随从,所有随从+1攻击力'230 def __init__(self) -> None:231 super().__init__()232 self.cost=['r' for i in range(6)]233 self.allCost=3234 self.buffNar=buff.Reinforce()235 def ability(self, MyMaster, Master, selectIndex=None):236 count=0237 for i in range(2):238 get=selectCards('servent',MyMaster.cardStorage)239 if get!=False:240 MyMaster.cardGround.append(get)241 MyMaster.cardStorage.remove(get)242 for ii in MyMaster.cardGround:243 ii.buff.append(self.buffNar)244class ElementAgitation(father.magic):245 name='ElementAgitation'246 narrate='召唤2个2-1的小火苗'247 def __init__(self) -> None:248 super().__init__()249 self.cost=['r' for i in range(2)]250 def ability(self, MyMaster, Master, selectIndex=None):251 MyMaster.cardGround.append(moreS.SmallFire())252 MyMaster.cardGround.append(moreS.SmallFire())253class ForestCover(father.magic):254 name='ForestCover'255 narrate='每有一张手牌,召唤一个2-2的树苗'256 def __init__(self) -> None:257 super().__init__()258 self.cost=['g' for i in range(3)]259 self.allCost=1260 def ability(self, MyMaster, Master, selectIndex=None):261 for i in range(len(MyMaster.cardHand)):262 MyMaster.cardGround.append(moreS.Sapling())263class DiffusePlague(father.magic):264 name='DiffusePlague'265 narrate='召唤1-5的甲虫,直到我方随从数量等于敌方随从数量'266 def __init__(self) -> None:267 super().__init__()268 self.cost=['bl' for i in range(4)]269 self.allCost=2270 def ability(self, MyMaster, Master, selectIndex=None):271 if len(MyMaster.cardGround)<len(Master.cardGround):272 for i in range(len(Master.cardGround)-len(MyMaster.cardGround)):273 MyMaster.cardGround.append(moreS.Beetle())274 else:275 MyMaster.cardGround.append(moreS.Beetle())276class WorldTreePower(father.magic):277 name='WorldTreePower'278 narrate='友方场上随从和牌库里的随从+5+5'279 def __init__(self) -> None:280 super().__init__()281 self.cost=['g' for i in range(8)]282 self.allCost=2283 self.buffNar=buff.WorldTreePower()284 def ability(self, MyMaster, Master, selectIndex=None):285 for i in MyMaster.cardGround:286 i.buff.append(self.buffNar)287 for ii in MyMaster.cardStorage:288 if ii.typeCard=='servent':289 ii.buff.append(self.buffNar)290class RainAndDew(father.magic):291 name='RainAndDew'292 narrate='+8+8分配给所有随从'293 def __init__(self) -> None:294 super().__init__()295 self.cost=['g' for i in range(4)]296 self.allCost=2297 self.buffNar=buff.RainAndDew()298 def ability(self, MyMaster, Master, selectIndex=None):299 for i in range(8):300 if len(MyMaster.cardGround)!=0:301 MyMaster.cardGround[random.randint(0,len(MyMaster.cardGround)-1)].buff.append(self.buffNar)302class ForestSpore(father.magic):303 name='ForestSpore'304 narrate='对所有敌方随从-1-1,对友方随从+1+1'305 def __init__(self) -> None:306 super().__init__()307 self.cost=['g' for i in range(3)]308 self.allCost=2309 self.buffNar=buff.ForestSpore()310 def ability(self, MyMaster, Master, selectIndex=None):311 for i in Master.cardGround:312 i.power-=1313 i.live-=1314 for ii in MyMaster.cardGround:315 ii.buff.append(self.buffNar)316class ExploreUnknow(father.magic):317 name='ExploreUnknow'318 narrate='抽两张牌,如果抽到的牌是法术则召唤1个2-2对树苗'319 def __init__(self) -> None:320 super().__init__()321 self.cost=['g' for i in range(3)]322 self.allCost=1323 def ability(self, MyMaster, Master, selectIndex=None):324 get=MyMaster.getCard(2)325 for i in get:326 if i.typeCard=='magic':327 MyMaster.cardGround.append(moreS.Sapling())328class GodGrace(father.magic):329 name='GodGrace'330 narrate='复活一个随从'331 def __init__(self) -> None:332 super().__init__()333 self.cost=['w' for i in range(2)]334 def ability(self, MyMaster, Master, selectIndex=None):335 if len(MyMaster.tomb)>0:336 r=re.compile(r"'.+'")337 getServent=MyMaster.tomb[random.randint(0,len(MyMaster.tomb)-1)]338 servent=eval((r.findall(str(type(getServent)))[0]).replace("'",'')+'()')339 MyMaster.cardGround.append(servent)340class HolyLightDispel(father.magic):341 name='HolyLightDispel'342 narrate='对敌方随从造成2点伤害,对我方随从恢复2点生命值'343 def __init__(self) -> None:344 super().__init__()345 self.cost=['w' for i in range(4)]346 def ability(self, MyMaster, Master, selectIndex=None):347 for i in Master.cardGround:348 i.live-=2349 for ii in MyMaster.cardGround:350 ii.live+=2351class HolyBlessing(father.magic):352 name='HolyBlessing'353 narrate='选择一个友方随从,使其生命翻倍'354 selectMode='osm'355 def __init__(self) -> None:356 super().__init__()357 self.cost=['w' for i in range(1)]358 self.allCost=2359 def ability(self, MyMaster, Master, selectIndex=None):360 selectIndex.live+=selectIndex.Rlive(MyMaster, Master)361 selectIndex.iniLive+=selectIndex.Rlive(MyMaster, Master)362class PuppetPossess(father.magic):363 name='PuppetPossess'364 narrate='复活三个随从,其生命和攻击力均为1'365 def __init__(self) -> None:366 super().__init__()367 self.cost=['w' for i in range(3)]368 self.allCost=1369 def ability(self, MyMaster, Master, selectIndex=None):370 r=re.compile(r"'.+'")371 cop=MyMaster.tomb.copy()372 random.shuffle(cop)373 print(cop)374 for i in range(3 if len(cop)>3 else len(cop)):375 376 servent=eval((r.findall(str(type(cop[i])))[0]).replace("'",'')+'()')377 servent.live=1378 servent.power=1379 MyMaster.cardGround.append(servent)380class HolySmite(father.magic):381 name='HolySmite'382 narrate='对一个随从造成3点伤害'383 selectMode='osa'384 def __init__(self) -> None:385 super().__init__()386 self.cost=['w']387 def ability(self, MyMaster, Master, selectIndex=None):388 selectIndex.live-=3389class Opportunity(father.magic):390 name='Opportunity'391 narrate='抽两张牌,如果是随从牌则恢复三点生命'392 def __init__(self) -> None:393 super().__init__()394 self.cost=['w' for i in range(3)]395 def ability(self, MyMaster, Master, selectIndex=None):396 get=MyMaster.getCard(2)397 for i in get:398 if i.typeCard=='servent':399 MyMaster.live+=3400class HeavyRain(father.magic):401 name='HeavyRain'402 narrate='抽两张牌,如果费用小于5则对所有敌方随从造成1点伤害'403 def __init__(self) -> None:404 super().__init__()405 self.cost=['bl' for i in range(3)]406 self.allCost=1407 def ability(self, MyMaster, Master, selectIndex=None):408 get=MyMaster.getCard(2)409 for i in get:410 if len(i.cost)+i.allCost<5:411 for ii in Master.cardGround:412 ii.live-=1413class AbyssDoor(father.magic):414 name='AbyssDoor'415 narrate='消灭场上所有随从,召唤一个所有随从属性总和的怪物'416 def __init__(self) -> None:417 super().__init__()418 self.cost=['bl' for i in range(8)]419 self.allCost=2420 def ability(self, MyMaster, Master, selectIndex=None):421 power=0422 live=0423 for i in MyMaster.cardGround.copy():424 power+=i.Rpower(MyMaster, Master)425 live+=i.Rlive(MyMaster, Master)426 i.dieth(MyMaster,Master)427 for ii in Master.cardGround.copy():428 power+=ii.Rpower(Master,MyMaster)429 live+=ii.Rlive(Master,MyMaster)430 ii.dieth(Master,MyMaster)431 servent=moreS.Cthulhu()432 servent.live+=live433 servent.iniLive+=live434 servent.power+=power435 servent.iniPower+=power436 MyMaster.cardGround.append(servent)437class LifeDrain(father.magic):438 name='LifeDrain'439 narrate="造成2点伤害,为我方英雄恢复2点生命"440 selectMode='oaa'441 def __init__(self) -> None:442 super().__init__()443 self.cost=['bk' for i in range(3)]444 def ability(self, MyMaster, Master, selectIndex=None):445 selectIndex.live-=2446 MyMaster.live+=2447class InterimAdjustment(father.magic):448 name='InterimAdjustment'449 narrate="为自己恢复5点生命值,抽一张牌"450 def __init__(self) -> None:451 super().__init__()452 self.cost=['w' for i in range(3)]453 def ability(self, MyMaster, Master, selectIndex=None):454 MyMaster.live+=5455 MyMaster.getCard(1)456class DoubleShot(father.magic):457 name='DoubleShot'458 narrate="对敌方随机两个随从造成2点伤害"459 def __init__(self) -> None:460 super().__init__()461 self.allCost=3462 def ability(self, MyMaster, Master, selectIndex=None):463 used=[]464 for i in range(2):465 get=selectCards('servent',Master.cardGround,used)466 if get!=False:467 used.append(get)468 get.live-=2469class InnerFire(father.magic):470 name='InnerFire'471 narrate="使一个随从的攻击力等于生命值"472 selectMode='osa'473 def __init__(self) -> None:474 super().__init__()475 self.cost=['w' for i in range(1)]476 self.buffNar=buff.InnerFire()477 def ability(self, MyMaster, Master, selectIndex=None):478 self.buffNar.buffType[0][1]=selectIndex.Rlive()-selectIndex.Rpower()479 selectIndex.buff.append(self.buffNar)480class UrgentRecruitment(father.magic):481 name='UrgentRecruitment'482 narrate="将你手牌的复制放入牌库"483 def __init__(self) -> None:484 super().__init__()485 self.allCost=3486 def ability(self, MyMaster, Master, selectIndex=None):487 for i in MyMaster.cardHand:488 MyMaster.cardStorage.append(copy.deepcopy(i))489class OceanCultivation(father.magic):490 name='OceanCultivation'491 narrate="加一点Ocean并抽一张牌"492 def __init__(self) -> None:493 super().__init__()494 self.cost=['bl' for i in range(3)]495 def ability(self, MyMaster, Master, selectIndex=None):496 MyMaster.groundList[1]+=1497 MyMaster.getCard(1)498class Scheming(father.magic):499 name='Scheming'500 narrate="选择一个随从,把其三张的复制塞入牌库"501 selectMode='osa'502 def __init__(self) -> None:503 super().__init__()504 self.cost=['bl' for i in range(2)]505 def ability(self, MyMaster, Master, selectIndex=None):506 for i in range(3):507 MyMaster.cardStorage.append(copy.deepcopy(selectIndex))508class SecretBlessings(father.magic):509 name='SecretBlessings'510 narrate="你卡牌里所有的牌的费用全部变成全比变成1蓝"511 def __init__(self) -> None:512 super().__init__()513 self.cost=['bl' for i in range(7)]514 def ability(self, MyMaster, Master, selectIndex=None):515 for i in MyMaster.cardStorage:516 i.allCost=0517 i.cost=['bl']518class Mimicry(father.magic):519 name='Mimicry'520 narrate="触发所有随从的亡语"521 def __init__(self) -> None:522 super().__init__()523 self.allCost=3524 def ability(self, MyMaster, Master, selectIndex=None):525 for i in MyMaster.cardGround:526 i.WangYu(MyMaster, Master)527class SellYourSoul(father.magic):528 name='SellYourSoul'529 narrate="杀死你的一个随从,是另外一个随从+4+4"530 selectMode='osm'531 def __init__(self) -> None:532 super().__init__()533 self.cost=['bk' for i in range(2)]534 self.buffNar=buff.SellYourSoul()535 def ability(self, MyMaster, Master, selectIndex=None):536 selectIndex.dieth(MyMaster,Master)537 if len(MyMaster.cardGround)!=0:538 MyMaster.cardGround[random.randint(0,len(MyMaster.cardGround))].buff.append(self.buffNar)539class ForestPlot(father.magic):540 name='ForestPlot'541 narrate="消灭场上所有随从,将场上的随从变成2-2的树苗"542 def __init__(self) -> None:543 super().__init__()544 self.cost=['g' for i in range(3)]545 self.allCost=1546 def ability(self, MyMaster, Master, selectIndex=None):547 for i in Master.cardGround.copy():548 i.dieth(Master,MyMaster)549 Master.cardGround.append(moreS.Sapling())550 for ii in MyMaster.cardGround.copy():551 ii.dieth(MyMaster,Master)552 MyMaster.cardGround.append(moreS.Sapling())553class DarkestOfDays(father.magic):554 name='DarkestOfDays'555 narrate="杀死你的一个随从,是所有友方随从+1+1"556 selectMode='osm'557 def __init__(self) -> None:558 super().__init__()559 self.cost=['bk' for i in range(1)]560 self.buffNar=buff.DarkestOfDays()561 def ability(self, MyMaster, Master, selectIndex=None):562 selectIndex.dieth(MyMaster,Master)563 for i in MyMaster.cardGround:...

Full Screen

Full Screen

activeLearning.py

Source:activeLearning.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Created on Thu Jan 17 15:04:40 201945@author: Unclered6"""7# 用主动学习的方式来增加数据打上标记89import numpy as np10import random11from math import log1213def randomSelect(restImages,restLabels,numIncre,inputSize=2500,numClass=35):14 # 随机选取一定数量的样本加上标记15 number = restImages.shape[0]16 indexList = range(number)17 selectIndex = random.sample(indexList, numIncre) # 从indexList中获得索引不相同的numIncre个元素18 increImages = np.zeros([numIncre,inputSize])19 increLabels = np.zeros([numIncre,numClass])20 for i in range(numIncre):21 increImages[i,:] = restImages[selectIndex[i],:]22 increLabels[i,:] = restLabels[selectIndex[i],:]23 minIndex = np.argsort(selectIndex)24 maxIndex = minIndex[::-1]25 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了26 for i in range(numIncre):27 select = maxIndex[i]28 restImages = np.delete(restImages,selectIndex[select],axis=0)29 restLabels = np.delete(restLabels,selectIndex[select],axis=0)30 return increImages, increLabels, restImages, restLabels3132def leastProb(restImages,restLabels,restProb,numIncre,inputSize=2500,numClass=35):33 # 获得最大概率与次大概率的差值,差值最小的就认为是最没有信心的。就加入进来34 number = restImages.shape[0]35 increImages = np.zeros([numIncre,inputSize])36 increLabels = np.zeros([numIncre,numClass])37 maxValueList = []38 maxIndex = np.argmax(restProb, axis=1)#最大值索引39 for i in range(number):40 maxValueList.append(restProb[i,maxIndex[i]])41 selectList = np.argsort(maxValueList)#从小到大排序42 selectIndex = selectList[:numIncre]#找寻最小的几个数 43 for i in range(numIncre):44 increImages[i,:] = restImages[selectIndex[i],:]45 increLabels[i,:] = restLabels[selectIndex[i],:]46 minIndex = np.argsort(selectIndex)47 maxIndex = minIndex[::-1]48 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了49 for i in range(numIncre):50 select = maxIndex[i]51 restImages = np.delete(restImages,selectIndex[select],axis=0)52 restLabels = np.delete(restLabels,selectIndex[select],axis=0)53 return increImages, increLabels, restImages, restLabels, maxValueList5455def entropySelect(restImages,restLabels,restProb,numIncre,inputSize=2500,numClass=35):56 # 用熵值来选取需要打标记的数据57 number = restImages.shape[0]58 entropyList = []59 increImages = np.zeros([numIncre,inputSize])60 increLabels = np.zeros([numIncre,numClass])61 for i in range(number):62 # 结束后获得一个信息熵列表63 entropy = 064 for j in range(numClass):65 # 获得每一个数据的信息熵66 entropy += restProb[i,j] * log(restProb[i,j], 2)67 entropyList.append(entropy) 68 selectList = np.argsort(entropyList) # 从小到大排序69 selectIndex = selectList[:numIncre] # 找寻最小的几个数 70 for i in range(numIncre):71 increImages[i,:] = restImages[selectIndex[i],:]72 increLabels[i,:] = restLabels[selectIndex[i],:]73 minIndex = np.argsort(selectIndex)74 maxIndex = minIndex[::-1]75 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了76 for i in range(numIncre):77 select = maxIndex[i]78 restImages = np.delete(restImages,selectIndex[select],axis=0)79 restLabels = np.delete(restLabels,selectIndex[select],axis=0)80 return increImages, increLabels, restImages, restLabels8182 83def marginSample(restImages,restLabels,restProb,numIncre,inputSize=2500,numClass=35):84 # 获得最大概率与次大概率的差值,差值最小的就认为是最没有信心的。就加入进来85 number = restImages.shape[0]86 increImages = np.zeros([numIncre,inputSize])87 increLabels = np.zeros([numIncre,numClass])88 maxValueList = []89 maxIndex = np.argmax(restProb, axis=1)#最大值索引90 for i in range(number):91 maxValueList.append(restProb[i,maxIndex[i]])92 restProb[i,maxIndex[i]] = 093 nextIndex = np.argmax(restProb, axis=1) # 次大值索引94 diffValueList = [maxValueList[i] - restProb[i,nextIndex[i]] for i in range(number)]95 selectList = np.argsort(diffValueList) # 从小到大排序96 selectIndex = selectList[:numIncre] # 找寻最小的几个数 97 for i in range(numIncre):98 increImages[i,:] = restImages[selectIndex[i],:]99 increLabels[i,:] = restLabels[selectIndex[i],:]100 minIndex = np.argsort(selectIndex)101 maxIndex = minIndex[::-1]102 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了103 for i in range(numIncre):104 select = maxIndex[i]105 restImages = np.delete(restImages,selectIndex[select],axis=0)106 restLabels = np.delete(restLabels,selectIndex[select],axis=0)107 return increImages, increLabels, restImages, restLabels, diffValueList108109def CSmarginSample(restImages,restLabels,restProb,numIncre,numGallery=25,inputSize=2500,numClass=35):110 # 获得最大概率与次大概率的差值,差值最小的就认为是最没有信心的。就加入进来111 # 对差值乘权重。同类权重为1,gi权重为2,ig权重为5?或者gi与ig权重相同会更好?112 # 毕竟也不一定是分类正确,只要可能分类错误就加倍更好113 # 信息熵的话,目测也有代价敏感信息熵?114 number = restImages.shape[0]115 increImages = np.zeros([numIncre,inputSize])116 increLabels = np.zeros([numIncre,numClass])117 maxValueList = []118 maxIndex = np.argmax(restProb, axis=1) # 最大值索引,也就是类别119 for i in range(number):120 maxValueList.append(restProb[i,maxIndex[i]])121 restProb[i,maxIndex[i]] = 0122 nextIndex = np.argmax(restProb, axis=1) # 次大值索引,也就是次大值类别123 diffValueList = [maxValueList[i] - restProb[i,nextIndex[i]] for i in range(number)]124 for i in range(number):125 if maxIndex[i] < numGallery and nextIndex[i] >= numGallery:126 diffValueList[i] = diffValueList[i] * 0.5 # gi的代价127 elif maxIndex[i] >= numGallery and nextIndex[i] < numGallery:128 diffValueList[i] = diffValueList[i] * 0.25 # ig的代价129 selectList = np.argsort(diffValueList) # 从小到大排序130 selectIndex = selectList[:numIncre] # 找寻最小的几个数 131 for i in range(numIncre):132 increImages[i,:] = restImages[selectIndex[i],:]133 increLabels[i,:] = restLabels[selectIndex[i],:]134 minIndex = np.argsort(selectIndex)135 maxIndex = minIndex[::-1]136 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了137 for i in range(numIncre):138 select = maxIndex[i]139 restImages = np.delete(restImages,selectIndex[select],axis=0)140 restLabels = np.delete(restLabels,selectIndex[select],axis=0)141 return increImages, increLabels, restImages, restLabels, diffValueList142 143def EQB(restImages,restLabels,restProb1,restProb2,restProb3,numIncre,numGallery=25,inputSize=2500,numClass=35): 144 number = restImages.shape[0]145 increImages = np.zeros([numIncre,inputSize])146 increLabels = np.zeros([numIncre,numClass])147 label1 = np.argmax(restProb1, axis=1) # 最大值索引,也就是类别148 label2 = np.argmax(restProb2, axis=1) # 最大值索引,也就是类别149 label3 = np.argmax(restProb3, axis=1) # 最大值索引,也就是类别150 entropy = [] # 依次计算每个样本的交叉熵,加负号这样就可以取最小151 for i in range(number):152 N={}153 Hbag = 0154 label = [label1[i],label2[i],label3[i]]155 # 制作类别列表156 for j in label:157 if j not in N:158 N[j] = 1159 else:160 N[j] += 1161 # 计算熵162 for key,value in N.items():163 P = value/3164 Hbag += P * log(P,10)165 entropy.append(Hbag)166 selectList = np.argsort(entropy) # 从小到大排序167 selectIndex = selectList[:numIncre] # 找寻最小的几个数 168 # print(selectIndex) 169 for i in range(numIncre):170 increImages[i,:] = restImages[selectIndex[i],:]171 increLabels[i,:] = restLabels[selectIndex[i],:]172 minIndex = np.argsort(selectIndex)173 maxIndex = minIndex[::-1]174 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了175 for i in range(numIncre):176 select = maxIndex[i]177 restImages = np.delete(restImages,selectIndex[select],axis=0)178 restLabels = np.delete(restLabels,selectIndex[select],axis=0)179 return increImages, increLabels, restImages, restLabels180181def CSEQB(restImages,restLabels,restProb1,restProb2,restProb3,numIncre,numGallery=25,inputSize=2500,numClass=35): 182 number = restImages.shape[0]183 increImages = np.zeros([numIncre,inputSize])184 increLabels = np.zeros([numIncre,numClass])185 label1 = np.argmax(restProb1, axis=1) # 最大值索引,也就是类别186 label2 = np.argmax(restProb2, axis=1) # 最大值索引,也就是类别187 label3 = np.argmax(restProb3, axis=1) # 最大值索引,也就是类别188 entropy = [] # 依次计算每个样本的交叉熵,加负号这样就可以取最小189 for i in range(number):190 key=[]191 value=[]192 Hbag = 0193 label = [label1[i],label2[i],label3[i]]194 # 制作类别列表195 for j in label:196 if j not in key:197 key.append(j)198 value.append(1)199 else:200 keyIndex=key.index(j)201 value[keyIndex] = value[keyIndex] + 1202 keyLabel = [m-numGallery+0.5 for m in key]203 # 计算熵204 if len(key) == 3:205 if keyLabel[0] * keyLabel[1] * keyLabel[2] < 0:206 if keyLabel[0]<0 and keyLabel[1]<0 and keyLabel[2]<0:207 Hbag=4208 else:209 Hbag=1210 else:211 if keyLabel[0]>0 and keyLabel[1]>0 and keyLabel[2]>0:212 Hbag=3213 else:214 Hbag=2215 elif len(key) == 2:216 if keyLabel[0] * keyLabel[1] < 0:217 Hbag=5218 else:219 Hbag=6220 elif len(key) == 1:221 Hbag=7222 entropy.append(Hbag)223 selectList = np.argsort(entropy) # 从小到大排序224 print(entropy[:25])225 selectIndex = selectList[:numIncre] # 找寻最小的几个数 226 # print(selectIndex) 227 for i in range(numIncre):228 increImages[i,:] = restImages[selectIndex[i],:]229 increLabels[i,:] = restLabels[selectIndex[i],:]230 minIndex = np.argsort(selectIndex)231 maxIndex = minIndex[::-1]232 # 根据索引删除数据一定要倒序删除。否则数据量减小,索引不再是原来的索引了233 for i in range(numIncre):234 select = maxIndex[i]235 restImages = np.delete(restImages,selectIndex[select],axis=0)236 restLabels = np.delete(restLabels,selectIndex[select],axis=0)237 return increImages, increLabels, restImages, restLabels238 239 240 241 242 243 244 245 246 247 248 ...

Full Screen

Full Screen

self_fieldsetting.py

Source:self_fieldsetting.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import kivy3kivy.require('1.11.0') # replace with your current kivy version !4import sys5import os6sys.path.append(os.path.join(os.path.dirname(__file__), ".." + os.sep + "sbase" + os.sep))7from kivy.lang import Builder8from kivy.uix.recycleview import RecycleView9from kivy.uix.recycleview.views import RecycleDataViewBehavior10from kivy.uix.label import Label11from kivy.properties import BooleanProperty12from kivy.uix.recycleboxlayout import RecycleBoxLayout13from kivy.uix.behaviors import FocusBehavior14from kivy.uix.recycleview.layout import LayoutSelectionBehavior15from kivy.uix.boxlayout import BoxLayout16from kivy.uix.floatlayout import FloatLayout17from kivy.uix.popup import Popup18from kivy.properties import ObjectProperty19import sconsts as CONSTS20import sutil21from selements import SLabel, SButton, SConfirmLayout, SDirSelectDialog22with open(os.path.join(os.path.dirname(__file__), "self_fieldsetting.kv"), encoding = "utf-8") as f:23 Builder.load_string(f.read())24class FieldSettingRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):25 ''' Adds selection and focus behaviour to the view. '''26class FieldSettingLabel(RecycleDataViewBehavior, Label):27 ''' Add selection support to the Label '''28 index = None29 selected = BooleanProperty(False)30 selectable = BooleanProperty(True)31 def refresh_view_attrs(self, rv, index, data):32 ''' Catch and handle the view changes '''33 self.index = index34 return super(FieldSettingLabel, self).refresh_view_attrs(35 rv, index, data)36 def on_touch_down(self, touch):37 ''' Add selection on touch down '''38 if super(FieldSettingLabel, self).on_touch_down(touch):39 return True40 if self.collide_point(*touch.pos) and self.selectable:41 return self.parent.select_with_touch(self.index, touch)42 def apply_selection(self, rv, index, is_selected):43 ''' Respond to the selection of items in the view. '''44 self.selected = is_selected45 if is_selected:46 rv.isSelectDict[index] = rv.data[index].get('text')47 else:48 rv.isSelectDict.pop(index, None)49 50class FieldSettingRV(RecycleView):51 52 isSelectDict = {}53 54 def __init__(self, **kwargs):55 super(FieldSettingRV, self).__init__(**kwargs)56 #self.data = [{'text': str(x)} for x in range(100)]57class SFieldSetting(BoxLayout):58 rightrv_id = ObjectProperty(None)59 ensurebtn_id = ObjectProperty(None)60 closebtn_id = ObjectProperty(None)61 sysConfDict = {}62 fieldSeqList = None63 kwargs = {}64 65 def __init__(self, refDict, **kwargs):66 super(SFieldSetting, self).__init__(**kwargs)67 self.app = refDict.get(CONSTS.S_APP)68 self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)69 70 filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")71 alist = sutil.getListFromFile(filePath)72 idDict = {}73 self.nameDict = {}74 seqList = []75 for astr in alist:76 tmpList = astr.strip().split(",")77 if len(tmpList) < 2:78 continue79 if tmpList[0] == "_SEQ_":80 seqList = tmpList[1].strip().split("|")81 else:82 idDict[tmpList[0]] = tmpList[1]83 self.nameDict[tmpList[1]] = tmpList[0]84 85 for seqId in seqList:86 adict = {}87 adict["text"] = idDict.get(seqId, "")88 self.rightrv_id.data.append(adict)89 def toUp(self):90 isSelectDict = self.rightrv_id.isSelectDict91 if len(isSelectDict) != 1:92 return93 94 selectIndex = list(isSelectDict.keys())[0]95 if selectIndex == 0:96 return97 adict = {}98 adict['text'] = isSelectDict.get(selectIndex)99 self.rightrv_id.data.pop(selectIndex)100 self.rightrv_id.data.insert(selectIndex - 1, adict)101 self.rightrv_id.layout_manager.selected_nodes = [selectIndex - 1]102 103 def toDown(self):104 isSelectDict = self.rightrv_id.isSelectDict105 if len(isSelectDict) != 1:106 return107 108 selectIndex = list(isSelectDict.keys())[0]109 if selectIndex == (len(self.rightrv_id.data) - 1):110 return111 adict = {}112 adict['text'] = isSelectDict.get(selectIndex)113 self.rightrv_id.data.pop(selectIndex)114 self.rightrv_id.data.insert(selectIndex + 1, adict)115 self.rightrv_id.layout_manager.selected_nodes = [selectIndex + 1]116 117 def toTop(self):118 isSelectDict = self.rightrv_id.isSelectDict119 if len(isSelectDict) != 1:120 return121 122 selectIndex = list(isSelectDict.keys())[0]123 if selectIndex == 0:124 return125 adict = {}126 adict['text'] = isSelectDict.get(selectIndex)127 self.rightrv_id.data.pop(selectIndex)128 self.rightrv_id.data.insert(0, adict)129 self.rightrv_id.layout_manager.selected_nodes = [0]130 131 def toBottom(self):132 isSelectDict = self.rightrv_id.isSelectDict133 if len(isSelectDict) != 1:134 return135 136 selectIndex = list(isSelectDict.keys())[0]137 if selectIndex == (len(self.rightrv_id.data) - 1):138 return139 adict = {}140 adict['text'] = isSelectDict.get(selectIndex)141 self.rightrv_id.data.pop(selectIndex)142 self.rightrv_id.data.append(adict)143 self.rightrv_id.layout_manager.selected_nodes = [len(self.rightrv_id.data) - 1]144 145 def saveData(self):146 filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")147 alist = sutil.getListFromFile(filePath) 148 with open(filePath, 'w', encoding = 'utf-8') as f:149 for tmpStr in alist:150 tmpList = tmpStr.strip().split(",")151 if len(tmpList) < 2:152 astr = tmpStr + "\n"153 f.write(astr)154 continue155 if tmpList[0] == "_SEQ_":156 aFieldId = None157 self.fieldSeqList = []158 astr = "_SEQ_,"159 for aDict in self.rightrv_id.data:160 aFieldId = self.nameDict.get(aDict.get("text"))161 astr += aFieldId + "|"162 self.fieldSeqList.append(aFieldId)163 astr = astr[0:-1] + "\n"164 else:165 astr = tmpStr + "\n" ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful