二次拟合MATLABm文件代码-genetic-mt1d:利用遗传算法对大地电磁数据进行一维反演

  • N5_748315
    了解作者
  • 28.6KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-23 07:47
    上传日期
二次拟合MATLAB m文件代码概述 Genetic-mt1d是一维大地电磁(MT)反演程序,它使用实值遗传算法为视电阻率和相位响应的数据集找到最合适的反演模型。 它是阿尔伯塔大学GEOPH526班级项目的一部分。 尽管我无法保证结果的正确性,但我成功地使用它来再现纸张的结果,因为他们将一维数据反转以找到电动Moho。 安装 Genetic-mt1d已写入并针对最新的稳定版本(在撰写本文时为0.4)进行了测试,因此您需要安装Julia来开始使用。 要安装generic-mt1d,请从Julia REPL中运行以下命令: Pkg . clone ( " https://github.com/alexjohnj/genetic-mt1d.git " , " MT1DGeneticInversion " ) 因为我没有在命名存储库时在考虑,所以您必须指定包的名称及其git地址。 用法 让我们用一个小例子来说明问题。 假设您在CSV文件中有一些数据,其中包括周期,视电阻率,相位及其相关的误差。 您要根据此数据反转3层模型。 使用您喜欢的方法(也许是readdlm ?)将数据加载到Julia中,
genetic-mt1d-master.zip
内容介绍
# Overview genetic-mt1d is a 1D magnetotelluric (MT) inversion program that uses a real valued genetic algorithm to find the best fitting inverse model for a data set of apparent resistivity and phase responses. It was written as part of a project for the GEOPH526 class at the University of Alberta. Although I can't make any guarantees about the correctness of the results, I've had success using it to reproduce the results of a paper by [Jones & Ferguson (2001)][electric-moho] where they inverted 1D data to find the electric Moho. [electric-moho]: http://www.nature.com/nature/journal/v409/n6818/abs/409331a0.html # Installation genetic-mt1d is written in [Julia][julia-lang] and tested against the latest stable build (0.4, at the time of writing), so you'll need to install Julia to get started. To install genetic-mt1d, run the following from a Julia REPL: ``` julia Pkg.clone("https://github.com/alexjohnj/genetic-mt1d.git", "MT1DGeneticInversion") ``` Because I wasn't thinking when I named the repository, you have to specify the package's name as well as its git address. [julia-lang]: http://julialang.org # Usage Let's use a little example to explain things. Say you have some data in a CSV file that consists of period, apparent resistivity, phase and their associated errors. You want to invert a 3 layer model from this data. Load this data into Julia using your preferred method (maybe `readdlm`?) and wrangle it into a matrix with 5 columns. The columns should be 1. Period (seconds) 2. Apparent resistivity (Ohm-metres) 3. Phase (degrees) 4. Apparent resistivity uncertainty (Ohm-metres) 5. Phase uncertainty (degrees) This is your `data` matrix. This is what we're going to invert. Now, in a Julia script, load genetic-mt1d: ``` julia using MT1DGeneticInversion ``` The first thing to do is define some constraints for the inversion. We'll want to place an upper and lower bound on resistivity and the depth to each layer. Constraints are represented by the `LayerBC` type, a simple struct with a `min` and `max` field. Each `LayerBC` instance represents the constraints for one parameter of one layer so we'll need two 3 element arrays of `LayerBC`s. Here, we'll set the same constraints for each layer: ``` julia zBounds = [LayerBC(0, 0) LayerBC(0, 1000) LayerBC(0, 1000)] # Depth rBounds = fill(LayerBC(1, 100), (3, 1)) # Resistivity ``` Note that for the depth constraints, the first layer is constrained to 0 m. This is a requirement and will produce an error if it's constrained to anything else. The depth to the other layers is constrained to 0--1000 m. Each layer's resistivity is constrained to 1--100 Ωm. Next we need to create an instance of the `Inversion` type using these constraints. We'll create an `Inversion` with a population size of 100 for the genetic algorithm. ``` julia I = Inversion(data, 100, zBounds, rBounds) ``` This creates an `Inversion` instance initialised with a population of 100 random models, generated within the constraints of `zBounds` and `rBounds`. The number of layers in the models is derived from the number of constraints provided. Using this constructor, the following parameters take their default values: - Number of elitist clones = 5% of the population size - Probability of mutation = 0.01 - Probability of selection = 0.65 - Tournament size = 2 - SBX Distribution index (η) = 2 If you want to change these, you can either modify the fields of `I` directly (see built in documentation) or use the more detailed constructor: ``` julia I = Inversion(data, 100, zBounds, rBounds, nElitist, probMut, probSel, tournSize, η) ``` Once the `Inversion` instance is created, we can evolve it using: ``` julia evolve!(I, 2000) ``` This evolves the population of `I` through 2000 generations, changing the state of `I` in the process. To get the best model after evolution, use the first element of `I`'s `pop` field: ```julia bestModel = I.pop[1] ``` The `pop` field is an array of `Model` instances sorted from fittest to weakest. `Model` instances have two important field. `Model.model` (confusing, sorry) accesses the matrix representation of the model where each row is a layer and the first column contains the depth to that layer while the second column contains its resistivity. `Model.fitness` gives you the root mean squared (RMS) misfit between the model's forward modelled response and the response in `data`. That is a (somewhat) long winded (but complete!, kinda) overview of using genetic-mt1d. Note that there is an example function in `examples/examples.jl` that inverts some real world data to find the depth to the electric Moho. You can probably use that as a starting point. Also, all the code's documented and it integrates with Julia's help system nicely. Try typing `?Inversion` at the REPL to get some more info on the `Inversion` type, for example. # How It Works The inversion makes use of a real valued genetic algorithm. Models are represented as Nx2 matrices (N = number of layers) and their apparent resistivity and phase response is forward modelled using [Wait (1954)][wait-recursion]. The genetic algorithm tries to minimise the RMS misfit between the models and the provided data until it is between 0.5 and 1.5. [wait-recursion]: http://library.seg.org/doi/abs/10.1190/1.1437994 Selection is implemented as a tournament selection with a customisable tournament size and selection probability. Crossover uses a simulated binary crossover (SBX) to combine two parents and produce two offsprings. In addition to the children, a certain number of elitist clones are copied over to the next generation. Mutation is applied per parameter in each model. For each parameter, we generate a random number and if it's less than the mutation chance, we pick a new value for the parameter within the layer's constraints. Because mutation is applied per parameter, the effect of the mutation rate will depend on the number of layers you're trying to invert in addition to the population size. # Performance Be warned, this isn't written with performance in mind. Nonetheless, the forward modelling calculation is relatively simple and for smallish populations (~100--200), performance is acceptable when running on a moderately powerful laptop (30s--60s for the example script). The genetic algorithm doesn't make use of multiple cores but one day I'd like to try and make it parallel. First I'll need to read the docs on parallel computing in Julia though. The forward modelling code is a straight up port of a MATLAB implementation I'd written that was highly vectorised. I'm aware that Julia's performance is worse with vectorised code so one day I'll explore devectorising the forward modelling code. Some initial benchmarks forward modelling a 3 layer model across 100,000 frequencies showed a large memory allocation, so there might be some performance to gain from devectorising.
评论
    相关推荐
    • Julia 集合。
      NULL 博文链接:https://croisee.iteye.com/blog/1280952
    • 物质点法开源代码MPM-Julia
      物质点法开源代码MPM-Julia, 是Julia语言编写,Julia这种专门为数值分析开发的语言不知道有没有未来。
    • GaloisFields.jl:Julia的有限字段
      GaloisFields.jl:Julia的有限字段
    • Gtk.jl, Julia接口到Gtk窗口工具箱.zip
      Gtk.jl, Julia接口到Gtk窗口工具箱 面向 Gtk 2 和 Gtk 3 GUI库的接口 使用Gtk库的GUI构建: http://www.gtk.org/完整的Gtk文档在 https://developer.gnome.org/gtk/stable 可
    • Juliaset.jl:生成Julia集图像
      使用以下命令: Pkg.clone("https://github.com/tanmaykm/Juliaset.jl.git"); using Juliaset; Juliaset.serve_juliabox(); Pkg.clone("https://github.com/tanmaykm/Juliaset.jl.git"); using Juliaset; Juliaset.
    • julia-workshop:Julia数据科学研讨会
      git clone https://github.com/crsl4/julia-workshop.git 教学大纲 会议 时间 话题 相关档案 在会议结束时 1个 30分钟 Julia入门 和 您将为在JuliaJulia)中的数据科学做好一切准备 2个 30分钟 数据工具说明 您将...
    • atom-language-julia-master.zip
      语言 julia 包 对 Atom 的 Julia 语言支持。 地位 鉴于我不再维护这个包,我已将language-julia句柄传递给以获取他的 。 请改用他的叉子! 向 Atom 中的 Julia 文件添加语法突出显示和片段。 版权所有 (c) 2014
    • Keras.jl:https://keras.io的Julia包装
      Keras.jl:https://keras.io的Julia包装
    • The Julia Language.zip
      Julia编程手册初始版Julia installation is straightforward, whether using precompiled binaries or compiling ... Download and install Julia by following the instructions at https://julialang.org/downloads/.
    • julia-cartridge:JuliaJulia Openshift)墨盒
      ~ $ rhc app create my_project_name https://raw.githubusercontent.com/ivandavid77/julia-cartridge/master/metadata/manifest.yml Your application 'my_project_name' is now available. URL: