def narrowing_by(f: Callable[[int], int]) -> List[Layer]: "List of layers with sizes determined by the given function, down to 10." def make_default_layer(size, more={}): return Layer(size, 'RandomUniform', 'selu', **more) sizes = list(narrowing_sizes(f)) if len(sizes) == 0: raise Exception("Not enough layers") elif len(sizes) == 1: layers = [Layer(sizes[0], 'RandomUniform', 'tanh')] else: layers = [make_default_layer(sizes[0], dict(input_shape=(28 * 28, )))] layers += [make_default_layer(size) for size in sizes[1:-1]] layers.append(Layer(sizes[-1], 'RandomUniform', 'tanh')) return layers
def create_layer_from_metadata_xml(resourcetype, xml, monitor=False, service=None, catalog=None): """ Create a layer / keyword list from a metadata record if it does not already exist. """ from models import gen_anytext, Layer if resourcetype == 'http://www.opengis.net/cat/csw/2.0.2': # Dublin core md = CswRecord(etree.fromstring(xml)) layer = Layer(is_monitored=monitor, name=md.title, title=md.title, abstract=md.abstract, xml=xml, service=service, catalog=catalog, anytext=gen_anytext(md.title, md.abstract, md.subjects)) if hasattr(md, 'alternative'): layer.name = md.alternative if md.bbox is not None: layer.bbox_x0 = format_float(md.bbox.minx) layer.bbox_y0 = format_float(md.bbox.miny) layer.bbox_x1 = format_float(md.bbox.maxx) layer.bbox_y1 = format_float(md.bbox.maxy) layer.wkt_geometry = bbox2wktpolygon( [md.bbox.minx, md.bbox.miny, md.bbox.maxx, md.bbox.maxy]) return layer, md.subjects
def post(self, request): vector_layer = request.data['layer'] features = request.data['features'] name = request.data['name'] schema = {'geometry': 'Polygon', 'properties': {'shaid': 'str'}} layer = Layer(name=name, field_names=['shaid'], schema=schema) layer.save() django_rq.enqueue(vector_catalog_save_layer, request.tenant.schema_name, layer, vector_layer, features, timeout=4800) return Response({'result': 'success'})
def post(self, request, *args, **kwargs): layers = request.POST.getlist('layer') for lay in layers: layer = json.loads(lay) # see if it's already in here. assume 'url' and 'layer' attributes make it unique l = Layer.objects.filter(url=layer['url'], layer=layer['layer']) if not l: # add the layer new_layer = Layer() for key, value in layer.iteritems(): if key == 'layer_params': # TODO: need to pass json object here pass else: setattr(new_layer, key, value) new_layer.save() return HttpResponseRedirect(reverse('layer-list'))
def setUp(self): for s in range(0, SERVICE_NUMBER): service = Service( url='http://%s.fakeurl.com' % s, title='Title %s' % s, type='OGC_WMS', ) service.save() for l in range(0, 20): layer = Layer(name='Layer %s, from service %s' % (l, s), bbox_x0=-179, bbox_x1=179, bbox_y0=-89, bbox_y1=89, service=service) layer.save() service.layer_set.add(layer) for c in range(0, TIMES_TO_CHECK): for s in range(0, SERVICE_NUMBER): service = Service.objects.all()[s] service.check() for layer in service.layer_set.all(): layer.check()
def add(): form = AddTaskForm(request.form) #pdb.set_trace() if request.method == 'POST': if form.validate_on_submit(): new_entry = Entry(form.entryDate.data, form.batch.data, form.action.data, form.actionNo.data, form.value.data, form.notes.data) ## TEMPORARY SKIP db.session.add(new_entry) db.session.commit() ###OLD CODE entryDate = form.entryDate.data batch = form.batch.data action = form.action.data actionNo = form.actionNo.data value = form.value.data notes = form.notes.data #dbTable = batch[:-3] #pdb.set_trace() if ("Sheep" or "Duck") in batch: flash('New entry was successfully posted!') return redirect(url_for('main')) #start new code if action == "Purchase": cvpb = value / actionNo #batch_detail = [batch, entryDate, actionNo, cvpb, 0, 0, 0, 0, 0, 0, value] if "Broiler" in batch: create_broiler = Broiler(batch, entryDate, actionNo, float(cvpb), 0, 0, 0, 0.0, 0.0, 0.0, float(value)) db.session.add(create_broiler) elif "Layer" in batch: create_layer = Layer(batch, entryDate, actionNo, float(cvpb), 0, 0, 0, 0.0, 0.0, 0.0, float(value)) db.session.add(create_layer) elif "Pig" in batch: create_pig = Broiler(batch, entryDate, actionNo, float(cvpb), 0, 0, 0, 0.0, 0.0, 0.0, float(value)) db.session.add(create_pig) db.session.commit() flash('New entry was successfully posted!') return redirect(url_for('main')) else: if "Broiler" in batch: #pdb.set_trace() table = Broiler record = db.session.query(Broiler).filter_by( batch=batch).first() elif "Layer" in batch: table = Layer record = db.session.query(Layer).filter_by( batch=batch).first() elif "Pig" in batch: table = Pig record = db.session.query(Pig).filter_by( batch=batch).first() #ogAlive = ogData[2] #ogCVPB = ogData[3] #ogSlaughtered = ogData[4] #ogSold = ogData[5] #ogDead = ogData[6] #ogFeed = ogData[7] #ogTime = ogData[8] #ogSales = ogData[9] #ogExp = ogData[10] #flag = False if action == "Dead" or action == "Lost": #update Dead data for batch, but data from animals table or form will be negative newVal = int(record.dead) - int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"dead": newVal}) alive = int(record.alive) + int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"alive": alive}) #may need to use str(action) elif "Slaughter" in action: #update slaughtered data #pdb.set_trace() newVal = int(record.special) - int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"special": newVal}) alive = int(record.alive) + int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"alive": alive}) newVal2 = float(record.sales) + float(value) db.session.query(table).filter_by(batch=batch).update( {"sales": newVal2}) elif action == "Tray": #pdb.set_trace() newVal = int(record.special) + int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"special": newVal}) newVal2 = float(record.sales) + float(value) db.session.query(table).filter_by(batch=batch).update( {"sales": newVal2}) elif action == "Sold": newVal = int(record.sold) - int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"sold": newVal}) newVal2 = float(record.sales) + float(value) db.session.query(table).filter_by(batch=batch).update( {"sales": newVal2}) alive = int(record.alive) + int(actionNo) db.session.query(table).filter_by(batch=batch).update( {"alive": alive}) elif action == "Feed": newVal = float(record.feed) + float(actionNo) db.session.query(table).filter_by(batch=batch).update( {"feed": newVal}) newVal2 = float(record.exp) + float(value) db.session.query(table).filter_by(batch=batch).update( {"exp": newVal2}) elif action == "Time": newVal = float(record.time) + float(actionNo) db.session.query(table).filter_by(batch=batch).update( {"time": newVal}) newVal2 = float(record.exp) + float(value) db.session.query(table).filter_by(batch=batch).update( {"exp": newVal2}) #End new code db.session.commit() flash('New entry was successfully posted!') return redirect(url_for('main'))
f = open(fname, 'r').readlines() for row in f: row = [x.strip() for x in row.split(',')] row = [int(num) for num in row] target.append(int(row[0])) attrs.append(row[1:]) if __name__ == '__main__': print "Parsing the training dataset..." # parse the training dataset and store its information into globals parse_data('mushroom-training.txt') # set up the layers to be used x = Layer(6, attrs[curr_point], 1) y = Layer(1, x.layer_out, 2) print "Begining training the neural network:" # iterate through to train the neural network while total_runs < NUM_TRAINING_ITERATIONS: # set the new input values x.input_vals = attrs[curr_point] # set up the first layer and evaluate it x.input_vals = attrs[curr_point] x.eval() # set up the second layer and evaluate it y.input_vals = x.layer_out y.eval()
for row in f: row = [x.strip() for x in row.split(',')] row = [int(num) for num in row] target.append(int( row[1])) #row[0] represent p class, row[1] represent e class. #if you represent e and p classes into one elment (0 for p and 1 for e, etc.), please modifiy. attrs.append(row[2:]) if __name__ == '__main__': print("Parsing the training dataset...") # parse the training dataset and store its information into globals parse_data('training.txt') # set up the layers to be used x = Layer(6, attrs[curr_point], 1) y = Layer(3, x1.layer_out, 2) print("Begining training the neural network:") # iterate through to train the neural network while total_runs < NUM_TRAINING_ITERATIONS: # set up the first layer and evaluate it raise Exception('Implement this part.') # set up the second layer and evaluate it raise Exception('Implement this part.') # backpropogate y.backprop(target[curr_point]) x.backprop(y)
def tanh(n=COUNT, dist=ru): return Layer(n, dist, 'tanh')
def selu(n=COUNT, dist=ru): return Layer(n, dist, 'selu')
def relu(n=COUNT, dist=ru): return Layer(n, dist, 'relu')
def layer(act='selu', dist=ru, n=COUNT) -> Layer: return Layer(n, dist, act)
def make_default_layer(size, more={}): return Layer(size, 'RandomUniform', 'selu', **more)