gempy
gempy.core.model.Project
gempy.core.model.Project.add_featuresgempy.core.model.Project.add_orientationsgempy.core.model.Project.add_seriesgempy.core.model.Project.add_surface_pointsgempy.core.model.Project.add_surface_valuesgempy.core.model.Project.add_surfacesgempy.core.model.Project.delete_featuresgempy.core.model.Project.delete_orientationsgempy.core.model.Project.delete_seriesgempy.core.model.Project.delete_surface_pointsgempy.core.model.Project.delete_surface_points_basementgempy.core.model.Project.delete_surface_valuesgempy.core.model.Project.delete_surfacesgempy.core.model.Project.get_active_gridsgempy.core.model.Project.get_additional_datagempy.core.model.Project.get_datagempy.core.model.Project.load_model_picklegempy.core.model.Project.map_geometric_data_dfgempy.core.model.Project.map_series_to_surfacesgempy.core.model.Project.map_stack_to_surfacesgempy.core.model.Project.modify_kriging_parametersgempy.core.model.Project.modify_optionsgempy.core.model.Project.modify_order_featuresgempy.core.model.Project.modify_order_seriesgempy.core.model.Project.modify_order_surfacesgempy.core.model.Project.modify_orientationsgempy.core.model.Project.modify_rescaling_parametersgempy.core.model.Project.modify_surface_pointsgempy.core.model.Project.modify_surface_valuesgempy.core.model.Project.new_modelgempy.core.model.Project.read_datagempy.core.model.Project.rename_featuresgempy.core.model.Project.rename_seriesgempy.core.model.Project.rename_surfacesgempy.core.model.Project.rename_featuresgempy.core.model.Project.reorder_seriesgempy.core.model.Project.save_modelgempy.core.model.Project.savel_model_picklegempy.core.model.Project.save_solutiongempy.core.model.Project.set_active_gridgempy.core.model.Project.set_bottom_relationgempy.core.model.Project.set_centered_gridgempy.core.model.Project.set_custom_gridgempy.core.model.Project.set_default_orientationgempy.core.model.Project.set_default_surface_pointgempy.core.model.Project.set_default_surfacesgempy.core.model.Project.set_extentgempy.core.model.Project.set_fault_objectgempy.core.model.Project.set_fault_relationgempy.core.model.Project.set_grid_objectgempy.core.model.Project.set_is_faultgempy.core.model.Project.set_is_finite_faultgempy.core.model.Project.set_orientationsgempy.core.model.Project.set_orientations_objectgempy.core.model.Project.set_regular_gridgempy.core.model.Project.set_section_gridgempy.core.model.Project.set_series_objectgempy.core.model.Project.set_surface_order_from_solutiongempy.core.model.Project.set_surface_pointsgempy.core.model.Project.set_surface_points_objectgempy.core.model.Project.set_surface_valuesgempy.core.model.Project.set_surfaces_objectgempy.core.model.Project.set_theano_functiongempy.core.model.Project.set_theano_graphgempy.core.model.Project.set_topographygempy.core.model.Project.update_additional_datagempy.core.model.Project.update_from_gridgempy.core.model.Project.update_from_seriesgempy.core.model.Project.update_from_surfacesgempy.core.model.Project.update_structuregempy.core.model.Project.update_to_interpolatorgempy.core.model.Project.additional_datagempy.core.model.Project.faultsgempy.core.model.Project.gridgempy.core.model.Project.interpolatorgempy.core.model.Project.orientationsgempy.core.model.Project.rescalinggempy.core.model.Project.seriesgempy.core.model.Project.stackgempy.core.model.Project.surface_pointsgempy.core.model.Project.surfaces
gempy.core.model.ImplicitCoKriging
gempy.core.model.ImplicitCoKriging.add_featuresgempy.core.model.ImplicitCoKriging.add_orientationsgempy.core.model.ImplicitCoKriging.add_seriesgempy.core.model.ImplicitCoKriging.add_surface_pointsgempy.core.model.ImplicitCoKriging.add_surface_valuesgempy.core.model.ImplicitCoKriging.add_surfacesgempy.core.model.ImplicitCoKriging.delete_featuresgempy.core.model.ImplicitCoKriging.delete_orientationsgempy.core.model.ImplicitCoKriging.delete_seriesgempy.core.model.ImplicitCoKriging.delete_surface_pointsgempy.core.model.ImplicitCoKriging.delete_surface_points_basementgempy.core.model.ImplicitCoKriging.delete_surface_valuesgempy.core.model.ImplicitCoKriging.delete_surfacesgempy.core.model.ImplicitCoKriging.get_active_gridsgempy.core.model.ImplicitCoKriging.map_geometric_data_dfgempy.core.model.ImplicitCoKriging.map_series_to_surfacesgempy.core.model.ImplicitCoKriging.map_stack_to_surfacesgempy.core.model.ImplicitCoKriging.modify_kriging_parametersgempy.core.model.ImplicitCoKriging.modify_optionsgempy.core.model.ImplicitCoKriging.modify_order_featuresgempy.core.model.ImplicitCoKriging.modify_order_seriesgempy.core.model.ImplicitCoKriging.modify_order_surfacesgempy.core.model.ImplicitCoKriging.modify_orientationsgempy.core.model.ImplicitCoKriging.modify_rescaling_parametersgempy.core.model.ImplicitCoKriging.modify_surface_pointsgempy.core.model.ImplicitCoKriging.modify_surface_valuesgempy.core.model.ImplicitCoKriging.rename_featuresgempy.core.model.ImplicitCoKriging.rename_seriesgempy.core.model.ImplicitCoKriging.rename_surfacesgempy.core.model.ImplicitCoKriging.reorder_featuresgempy.core.model.ImplicitCoKriging.reorder_seriesgempy.core.model.ImplicitCoKriging.set_active_gridgempy.core.model.ImplicitCoKriging.set_bottom_relationgempy.core.model.ImplicitCoKriging.set_centered_gridgempy.core.model.ImplicitCoKriging.set_custom_gridgempy.core.model.ImplicitCoKriging.set_default_orientationgempy.core.model.ImplicitCoKriging.set_default_surface_pointgempy.core.model.ImplicitCoKriging.set_default_surfacesgempy.core.model.ImplicitCoKriging.set_extentgempy.core.model.ImplicitCoKriging.set_fault_objectgempy.core.model.ImplicitCoKriging.set_fault_relationgempy.core.model.ImplicitCoKriging.set_grid_objectgempy.core.model.ImplicitCoKriging.set_is_faultgempy.core.model.ImplicitCoKriging.set_is_finite_faultgempy.core.model.ImplicitCoKriging.set_orientationsgempy.core.model.ImplicitCoKriging.set_orientations_objectgempy.core.model.ImplicitCoKriging.set_regular_gridgempy.core.model.ImplicitCoKriging.set_section_gridgempy.core.model.ImplicitCoKriging.set_series_objectgempy.core.model.ImplicitCoKriging.set_surface_order_from_solutiongempy.core.model.ImplicitCoKriging.set_surface_pointsgempy.core.model.ImplicitCoKriging.set_surface_points_objectgempy.core.model.ImplicitCoKriging.set_surface_valuesgempy.core.model.ImplicitCoKriging.set_surfaces_objectgempy.core.model.ImplicitCoKriging.set_theano_functiongempy.core.model.ImplicitCoKriging.set_theano_graphgempy.core.model.ImplicitCoKriging.set_topographygempy.core.model.ImplicitCoKriging.update_additional_datagempy.core.model.ImplicitCoKriging.update_from_gridgempy.core.model.ImplicitCoKriging.update_from_seriesgempy.core.model.ImplicitCoKriging.update_from_surfacesgempy.core.model.ImplicitCoKriging.update_structuregempy.core.model.ImplicitCoKriging.update_to_interpolatorgempy.core.model.ImplicitCoKriging.additional_datagempy.core.model.ImplicitCoKriging.faultsgempy.core.model.ImplicitCoKriging.gridgempy.core.model.ImplicitCoKriging.interpolatorgempy.core.model.ImplicitCoKriging.orientationsgempy.core.model.ImplicitCoKriging.rescalinggempy.core.model.ImplicitCoKriging.seriesgempy.core.model.ImplicitCoKriging.stackgempy.core.model.ImplicitCoKriging.surface_pointsgempy.core.model.ImplicitCoKriging.surfaces
gempy.core.data_modules.stack.Stack
gempy.core.data_modules.stack.Series
gempy.core.data_modules.stack.Faults
gempy.core.data.Surfaces
gempy.core.data.Structure
gempy.core.data.KrigingParameters
gempy.core.data.Options
gempy.core.data.AdditionalData
gempy.core.data.Grid
gempy.core.grid_modules.grid_types.RegularGrid
gempy.core.grid_modules.grid_types.CustomGrid
gempy.core.grid_modules.topography.Topography
gempy.core.grid_modules.grid_types.Sections
gempy.core.grid_modules.grid_types.CenteredGrid
gempy.core.data_modules.geometric_data.SurfacePoints
gempy.core.data_modules.geometric_data.Orientations
gempy.core.interpolator.InterpolatorModel
gempy.core.interpolator.InterpolatorModel.calculate_Vgempy.core.interpolator.InterpolatorModel.calculate_tzgempy.core.interpolator.InterpolatorModel.compile_th_fn_geogempy.core.interpolator.InterpolatorModel.crate_theano_graphgempy.core.interpolator.InterpolatorModel.get_python_input_blockgempy.core.interpolator.InterpolatorModel.modify_results_matrices_progempy.core.interpolator.InterpolatorModel.modify_results_weightsgempy.core.interpolator.InterpolatorModel.print_theano_sharedgempy.core.interpolator.InterpolatorModel.remove_series_without_datagempy.core.interpolator.InterpolatorModel.reset_flow_control_initial_resultsgempy.core.interpolator.InterpolatorModel.set_all_shared_parametersgempy.core.interpolator.InterpolatorModel.set_flow_controlgempy.core.interpolator.InterpolatorModel.set_initial_resultsgempy.core.interpolator.InterpolatorModel.set_initial_results_matricesgempy.core.interpolator.InterpolatorModel.set_theano_graphgempy.core.interpolator.InterpolatorModel.set_theano_shared_Vs_kernelgempy.core.interpolator.InterpolatorModel.set_theano_shared_fault_relationgempy.core.interpolator.InterpolatorModel.set_theano_shared_faultsgempy.core.interpolator.InterpolatorModel.set_theano_shared_gravitygempy.core.interpolator.InterpolatorModel.set_theano_shared_gridgempy.core.interpolator.InterpolatorModel.set_theano_shared_is_faultgempy.core.interpolator.InterpolatorModel.set_theano_shared_is_finitegempy.core.interpolator.InterpolatorModel.set_theano_shared_kriginggempy.core.interpolator.InterpolatorModel.set_theano_shared_l0_l1gempy.core.interpolator.InterpolatorModel.set_theano_shared_loopgempy.core.interpolator.InterpolatorModel.set_theano_shared_magnetic_ctsgempy.core.interpolator.InterpolatorModel.set_theano_shared_magneticsgempy.core.interpolator.InterpolatorModel.set_theano_shared_nuggetsgempy.core.interpolator.InterpolatorModel.set_theano_shared_onlap_erodegempy.core.interpolator.InterpolatorModel.set_theano_shared_pos_densitygempy.core.interpolator.InterpolatorModel.set_theano_shared_pos_magneticsgempy.core.interpolator.InterpolatorModel.set_theano_shared_relationsgempy.core.interpolator.InterpolatorModel.set_theano_shared_structuregempy.core.interpolator.InterpolatorModel.set_theano_shared_structure_surfacesgempy.core.interpolator.InterpolatorModel.set_theano_shared_topologygempy.core.interpolator.InterpolatorModel.set_theano_shared_tz_kernelgempy.core.interpolator.InterpolatorModel.set_theano_shared_weights
gempy.core.interpolator.InterpolatorGravity
gempy.core.solution.Solution

set_theano_function

set_theano_function是在Gempy项目中定义Theano函数的方法之一。Theano是一种符号计算的库,可以用来定义并优化数学表达式,特别适合用于深度学习中的计算。在Gempy项目中,Theano函数通常用于定义构建地质模型时计算底层函数的方法。

语法

def set_theano_function(self, name: str, inputs: Tuple[Type[tt.TensorVariable], ...], outputs: Tuple[Type[tt.TensorVariable], ...], updates: Optional[Dict[tt.TensorVariable, tt.TensorVariable]] = None, allow_input_downcast: bool = False, on_unused_input: Union[Literal['raise'], Literal['warn'], Literal['ignore']] = 'warn') -> None:

参数

  • name: str,定义Theano函数的名称。
  • inputs: Tuple[Type[tt.TensorVariable], ...],定义Theano函数的输入参数的类型。
  • outputs: Tuple[Type[tt.TensorVariable], ...],定义Theano函数的输出参数的类型。
  • updates: Optional[Dict[tt.TensorVariable, tt.TensorVariable]],定义更新Theano函数中变量的功能。如果没有需要就可以不指定。
  • allow_input_downcast: bool,如果浮点数类型不一致,是否允许Theano函数将输入类型降级为更低的精度。
  • on_unused_input: Union[Literal['raise'], Literal['warn'], Literal['ignore']],定义如果有未使用的输入参数时的行为。默认为'warn'

返回值

  • None

示例

下面是一个设置Theano函数的示例:

import gempy as gp
import theano.tensor as tt

# 创建Gempy项目
geo_model = gp.create_model('Test_Project')

# 定义Theano函数
a = tt.matrix()
b = tt.matrix()
c = tt.dot(a, b)

# 设置Theano函数
geo_model.set_theano_function('test_theano_function', inputs=[a, b], outputs=[c])

# 获取Theano函数
theano_fn = geo_model.interpolator.tg.njit(
    [a.type(), b.type()], [c.type()],
    inline='always')

解释

该示例中首先创建了一个Gempy项目,然后以theano.tensor库定义了一个简单的Theano函数,然后使用set_theano_function设置了该Theano函数到Gempy项目中。

注意事项

  • 必须使用Theano返回的类型定义输入和输出参数的类型。如下:
import theano.tensor as tt

a = tt.matrix()  # 使用Theano定义的类型作为输入参数
b = tt.matrix()
c = tt.dot(a, b)  # 使用Theano定义的类型作为输出参数

否则,可能会出现以下错误:

TypeError: ('The following error happened while compiling the node', Dot22_scalar_<TensorType(float32, matrix), InplaceBlasTheano(gemv_inplace=True, openmp=False)>, '\n', 'Compilation failed (return status=1): /tmp/try_flags_54htf24n/mod.cpp:3:2: error: #error "Use "float32" or "float64" to represent a floating-point dtype." \n #error "Use "float32" or "float64" to represent a floating-point dtype." \n ^~~~ \n. To debug this error try the command: \npython -c \'import theano, theano.config, theano.gof.compiledir; print(theano.gof.compiledir.compile_args, file=sys.stderr); print(theano.gof.compiledir.cmodule_extensions(), file=sys.stderr)\' \n.```
- Theano函数输入参数最大数量不能超过8192个。