def menu():
    while (True):
        print("\nWhat algorithm you want to launch?")
        print('1. FCFS')
        print('2. SJF')
        print('3. Priority')
        print('4. RoundRobin')
        z = input('(1-4): ')
        print()
        if z == '1':
            fcfs = FCFS(list_processes)
            fcfs.run()
        elif z == '2':
            sjf = SJF(list_processes)
            sjf.run()
        elif z == '3':
            pr = Priority(list_processes)
            pr.run()
        elif z == '4':
            quantumn_time = float(input('Quantumn time: '))
            rr = RoundRobin(list_processes, quantumn_time)
            rr.run()
        else:
            print("Wrong input")
            pass
class Classifier:

  #constructor
  def __init__(self):
    self.assessments = Assessments()
    self.authority = Authority()
    self.causation = Causation()
    self.conditionals = Conditionals()
    self.contrast = Contrast()
    self.difficulty = Difficulty()
    self.doubt = Doubt()
    self.emphasis = Emphasis()
    self.generalization = Generalization()
    self.inconsistency = Inconsistency()
    self.inyourshoes = Inyourshoes()
    self.necessity = Necessity()
    self.possibility = Possibility()
    self.priority = Priority()
    self.rhetoricalquestion = Rhetoricalquestion()
    self.structure = Structure()
    self.wants = Wants()


  def list_categories_names(self):
    return ["Assessments","Authority","Causation","Conditionals","Contrast","Difficulty","Doubt","Emphasis","Generalization","Inconsistency","Inyourshoes","Necessity","Possibility","Priority","Rhetoricalquestion","Structure","Wants"]


  # function to count Assessments n-grams from text
  def analyse(self,text):

    result = []

    # counter of ngrams matched
    ngrams = 0

    # Analyse the text for each category
    result.append(self.assessments.analyse(text))
    result.append(self.authority.analyse(text))
    result.append(self.causation.analyse(text))
    result.append(self.conditionals.analyse(text))
    result.append(self.contrast.analyse(text))
    result.append(self.difficulty.analyse(text))
    result.append(self.doubt.analyse(text))
    result.append(self.emphasis.analyse(text))
    result.append(self.generalization.analyse(text))
    result.append(self.inconsistency.analyse(text))
    result.append(self.inyourshoes.analyse(text))
    result.append(self.necessity.analyse(text))
    result.append(self.possibility.analyse(text))
    result.append(self.priority.analyse(text))
    result.append(self.rhetoricalquestion.analyse(text))
    result.append(self.structure.analyse(text))
    result.append(self.wants.analyse(text))

    #normalize all categories count by percentage
    ngrams = sum(i for i in result)
    result = list(map((lambda x: round(float(x)/ngrams,5)), result))


    return result
Exemplo n.º 3
0
    def find_most_anamalous_records_given_streams(self,cur_anamalous_streams,stream_ids, location_ids, counts, baselines,distribution_type, type_of_test):
        print  sys._getframe().f_code.co_name
        aggregate_counts, aggregate_baselines = self.aggregate_counts_baselines_across_streams(cur_anamalous_streams, stream_ids,location_ids,counts,baselines)
        pr = Priority()
        priorities_locations = pr.calculate_priority(aggregate_counts,aggregate_baselines,distribution_type, type_of_test)

        priorities_locations_df = pd.DataFrame(priorities_locations)
        location_ids_df = pd.DataFrame(location_ids)
        aggregate_counts_df = pd.DataFrame(aggregate_counts)
        aggregate_baselines_df = pd.DataFrame(aggregate_baselines)
        frame = [location_ids_df,priorities_locations_df,aggregate_counts_df,aggregate_baselines_df]
        final_frame = pd.concat(frame , axis =1 )
        #print final_frame
        final_frame.columns = ['locations' , 'priorities' , 'counts', 'baselines']
        final_frame= final_frame.sort(['priorities'], ascending=[False])
        print final_frame
        max_f_score = None
        max_score_index = None
        counts= np.array(final_frame['counts'])
        baselines = np.array(final_frame['baselines'])
        locations = np.array(final_frame['locations'])
        priorities = np.array(final_frame['priorities'])
        print counts,baselines,locations,priorities
      # This for loop scans over all the subsets containing top-j priority records and compute their score F(S)

        for i in range(1,len(final_frame)):
            sfn=ScoringFunctions()
            f_score_i = sfn.f_score_statistic_subset_aggregation(counts[0:i], baselines[0:i], distribution_type, type_of_test)
            print "Fscore per records subset for a set of streams"
            print f_score_i
            if max_f_score == None:
                max_f_score =  f_score_i
                max_score_index = i
            elif max_f_score < f_score_i :
                 max_f_score =  f_score_i
                 max_score_index = i
            else:
                 max_f_score = max_f_score
                 max_score_index = max_score_index

        most_anamalous_subset = []
        for i in range(0, max_score_index):
                print final_frame['locations'][i]
                most_anamalous_subset.append(final_frame['locations'][i])
        print "anamalous records"
        print most_anamalous_subset
        return most_anamalous_subset,max_f_score
 def __init__(self):
   self.assessments = Assessments()
   self.authority = Authority()
   self.causation = Causation()
   self.conditionals = Conditionals()
   self.contrast = Contrast()
   self.difficulty = Difficulty()
   self.doubt = Doubt()
   self.emphasis = Emphasis()
   self.generalization = Generalization()
   self.inconsistency = Inconsistency()
   self.inyourshoes = Inyourshoes()
   self.necessity = Necessity()
   self.possibility = Possibility()
   self.priority = Priority()
   self.rhetoricalquestion = Rhetoricalquestion()
   self.structure = Structure()
   self.wants = Wants()
Exemplo n.º 5
0
def menu():
    print("\nWhat algorithm you want to launch?")
    print('1. FCFS')
    print('2. SJF')
    print('3. Priority')
    print('4. End')
    z = int(input('(1-4):'))
    if z == 1:
        fcfs = FCFS(words)
        fcfs.run()
    elif z == 2:
        sjf = SJF(words)
        sjf.run()
    elif z == 3:
        pr = Priority(words)
        pr.run()
    elif z == 4:
        pass
    else:
        print("Wrong input")
        menu()
Exemplo n.º 6
0
    def find_most_anamalous_streams_given_records(self, cur_anamalous_locations ,counts,baselines,stream_ids,location_ids,distribution_type, type_of_test):
        print  sys._getframe().f_code.co_name
        stream_counts , stream_baselines = self.aggregate_counts_baselines_over_the_records(cur_anamalous_locations,stream_ids,location_ids,counts,baselines)
        pr=Priority()
        priorities_streams = pr.calculate_priority(stream_counts,stream_baselines,distribution_type, type_of_test)
        priorities_streams_df = pd.DataFrame(priorities_streams)
        stream_ids_df = pd.DataFrame(stream_ids)
        stream_counts_df = pd.DataFrame(stream_counts)
        stream_baselines_df = pd.DataFrame(stream_baselines)
        frame = [stream_ids_df,priorities_streams_df,stream_counts_df,stream_baselines_df]
        final_frame = pd.concat(frame , axis =1 )
        final_frame.columns = ['stream_ids' , 'priorities' , 'stream_counts','stream_baselines']
        final_frame= final_frame.sort(['priorities'], ascending=[False])
        counts= np.array(final_frame['stream_counts'])
        baselines = np.array(final_frame['stream_baselines'])
        streams = np.array(final_frame['stream_ids'])
        priorities = np.array(final_frame['priorities'])
        max_f_score = None
        max_score_index = None

        # This for loop scans over all the subsets containing top-j priority records and compute their score F(S)
        for i in range(0,len(final_frame)):
            sfn=ScoringFunctions()
            f_score_i = sfn.f_score_statistic(counts[0:i], baselines[0:i], distribution_type, type_of_test)
            if max_f_score == None:
                max_f_score =  f_score_i
                max_score_index = i
            elif max_f_score < f_score_i :
                 max_f_score =  f_score_i
                 max_score_index = i
            else:
                 max_f_score = max_f_score
                 max_score_index = max_score_index

        most_anamalous_subset = []
        for i in range(0, max_score_index):
                most_anamalous_subset.append(final_frame['stream_ids'][i])
        print "Most anamalous streams"
        print most_anamalous_subset
        return most_anamalous_subset,max_f_score
Exemplo n.º 7
0
    def __init__(self,
                 tree_structure: TreeStructure,
                 deterministic: bool = True):
        """
        Constructor

        Parameters
        ----------
        tree_structure
            TreeStructure
        """
        self.tree: TreeStructure = tree_structure
        self.to_replace: int = 2
        self.deterministic = deterministic

        priority_size: int = (self.tree.number_of_ancestors *
                              (self.tree.gene_number + 500)) * 2
        self.priorities: List[Priority] = [
            Priority(priority_size) for _ in range(163)
        ]
Exemplo n.º 8
0

PID_need_reset = False
oldValue = 0.0
integral = 0.0

sche = None
preemption = False
scheMethod = 'Priority'

if scheMethod == 'EDF':
    sche = EDF(preemption)
elif scheMethod == 'FIFO':
    sche = FIFO()
elif scheMethod == 'Priority':
    sche = Priority(preemption)
elif scheMethod == 'RoundRobin':
    sche = RoundRobin()


def applyPID(yellow_line_angle):
    global PID_need_reset
    global oldValue
    global integral
    if PID_need_reset:
        oldValue = yellow_line_angle
        integral = 0.0
        PID_need_reset = False

    sign = lambda x: math.copysign(1, x)
    if sign(yellow_line_angle) != sign(oldValue):
from fcfs import fcfs
from Priority import Priority
from RR import RR
from sjf import sjf
n=int(input("Enter the number of processes: "))
proc=[]
for i in range(n):
    print("Process: ",i+1,":--")
    b=int(input("\tEnter Burst time: "))
    a=int(input("\tEnter arrival time: "))
    p=int(input("\tEnter priority: "))
    proc.append([i+1,b,a,p])
quantum =int(input("Enter the Quantum: "))
f=fcfs()
p=Priority()
r=RR()
s=sjf()
print("\t\t:: Scheduling Algorithm ::")
print("<===============================================>")
print("FCFS:")
f.findavgTime(proc,n)
print("<===============================================>")
print("\nSJF:")
s.findavgTime(proc, n)
print("<===============================================>")
print("\nRR:")
r.findavgTime(proc, n,quantum)
print("<===============================================>")
print("\nPriority:")
p.priorityScheduling(proc, n)