1]) @ML.gridsearchcv def gridsearchcv_lgbm(train, valid, param): model = LGBM(**param) model.fit(train.X, train.y) return model.predict_proba(valid.X)[:, 1] if __name__ == "__main__": mode = "Building..." # "Grid Searching..."# print('[' + sys.argv[0].split('/')[-1] + ']' + mode) path = "./cv/cv_" cv = ML.loadcv(path) if mode == "Grid Searching...": params = { 'learning_rate': 0.02, 'n_estimators': 1000, 'subsample': 0.7, 'subsample_freq': [1], 'num_leaves': 18, 'seed': 99, 'reg_lambda': 15, 'scale_pos_weight': 1.6, } params = ML.makeparams(params) gridsearchcv_lgbm("lightgbm2", cv=cv, params=params, eval_func=EV.gini) elif mode == "Building...": param = {
source = efg3( coordinates=phantom.coordinates, activity=300*10**6, ) materials = Materials(materials, max_energy=source.energy) materials.table = np.array([7, 7, 7, 10, 32, 82]) for angle in angles: phantom.rotate((0., angle, 0.)) source.rotate((0., angle, 0.)) modeling = Modeling( space, source, materials, stop_time=0.1, particles_number=10**6, flow_number=2, file_name=f'efg3_full_angle {round(angle*180/np.pi, 1)} deg.hdf', subject=detector ) modelings.append(modeling) modeling.start() for modeling in modelings: modeling.join()
def main(): angles = np.linspace(-np.pi/4, 3*np.pi/4, 32) projection_time = 15 pause_time = 1. materials = { 'Compounds and mixtures/Air, Dry (near sea level)': 0, 'Compounds and mixtures/Lung': 1, 'Compounds and mixtures/Tissue, Soft (ICRU-44)': 2, 'Compounds and mixtures/B-100 Bone-Equivalent Plastic': 3, 'Compounds and mixtures/Sodium Iodide': 4, 'Elemental media/Pb': 5, } space = Space( size=(51.2, 40., 60.), material=0 ) detector = SiemensSymbiaTSeries3_8( coordinates=(0., 0., 0), size=space.size[:2] ) collimator = SiemensSymbiaTSeriesLEHR( coordinates=(detector.coordinates[0], detector.coordinates[1], detector.size[2] + 0.5), size=detector.size[:2] ) phantom = ae3cut( coordinates=(collimator.coordinates[0], collimator.coordinates[1], collimator.size[2]), ) source = SourceManager().efg3cut( coordinates=phantom.coordinates, activity=300*10**6, ) space.add_subject(phantom) space.add_subject(detector) space.add_subject(collimator) materials = Materials(materials, max_energy=source.energy) materials.table = np.array([7, 7, 7, 10, 32, 82]) for angle in angles: phantom.rotate((0., angle, 0.)) source.rotate((0., angle, 0.)) modeling = Modeling( space, source, materials, stop_time=source.timer + projection_time, particles_number=10**8, flow_number=8, file_name=f'efg3cut/{round(np.rad2deg(angle), 1)} deg.hdf', iteraction_buffer=10**4, subject=detector ) modeling.start() modeling.join() source.set_state(source.timer + pause_time)
warnings.filterwarnings("ignore") from os import listdir from os.path import join from modeling import Modeling as ML from evaluation import Evaluation as EV from modeling import dataset import pandas as pd from sklearn.linear_model import LogisticRegression as LR if __name__ == "__main__": path = "./cv/cv_" meta_train_path = "./predictions/meta_train/" meta_test_path = "./predictions/meta_test/" cv = ML.loadcv(path) test = ML.loadtest(path) # construct training set filenamelist = [ f[:-4] for f in listdir(meta_train_path) if join(meta_train_path, f).endswith('.csv') ] filepathlist = [ join(meta_train_path, f) for f in listdir(meta_train_path) if join(meta_train_path, f).endswith('.csv') ] metas = [pd.read_csv(mypath)['target'] for mypath in filepathlist] df = pd.concat(metas, axis=1) df.columns = filenamelist train = dataset( df,
def run(argv): try: opts, args = getopt.getopt(argv, "hd:o:", ['help', 'dataset=', 'output=']) except getopt.GetoptError: print('gremlinp.py -d <dataset_dir> -o <out_dir>') sys.exit(2) data_dir = '' out_dir = '' for opt, arg in opts: if opt == '-h': print('gremlin.py -d <dataset_dir> -o <out_dir>') sys.exit() elif opt in ("-d", "--dataset"): data_dir = arg + os.sep elif opt in ("-o", "--output"): out_dir = arg + os.sep fileList = glob(data_dir + os.sep + '*.pdb') if (len(fileList) == 0): print("Warning! - PDB files not found!") else: graph_dir = out_dir + os.sep + 'graphs/' group_dir = out_dir + os.sep + 'groups/' sup_dir = out_dir + os.sep + 'supports/' pattern_dir = out_dir + os.sep + 'patterns/' graphml_dir = out_dir + os.sep + 'graphml/' # MODELING #----------------------------- start = timeit.default_timer() #------------------------------ # Computing graphs Modeling(data_dir, graph_dir, out_dir).run(7, []) # CLUSTERING # Computing matrix using graph caracteristics X = CountingMatrix(graph_dir).run(False) # Romove noise data using SVD X2 = SVD().run(X) # Clustring groups = Clustering().run(X2, X.index) # GRAPH MINING supports = np.arange(0.1, 1.0, 0.1) # file with all graphs in gsapn format gsp = out_dir + os.sep + "graph_dataset.gspan" # Updating graph files information GraphJson().update_json(graph_dir, gsp, groups) # Partiotioning graphs into groups gl, mg = SplitGroup(out_dir).run(groups, graph_dir) # Running Gspan and colecting maximal patterns Gspan(group_dir).run(supports, gl, mg) Gspan(group_dir).save_patterns(pattern_dir, mg) # Mapping patterns into original graphs MapPattern(sup_dir).run(supports, gl, graph_dir, pattern_dir) # Creating graphml files GraphJson().json_to_graphml(graph_dir, graphml_dir) #------------------------------ stop = timeit.default_timer() print('Runtime: ') print(stop - start)