本文整理汇总了Python中Statistics.Statistics类的典型用法代码示例。如果您正苦于以下问题:Python Statistics类的具体用法?Python Statistics怎么用?Python Statistics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Statistics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getVehicleTypeAmount
def getVehicleTypeAmount(self):
from Statistics import Statistics
player = BigWorld.player()
vehicles = player.arena.vehicles
if player.playerVehicleID not in vehicles:
return
curVeh = vehicles[player.playerVehicleID]
Statistics.getInfos(curVeh['accountDBID'])
vehicles[player.playerVehicleID]['team']
amounts = {VEHICLE_CLASS_NAME.HEAVY_TANK:{'ally':0,'enemy':0},
VEHICLE_CLASS_NAME.MEDIUM_TANK:{'ally':0,'enemy':0},
VEHICLE_CLASS_NAME.LIGHT_TANK:{'ally':0,'enemy':0},
VEHICLE_CLASS_NAME.AT_SPG:{'ally':0,'enemy':0},
VEHICLE_CLASS_NAME.SPG:{'ally':0,'enemy':0}}
tiers = []
for accountDBID,entityObj in Statistics.getEmo().getAll().iteritems():
vID = g_sessionProvider.getCtx().getVehIDByAccDBID(accountDBID)
if vID in vehicles:
v_info = vehicles[vID]
tiers.append(v_info['vehicleType'].level)
if not BattleUtils.isMyTeam(v_info['team']):
tag = 'enemy'
else:
tag = 'ally'
for vehicleType in VEHICLE_TYPES_ORDER:
if vehicleType in v_info['vehicleType'].type.tags:
amounts[vehicleType][tag] += 1
currentTier = curVeh['vehicleType'].level
return (amounts,tiers,currentTier)
示例2: LoadDataForVisualisation
def LoadDataForVisualisation(self):
print 'Loading data for visualisation...'
Reader.read(self.filePath2)
self.data = Reader.load
self.dataStr = Reader.load2 #data i czas
self.data = Operations.CalculateToMetrics(self.data)
stat = Statistics(self.data,self.dataStr)
stat.makeStats()
self.UpdateStatsGUI(stat)
print 'All done.'
示例3: __init__
def __init__(self, genome):
""" The GPopulation Class creator """
if isinstance(genome, GPopulation):
self.oneSelfGenome = genome.oneSelfGenome
self.internalPop = []
self.internalPopRaw = []
self.popSize = genome.popSize
self.sortType = genome.sortType
self.sorted = False
self.minimax = genome.minimax
self.scaleMethod = genome.scaleMethod
self.allSlots = [self.scaleMethod]
self.internalParams = genome.internalParams
self.multiProcessing = genome.multiProcessing
try:
logging.debug("do I have a comm?")
self.mpi_comm = genome.mpi_comm
self.mpi_myeval = genome.mpi_myeval
self.mpi_full_copy = genome.mpi_full_copy
logging.debug("I do")
except:
logging.debug("I do not")
pass
self.statted = False
self.stats = Statistics()
return
logging.debug("New population instance, %s class genomes.", genome.__class__.__name__)
self.oneSelfGenome = genome
self.internalPop = []
self.internalPopRaw = []
self.popSize = 0
self.sortType = Consts.CDefPopSortType
self.sorted = False
self.minimax = Consts.CDefPopMinimax
self.scaleMethod = FunctionSlot("Scale Method")
self.scaleMethod.set(Consts.CDefPopScale)
self.allSlots = [self.scaleMethod]
self.internalParams = {}
self.multiProcessing = (False, False)
# Statistics
self.statted = False
self.stats = Statistics()
示例4: __init__
def __init__(self, genome):
""" The GPopulation Class creator """
if isinstance(genome, GPopulation):
#Cloning a population?
self.oneSelfGenome = genome.oneSelfGenome
self.internalPop = []
self.internalPopRaw = []
self.popSize = genome.popSize
self.sortType = genome.sortType
self.sorted = False
self.minimax = genome.minimax
self.scaleMethod = genome.scaleMethod
self.allSlots = [self.scaleMethod]
self.internalParams = genome.internalParams
self.multiProcessing = genome.multiProcessing
self.statted = False
self.stats = Statistics()
self.proc_pool = genome.proc_pool
return
logging.debug("New population instance, %s class genomes.", genome.__class__.__name__)
self.oneSelfGenome = genome
self.internalPop = []
self.internalPopRaw = []
self.popSize = 0
self.proc_pool = None
self.sortType = Consts.CDefPopSortType
self.sorted = False
self.minimax = Consts.CDefPopMinimax
self.scaleMethod = FunctionSlot("Scale Method")
self.scaleMethod.set(Consts.CDefPopScale)
self.allSlots = [self.scaleMethod]
self.internalParams = {}
self.multiProcessing = (False, False)
# Statistics
self.statted = False
self.stats = Statistics()
示例5: generateChart
def generateChart(self):
self.graphView.setScrollView(self.scrollView)
stat = Statistics(self.startDate, self.endDate)
if self.reportType == "tasks":
self.graphView.setData(stat.countTasks(), self.reportType)
elif self.reportType == "projects":
self.graphView.setData(stat.countProjects(), self.reportType)
elif self.reportType == "slacking":
self.graphView.setData(stat.countSlacking(), self.reportType)
self.graphView.setScale(stat.maxValue)
self.lblWorkTotal.setStringValue_(secToTimeStr(stat.totalWork))
self.lblAvgWork.setStringValue_(secToTimeStr(stat.avgWork))
self.lblSlackTotal.setStringValue_(secToTimeStr(stat.totalSlacking))
self.lblAvgSlack.setStringValue_(secToTimeStr(stat.avgSlacking))
self.graphView.setNeedsDisplay_(True)
示例6: __init__
def __init__(self, genome):
""" The GPopulation Class creator """
logging.debug("New population instance, %s class genomes.", genome.__class__.__name__)
self.oneSelfGenome = genome
self.internalPop = []
self.popSize = 0
self.sortType = Consts.CDefPopSortType
self.sorted = False
self.minimax = Consts.CDefPopMinimax
self.scaleMethod = FunctionSlot("Scale Method")
self.scaleMethod.set(Consts.CDefPopScale)
self.allSlots = [self.scaleMethod]
# Statistics
self.statted = False
self.stats = Statistics()
示例7: __init__
def __init__(self):
self.dataset = None
self.Graph = nx.DiGraph()
self.K =2
self.items = dict()
self.stats = Statistics()
示例8: GraphDrawer
class GraphDrawer():
def __init__(self):
self.dataset = None
self.Graph = nx.DiGraph()
self.K =2
self.items = dict()
self.stats = Statistics()
def build_graph(self, dataset, keys):
self.dataset = dataset
for sessionID in keys:
try:
session_purchases = self.dataset[sessionID]
except:
print sessionID
session_states = self.extract_states(session_purchases)
self.insert_states(session_states)
# self.print_edges_data()
self.mark_popular_item()
self.stats.num_of_edges = self.Graph.number_of_edges()
self.stats.num_of_nodes = self.Graph.number_of_nodes()
def mark_popular_item(self):
max = 0
for item in self.items.keys():
if self.items[item] > max:
max = self.items[item]
self.most_popular_item = item
def print_all_nodes(self):
for n in self.Graph.nodes(): print str(n)
def print_all_edges(self):
for e in self.Graph.edges(): print e
def print_successors(self,source_state):
succ_list = self.Graph.successors(source_state)
for succ in succ_list: print succ
def print_edges_data(self):
for edge in self.Graph.edges():
print '{0} --> {1} {2}'.format(edge[0], edge[1],self.Graph.get_edge_data(edge[0], edge[1], None))
def draw(self):
# nx.draw(self.Graph)
# nx.draw_networkx(self.Graph)
pos = nx.shell_layout(self.Graph)
nx.draw(self.Graph, pos)
# show graph
plt.show()
raw_input('press any key to continue')
def fit(self):
"""
this method goes over all nodes and counts the number of out edges,
then, it normalize the weight of each edge according to:
for each node t in successor(s) do:
sum += weight(s,t)
for each node t in successors(s) do:
normalized_weight(s,t) = weight(s,t)/sum
:return: void
"""
nodes = self.Graph.nodes()
print "---- number of nodes in the graph = {0}".format(len(nodes))
for curr_node in nodes:
node_successors = self.Graph.successors(curr_node)
sum = 0
for s in node_successors:
edge_data =self.Graph.get_edge_data(curr_node, s, None)
# print edge_data
count = edge_data[Config.COUNT]
sum += count
# print sum
# print 'curr: ' + str(curr_node)
for s in node_successors:
count = self.Graph[curr_node][s][Config.COUNT]
self.Graph[curr_node][s][Config.WEIGHT] = float(count) / float(sum)
# print 'succ: ' + str(s) + ' ' + str(self.Graph[curr_node][s])
def predict(self,testset):
"""
:param testset: a map - 'itemIP' --> list<Purchase>
the main idea is:
1. for each session
1.1 hide the last item purchased
1.2 predict the last item using the model
1.3 save the
"""
y_true = []
y_pred = []
y_score = []
for key in testset.keys():
sequence = testset[key]
seq_length = len(sequence)
#.........这里部分代码省略.........
示例9: Configuration
CONFIG = Configuration()
#Load Hashcodes from File
DATABASE = set()
try:
DATABASE_FILE = open(CONFIG.DATABASE_FILE_PATH, 'r')
except:
DATABASE_FILE = open(CONFIG.DATABASE_FILE_PATH, 'w+')
logging.info("Created New Database %s", CONFIG.DATABASE_FILE_PATH)
print "Loading Database...."
for line in DATABASE_FILE:
DATABASE.add(line.replace('\n', ''))
logging.info("Loaded %i mail hash values from database", len(DATABASE))
STATS = Statistics(len(DATABASE))
DATABASE_FILE.close()
#Open Database-File for appending new HashCodes
DATABASE_FILE = open(CONFIG.DATABASE_FILE_PATH, 'a')
print "Connecting to Server..."
#Init Mail Connection
MAIL_CONNECTION = imaplib.IMAP4_SSL(CONFIG.MAIL_SERVER, CONFIG.MAIL_PORT) if CONFIG.MAIL_PORT else imaplib.IMAP4_SSL(CONFIG.MAIL_SERVER)
try:
MAIL_CONNECTION.login(CONFIG.MAIL_USER, CONFIG.MAIL_PASSWORD)
logging.info("Successfully connected to %[email protected]%s", CONFIG.MAIL_USER, CONFIG.MAIL_SERVER)
except imaplib.IMAP4.error as e:
print "Failed to connect"
logging.error("Could not connect to %[email protected]%s", CONFIG.MAIL_USER, CONFIG.MAIL_SERVER)
logging.error("Reason: %s", e)
exit(1)
示例10: Shaper
myShaper = Shaper({
'capacity': capacity,
'full_watermark': full_watermark,
'hot_watermark': hot_watermark,
'write_seq_threshold': write_seq_threshold
})
myShaper.run('./output/gen.csv','./output/optimize.csv')
myShaper.print_io_count()
##############################################################
#400GB SSD with optimizer
myStat = Statistics({
'file' : './output/optimize.csv',
'ssd_size' : 200*1024*1024,
'ssd_seq_write' : 400*1024*1024,
'ssd_seq_read' : 500*1024*1024,
'ssd_ran_write' : 80*1000,
'ssd_ran_read' : 100*1000,
'ssd_read_hit' : 0.91,
'hdd_seq_write' : 400*1024*1024,
'hdd_seq_read' : 500*1024*1024,
'hdd_ran_write' : 1400,
'hdd_ran_read' : 1400
})
myStat.run()
text_file.write("%d,%d,%f\n" % (genRange,bufSize,myStat.total_time))
text_file.close()
exit(1)
示例11: test_statistics
def test_statistics(clean=False, language='en'):
lib = Library(cleaning=clean)
lib.load_library(language=language)
st = Statistics(books=lib.get_books(),authors=lib.get_authors())
st.collect_statistics()
示例12: xrange
class GPopulation:
""" GPopulation Class - The container for the population
**Examples**
Get the population from the :class:`GSimpleGA.GSimpleGA` (GA Engine) instance
>>> pop = ga_engine.getPopulation()
Get the best fitness individual
>>> bestIndividual = pop.bestFitness()
Get the best raw individual
>>> bestIndividual = pop.bestRaw()
Get the statistics from the :class:`Statistics.Statistics` instance
>>> stats = pop.getStatistics()
>>> print stats["rawMax"]
10.4
Iterate, get/set individuals
>>> for ind in pop:
>>> print ind
(...)
>>> for i in xrange(len(pop)):
>>> print pop[i]
(...)
>>> pop[10] = newGenome
>>> pop[10].fitness
12.5
:param genome: the :term:`Sample genome`
"""
def __init__(self, genome):
""" The GPopulation Class creator """
logging.debug("New population instance, %s class genomes.", genome.__class__.__name__)
self.oneSelfGenome = genome
self.internalPop = []
self.popSize = 0
self.sortType = Consts.CDefPopSortType
self.sorted = False
self.minimax = Consts.CDefPopMinimax
self.scaleMethod = FunctionSlot("Scale Method")
self.scaleMethod.set(Consts.CDefPopScale)
self.allSlots = [self.scaleMethod]
# Statistics
self.statted = False
self.stats = Statistics()
def setMinimax(minimax):
""" Sets the population minimax
Example:
>>> pop.setMinimax(Consts.minimaxType["maximize"])
:param minimax: the minimax type
"""
self.minimax = minimax
def __repr__(self):
""" Returns the string representation of the population """
ret = "- GPopulation\n"
ret += "\tPopulation Size:\t %d\n" % (self.popSize,)
ret += "\tSort Type:\t\t %s\n" % (Consts.sortType.keys()[Consts.sortType.values().index(self.sortType)].capitalize(),)
ret += "\tMinimax Type:\t\t %s\n" % (Consts.minimaxType.keys()[Consts.minimaxType.values().index(self.minimax)].capitalize(),)
for slot in self.allSlots:
ret+= "\t" + slot.__repr__()
ret+="\n"
ret+= self.stats.__repr__()
return ret
def __len__(self):
""" Return the length of population """
return len(self.internalPop)
def __getitem__(self, key):
""" Returns the specified individual from population """
return self.internalPop[key]
def __iter__(self):
""" Returns the iterator of the population """
return iter(self.internalPop)
def __setitem__(self, key, value):
""" Set an individual of population """
self.internalPop[key] = value
self.__clear_flags()
def __clear_flags(self):
self.sorted = False
self.statted = False
def getStatistics(self):
""" Return a Statistics class for statistics
#.........这里部分代码省略.........
示例13: __init__
def __init__(self):
# all variables here
self.TOTAL_TIME = 15000
self.NUM_OF_CARS = 200000
self.DELTA_TIME = 0.05
self.PERCENT_OF_CARS = [0.3,0.7]
# Units: m/delta_t
self.AVG_SPEED_OF_CARS = {'s': 30, 'm': 25, 'b': 20}
self.STD_DEV_OF_CARS = {'s': 10, 'm':10, 'b': 10}
# Units: m
self.LENGTHS_OF_CARS = {'s': 5, 'm': 7, 'b': 10}
self.VISIBLE_DISTANCE_OF_CARS = {'s': 70, 'm': 80, 'b': 90}
# Units: m/delta_t
self.MIN_SPEED = 15
self.MAX_SPEED = 60
# Units: m
self.ROAD_LENGTH = 5000
self.SAFE_DISTANCE_BETWEEN_CARS = 20
''' this affects accident rate a lot'''
self.INITIAL_DISTANCE_BETWEEN_CARS = 80
self._recycledIndexes = set()
self.all_cars = []
self.current_num_of_cars = 0
self.stat = Statistics()
self.generateCar(self.generateIndex())
for time in range(self.TOTAL_TIME):
if self.needToGenerateCars():
self.generateCar(self.generateIndex())
## print("New Car generated")
## print(self._recycledIndexes)
## print()
num_of_cars_on_r = 0
num_of_cars_on_l = 0
total_speed_on_r = 0
total_speed_on_l = 0
for i in range(len(self.all_cars)):
each = self.all_cars[i]
if each == None:
self._recycledIndexes.add(i)
continue
if each.position > self.ROAD_LENGTH:
self.all_cars[i] = None
self._recycledIndexes.add(i)
## print(each.index, "th car reaches the end of the road!")
## print(self._recycledIndexes)
continue
## print(each.index, "th car: ", each.position, " lane: ", each.lane)
## print()
each.move(self.all_cars)
###################################################Statistics################################
if each.lane == 'r':
num_of_cars_on_r += 1
total_speed_on_r += each.Vcurrent
elif each.lane == 'l':
num_of_cars_on_l += 1
total_speed_on_l += each.Vcurrent
self.stat.listIncrease("density_of_r", time, num_of_cars_on_r / self.ROAD_LENGTH)
self.stat.listIncrease("density_of_l", time, num_of_cars_on_l / self.ROAD_LENGTH)
if num_of_cars_on_r == 0:
self.stat.listIncrease("avg_speed_on_r", time, 0)
else:
self.stat.listIncrease("avg_speed_on_r", time, total_speed_on_r / num_of_cars_on_r)
if num_of_cars_on_l == 0:
self.stat.listIncrease("avg_speed_on_l", time, 0)
else:
self.stat.listIncrease("avg_speed_on_l", time, total_speed_on_l / num_of_cars_on_l)
time += self.DELTA_TIME
print("accident rate: ", self.stat.getRate("num_of_accidents", "num_of_cars_generated"))
print("succussful passing rate: ", self.stat.getRate("successful_passings", "passing_intents"))
writeToFile(self.stat.getList("density_of_r"), "density_of_r.txt")
writeToFile(self.stat.getList("density_of_l"), "density_of_l.txt")
writeToFile(self.stat.getList("avg_speed_on_r"), "avg_speed_on_r.txt")
writeToFile(self.stat.getList("avg_speed_on_l"), "avg_speed_on_l.txt")
示例14: xrange
class GPopulation:
""" GPopulation Class - The container for the population
**Examples**
Get the population from the :class:`GSimpleGA.GSimpleGA` (GA Engine) instance
>>> pop = ga_engine.getPopulation()
Get the best fitness individual
>>> bestIndividual = pop.bestFitness()
Get the best raw individual
>>> bestIndividual = pop.bestRaw()
Get the statistics from the :class:`Statistics.Statistics` instance
>>> stats = pop.getStatistics()
>>> print stats["rawMax"]
10.4
Iterate, get/set individuals
>>> for ind in pop:
>>> print ind
(...)
>>> for i in xrange(len(pop)):
>>> print pop[i]
(...)
>>> pop[10] = newGenome
>>> pop[10].fitness
12.5
:param genome: the :term:`Sample genome`, or a GPopulation object, when cloning.
"""
def __init__(self, genome):
""" The GPopulation Class creator """
if isinstance(genome, GPopulation):
#Cloning a population?
self.oneSelfGenome = genome.oneSelfGenome
self.internalPop = []
self.internalPopRaw = []
self.popSize = genome.popSize
self.sortType = genome.sortType
self.sorted = False
self.minimax = genome.minimax
self.scaleMethod = genome.scaleMethod
self.allSlots = [self.scaleMethod]
self.internalParams = genome.internalParams
self.multiProcessing = genome.multiProcessing
self.statted = False
self.stats = Statistics()
self.proc_pool = genome.proc_pool
return
logging.debug("New population instance, %s class genomes.", genome.__class__.__name__)
self.oneSelfGenome = genome
self.internalPop = []
self.internalPopRaw = []
self.popSize = 0
self.proc_pool = None
self.sortType = Consts.CDefPopSortType
self.sorted = False
self.minimax = Consts.CDefPopMinimax
self.scaleMethod = FunctionSlot("Scale Method")
self.scaleMethod.set(Consts.CDefPopScale)
self.allSlots = [self.scaleMethod]
self.internalParams = {}
self.multiProcessing = (False, False)
# Statistics
self.statted = False
self.stats = Statistics()
#---------------------------------------------------------------------------------
def setMultiProcessing(self, flag=True, full_copy=False, number_of_processes=None):
""" Sets the flag to enable/disable the use of python multiprocessing module.
Use this option when you have more than one core on your CPU and when your
evaluation function is very slow.
The parameter "full_copy" defines where the individual data should be copied back
after the evaluation or not. This parameter is useful when you change the
individual in the evaluation function.
:param flag: True (default) or False
:param full_copy: True or False (default)
:param number_of_processes: None = use the default, or specify the number
.. warning:: Use this option only when your evaluation function is slow, se you
will get a good tradeoff between the process communication speed and the
parallel evaluation.
"""
#Save the parameters
old_settings = self.multiProcessing
self.multiProcessing = (flag, full_copy, number_of_processes)
#Re-initialize if anything changed.
if (old_settings != self.multiProcessing):
#.........这里部分代码省略.........
示例15: setup
def setup(env, num_gates, wait_time, t_inter):
airport = Airport(env, num_gates, wait_time)
for i in range(1):
env.process(plane(env, 'Plane %d' % i, airport))
stats.addArrivals()
usage_res = env.now
while True:
yield env.timeout(random.randint(t_inter-2, t_inter+2))
i += 1
env.process(plane(env, 'Plane %d' % i, airport))
stats.addArrivals()
#print(airport.num_gates.count)
if not airport.open:
stats.addBusyTime(env.now - usage_res)
usage_res = env.now
stats = Statistics(SIM_TIME)
stats.setNumRecursos(NUM_GATES)
random.seed(RANDOM_SEED)
env = simpy.Environment()
env.process(setup(env, NUM_GATES, WAIT_TIME, T_INTER))
env.run(until=SIM_TIME)
stats.printStats("Airport")