def _tmp_infer_forces(eptm, t_sum, sup_param="areas"): """Given a value for the total tension, computes the force infered mesh. ***************** Parameters: eptm : :class:`Epithelium` object t_sum : float The total tension to set in the force inference problem. sup_param : string, one of '', 'pressions' or 'areas' '': computes only tensions 'areas': computes tensions and the difference between cells area and cells prefered area. ***************** Returns tmp_organo : :class:`Epithelium` object The mesh infered by force inference. Note that energy minization is applied. ***************** """ tmp_organo = eptm.copy() fi_params = infer_forces(eptm, sup_param, t_sum, verbose=False) tmp_organo.edge_df.loc[:, "line_tension"] = prepare_tensions( tmp_organo, fi_params["tensions"] ) tmp_organo.face_df.loc[:, "prefered_area"] = ( tmp_organo.face_df.area.values + fi_params["areas"][:-1] ) tmp_organo.settings["lumen_prefered_vol"] = ( tmp_organo.settings["lumen_volume"] + fi_params["areas"][-1] ) Solver.find_energy_min(tmp_organo, geom, model) return tmp_organo
def run_nr_nl_optimization(organo, noisy, thet, energy_min, main_min, initial_min=None): """Run the optimization process when lumen volume is not a parameter and there is no regularization module. Parameters ---------- organo: class AnnularSheet the theoritical mesh. noisy: class AnnularSheet the experimental mesh. main_min: dictionnary the optimization options passed to the solver for the main optimization. energy_min: dictionnary the optimization options passed to the tyssue.solver.find_energy_min function initial_min: dictionnary the optimization options passed to the search of the initial point if applicable. Returns noisy: class AnnularSheet the experimental organoid after the optimization process opt_res: dictionnary dictionnary containing relevant info on the optimization process. Fit to the requirements of save_optimization_resultsself. ---------- """ alpha = 1 + 1/(20*(organo.settings['R_out']-organo.settings['R_in'])) true_tensions = organo.edge_df.line_tension[:3*organo.Nf].values print(true_tensions) # initial_guess = true_tensions * np.random.normal(1, thet, # true_tensions.shape) initial_guess = true_tensions start = time.clock() res = adjust_tensions(noisy, initial_guess, {'dic': {}, 'weight': 0}, energy_min, initial_min, **main_min) print(true_tensions) if main_min['method'] == 'PSQP': res_x = res['x'] else: res_x = res.x noisy.edge_df.line_tension = prepare_tensions(noisy, res_x) Solver.find_energy_min(noisy, geom, model) res_time = time.clock()-start tension_error = np.divide(true_tensions-res_x, np.full(true_tensions.shape, np.mean(true_tensions))) opt_res = res opt_res['res_time'] = res_time opt_res['tension_error'] = list(tension_error) opt_res['git_revision'] = version.git_revision var_tens = np.divide(np.abs(true_tensions-res_x), np.full(true_tensions.shape, np.mean(true_tensions))) # (slope, intercept, r_value, p_value, std_err) opt_res['linregress'] = list(stats.linregress(true_tensions, var_tens)) return noisy, opt_res
def test_prepare_tensions(): organo = generate_ring(3, 1, 2) organo.edge_df.loc[:, 'line_tension'] = np.ones(12) tension_array = organo.edge_df.loc[:, 'line_tension'][:3 * organo.Nf] tension_array[0] += 1 tension_array[3 * organo.Nf - 1] += 1 tensions = prepare_tensions(organo, tension_array) assert len(tensions) == 4 * organo.Nf assert np.all( np.equal(tensions[:3 * organo.Nf], tension_array[:3 * organo.Nf])) assert np.all( np.equal(np.roll(tensions[3 * organo.Nf:], 1), tension_array[2 * organo.Nf:]))
def run_r_l_optimization(organo, noisy, energy_min, main_min, initial_min=None): """Run the optimization process when lumen volume IS a parameter and there IS regularization module. Parameters ---------- organo: class AnnularSheet the theoritical mesh. noisy: class AnnularSheet the experimental mesh. main_min: dictionnary the optimization options passed to the solver for the main optimization. energy_min: dictionnary the optimization options passed to the tyssue.solver.find_energy_min function initial_min: dictionnary the optimization options passed to the search of the initial point if applicable. Returns noisy: class AnnularSheet the experimental organoid after the optimization process opt_res: dictionnary print(ind, type(res[ind])) dictionnary containing relevant info on the optimization process. Fit to the requirements of save_optimization_resultsself. ---------- """ alpha = 1 + 1/(20*(organo.settings['R_out']-organo.settings['R_in'])) initial_guess = set_init_point(organo.settings['R_in'], organo.settings['R_out'], organo.Nf, alpha) initial_guess = np.concatenate((initial_guess, [organo.settings['lumen_volume']])) if initial_min is not None: if len(initial_min['bounds']) <= len(initial_guess): initial_min['bounds'][0].append(-1e-8) initial_min['bounds'][1].append(1e6) if main_min['method'] in ('bfgs', 'trf'): if len(main_min['bounds']) <= len(initial_guess): main_min['bounds'][0].append(-1e-8) main_min['bounds'][1].append(1e6) start = time.clock() res = adjust_tensions(noisy, initial_guess, {'dic': {'basal': True, 'apical': True}, 'weight': 0.001}, energy_min, initial_min, **main_min) if main_min['method'] == 'PSQP': res_x = res['x'] else: res_x = res.x noisy.edge_df.line_tension = prepare_tensions(noisy, res_x) Solver.find_energy_min(noisy, geom, model) res_time = time.clock()-start tension_error = np.divide((initial_guess-res_x), initial_guess) opt_res = res opt_res['res_time'] = res_time opt_res['tension_error'] = list(tension_error) opt_res['git_revision'] = version.git_revision true_tensions = organo.edge_df.line_tension[:3*organo.Nf].values var_tens = np.divide(np.abs(true_tensions-res_x), np.full(true_tensions.shape, np.mean(true_tensions))) # (slope, intercept, r_value, p_value, std_err) opt_res['linregress'] = list(stats.linregress(true_tensions, var_tens)) return noisy, opt_res
def create_organo(nb_cells, r_in, r_out, seed=None, rot=None, geom=geom): organo = generate_ring(nb_cells, r_in, r_out) Nf = organo.Nf geom.update_all(organo) alpha = 1 + 1 / (20 * (organo.settings['R_out'] - organo.settings['R_in'])) specs = { 'face': { 'is_alive': 1, 'prefered_area': organo.face_df.area, 'area_elasticity': 1., }, 'edge': { 'ux': 0., 'uy': 0., 'uz': 0., 'line_tension': 0.1, 'is_active': 1 }, 'vert': { 'adhesion_strength': 0.01, 'x_ecm': 0., 'y_ecm': 0., 'is_active': 1 }, 'settings': { 'lumen_elasticity': 1., 'lumen_prefered_vol': organo.settings['lumen_volume'], 'lumen_volume': organo.settings['lumen_volume'] } } organo.update_specs(specs, reset=True) normalize_scale(organo, geom, refer='edges') geom.update_all(organo) if seed is not None: symetric_tensions = set_init_point(organo.settings['R_in'], organo.settings['R_out'], organo.Nf, alpha) sin_mul = 1 + (np.sin( np.linspace(0, 2 * np.pi, organo.Nf, endpoint=False)))**2 organo.face_df.prefered_area *= np.random.normal(1.0, 0.05, organo.Nf) organo.edge_df.line_tension = prepare_tensions(organo, symetric_tensions) organo.edge_df.loc[:Nf - 1, 'line_tension'] *= sin_mul * np.random.normal( 1.0, 0.05, organo.Nf) geom.update_all(organo) if rot is not None: organo.vert_df.loc[:, 'x'] = (organo.vert_df.x.copy() * np.cos(rot) - organo.vert_df.y.copy() * np.sin(rot)) print( 'rotated x', organo.vert_df.x.copy() * np.cos(rot) - organo.vert_df.y.copy() * np.sin(rot)) organo.vert_df.loc[:, 'y'] = (organo.vert_df.x.copy() * np.sin(rot) + organo.vert_df.y.copy() * np.cos(rot)) print( 'rotated y', organo.vert_df.x.copy() * np.sin(rot) + organo.vert_df.y.copy() * np.cos(rot)) geom.update_all(organo) organo.vert_df[['x_ecm', 'y_ecm']] = organo.vert_df[['x', 'y']] organo.vert_df.loc[organo.basal_verts, 'adhesion_strength'] = 0.01 new_tensions = organo.edge_df.line_tension organo.edge_df.loc[:, 'line_tension'] = new_tensions return organo