Exemple #1
0
    def do_fit(self, dataframe: pd.DataFrame,
               labeled_segments: List[AnalyticSegment],
               deleted_segments: List[AnalyticSegment],
               learning_info: LearningInfo) -> None:
        data = utils.cut_dataframe(dataframe)
        data = data['value']
        last_pattern_center = self.state.pattern_center
        self.state.pattern_center = utils.remove_duplicates_and_sort(
            last_pattern_center + learning_info.segment_center_list)
        self.state.pattern_model = utils.get_av_model(
            learning_info.patterns_list)
        convolve_list = utils.get_convolve(self.state.pattern_center,
                                           self.state.pattern_model, data,
                                           self.state.window_size)
        correlation_list = utils.get_correlation(self.state.pattern_center,
                                                 self.state.pattern_model,
                                                 data, self.state.window_size)

        del_conv_list = []
        delete_pattern_timestamp = []
        for segment in deleted_segments:
            del_mid_index = segment.center_index
            delete_pattern_timestamp.append(segment.pattern_timestamp)
            deleted_pat = utils.get_interval(data, del_mid_index,
                                             self.state.window_size)
            deleted_pat = utils.subtract_min_without_nan(deleted_pat)
            del_conv_pat = scipy.signal.fftconvolve(deleted_pat,
                                                    self.state.pattern_model)
            if len(del_conv_pat): del_conv_list.append(max(del_conv_pat))

        self.state.convolve_min, self.state.convolve_max = utils.get_min_max(
            convolve_list, self.state.window_size / 3)
        self.state.conv_del_min, self.state.conv_del_max = utils.get_min_max(
            del_conv_list, self.state.window_size)
Exemple #2
0
 def _update_fiting_result(self,
                           state: ModelState,
                           confidences: list,
                           convolve_list: list,
                           del_conv_list: list,
                           height_list: Optional[list] = None) -> None:
     state.confidence = float(min(confidences, default=1.5))
     state.convolve_min, state.convolve_max = utils.get_min_max(
         convolve_list, state.window_size)
     state.conv_del_min, state.conv_del_max = utils.get_min_max(
         del_conv_list, 0)
     if height_list is not None:
         state.height_min, state.height_max = utils.get_min_max(
             height_list, 0)
Exemple #3
0
def main():
    print("Image:")
    image = input("")

    features = finding_face_landmark.finding_face_landmark(image)
    if (len(features) == 0):
        exit(0)

    data_file_name = "features.csv"
    X, Y, Q = utils.get_data(data_file_name, 2000)

    x_min, x_max = utils.get_min_max(X)
    X = utils.normalize_features(x_min, x_max, X)

    test_file_name = "test.csv"
    T, P, L = utils.get_data_test(test_file_name, x_min, x_max, len(X), Q, Y)

    model_file_name = './my_test_model.ckpt'
    neural_network = n.Neural_Network(X, Y, model_file_name)
    # neural_network.training()
    # neural_network.test(T,P)

    features = utils.normalize_features(x_min, x_max, features)

    predict = neural_network.predict([features])
    image_path = Q[predict][0].strip()

    metadata = 'C:\\ProjekatSoft\\wiki_crop\\wiki.mat'
    name = utils.get_name(image_path, metadata)

    percent = utils.get_percent(features, X[predict:predict + 1, :15][0])
    utils.show_image('C:\\ProjekatSoft\\wiki_crop\\' + image_path, name,
                     percent)
    def do_fit(self, dataframe: pd.DataFrame, labeled_segments: list, deleted_segments: list, learning_info: dict) -> None:
        data = utils.cut_dataframe(dataframe)
        data = data['value']
        last_pattern_center = self.state.get('pattern_center', [])
        self.state['pattern_center'] = list(set(last_pattern_center + learning_info['segment_center_list']))
        self.state['pattern_model'] = utils.get_av_model(learning_info['patterns_list'])
        convolve_list = utils.get_convolve(self.state['pattern_center'], self.state['pattern_model'], data, self.state['WINDOW_SIZE'])
        correlation_list = utils.get_correlation(self.state['pattern_center'], self.state['pattern_model'], data, self.state['WINDOW_SIZE'])

        del_conv_list = []
        delete_pattern_timestamp = []
        for segment in deleted_segments:
            del_mid_index = segment.center_index
            delete_pattern_timestamp.append(segment.pattern_timestamp)
            deleted_pat = utils.get_interval(data, del_mid_index, self.state['WINDOW_SIZE'])
            deleted_pat = utils.subtract_min_without_nan(deleted_pat)
            del_conv_pat = scipy.signal.fftconvolve(deleted_pat, self.state['pattern_model'])
            if len(del_conv_pat): del_conv_list.append(max(del_conv_pat))

        self.state['convolve_min'], self.state['convolve_max'] = utils.get_min_max(convolve_list, self.state['WINDOW_SIZE'] / 3)
        self.state['conv_del_min'], self.state['conv_del_max'] = utils.get_min_max(del_conv_list, self.state['WINDOW_SIZE'])
Exemple #5
0
def group_projects(projects, by_programme=False, by_year=False):
    """ group projects by theme.
    """

    min_y = max_y = None
    if by_year:
        min_y, max_y = get_min_max(projects, key=lambda x: x['call year'])

    mapping = {}
    for programme in PROGRAMMES:
        for name in PROGRAMMES[programme]:
            if min_y is None or max_y is None:
                mapping[name] = programme if by_programme else name
            else:
                for year in range(min_y, max_y + 1):
                    mapping['{0}_{1}'.format(year, name)] = '{0}_{1}'.format(
                        year, programme if by_programme else name)

    matrices = {}
    for key in mapping:
        matrices[mapping[key]] = []

    for project in projects:
        name = project['Theme']
        if by_year:
            name = '{0}_{1}'.format(project['call year'], name)

        key = mapping.get(name, None)
        if key is None:
            print "error: unknown theme ``{0}''".format(project['Theme'])
            continue
        matrices[key].append(project)

    matrices = {key: value for key, value in matrices.iteritems() if len(value)}

    for key in matrices:
        print "Grouped {0} projects under ``{1}''".format(
            len(matrices[key]), key)

    return matrices
Exemple #6
0
def main():

    ROOT.gROOT.SetBatch()
    ROOT.TGaxis.SetMaxDigits(5)

    file = ROOT.TFile('inputs/interference_functions.root')
    masses = [400, 600, 800]
    widths = [0.01, 0.05, 0.1]
    l_width = 3
    tot, sig, Hh, HB = None, None, None, None
    #for big_bad_index in range( 100 ):
    canvas, pad, pads = utils.create_special_canvas(
        'plot_interference_example')
    tot_hist, sig_hist, Hh_hist, HB_hist = {}, {}, {}, {}
    for index, (mass, width) in enumerate(product(masses, widths)):
        pads[index + 1].cd()
        tot = file.Get('tot___m%d___w%d' % (mass, width * 100))
        sig = file.Get('sig___m%d___w%d' % (mass, width * 100))
        Hh = file.Get('Hh___m%d___w%d' % (mass, width * 100))
        HB = file.Get('HB___m%d___w%d' % (mass, width * 100))
        x_min, x_max = utils.get_extremes(
            mass, width)  #utils.get_min_max_shift( mass, width )
        mw_str = '_hist___m%d___w%d' % (mass, width * 100)
        tot_hist['tot' + mw_str] = ROOT.TH1F('tot' + mw_str, '', 1000, x_min,
                                             x_max)
        tot_hist['tot' + mw_str].Add(tot, 1.)
        integral = tot_hist['tot' + mw_str].Integral()
        tot_hist['tot' + mw_str].Scale(1. / integral)
        sig_hist['sig' + mw_str] = ROOT.TH1F('sig' + mw_str, '', 1000, x_min,
                                             x_max)
        sig_hist['sig' + mw_str].Add(sig, 1. / integral)
        Hh_hist['Hh' + mw_str] = ROOT.TH1F('Hh' + mw_str, '', 1000, x_min,
                                           x_max)
        Hh_hist['Hh' + mw_str].Add(Hh, 1. / integral)
        HB_hist['HB' + mw_str] = ROOT.TH1F('HB' + mw_str, '', 1000, x_min,
                                           x_max)
        HB_hist['HB' + mw_str].Add(HB, 1. / integral)
        #print integral
        #integral = 1.
        y_min, y_max = utils.get_min_max(tot_hist['tot' + mw_str],
                                         sig_hist['sig' + mw_str],
                                         Hh_hist['Hh' + mw_str],
                                         HB_hist['HB' + mw_str])
        #y_min, y_max = -0.0015, 0.0075
        tot_hist['tot' + mw_str].SetMinimum(y_min)
        tot_hist['tot' + mw_str].SetMaximum(y_max)
        tot_hist['tot' + mw_str].Draw('c')
        tot_hist['tot' + mw_str].GetXaxis().SetLabelSize(10)
        tot_hist['tot' + mw_str].GetYaxis().SetLabelSize(10)
        tot_hist['tot' + mw_str].SetLineWidth(l_width)
        sig_hist['sig' + mw_str].SetLineColor(ROOT.kOrange + 10)
        sig_hist['sig' + mw_str].SetLineStyle(2)
        sig_hist['sig' + mw_str].SetLineWidth(l_width)
        sig_hist['sig' + mw_str].Draw('c same')
        Hh_hist['Hh' + mw_str].SetLineColor(ROOT.kGreen + 1)
        Hh_hist['Hh' + mw_str].SetLineStyle(4)
        Hh_hist['Hh' + mw_str].SetLineWidth(l_width)
        Hh_hist['Hh' + mw_str].Draw('c same')
        HB_hist['HB' + mw_str].SetLineColor(ROOT.kBlue)
        HB_hist['HB' + mw_str].SetLineStyle(3)
        HB_hist['HB' + mw_str].SetLineWidth(l_width)
        HB_hist['HB' + mw_str].Draw('c same')
        tot_hist['tot' + mw_str].Draw('c same')
        l = utils.draw_small_latex(mass, width)
    canvas.cd()
    x_l1, y_l1, latex1 = utils.draw_special_latex()
    latex1.DrawLatex(x_l1, y_l1 - 0.045, utils.plot_tag)
    l2 = utils.draw_x_axis_latex('Particle-level ' +
                                 utils.m4l)  #it{m_{4l}} [GeV]' )
    l3 = utils.draw_y_axis_latex('1/N #upoint dN/d#it{m}_{4#it{l}} [GeV^{-1}]')
    leg = utils.create_special_legend()
    leg.AddEntry(tot_hist['tot' + mw_str], 'Signal + Interference', 'l')
    leg.AddEntry(sig_hist['sig' + mw_str], 'Signal only', 'l')
    leg.AddEntry(Hh_hist['Hh' + mw_str], '#it{H-h} Interference', 'l')
    leg.AddEntry(HB_hist['HB' + mw_str], '#it{H-B} Interference', 'l')
    leg.Draw()
    utils.save(canvas)
    ROOT.TGaxis.SetMaxDigits(4)