# create a mesh of 8 by 8 by 8 hexes for a unit cube nd = 3 elemtype = 0 mesh['p'], mesh['t'] = Mesh.gmshcall(pde, "coneincube", nd, elemtype)[0:2] # expressions for domain boundaries mesh['boundaryexpr'] = [ lambda p: (p[1, :] < -10.0 + 1e-3), lambda p: (p[0, :] > 10.0 - 1e-3), lambda p: (p[1, :] > 10.0 - 1e-3), lambda p: (p[0, :] < -10.0 + 1e-3), lambda p: (p[2, :] < -10.0 + 1e-3), lambda p: (p[2, :] > 10.0 - 1e-3), lambda p: (p[2, :] < 1e+3) ] mesh['boundarycondition'] = numpy.array([2, 2, 2, 2, 2, 2, 1]) # Set boundary condition for each boundary # # # call exasim to generate and run C++ code to solve the PDE model sol, pde, mesh = Postprocessing.exasim(pde, mesh)[0:3] #Postprocessing.producecode(pde,mesh); # visualize the numerical solution of the PDE model using Paraview pde['visscalars'] = ["temperature", 0] # list of scalar fields for visualization pde['visvectors'] = [ "temperature gradient", numpy.array([1, 2, 3]).astype(int) ] # list of vector fields for visualization dgnodes = Postprocessing.vis(sol, pde, mesh) # visualize the numerical solution # x = dgnodes[:,0,:]; y = dgnodes[:,1,:]; z = dgnodes[:,2,:]; # uexact = numpy.sin(numpy.pi*x)*numpy.sin(numpy.pi*y)*numpy.sin(numpy.pi*z); # exact solution # uh = sol[:,0,:]; # numerical solution
# unit thermal conductivity pde['tau'] = numpy.array([1.0]) # DG stabilization parameter # create a mesh of 8 by 8 quads on a square domain mesh['p'], mesh['t'] = Mesh.SquareMesh(16, 16, 1)[0:2] # expressions for domain boundaries mesh['boundaryexpr'] = [ lambda p: (p[1, :] < 1e-3), lambda p: (p[0, :] > 1 - 1e-3), lambda p: (p[1, :] > 1 - 1e-3), lambda p: (p[0, :] < 1e-3) ] mesh['boundarycondition'] = numpy.array([1, 1, 1, 1]) # Set boundary condition for each boundary # call exasim to generate and run C++ code to solve the PDE model sol, pde, mesh = Postprocessing.exasim(pde, mesh)[0:3] # visualize the numerical solution of the PDE model using Paraview pde['visscalars'] = ["temperature", 0] # list of scalar fields for visualization pde['visvectors'] = ["temperature gradient", numpy.array([1, 2]).astype(int)] # list of vector fields for visualization Postprocessing.vis(sol, pde, mesh) # visualize the numerical solution print("Done!") # npf = dmd[0]['facecon'].shape[0]; # nf = dmd[0]['facecon'].shape[2]; # print(numpy.reshape(dmd[0]['facecon'][:,0,:],(npf,nf),'F').T) # print(numpy.reshape(dmd[0]['facecon'][:,1,:],(npf,nf),'F').T)
pinf = 1/(gam*Minf**2); # freestream pressure rEinf = 0.5+pinf/(gam-1); # freestream energy pde['physicsparam'] = [gam, Minf, rinf, ruinf, rvinf, rEinf]; pde['tau'] = numpy.array([2.0]); # DG stabilization parameter pde['GMRESrestart']=30; # number of GMRES restarts pde['linearsolvertol']=0.0001; # GMRES tolerance pde['linearsolveriter']=31; # number of GMRES iterations pde['precMatrixType']=2; # preconditioning type pde['NLtol'] = 1e-7; # Newton tolerance pde['NLiter']=3; # Newton iterations # read a grid from a file mesh['p'], mesh['t'] = Mesh.readmesh("grid.bin",0); mesh['t'] = mesh['t'] - 1; # expressions for domain boundaries mesh['boundaryexpr'] = [lambda p: (numpy.sqrt((p[0,:]-0.5)*(p[0,:]-0.5)+p[1,:]*p[1,:]) < 3), lambda p: (p[0,:] < 20)]; mesh['boundarycondition'] = numpy.array([1, 2]); # Set boundary condition for each boundary #expressions for curved boundaries mesh['curvedboundary'] = numpy.array([1, 0]); mesh['curvedboundaryexpr'] = [lambda p: p[1,:]**2-(5*0.01*12*(0.29690*numpy.sqrt(numpy.abs(p[0,:]))-0.12600*p[0,:]-0.35160*p[0,:]**2+0.28430*p[0,:]**3-0.10150*p[0,:]**4))**2, lambda p: 0]; # call exasim to generate and run C++ code to solve the PDE model sol, pde, mesh = Postprocessing.exasim(pde,mesh)[0:3]; # visualize the numerical solution of the PDE model using Paraview pde['visscalars'] = ["density", 0, "energy", 3]; # list of scalar fields for visualization pde['visvectors'] = ["momentum", [1, 2]]; # list of vector fields for visualization Postprocessing.vis(sol,pde,mesh); # visualize the numerical solution print("Done!");
else: # Load in the two models: print >> sys.stderr, "Loading models..." rc = RelationDetector('SVM', params=[10, 0.01]) rc.load(args.detector_model) rcl = RelationClassifier('SVM', params=[10, 0.001]) rcl.load(args.classifier_model) print >> sys.stderr, "Loading data..." sentences = Preprocessing.parse_processed_sentence_file( args.sentences) pos = Preprocessing.parse_processed_sentence_file(args.pos) ne_plain = Preprocessing.parse_processed_sentence_file(args.ne) ne = [ Preprocessing.process_named_entities(n) for n in ne_plain ] print >> sys.stderr, "Running detector..." pred = rc.predict_sentences(zip(sentences, ne, pos)) print >> sys.stderr, "Running classifier..." predictions = rcl.predict_sentences(zip(sentences, ne, pos), pred, output_dictionary=True) Postprocessing.print_sentence_pos_ne_relation_list( sentences, pos, ne_plain, predictions) else: print >> sys.stderr, 'Missing input'
def process_dependency_parse(sentence): G = nx.DiGraph() G.add_node(0, word='HEAD', type='HEAD') for elem in sentence: G.add_node(int(elem[0]), word=elem[1], type=elem[7]) G.add_edge(int(elem[0]), int(elem[6])) return G if __name__ == '__main__': parser = argparse.ArgumentParser(description="Contains implementation for two relation extraction strategies.") parser.add_argument("--input", required=True, help="Specify the input file") parser.add_argument("--extract", required=False) args = parser.parse_args() f = args.input if args.extract: sentences, _, ne, pos = parse_full_re_file(f, zip_ne_to_dictionary=False) if args.extract == 'pos': Postprocessing.print_sentence_list(pos) elif args.extract == 'sentences': Postprocessing.print_sentence_list(sentences) elif args.extract == 'ne': Postprocessing.print_sentence_list(ne) else: sentences = parse_sentence_file(f) Postprocessing.print_sentence_list(sentences)
"initial_memberships": initial_memberships } out = al_model(input_dict) if args.vis_seq_rep: mem = [out[3 * i] for i in range(int(len(out) / 3))] seq_rep = [out[3 * i + 1] for i in range(int(len(out) / 3))] cons_rep = [out[3 * i + 2] for i in range(int(len(out) / 3))] else: if AlignmentModel.NUM_ITERATIONS == 1: mem = [out] else: mem = out cols = Postprocessing.seq_consistent(msa, mem[-1]) end_time = time.time() print("prec, recall: ", msa.recall_prec(cols)) print("It took ", end_time - start_time, " seconds to construct the alignment.") ################################################################################################################################################ ################################################################################################################################################ if args.o != "": MSA.column_pred_to_fasta(msa, cols, args.o) ################################################################################################################################################ ################################################################################################################################################