{"text": "# ------------------------------------------------------------------------------------------\n# # Multiple dispatch\n# ------------------------------------------------------------------------------------------\n\n# ------------------------------------------------------------------------------------------\n# In this notebook we'll explore **multiple dispatch**, which is a key feature of Julia.\n#\n# Multiple dispatch makes software *generic* and *fast*!\n#\n# #### Starting with the familiar\n#\n# To understand multiple dispatch in Julia, let's start with what we've already seen.\n#\n# We can declare functions in Julia without giving Julia any information about the types of\n# the input arguments that function will receive:\n# ------------------------------------------------------------------------------------------\n\nf(x) = x^2\n\n# ------------------------------------------------------------------------------------------\n# and then Julia will determine on its own which input argument types make sense and which\n# do not:\n# ------------------------------------------------------------------------------------------\n\nf(10)\n\nf([1, 2, 3])\n\n# ------------------------------------------------------------------------------------------\n# #### Specifying the types of our input arguments\n#\n# However, we also have the *option* to tell Julia explicitly what types our input arguments\n# are allowed to have.\n#\n# For example, let's write a function `foo` that only takes strings as inputs.\n# ------------------------------------------------------------------------------------------\n\nfoo(x::String, y::String) = println(\"My inputs x and y are both strings!\")\n\n# ------------------------------------------------------------------------------------------\n# We see here that in order to restrict the type of `x` and `y` to `String`s, we just follow\n# the input argument name by a double colon and the keyword `String`.\n#\n# Now we'll see that `foo` works on `String`s and doesn't work on other input argument\n# types.\n# ------------------------------------------------------------------------------------------\n\nfoo(\"hello\", \"hi!\")\n\nfoo(3, 4)\n\n# ------------------------------------------------------------------------------------------\n# To get `foo` to work on integer (`Int`) inputs, let's tack `::Int` onto our input\n# arguments when we declare `foo`.\n# ------------------------------------------------------------------------------------------\n\nfoo(x::Int, y::Int) = println(\"My inputs x and y are both integers!\")\n\nfoo(3, 4)\n\n# ------------------------------------------------------------------------------------------\n# Now `foo` works on integers! But look, `foo` also still works when `x` and `y` are\n# strings!\n# ------------------------------------------------------------------------------------------\n\nfoo(\"hello\", \"hi!\")\n\n# ------------------------------------------------------------------------------------------\n# This is starting to get to the heart of multiple dispatch. When we declared\n#\n# ```julia\n# foo(x::Int, y::Int) = println(\"My inputs x and y are both integers!\")\n# ```\n# we didn't overwrite or replace\n# ```julia\n# foo(y::String, y::String)```\n#\n# Instead, we just added an additional ***method*** to the ***generic function*** called\n# `foo`.\n#\n# A ***generic function*** is the abstract concept associated with a particular operation.\n#\n# For example, the generic function `+` represents the concept of addition.\n#\n# A ***method*** is a specific implementation of a generic function for *particular argument\n# types*.\n#\n# For example, `+` has methods that accept floating point numbers, integers, matrices, etc.\n#\n# We can use the `methods` to see how many methods there are for `foo`.\n# ------------------------------------------------------------------------------------------\n\nmethods(foo)\n\nmethods(+)\n\n# ------------------------------------------------------------------------------------------\n# So, we now can call `foo` on integers or strings. When you call `foo` on a particular set\n# of arguments, Julia will infer the types of the inputs and dispatch the appropriate\n# method. *This* is multiple dispatch.\n#\n# Multiple dispatch makes our code generic and fast. Our code can be generic and flexible\n# because we can write code in terms of abstract operations such as addition and\n# multiplication, rather than in terms of specific implementations. At the same time, our\n# code runs quickly because Julia is able to call efficient methods for the relevant types.\n#\n# To see which method is being dispatched when we call a generic function, we can use the\n# @which macro:\n# ------------------------------------------------------------------------------------------\n\n@which foo(3, 4)\n\n@which 3.0 + 3.0\n\n# ------------------------------------------------------------------------------------------\n# Given that a method written specifically for floating point numbers is dispatched on `3.0\n# + 3.0`, the LLVM code generated is extremely terse:\n# ------------------------------------------------------------------------------------------\n\n@code_llvm 3.0 + 3.0\n\n# ------------------------------------------------------------------------------------------\n# Note that Julia is fast even when we write generic function definitions because, at the\n# end of the day, specific/tailored methods are called under the hood.\n#\n# For example, note that we can declare the adding function `myadd` without providing any\n# type annotations -\n# ------------------------------------------------------------------------------------------\n\nmyadd(x, y) = x + y\n\n# ------------------------------------------------------------------------------------------\n# and though we haven't constrained the types of `x` and `y`, we'll see that the LLVM code\n# generated for `myadd(3.0, 3.0)` looks like that of `3.0 + 3.0`\n# ------------------------------------------------------------------------------------------\n\n@code_llvm myadd(3.0, 3.0)\n", "meta": {"hexsha": "bbd3b8e278c9a68a5fe32c4cb9090b049bf6aa32", "size": 5929, "ext": "jl", "lang": "Julia", "max_stars_repo_path": ".nbexports/introductory-tutorials/intro-to-julia/short-version/06.Multiple_dispatch.jl", "max_stars_repo_name": "grenkoca/JuliaTutorials", "max_stars_repo_head_hexsha": "3968e0430db77856112521522e10f7da0d7610a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 535, "max_stars_repo_stars_event_min_datetime": "2020-07-15T14:56:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T12:50:32.000Z", "max_issues_repo_path": ".nbexports/introductory-tutorials/intro-to-julia/short-version/06.Multiple_dispatch.jl", "max_issues_repo_name": "grenkoca/JuliaTutorials", "max_issues_repo_head_hexsha": "3968e0430db77856112521522e10f7da0d7610a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 42, "max_issues_repo_issues_event_min_datetime": "2018-02-25T22:53:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-14T02:15:50.000Z", "max_forks_repo_path": ".nbexports/introductory-tutorials/intro-to-julia/short-version/06.Multiple_dispatch.jl", "max_forks_repo_name": "grenkoca/JuliaTutorials", "max_forks_repo_head_hexsha": "3968e0430db77856112521522e10f7da0d7610a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 394, "max_forks_repo_forks_event_min_datetime": "2020-07-14T23:22:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T20:12:57.000Z", "avg_line_length": 42.9637681159, "max_line_length": 92, "alphanum_fraction": 0.4456063417, "num_tokens": 1033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.46490157137338844, "lm_q2_score": 0.21469142916152645, "lm_q1q2_score": 0.09981038277759216}} {"text": "### A Pluto.jl notebook ###\n# v0.17.4\n\nusing Markdown\nusing InteractiveUtils\n\n# ╔═╡ bbe90636-9d1f-4ee0-8e35-c285f7b922d0\nbegin\n\timport CSV, DataFrames\n\tusing EvoTrees\n \tusing MLJ \n \tusing MLJLinearModels\n\tusing MLJBase\n \tusing MLJMultivariateStatsInterface\n \tusing UrlDownload\n\tusing PlutoUI\nend\n\n\n# ╔═╡ 83a7b4d7-6442-44b2-9388-8330b19cd537\nhtml\"\"\"\n
\n\nTutorial - Part 3
\n\nMachine Learning in Julia\n
\n\"\"\"\n\n# ╔═╡ 24abafc3-0e26-4cd2-9bca-7c69b794f8ce\nPlutoUI.TableOfContents(title = \"MLJ Tutorial - Part 3\")\n\n# ╔═╡ b67c62c2-15ab-4328-b795-033f6f2a0674\nmd\"\"\"\nAn introduction to the\n[MLJ](https://alan-turing-institute.github.io/MLJ.jl/stable/)\ntoolbox.\n\"\"\"\n\n# ╔═╡ bc689638-fd19-4c9f-935f-ddf6a6bfbbdd\nmd\"## Set-up\"\n\n# ╔═╡ 197fd00e-9068-46ea-af2a-25235e544a31\nmd\"Inspect Julia version:\"\n\n# ╔═╡ f6d4f8c4-e441-45c4-8af5-148d95ea2900\nVERSION\n\n# ╔═╡ 45740c4d-b789-45dc-a6bf-47194d7e8e12\nmd\"The following instantiates a package environment.\"\n\n# ╔═╡ 42b0f1e1-16c9-4238-828a-4cc485149963\nmd\"\"\"\nThe package environment has been created using **Julia 1.6** and may not\ninstantiate properly for other Julia versions.\n\"\"\"\n\n# ╔═╡ 499cbc31-83ba-4583-ba1f-6363f43ec697\nmd\"## General resources\"\n\n# ╔═╡ db5821e8-956a-4a46-95ea-2955abd45275\nmd\"\"\"\n- [MLJ Cheatsheet](https://alan-turing-institute.github.io/MLJ.jl/dev/mlj_cheatsheet/)\n- [Common MLJ Workflows](https://alan-turing-institute.github.io/MLJ.jl/dev/common_mlj_workflows/)\n- [MLJ manual](https://alan-turing-institute.github.io/MLJ.jl/dev/)\n- [Data Science Tutorials in Julia](https://juliaai.github.io/DataScienceTutorials.jl/)\n\"\"\"\n\n# ╔═╡ 1e248249-5629-412f-b1b3-dd47e367ba54\nmd\"# Part 3 - Transformers and Pipelines\"\n\n# ╔═╡ d055d24f-1b2d-48a6-8d7e-8e449afd1c48\nmd\"## Transformers\"\n\n# ╔═╡ 0dc40881-6163-4948-a949-7f3bd292fe31\nmd\"\"\"\nUnsupervised models, which receive no target `y` during training,\nalways have a `transform` operation. They sometimes also support an\n`inverse_transform` operation, with obvious meaning, and sometimes\nsupport a `predict` operation (see the clustering example discussed\n[here](https://alan-turing-institute.github.io/MLJ.jl/dev/transformers/#Transformers-that-also-predict-1)).\nOtherwise, they are handled much like supervised models.\n\"\"\"\n\n# ╔═╡ 0d066909-c9bf-4ae3-8514-99938a2932db\nmd\"Here's a simple standardization example:\"\n\n# ╔═╡ 29ea6531-1337-4527-92bd-6ebccf75659a\n x = rand(100)\n\n# ╔═╡ ad63ad4b-04c0-491b-a0de-1721c1bc2df2\n(mean(x), std(x))\n\n# ╔═╡ f86b62eb-6853-482a-bca8-7eec7950fd82\nbegin\n model = Standardizer() # a built-in model\n mach1 = machine(model, x)\n fit!(mach1)\n xhat = MLJ.transform(mach1, x);\n (mean(xhat), std(xhat))\nend\n\n# ╔═╡ 58686fe6-088a-4751-9873-1b1430e635cc\nmd\"This particular model has an `inverse_transform`:\"\n\n# ╔═╡ 8b90b209-cb98-4116-b43e-d0ebe87da176\ninverse_transform(mach1, xhat) ≈ x\n\n# ╔═╡ f1b47e75-0ce3-4e90-9009-4cfb2012998f\nmd\"## Re-encoding the King County House data as continuous\"\n\n# ╔═╡ e904fcb3-7603-40d2-abd3-cb77d7a79683\nmd\"\"\"\nFor further illustrations of transformers, let's re-encode *all* of the\nKing County House input features (see [Ex\n3](#exercise-3-fixing-scitypes-in-a-table)) into a set of `Continuous`\nfeatures. We do this with the `ContinuousEncoder` model, which, by\ndefault, will:\n\"\"\"\n\n# ╔═╡ e93966db-0dab-42ca-879e-dc128f3db7b3\nmd\"\"\"\n- one-hot encode all `Multiclass` features\n- coerce all `OrderedFactor` features to `Continuous` ones\n- coerce all `Count` features to `Continuous` ones (there aren't any)\n- drop any remaining non-Continuous features (none of these either)\n\"\"\"\n\n# ╔═╡ 2564f31e-4704-4820-a367-9aa3c6cf34d0\nmd\"First, we reload the data and fix the scitypes (Exercise 3):\"\n\n# ╔═╡ 7e23f8f6-1634-45c8-bf32-94657e65284e\nbegin\n \n house_csv = urldownload(\"https://raw.githubusercontent.com/ablaom/\"*\n \"MachineLearningInJulia2020/for-MLJ-version-0.16/\"*\n \"data/house.csv\");\n house = DataFrames.DataFrame(house_csv)\n coerce!(house, autotype(house_csv));\n coerce!(house, Count => Continuous, :zipcode => Multiclass);\n schema(house)\nend\n\n# ╔═╡ 348ff9a2-89ab-434a-9afd-65a5b5facac9\nyHouse, XHouse = unpack(house, ==(:price), rng=123);\n\n# ╔═╡ c7e83ce7-f067-4049-b6c8-54f5ed90a964\nmd\"Instantiate the unsupervised model (transformer):\"\n\n# ╔═╡ a6106065-1baf-4720-9292-fe822525fc77\nencoder = ContinuousEncoder() # a built-in model; no need to @load it\n\n# ╔═╡ 703d4ac3-116e-4e05-ae5e-4b83dcbc9675\nmd\"Bind the model to the data and fit!\"\n\n# ╔═╡ 5d976f7e-45ee-4cbb-8a29-32f11452654a\nmach2 = machine(encoder, XHouse) |> fit!\n\n# ╔═╡ aad55579-14f3-439a-a5f1-151fcbe229a2\nmd\"Transform and inspect the result:\"\n\n# ╔═╡ a6c1d3ea-6f43-42c7-8950-2f4327f23c1f\nXHouseCont = MLJ.transform(mach2, XHouse)\n\n# ╔═╡ 9f2f583a-e90a-43f6-81bc-2d5603785a09\nschema(XHouseCont)\n\n# ╔═╡ 828460a7-7d4e-444e-9d87-1d1fbb0e3997\nmd\"## More transformers\"\n\n# ╔═╡ 12631f23-8262-475d-b950-fddef2a1fb10\nmd\"Here's how to list all of MLJ's unsupervised models:\"\n\n# ╔═╡ d9069be8-d8c5-43ab-951b-64cb2a36c8e3\nmodels(m->!m.is_supervised)\n\n# ╔═╡ 4dee7ef6-b472-4b9c-b0e6-441461cc8770\nmd\"Some commonly used ones are built-in (do not require `@load`ing):\"\n\n# ╔═╡ 7a6df9e6-89f1-4117-8cb0-de601961bc02\nmd\"\"\"\nmodel type | does what?\n:----------------------------|:----------------------------------------------\nContinuousEncoder | transform input table to a table of `Continuous` features (see above)\nFeatureSelector | retain or dump selected features\nFillImputer | impute missing values\nOneHotEncoder | one-hot encoder `Multiclass` (and optionally `OrderedFactor`) features\nStandardizer | standardize (whiten) a vector or all `Continuous` features of a table\nUnivariateBoxCoxTransformer | apply a learned Box-Cox transformation to a vector\nUnivariateDiscretizer | discretize a `Continuous` vector, and hence render its elscitypw `OrderedFactor`\n\"\"\"\n\n# ╔═╡ 8ff17b93-2830-41e2-a87d-950c50fb2955\nmd\"\"\"\nIn addition to \"dynamic\" transformers (ones that learn something\nfrom the data and must be `fit!`) users can wrap ordinary functions\nas transformers, and such *static* transformers can depend on\nparameters, like the dynamic ones. See\n[here](https://alan-turing-institute.github.io/MLJ.jl/dev/transformers/#Static-transformers-1)\nfor how to define your own static transformers.\n\"\"\"\n\n# ╔═╡ d45a81ec-f978-4483-8448-4bcb089096cd\nmd\"## Pipelines\"\n\n# ╔═╡ b454845b-3b3b-4c46-a012-a84240254fb6\nlength(schema(XHouseCont).names)\n\n# ╔═╡ 28cf44d4-3f4b-485f-bbdd-9799f7bb2e60\nmd\"\"\"\nLet's suppose that additionally we'd like to reduce the dimension of\nour data. A model that will do this is `PCA` from\n`MultivariateStats.jl`:\n\"\"\"\n\n# ╔═╡ 1e780939-abf0-4203-97a7-88e3af4f10ee\nPCA = @load PCA\n\n# ╔═╡ 09ece795-72e1-4240-a833-1b098ab27d3f\nreducer = PCA()\n\n# ╔═╡ 8e76b5a5-7c80-4684-b372-8c9866e51852\nmd\"\"\"\nNow, rather simply repeating the work-flow above, applying the new\ntransformation to `XHouseCont`, we can combine both the encoding and the\ndimension-reducing models into a single model, known as a\n*pipeline*. While MLJ offers a powerful interface for composing\nmodels in a variety of ways, we'll stick to these simplest class of\ncomposite models for now. The simplest way to construct a pipeline is using the Julia's `|>` syntax:\n\"\"\"\n\n# ╔═╡ 5ed77309-afa6-4c94-88c0-761fe6b5a5d4\npipe1 = encoder |> reducer\n\n# ╔═╡ d45ff6ec-2dd6-4a9c-a97e-79337b0be5c8\nmd\"\"\"\nNotice that the model `pipe` has other models as hyperparameters (with names automatically generated based on the mode type name). The hyperparameters of the component models are are now nested, but we can still access them:\n\"\"\"\n\n# ╔═╡ 4a0b7419-d9ae-4570-b9b6-029e155045c0\npipe1.pca.pratio\n\n# ╔═╡ 3958b3df-51cd-4920-8f28-382c4a088a8f\npipe1.pca.pratio = 0.85\n\n# ╔═╡ e68044d8-42b4-49cd-86cf-35420d9e6995\nmd\"The pipeline model behaves like any other transformer:\"\n\n# ╔═╡ 26d649a8-3d96-4479-a29a-8d0445351914\nbegin\n mach3 = machine(pipe1, XHouse)\n fit!(mach3)\n XHouseSmall = transform(mach3, XHouse)\n schema(XHouseSmall)\nend\n\n# ╔═╡ 7f60c74e-b708-46f4-be65-28d0fcca50a8\nmd\"Want to combine this pre-processing with ridge regression?\"\n\n# ╔═╡ c8c960f0-2a46-42c2-8754-8bd531c8db8e\nRidgeRegressor = @load RidgeRegressor pkg=MLJLinearModels\n\n# ╔═╡ 4e327bb5-8abc-4e68-9832-d4c16415df30\nrgs = RidgeRegressor()\n\n# ╔═╡ f96a84ec-1cc0-400c-9493-9c2a2e3c5b51\npipe2 = pipe1 |> rgs\n\n# ╔═╡ fbb24be1-fe01-4489-b5fa-cb79ebf595ef\nmd\"\"\"\nNow our pipeline is a supervised model, instead of a transformer,\nwhose performance we can evaluate:\n\"\"\"\n\n# ╔═╡ 958f9a9a-23d5-446b-aa54-f7a086cb0264\nmach4 = machine(pipe2, XHouse, yHouse)\n\n# ╔═╡ ea64dbb5-963a-4da4-91c5-524da38aa391\nevaluate!(mach4, measure=mae, resampling=Holdout()) # CV(nfolds=6) is default\n\n# ╔═╡ 1ce36a90-ea25-48d6-ad90-b4405b216771\nmd\"## Training of composite models is \\\"smart\\\"\"\n\n# ╔═╡ 4270976f-1207-4086-895b-997a92b731e0\nmd\"\"\"\nNow notice what happens if we train on all the data, then change a\nregressor hyper-parameter and retrain:\n\"\"\"\n\n# ╔═╡ 1d0bce6b-ffff-4f30-a525-e9b04a4bd246\nfit!(mach4)\n\n# ╔═╡ 64a648e0-d5c9-4c3d-80f0-ba7781e173cf\nwith_terminal() do\n pipe2.ridge_regressor.lambda = 0.1\n fit!(mach4)\nend\n\n# ╔═╡ 5dcd0d55-bb5d-459a-9cbc-9a2c39793333\nmd\"Second time only the ridge regressor is retrained!\"\n\n# ╔═╡ 234c586e-862f-4216-b887-2b16710e5502\nmd\"\"\"\nMutate a hyper-parameter of the `PCA` model and every model except\nthe `ContinuousEncoder` (which comes before it will be retrained):\n\"\"\"\n\n# ╔═╡ b8e84a2c-2c7f-41f5-9452-5298a8a4a401\nwith_terminal() do\n pipe2.pca.pratio = 0.9999\n fit!(mach4)\nend\n\n# ╔═╡ 95b75a71-47b5-49b1-b017-96f1602f2cad\nmd\"## Inspecting composite models\"\n\n# ╔═╡ 5de9f9a0-ad8f-47de-8be2-2a4017c45345\nmd\"\"\"\nThe dot syntax used above to change the values of *nested*\nhyper-parameters is also useful when inspecting the learned\nparameters and report generated when training a composite model:\n\"\"\"\n\n# ╔═╡ aa7bdff7-7d1b-43b1-a7ad-80d84f5b0070\nfitted_params(mach4).ridge_regressor\n\n# ╔═╡ 92c5bc62-b430-41b8-8378-5aa686f0b407\nreport(mach4).pca\n\n# ╔═╡ adcb0506-e89d-43b0-9f43-49763e8691a1\nmd\"## Incorporating target transformations\"\n\n# ╔═╡ 667917e3-25d2-435c-bb0e-3a45761c733a\nmd\"\"\"\nNext, suppose that instead of using the raw `:price` as the\ntraining target, we want to use the log-price (a common practice in\ndealing with house price data). However, suppose that we still want\nto report final *predictions* on the original linear scale (and use\nthese for evaluation purposes). Then we wrap our unsupervised model using `TransformedTargetModel`, which has\nthe key-word arguments `target` and `inverse`.\n\"\"\"\n\n# ╔═╡ f71e4957-b6aa-480f-8acf-0c1d237fe9f9\nmd\"\"\"\nFirst we'll overload `log` and `exp` for broadcasting:\n\"\"\"\n\n# ╔═╡ dc119abd-72a1-4781-811d-5998beb56406\nbegin\n\tBase.log(v::AbstractArray) = log.(v)\n\tBase.exp(v::AbstractArray) = exp.(v)\nend\n\n# ╔═╡ 0398adfe-721a-4b97-910b-f8a9a217eff2\nmd\"Now for the new pipeline:\"\n\n# ╔═╡ 85f71232-0ec4-40a8-81b7-e11a56b42313\nrgs_log = TransformedTargetModel(rgs, target = log, inverse = exp)\n\n# ╔═╡ d1af0582-9074-4355-9d03-7ceec3db5d7f\npipe3 = pipe1 |> rgs_log\n\n# ╔═╡ 06fac83d-ec17-4503-b3b1-670e16d4251a\nmach5 = machine(pipe3, XHouse, yHouse)\n\n# ╔═╡ 9335bbb6-7169-47a2-8ccb-85c839a68433\nevaluate!(mach5, measure = mae)\n\n# ╔═╡ fbe0163a-ed06-49ea-8faa-017fa7aeca69\nmd\"\"\"\nMLJ will also allow you to insert *learned* target\ntransformations. For example, we might want to apply\n`Standardizer()` to the target, to standardize it, or\n`UnivariateBoxCoxTransformer()` to make it look Gaussian. Then\ninstead of specifying a *function* for `target`, we specify a\nunsupervised *model* (or model type). One does not specify `inverse`\nbecause only models implementing `inverse_transform` are\nallowed.\n\"\"\"\n\n# ╔═╡ 4fd0807d-61e5-4b4b-a1cb-54e34396a855\nmd\"Let's see which of these two options results in a better outcome:\"\n\n# ╔═╡ 1957f387-aee4-4c08-9838-327b915082f8\nbox = UnivariateBoxCoxTransformer(n=20)\n\n# ╔═╡ 7b59b396-daac-4dea-bc51-54fafe346cd8\nstand = Standardizer()\n\n# ╔═╡ 2efdfa9c-8e70-4c09-b9f9-85c873edc16a\nrgs_box = TransformedTargetModel(rgs, target=box)\n\n# ╔═╡ dcf51860-a300-453e-87fc-345e741f94d0\npipe4 = pipe1 |> rgs_box\n\n# ╔═╡ c54f41ee-75e6-4181-8de7-d194004c9700\nmach6 = machine(pipe4, XHouse, yHouse)\n\n# ╔═╡ cb026565-6c5c-4f7a-91b6-417cfea74d41\nevaluate!(mach6, measure = mae)\n\n# ╔═╡ e073f936-f2a0-4609-83fe-bd8afb87cfc1\npipe4.transformed_target_model_deterministic.target = stand\n\n# ╔═╡ 91cca9cb-db5f-4d9f-983b-3f2b20444662\nevaluate!(mach6, measure = mae)\n\n# ╔═╡ a0488295-9642-4156-b7cc-46f4ef988c68\nmd\"# Resources for Part 3\"\n\n# ╔═╡ d59d9e91-b26d-4342-90fb-7f2721f6fcc7\nmd\"\"\"\n- From the MLJ manual:\n - [Transformers and other unsupervised models](https://alan-turing-institute.github.io/MLJ.jl/dev/transformers/)\n - [Linear pipelines](https://alan-turing-institute.github.io/MLJ.jl/dev/linear_pipelines/#Linear-Pipelines)\n- From Data Science Tutorials:\n - [Composing models](https://juliaai.github.io/DataScienceTutorials.jl/getting-started/composing-models/)\n\"\"\"\n\n# ╔═╡ c4f30527-c9b4-44e9-af65-ccd25ecb9818\nmd\"# Exercises for Part 3\"\n\n# ╔═╡ 25a6fd3c-60d1-44dd-8890-979691212d9b\nmd\"#### Exercise 7\"\n\n# ╔═╡ aed2b274-cc0c-42f2-a6fa-eaf14df5d44b\nmd\"\"\"\nConsider again the Horse Colic classification problem considered in\nExercise 6, but with all features, `Finite` and `Infinite`:\n\"\"\"\n\n# ╔═╡ 0df6be04-24fe-4417-8025-5084804a9f6c\nbegin\n csv_file = urldownload(\"https://raw.githubusercontent.com/ablaom/\"*\n \"MachineLearningInJulia2020/\"*\n \"for-MLJ-version-0.16/data/horse.csv\");\n horse = DataFrames.DataFrame(csv_file); # convert to data frame\n coerce!(horse, autotype(horse));\n coerce!(horse, Count => Continuous);\n coerce!(horse,\n :surgery => Multiclass,\n :age => Multiclass,\n :mucous_membranes => Multiclass,\n :capillary_refill_time => Multiclass,\n :outcome => Multiclass,\n :cp_data => Multiclass);\n \n yHorse, XHorse = unpack(horse, ==(:outcome));\n schema(XHorse)\nend\n\n# ╔═╡ 9abf25a8-7231-43f5-9e90-09023d201062\nmd\"\"\"\n(a) Define a pipeline that:\n- uses `Standardizer` to ensure that features that are already\n continuous are centered at zero and have unit variance\n- re-encodes the full set of features as `Continuous`, using\n `ContinuousEncoder`\n- uses the `KMeans` clustering model from `Clustering.jl`\n to reduce the dimension of the feature space to `k=10`.\n- trains a `EvoTreeClassifier` (a gradient tree boosting\n algorithm in `EvoTrees.jl`) on the reduced data, using\n `nrounds=50` and default values for the other\n hyper-parameters\n\n(b) Evaluate the pipeline on all data, using 6-fold cross-validation\nand `cross_entropy` loss.\n\n $\\star$ (c) Plot a learning curve which examines the effect on this loss\nas the tree booster parameter `max_depth` varies from 2 to 10.\n\"\"\"\n\n# ╔═╡ 6cce6530-0d12-4862-af4f-11c7de9e21dd\nhtml\"\"\n\n# ╔═╡ 135dac9b-0bd9-4e1d-8dba-241d9b744683\nmd\"\"\"\n---\n\n*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*\n\"\"\"\n\n# ╔═╡ 00000000-0000-0000-0000-000000000001\nPLUTO_PROJECT_TOML_CONTENTS = \"\"\"\n[deps]\nCSV = \"336ed68f-0bac-5ca0-87d4-7b16caf5d00b\"\nDataFrames = \"a93c6f00-e57d-5684-b7b6-d8193f3e46c0\"\nEvoTrees = \"f6006082-12f8-11e9-0c9c-0d5d367ab1e5\"\nMLJ = \"add582a8-e3ab-11e8-2d5e-e98b27df1bc7\"\nMLJBase = \"a7f614a8-145f-11e9-1d2a-a57a1082229d\"\nMLJLinearModels = \"6ee0df7b-362f-4a72-a706-9e79364fb692\"\nMLJMultivariateStatsInterface = \"1b6a4a23-ba22-4f51-9698-8599985d3728\"\nPlutoUI = \"7f904dfe-b85e-4ff6-b463-dae2292396a8\"\nUrlDownload = \"856ac37a-3032-4c1c-9122-f86d88358c8b\"\n\n[compat]\nCSV = \"~0.9.11\"\nDataFrames = \"~1.3.1\"\nEvoTrees = \"~0.9.1\"\nMLJ = \"~0.17.0\"\nMLJBase = \"~0.19.2\"\nMLJLinearModels = \"~0.5.7\"\nMLJMultivariateStatsInterface = \"~0.2.2\"\nPlutoUI = \"~0.7.27\"\nUrlDownload = \"~1.0.0\"\n\"\"\"\n\n# ╔═╡ 00000000-0000-0000-0000-000000000002\nPLUTO_MANIFEST_TOML_CONTENTS = \"\"\"\n# This file is machine-generated - editing it directly is not advised\n\n[[ARFFFiles]]\ndeps = [\"CategoricalArrays\", \"Dates\", \"Parsers\", \"Tables\"]\ngit-tree-sha1 = \"e8c8e0a2be6eb4f56b1672e46004463033daa409\"\nuuid = \"da404889-ca92-49ff-9e8b-0aa6b4d38dc8\"\nversion = \"1.4.1\"\n\n[[AbstractFFTs]]\ndeps = [\"LinearAlgebra\"]\ngit-tree-sha1 = \"485ee0867925449198280d4af84bdb46a2a404d0\"\nuuid = \"621f4979-c628-5d54-868e-fcf4e3e8185c\"\nversion = \"1.0.1\"\n\n[[AbstractPlutoDingetjes]]\ndeps = [\"Pkg\"]\ngit-tree-sha1 = \"8eaf9f1b4921132a4cff3f36a1d9ba923b14a481\"\nuuid = \"6e696c72-6542-2067-7265-42206c756150\"\nversion = \"1.1.4\"\n\n[[Adapt]]\ndeps = [\"LinearAlgebra\"]\ngit-tree-sha1 = \"af92965fb30777147966f58acb05da51c5616b5f\"\nuuid = \"79e6a3ab-5dfb-504d-930d-738a2a938a0e\"\nversion = \"3.3.3\"\n\n[[ArgTools]]\nuuid = \"0dad84c5-d112-42e6-8d28-ef12dabb789f\"\n\n[[Arpack]]\ndeps = [\"Arpack_jll\", \"Libdl\", \"LinearAlgebra\"]\ngit-tree-sha1 = \"2ff92b71ba1747c5fdd541f8fc87736d82f40ec9\"\nuuid = \"7d9fca2a-8960-54d3-9f78-7d1dccf2cb97\"\nversion = \"0.4.0\"\n\n[[Arpack_jll]]\ndeps = [\"Libdl\", \"OpenBLAS_jll\", \"Pkg\"]\ngit-tree-sha1 = \"e214a9b9bd1b4e1b4f15b22c0994862b66af7ff7\"\nuuid = \"68821587-b530-5797-8361-c406ea357684\"\nversion = \"3.5.0+3\"\n\n[[ArrayInterface]]\ndeps = [\"Compat\", \"IfElse\", \"LinearAlgebra\", \"Requires\", \"SparseArrays\", \"Static\"]\ngit-tree-sha1 = \"1ee88c4c76caa995a885dc2f22a5d548dfbbc0ba\"\nuuid = \"4fba245c-0d91-5ea0-9b3e-6abc04ee57a9\"\nversion = \"3.2.2\"\n\n[[Artifacts]]\nuuid = \"56f22d72-fd6d-98f1-02f0-08ddc0907c33\"\n\n[[BFloat16s]]\ndeps = [\"LinearAlgebra\", \"Printf\", \"Random\", \"Test\"]\ngit-tree-sha1 = \"a598ecb0d717092b5539dbbe890c98bac842b072\"\nuuid = \"ab4f0b2a-ad5b-11e8-123f-65d77653426b\"\nversion = \"0.2.0\"\n\n[[BSON]]\ngit-tree-sha1 = \"ebcd6e22d69f21249b7b8668351ebf42d6dc87a1\"\nuuid = \"fbb218c0-5317-5bc6-957e-2ee96dd4b1f0\"\nversion = \"0.3.4\"\n\n[[Base64]]\nuuid = \"2a0f44e3-6c83-55bd-87e4-b1978d98bd5f\"\n\n[[CEnum]]\ngit-tree-sha1 = \"215a9aa4a1f23fbd05b92769fdd62559488d70e9\"\nuuid = \"fa961155-64e5-5f13-b03f-caf6b980ea82\"\nversion = \"0.4.1\"\n\n[[CSV]]\ndeps = [\"CodecZlib\", \"Dates\", \"FilePathsBase\", \"InlineStrings\", \"Mmap\", \"Parsers\", \"PooledArrays\", \"SentinelArrays\", \"Tables\", \"Unicode\", \"WeakRefStrings\"]\ngit-tree-sha1 = \"49f14b6c56a2da47608fe30aed711b5882264d7a\"\nuuid = \"336ed68f-0bac-5ca0-87d4-7b16caf5d00b\"\nversion = \"0.9.11\"\n\n[[CUDA]]\ndeps = [\"AbstractFFTs\", \"Adapt\", \"BFloat16s\", \"CEnum\", \"CompilerSupportLibraries_jll\", \"ExprTools\", \"GPUArrays\", \"GPUCompiler\", \"LLVM\", \"LazyArtifacts\", \"Libdl\", \"LinearAlgebra\", \"Logging\", \"Printf\", \"Random\", \"Random123\", \"RandomNumbers\", \"Reexport\", \"Requires\", \"SparseArrays\", \"SpecialFunctions\", \"TimerOutputs\"]\ngit-tree-sha1 = \"429a1a05348ce948a96adbdd873fbe6d9e5e052f\"\nuuid = \"052768ef-5323-5732-b1bb-66c8b64840ba\"\nversion = \"3.6.2\"\n\n[[CategoricalArrays]]\ndeps = [\"DataAPI\", \"Future\", \"Missings\", \"Printf\", \"Requires\", \"Statistics\", \"Unicode\"]\ngit-tree-sha1 = \"c308f209870fdbd84cb20332b6dfaf14bf3387f8\"\nuuid = \"324d7699-5711-5eae-9e2f-1d82baa6b597\"\nversion = \"0.10.2\"\n\n[[CategoricalDistributions]]\ndeps = [\"CategoricalArrays\", \"Distributions\", \"Missings\", \"OrderedCollections\", \"Random\", \"ScientificTypesBase\", \"UnicodePlots\"]\ngit-tree-sha1 = \"a5734a58e5dc8c749b5507d03ba5e457d077181b\"\nuuid = \"af321ab8-2d2e-40a6-b165-3d674595d28e\"\nversion = \"0.1.4\"\n\n[[ChainRulesCore]]\ndeps = [\"Compat\", \"LinearAlgebra\", \"SparseArrays\"]\ngit-tree-sha1 = \"926870acb6cbcf029396f2f2de030282b6bc1941\"\nuuid = \"d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4\"\nversion = \"1.11.4\"\n\n[[ChangesOfVariables]]\ndeps = [\"ChainRulesCore\", \"LinearAlgebra\", \"Test\"]\ngit-tree-sha1 = \"bf98fa45a0a4cee295de98d4c1462be26345b9a1\"\nuuid = \"9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0\"\nversion = \"0.1.2\"\n\n[[CodecZlib]]\ndeps = [\"TranscodingStreams\", \"Zlib_jll\"]\ngit-tree-sha1 = \"ded953804d019afa9a3f98981d99b33e3db7b6da\"\nuuid = \"944b1d66-785c-5afd-91f1-9de20f533193\"\nversion = \"0.7.0\"\n\n[[ColorTypes]]\ndeps = [\"FixedPointNumbers\", \"Random\"]\ngit-tree-sha1 = \"024fe24d83e4a5bf5fc80501a314ce0d1aa35597\"\nuuid = \"3da002f7-5984-5a60-b8a6-cbb66c0b333f\"\nversion = \"0.11.0\"\n\n[[CommonSubexpressions]]\ndeps = [\"MacroTools\", \"Test\"]\ngit-tree-sha1 = \"7b8a93dba8af7e3b42fecabf646260105ac373f7\"\nuuid = \"bbf7d656-a473-5ed7-a52c-81e309532950\"\nversion = \"0.3.0\"\n\n[[Compat]]\ndeps = [\"Base64\", \"Dates\", \"DelimitedFiles\", \"Distributed\", \"InteractiveUtils\", \"LibGit2\", \"Libdl\", \"LinearAlgebra\", \"Markdown\", \"Mmap\", \"Pkg\", \"Printf\", \"REPL\", \"Random\", \"SHA\", \"Serialization\", \"SharedArrays\", \"Sockets\", \"SparseArrays\", \"Statistics\", \"Test\", \"UUIDs\", \"Unicode\"]\ngit-tree-sha1 = \"44c37b4636bc54afac5c574d2d02b625349d6582\"\nuuid = \"34da2185-b29b-5c13-b0c7-acf172513d20\"\nversion = \"3.41.0\"\n\n[[CompilerSupportLibraries_jll]]\ndeps = [\"Artifacts\", \"Libdl\"]\nuuid = \"e66e0078-7015-5450-92f7-15fbd957f2ae\"\n\n[[ComputationalResources]]\ngit-tree-sha1 = \"52cb3ec90e8a8bea0e62e275ba577ad0f74821f7\"\nuuid = \"ed09eef8-17a6-5b46-8889-db040fac31e3\"\nversion = \"0.3.2\"\n\n[[Crayons]]\ngit-tree-sha1 = \"b618084b49e78985ffa8422f32b9838e397b9fc2\"\nuuid = \"a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f\"\nversion = \"4.1.0\"\n\n[[DataAPI]]\ngit-tree-sha1 = \"cc70b17275652eb47bc9e5f81635981f13cea5c8\"\nuuid = \"9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a\"\nversion = \"1.9.0\"\n\n[[DataFrames]]\ndeps = [\"Compat\", \"DataAPI\", \"Future\", \"InvertedIndices\", \"IteratorInterfaceExtensions\", \"LinearAlgebra\", \"Markdown\", \"Missings\", \"PooledArrays\", \"PrettyTables\", \"Printf\", \"REPL\", \"Reexport\", \"SortingAlgorithms\", \"Statistics\", \"TableTraits\", \"Tables\", \"Unicode\"]\ngit-tree-sha1 = \"cfdfef912b7f93e4b848e80b9befdf9e331bc05a\"\nuuid = \"a93c6f00-e57d-5684-b7b6-d8193f3e46c0\"\nversion = \"1.3.1\"\n\n[[DataStructures]]\ndeps = [\"Compat\", \"InteractiveUtils\", \"OrderedCollections\"]\ngit-tree-sha1 = \"3daef5523dd2e769dad2365274f760ff5f282c7d\"\nuuid = \"864edb3b-99cc-5e75-8d2d-829cb0a9cfe8\"\nversion = \"0.18.11\"\n\n[[DataValueInterfaces]]\ngit-tree-sha1 = \"bfc1187b79289637fa0ef6d4436ebdfe6905cbd6\"\nuuid = \"e2d170a0-9d28-54be-80f0-106bbe20a464\"\nversion = \"1.0.0\"\n\n[[Dates]]\ndeps = [\"Printf\"]\nuuid = \"ade2ca70-3891-5945-98fb-dc099432e06a\"\n\n[[DelimitedFiles]]\ndeps = [\"Mmap\"]\nuuid = \"8bb1440f-4735-579b-a4ab-409b98df4dab\"\n\n[[DensityInterface]]\ndeps = [\"InverseFunctions\", \"Test\"]\ngit-tree-sha1 = \"80c3e8639e3353e5d2912fb3a1916b8455e2494b\"\nuuid = \"b429d917-457f-4dbc-8f4c-0cc954292b1d\"\nversion = \"0.4.0\"\n\n[[DiffResults]]\ndeps = [\"StaticArrays\"]\ngit-tree-sha1 = \"c18e98cba888c6c25d1c3b048e4b3380ca956805\"\nuuid = \"163ba53b-c6d8-5494-b064-1a9d43ac40c5\"\nversion = \"1.0.3\"\n\n[[DiffRules]]\ndeps = [\"LogExpFunctions\", \"NaNMath\", \"Random\", \"SpecialFunctions\"]\ngit-tree-sha1 = \"9bc5dac3c8b6706b58ad5ce24cffd9861f07c94f\"\nuuid = \"b552c78f-8df3-52c6-915a-8e097449b14b\"\nversion = \"1.9.0\"\n\n[[Distances]]\ndeps = [\"LinearAlgebra\", \"SparseArrays\", \"Statistics\", \"StatsAPI\"]\ngit-tree-sha1 = \"3258d0659f812acde79e8a74b11f17ac06d0ca04\"\nuuid = \"b4f34e82-e78d-54a5-968a-f98e89d6e8f7\"\nversion = \"0.10.7\"\n\n[[Distributed]]\ndeps = [\"Random\", \"Serialization\", \"Sockets\"]\nuuid = \"8ba89e20-285c-5b6f-9357-94700520ee1b\"\n\n[[Distributions]]\ndeps = [\"ChainRulesCore\", \"DensityInterface\", \"FillArrays\", \"LinearAlgebra\", \"PDMats\", \"Printf\", \"QuadGK\", \"Random\", \"SparseArrays\", \"SpecialFunctions\", \"Statistics\", \"StatsBase\", \"StatsFuns\", \"Test\"]\ngit-tree-sha1 = \"6a8dc9f82e5ce28279b6e3e2cea9421154f5bd0d\"\nuuid = \"31c24e10-a181-5473-b8eb-7969acd0382f\"\nversion = \"0.25.37\"\n\n[[DocStringExtensions]]\ndeps = [\"LibGit2\"]\ngit-tree-sha1 = \"b19534d1895d702889b219c382a6e18010797f0b\"\nuuid = \"ffbed154-4ef7-542d-bbb7-c09d3a79fcae\"\nversion = \"0.8.6\"\n\n[[Downloads]]\ndeps = [\"ArgTools\", \"LibCURL\", \"NetworkOptions\"]\nuuid = \"f43a241f-c20a-4ad4-852c-f6b1247861c6\"\n\n[[EarCut_jll]]\ndeps = [\"Artifacts\", \"JLLWrappers\", \"Libdl\", \"Pkg\"]\ngit-tree-sha1 = \"3f3a2501fa7236e9b911e0f7a588c657e822bb6d\"\nuuid = \"5ae413db-bbd1-5e63-b57d-d24a61df00f5\"\nversion = \"2.2.3+0\"\n\n[[EarlyStopping]]\ndeps = [\"Dates\", \"Statistics\"]\ngit-tree-sha1 = \"98fdf08b707aaf69f524a6cd0a67858cefe0cfb6\"\nuuid = \"792122b4-ca99-40de-a6bc-6742525f08b6\"\nversion = \"0.3.0\"\n\n[[EvoTrees]]\ndeps = [\"BSON\", \"CUDA\", \"CategoricalArrays\", \"Distributions\", \"MLJModelInterface\", \"NetworkLayout\", \"Random\", \"RecipesBase\", \"SpecialFunctions\", \"StaticArrays\", \"Statistics\", \"StatsBase\"]\ngit-tree-sha1 = \"d1d91fd0643d6eb7946c15115b625b0b1e1a5393\"\nuuid = \"f6006082-12f8-11e9-0c9c-0d5d367ab1e5\"\nversion = \"0.9.1\"\n\n[[ExprTools]]\ngit-tree-sha1 = \"b7e3d17636b348f005f11040025ae8c6f645fe92\"\nuuid = \"e2ba6199-217a-4e67-a87a-7c52f15ade04\"\nversion = \"0.1.6\"\n\n[[FilePathsBase]]\ndeps = [\"Compat\", \"Dates\", \"Mmap\", \"Printf\", \"Test\", \"UUIDs\"]\ngit-tree-sha1 = \"04d13bfa8ef11720c24e4d840c0033d145537df7\"\nuuid = \"48062228-2e41-5def-b9a4-89aafe57970f\"\nversion = \"0.9.17\"\n\n[[FillArrays]]\ndeps = [\"LinearAlgebra\", \"Random\", \"SparseArrays\", \"Statistics\"]\ngit-tree-sha1 = \"8756f9935b7ccc9064c6eef0bff0ad643df733a3\"\nuuid = \"1a297f60-69ca-5386-bcde-b61e274b549b\"\nversion = \"0.12.7\"\n\n[[FiniteDiff]]\ndeps = [\"ArrayInterface\", \"LinearAlgebra\", \"Requires\", \"SparseArrays\", \"StaticArrays\"]\ngit-tree-sha1 = \"8b3c09b56acaf3c0e581c66638b85c8650ee9dca\"\nuuid = \"6a86dc24-6348-571c-b903-95158fe2bd41\"\nversion = \"2.8.1\"\n\n[[FixedPointNumbers]]\ndeps = [\"Statistics\"]\ngit-tree-sha1 = \"335bfdceacc84c5cdf16aadc768aa5ddfc5383cc\"\nuuid = \"53c48c17-4a7d-5ca2-90c5-79b7896eea93\"\nversion = \"0.8.4\"\n\n[[Formatting]]\ndeps = [\"Printf\"]\ngit-tree-sha1 = \"8339d61043228fdd3eb658d86c926cb282ae72a8\"\nuuid = \"59287772-0a20-5a39-b81b-1366585eb4c0\"\nversion = \"0.4.2\"\n\n[[ForwardDiff]]\ndeps = [\"CommonSubexpressions\", \"DiffResults\", \"DiffRules\", \"LinearAlgebra\", \"LogExpFunctions\", \"NaNMath\", \"Preferences\", \"Printf\", \"Random\", \"SpecialFunctions\", \"StaticArrays\"]\ngit-tree-sha1 = \"2b72a5624e289ee18256111657663721d59c143e\"\nuuid = \"f6369f11-7733-5829-9624-2563aa707210\"\nversion = \"0.10.24\"\n\n[[Future]]\ndeps = [\"Random\"]\nuuid = \"9fa8497b-333b-5362-9e8d-4d0656e87820\"\n\n[[GPUArrays]]\ndeps = [\"Adapt\", \"LinearAlgebra\", \"Printf\", \"Random\", \"Serialization\", \"Statistics\"]\ngit-tree-sha1 = \"d9681e61fbce7dde48684b40bdb1a319c4083be7\"\nuuid = \"0c68f7d7-f131-5f86-a1c3-88cf8149b2d7\"\nversion = \"8.1.3\"\n\n[[GPUCompiler]]\ndeps = [\"ExprTools\", \"InteractiveUtils\", \"LLVM\", \"Libdl\", \"Logging\", \"TimerOutputs\", \"UUIDs\"]\ngit-tree-sha1 = \"2cac236070c2c4b36de54ae9146b55ee2c34ac7a\"\nuuid = \"61eb1bfa-7361-4325-ad38-22787b887f55\"\nversion = \"0.13.10\"\n\n[[GeometryBasics]]\ndeps = [\"EarCut_jll\", \"IterTools\", \"LinearAlgebra\", \"StaticArrays\", \"StructArrays\", \"Tables\"]\ngit-tree-sha1 = \"58bcdf5ebc057b085e58d95c138725628dd7453c\"\nuuid = \"5c1252a2-5f33-56bf-86c9-59e7332b4326\"\nversion = \"0.4.1\"\n\n[[HTTP]]\ndeps = [\"Base64\", \"Dates\", \"IniFile\", \"Logging\", \"MbedTLS\", \"NetworkOptions\", \"Sockets\", \"URIs\"]\ngit-tree-sha1 = \"0fa77022fe4b511826b39c894c90daf5fce3334a\"\nuuid = \"cd3eb016-35fb-5094-929b-558a96fad6f3\"\nversion = \"0.9.17\"\n\n[[Hyperscript]]\ndeps = [\"Test\"]\ngit-tree-sha1 = \"8d511d5b81240fc8e6802386302675bdf47737b9\"\nuuid = \"47d2ed2b-36de-50cf-bf87-49c2cf4b8b91\"\nversion = \"0.0.4\"\n\n[[HypertextLiteral]]\ngit-tree-sha1 = \"2b078b5a615c6c0396c77810d92ee8c6f470d238\"\nuuid = \"ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2\"\nversion = \"0.9.3\"\n\n[[IOCapture]]\ndeps = [\"Logging\", \"Random\"]\ngit-tree-sha1 = \"f7be53659ab06ddc986428d3a9dcc95f6fa6705a\"\nuuid = \"b5f81e59-6552-4d32-b1f0-c071b021bf89\"\nversion = \"0.2.2\"\n\n[[IfElse]]\ngit-tree-sha1 = \"debdd00ffef04665ccbb3e150747a77560e8fad1\"\nuuid = \"615f187c-cbe4-4ef1-ba3b-2fcf58d6d173\"\nversion = \"0.1.1\"\n\n[[IniFile]]\ndeps = [\"Test\"]\ngit-tree-sha1 = \"098e4d2c533924c921f9f9847274f2ad89e018b8\"\nuuid = \"83e8ac13-25f8-5344-8a64-a9f2b223428f\"\nversion = \"0.5.0\"\n\n[[InlineStrings]]\ndeps = [\"Parsers\"]\ngit-tree-sha1 = \"8d70835a3759cdd75881426fced1508bb7b7e1b6\"\nuuid = \"842dd82b-1e85-43dc-bf29-5d0ee9dffc48\"\nversion = \"1.1.1\"\n\n[[InteractiveUtils]]\ndeps = [\"Markdown\"]\nuuid = \"b77e0a4c-d291-57a0-90e8-8db25a27a240\"\n\n[[InverseFunctions]]\ndeps = [\"Test\"]\ngit-tree-sha1 = \"a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65\"\nuuid = \"3587e190-3f89-42d0-90ee-14403ec27112\"\nversion = \"0.1.2\"\n\n[[InvertedIndices]]\ngit-tree-sha1 = \"bee5f1ef5bf65df56bdd2e40447590b272a5471f\"\nuuid = \"41ab1584-1d38-5bbf-9106-f11c6c58b48f\"\nversion = \"1.1.0\"\n\n[[IrrationalConstants]]\ngit-tree-sha1 = \"7fd44fd4ff43fc60815f8e764c0f352b83c49151\"\nuuid = \"92d709cd-6900-40b7-9082-c6be49f344b6\"\nversion = \"0.1.1\"\n\n[[IterTools]]\ngit-tree-sha1 = \"fa6287a4469f5e048d763df38279ee729fbd44e5\"\nuuid = \"c8e1da08-722c-5040-9ed9-7db0dc04731e\"\nversion = \"1.4.0\"\n\n[[IterationControl]]\ndeps = [\"EarlyStopping\", \"InteractiveUtils\"]\ngit-tree-sha1 = \"83c84b7b87d3063e48a909a86c3c5bf4c3521962\"\nuuid = \"b3c1a2ee-3fec-4384-bf48-272ea71de57c\"\nversion = \"0.5.2\"\n\n[[IterativeSolvers]]\ndeps = [\"LinearAlgebra\", \"Printf\", \"Random\", \"RecipesBase\", \"SparseArrays\"]\ngit-tree-sha1 = \"1169632f425f79429f245113b775a0e3d121457c\"\nuuid = \"42fd0dbc-a981-5370-80f2-aaf504508153\"\nversion = \"0.9.2\"\n\n[[IteratorInterfaceExtensions]]\ngit-tree-sha1 = \"a3f24677c21f5bbe9d2a714f95dcd58337fb2856\"\nuuid = \"82899510-4779-5014-852e-03e436cf321d\"\nversion = \"1.0.0\"\n\n[[JLLWrappers]]\ndeps = [\"Preferences\"]\ngit-tree-sha1 = \"642a199af8b68253517b80bd3bfd17eb4e84df6e\"\nuuid = \"692b3bcd-3c85-4b1f-b108-f13ce0eb3210\"\nversion = \"1.3.0\"\n\n[[JLSO]]\ndeps = [\"BSON\", \"CodecZlib\", \"FilePathsBase\", \"Memento\", \"Pkg\", \"Serialization\"]\ngit-tree-sha1 = \"e00feb9d56e9e8518e0d60eef4d1040b282771e2\"\nuuid = \"9da8a3cd-07a3-59c0-a743-3fdc52c30d11\"\nversion = \"2.6.0\"\n\n[[JSON]]\ndeps = [\"Dates\", \"Mmap\", \"Parsers\", \"Unicode\"]\ngit-tree-sha1 = \"8076680b162ada2a031f707ac7b4953e30667a37\"\nuuid = \"682c06a0-de6a-54ab-a142-c8b1cf79cde6\"\nversion = \"0.21.2\"\n\n[[LLVM]]\ndeps = [\"CEnum\", \"LLVMExtra_jll\", \"Libdl\", \"Printf\", \"Unicode\"]\ngit-tree-sha1 = \"7cc22e69995e2329cc047a879395b2b74647ab5f\"\nuuid = \"929cbde3-209d-540e-8aea-75f648917ca0\"\nversion = \"4.7.0\"\n\n[[LLVMExtra_jll]]\ndeps = [\"Artifacts\", \"JLLWrappers\", \"Libdl\", \"Pkg\"]\ngit-tree-sha1 = \"c5fc4bef251ecd37685bea1c4068a9cfa41e8b9a\"\nuuid = \"dad2f222-ce93-54a1-a47d-0025e8a3acab\"\nversion = \"0.0.13+0\"\n\n[[LatinHypercubeSampling]]\ndeps = [\"Random\", \"StableRNGs\", \"StatsBase\", \"Test\"]\ngit-tree-sha1 = \"42938ab65e9ed3c3029a8d2c58382ca75bdab243\"\nuuid = \"a5e1c1ea-c99a-51d3-a14d-a9a37257b02d\"\nversion = \"1.8.0\"\n\n[[LazyArtifacts]]\ndeps = [\"Artifacts\", \"Pkg\"]\nuuid = \"4af54fe1-eca0-43a8-85a7-787d91b784e3\"\n\n[[LearnBase]]\ngit-tree-sha1 = \"a0d90569edd490b82fdc4dc078ea54a5a800d30a\"\nuuid = \"7f8f8fb0-2700-5f03-b4bd-41f8cfc144b6\"\nversion = \"0.4.1\"\n\n[[LibCURL]]\ndeps = [\"LibCURL_jll\", \"MozillaCACerts_jll\"]\nuuid = \"b27032c2-a3e7-50c8-80cd-2d36dbcbfd21\"\n\n[[LibCURL_jll]]\ndeps = [\"Artifacts\", \"LibSSH2_jll\", \"Libdl\", \"MbedTLS_jll\", \"Zlib_jll\", \"nghttp2_jll\"]\nuuid = \"deac9b47-8bc7-5906-a0fe-35ac56dc84c0\"\n\n[[LibGit2]]\ndeps = [\"Base64\", \"NetworkOptions\", \"Printf\", \"SHA\"]\nuuid = \"76f85450-5226-5b5a-8eaa-529ad045b433\"\n\n[[LibSSH2_jll]]\ndeps = [\"Artifacts\", \"Libdl\", \"MbedTLS_jll\"]\nuuid = \"29816b5a-b9ab-546f-933c-edad1886dfa8\"\n\n[[Libdl]]\nuuid = \"8f399da3-3557-5675-b5ff-fb832c97cbdb\"\n\n[[LineSearches]]\ndeps = [\"LinearAlgebra\", \"NLSolversBase\", \"NaNMath\", \"Parameters\", \"Printf\"]\ngit-tree-sha1 = \"f27132e551e959b3667d8c93eae90973225032dd\"\nuuid = \"d3d80556-e9d4-5f37-9878-2ab0fcc64255\"\nversion = \"7.1.1\"\n\n[[LinearAlgebra]]\ndeps = [\"Libdl\"]\nuuid = \"37e2e46d-f89d-539d-b4ee-838fcccc9c8e\"\n\n[[LinearMaps]]\ndeps = [\"LinearAlgebra\", \"SparseArrays\"]\ngit-tree-sha1 = \"dbb14c604fc47aa4f2e19d0ebb7b6416f3cfa5f5\"\nuuid = \"7a12625a-238d-50fd-b39a-03d52299707e\"\nversion = \"3.5.1\"\n\n[[LogExpFunctions]]\ndeps = [\"ChainRulesCore\", \"ChangesOfVariables\", \"DocStringExtensions\", \"InverseFunctions\", \"IrrationalConstants\", \"LinearAlgebra\"]\ngit-tree-sha1 = \"e5718a00af0ab9756305a0392832c8952c7426c1\"\nuuid = \"2ab3a3ac-af41-5b50-aa03-7779005ae688\"\nversion = \"0.3.6\"\n\n[[Logging]]\nuuid = \"56ddb016-857b-54e1-b83d-db4d58db5568\"\n\n[[LossFunctions]]\ndeps = [\"InteractiveUtils\", \"LearnBase\", \"Markdown\", \"RecipesBase\", \"StatsBase\"]\ngit-tree-sha1 = \"0f057f6ea90a84e73a8ef6eebb4dc7b5c330020f\"\nuuid = \"30fc2ffe-d236-52d8-8643-a9d8f7c094a7\"\nversion = \"0.7.2\"\n\n[[MLJ]]\ndeps = [\"CategoricalArrays\", \"ComputationalResources\", \"Distributed\", \"Distributions\", \"LinearAlgebra\", \"MLJBase\", \"MLJEnsembles\", \"MLJIteration\", \"MLJModels\", \"MLJSerialization\", \"MLJTuning\", \"OpenML\", \"Pkg\", \"ProgressMeter\", \"Random\", \"ScientificTypes\", \"Statistics\", \"StatsBase\", \"Tables\"]\ngit-tree-sha1 = \"3b4ebc5023cc039c65a1089e6d8c248a9b96dfd1\"\nuuid = \"add582a8-e3ab-11e8-2d5e-e98b27df1bc7\"\nversion = \"0.17.0\"\n\n[[MLJBase]]\ndeps = [\"CategoricalArrays\", \"CategoricalDistributions\", \"ComputationalResources\", \"Dates\", \"DelimitedFiles\", \"Distributed\", \"Distributions\", \"InteractiveUtils\", \"InvertedIndices\", \"LinearAlgebra\", \"LossFunctions\", \"MLJModelInterface\", \"Missings\", \"OrderedCollections\", \"Parameters\", \"PrettyTables\", \"ProgressMeter\", \"Random\", \"ScientificTypes\", \"StatisticalTraits\", \"Statistics\", \"StatsBase\", \"Tables\"]\ngit-tree-sha1 = \"54cae1f0bde7bbc72fe7ff42353b7880347bd0d5\"\nuuid = \"a7f614a8-145f-11e9-1d2a-a57a1082229d\"\nversion = \"0.19.2\"\n\n[[MLJEnsembles]]\ndeps = [\"CategoricalArrays\", \"CategoricalDistributions\", \"ComputationalResources\", \"Distributed\", \"Distributions\", \"MLJBase\", \"MLJModelInterface\", \"ProgressMeter\", \"Random\", \"ScientificTypesBase\", \"StatsBase\"]\ngit-tree-sha1 = \"4279437ccc8ece8f478ded5139334b888dcce631\"\nuuid = \"50ed68f4-41fd-4504-931a-ed422449fee0\"\nversion = \"0.2.0\"\n\n[[MLJIteration]]\ndeps = [\"IterationControl\", \"MLJBase\", \"Random\"]\ngit-tree-sha1 = \"5f32c3d281904d6e5fc64250f55732d4b24014de\"\nuuid = \"614be32b-d00c-4edb-bd02-1eb411ab5e55\"\nversion = \"0.4.1\"\n\n[[MLJLinearModels]]\ndeps = [\"DocStringExtensions\", \"IterativeSolvers\", \"LinearAlgebra\", \"LinearMaps\", \"MLJModelInterface\", \"Optim\", \"Parameters\"]\ngit-tree-sha1 = \"dfbf4a5a8454034d21b6cfd9fd5a7960c8f7fb88\"\nuuid = \"6ee0df7b-362f-4a72-a706-9e79364fb692\"\nversion = \"0.5.7\"\n\n[[MLJModelInterface]]\ndeps = [\"Random\", \"ScientificTypesBase\", \"StatisticalTraits\"]\ngit-tree-sha1 = \"7ffdd75b2b13d1ec8640bfe80ab81bb158910a1d\"\nuuid = \"e80e1ace-859a-464e-9ed9-23947d8ae3ea\"\nversion = \"1.3.5\"\n\n[[MLJModels]]\ndeps = [\"CategoricalArrays\", \"CategoricalDistributions\", \"Dates\", \"Distances\", \"Distributions\", \"InteractiveUtils\", \"LinearAlgebra\", \"MLJModelInterface\", \"OrderedCollections\", \"Parameters\", \"Pkg\", \"PrettyPrinting\", \"REPL\", \"Random\", \"Requires\", \"ScientificTypes\", \"StatisticalTraits\", \"Statistics\", \"StatsBase\", \"Tables\"]\ngit-tree-sha1 = \"cecd98731368f1eb46634d1476f49332560f886f\"\nuuid = \"d491faf4-2d78-11e9-2867-c94bc002c0b7\"\nversion = \"0.15.1\"\n\n[[MLJMultivariateStatsInterface]]\ndeps = [\"Distances\", \"LinearAlgebra\", \"MLJModelInterface\", \"MultivariateStats\", \"StatsBase\"]\ngit-tree-sha1 = \"0cfc81ff677ea13ed72894992ee9e5f8ae4dbb9d\"\nuuid = \"1b6a4a23-ba22-4f51-9698-8599985d3728\"\nversion = \"0.2.2\"\n\n[[MLJSerialization]]\ndeps = [\"IterationControl\", \"JLSO\", \"MLJBase\", \"MLJModelInterface\"]\ngit-tree-sha1 = \"cc5877ad02ef02e273d2622f0d259d628fa61cd0\"\nuuid = \"17bed46d-0ab5-4cd4-b792-a5c4b8547c6d\"\nversion = \"1.1.3\"\n\n[[MLJTuning]]\ndeps = [\"ComputationalResources\", \"Distributed\", \"Distributions\", \"LatinHypercubeSampling\", \"MLJBase\", \"ProgressMeter\", \"Random\", \"RecipesBase\"]\ngit-tree-sha1 = \"a443cc088158b949876d7038a1aa37cfc8c5509b\"\nuuid = \"03970b2e-30c4-11ea-3135-d1576263f10f\"\nversion = \"0.6.16\"\n\n[[MacroTools]]\ndeps = [\"Markdown\", \"Random\"]\ngit-tree-sha1 = \"3d3e902b31198a27340d0bf00d6ac452866021cf\"\nuuid = \"1914dd2f-81c6-5fcd-8719-6d5c9610ff09\"\nversion = \"0.5.9\"\n\n[[Markdown]]\ndeps = [\"Base64\"]\nuuid = \"d6f4376e-aef5-505a-96c1-9c027394607a\"\n\n[[MbedTLS]]\ndeps = [\"Dates\", \"MbedTLS_jll\", \"Random\", \"Sockets\"]\ngit-tree-sha1 = \"1c38e51c3d08ef2278062ebceade0e46cefc96fe\"\nuuid = \"739be429-bea8-5141-9913-cc70e7f3736d\"\nversion = \"1.0.3\"\n\n[[MbedTLS_jll]]\ndeps = [\"Artifacts\", \"Libdl\"]\nuuid = \"c8ffd9c3-330d-5841-b78e-0817d7145fa1\"\n\n[[Memento]]\ndeps = [\"Dates\", \"Distributed\", \"Requires\", \"Serialization\", \"Sockets\", \"Test\", \"UUIDs\"]\ngit-tree-sha1 = \"9b0b0dbf419fbda7b383dc12d108621d26eeb89f\"\nuuid = \"f28f55f0-a522-5efc-85c2-fe41dfb9b2d9\"\nversion = \"1.3.0\"\n\n[[Missings]]\ndeps = [\"DataAPI\"]\ngit-tree-sha1 = \"bf210ce90b6c9eed32d25dbcae1ebc565df2687f\"\nuuid = \"e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28\"\nversion = \"1.0.2\"\n\n[[Mmap]]\nuuid = \"a63ad114-7e13-5084-954f-fe012c677804\"\n\n[[MozillaCACerts_jll]]\nuuid = \"14a3606d-f60d-562e-9121-12d972cd8159\"\n\n[[MultivariateStats]]\ndeps = [\"Arpack\", \"LinearAlgebra\", \"SparseArrays\", \"Statistics\", \"StatsBase\"]\ngit-tree-sha1 = \"8d958ff1854b166003238fe191ec34b9d592860a\"\nuuid = \"6f286f6a-111f-5878-ab1e-185364afe411\"\nversion = \"0.8.0\"\n\n[[NLSolversBase]]\ndeps = [\"DiffResults\", \"Distributed\", \"FiniteDiff\", \"ForwardDiff\"]\ngit-tree-sha1 = \"50310f934e55e5ca3912fb941dec199b49ca9b68\"\nuuid = \"d41bc354-129a-5804-8e4c-c37616107c6c\"\nversion = \"7.8.2\"\n\n[[NaNMath]]\ngit-tree-sha1 = \"f755f36b19a5116bb580de457cda0c140153f283\"\nuuid = \"77ba4419-2d1f-58cd-9bb1-8ffee604a2e3\"\nversion = \"0.3.6\"\n\n[[NetworkLayout]]\ndeps = [\"GeometryBasics\", \"LinearAlgebra\", \"Random\", \"Requires\", \"SparseArrays\"]\ngit-tree-sha1 = \"cac8fc7ba64b699c678094fa630f49b80618f625\"\nuuid = \"46757867-2c16-5918-afeb-47bfcb05e46a\"\nversion = \"0.4.4\"\n\n[[NetworkOptions]]\nuuid = \"ca575930-c2e3-43a9-ace4-1e988b2c1908\"\n\n[[OpenBLAS_jll]]\ndeps = [\"Artifacts\", \"CompilerSupportLibraries_jll\", \"Libdl\"]\nuuid = \"4536629a-c528-5b80-bd46-f80d51c5b363\"\n\n[[OpenLibm_jll]]\ndeps = [\"Artifacts\", \"Libdl\"]\nuuid = \"05823500-19ac-5b8b-9628-191a04bc5112\"\n\n[[OpenML]]\ndeps = [\"ARFFFiles\", \"HTTP\", \"JSON\", \"Markdown\", \"Pkg\"]\ngit-tree-sha1 = \"06080992e86a93957bfe2e12d3181443cedf2400\"\nuuid = \"8b6db2d4-7670-4922-a472-f9537c81ab66\"\nversion = \"0.2.0\"\n\n[[OpenSpecFun_jll]]\ndeps = [\"Artifacts\", \"CompilerSupportLibraries_jll\", \"JLLWrappers\", \"Libdl\", \"Pkg\"]\ngit-tree-sha1 = \"13652491f6856acfd2db29360e1bbcd4565d04f1\"\nuuid = \"efe28fd5-8261-553b-a9e1-b2916fc3738e\"\nversion = \"0.5.5+0\"\n\n[[Optim]]\ndeps = [\"Compat\", \"FillArrays\", \"ForwardDiff\", \"LineSearches\", \"LinearAlgebra\", \"NLSolversBase\", \"NaNMath\", \"Parameters\", \"PositiveFactorizations\", \"Printf\", \"SparseArrays\", \"StatsBase\"]\ngit-tree-sha1 = \"916077e0f0f8966eb0dc98a5c39921fdb8f49eb4\"\nuuid = \"429524aa-4258-5aef-a3af-852621145aeb\"\nversion = \"1.6.0\"\n\n[[OrderedCollections]]\ngit-tree-sha1 = \"85f8e6578bf1f9ee0d11e7bb1b1456435479d47c\"\nuuid = \"bac558e1-5e72-5ebc-8fee-abe8a469f55d\"\nversion = \"1.4.1\"\n\n[[PDMats]]\ndeps = [\"LinearAlgebra\", \"SparseArrays\", \"SuiteSparse\"]\ngit-tree-sha1 = \"ee26b350276c51697c9c2d88a072b339f9f03d73\"\nuuid = \"90014a1f-27ba-587c-ab20-58faa44d9150\"\nversion = \"0.11.5\"\n\n[[Parameters]]\ndeps = [\"OrderedCollections\", \"UnPack\"]\ngit-tree-sha1 = \"34c0e9ad262e5f7fc75b10a9952ca7692cfc5fbe\"\nuuid = \"d96e819e-fc66-5662-9728-84c9c7592b0a\"\nversion = \"0.12.3\"\n\n[[Parsers]]\ndeps = [\"Dates\"]\ngit-tree-sha1 = \"d7fa6237da8004be601e19bd6666083056649918\"\nuuid = \"69de0a69-1ddd-5017-9359-2bf0b02dc9f0\"\nversion = \"2.1.3\"\n\n[[Pkg]]\ndeps = [\"Artifacts\", \"Dates\", \"Downloads\", \"LibGit2\", \"Libdl\", \"Logging\", \"Markdown\", \"Printf\", \"REPL\", \"Random\", \"SHA\", \"Serialization\", \"TOML\", \"Tar\", \"UUIDs\", \"p7zip_jll\"]\nuuid = \"44cfe95a-1eb2-52ea-b672-e2afdf69b78f\"\n\n[[PlutoUI]]\ndeps = [\"AbstractPlutoDingetjes\", \"Base64\", \"ColorTypes\", \"Dates\", \"Hyperscript\", \"HypertextLiteral\", \"IOCapture\", \"InteractiveUtils\", \"JSON\", \"Logging\", \"Markdown\", \"Random\", \"Reexport\", \"UUIDs\"]\ngit-tree-sha1 = \"fed057115644d04fba7f4d768faeeeff6ad11a60\"\nuuid = \"7f904dfe-b85e-4ff6-b463-dae2292396a8\"\nversion = \"0.7.27\"\n\n[[PooledArrays]]\ndeps = [\"DataAPI\", \"Future\"]\ngit-tree-sha1 = \"db3a23166af8aebf4db5ef87ac5b00d36eb771e2\"\nuuid = \"2dfb63ee-cc39-5dd5-95bd-886bf059d720\"\nversion = \"1.4.0\"\n\n[[PositiveFactorizations]]\ndeps = [\"LinearAlgebra\"]\ngit-tree-sha1 = \"17275485f373e6673f7e7f97051f703ed5b15b20\"\nuuid = \"85a6dd25-e78a-55b7-8502-1745935b8125\"\nversion = \"0.2.4\"\n\n[[Preferences]]\ndeps = [\"TOML\"]\ngit-tree-sha1 = \"2cf929d64681236a2e074ffafb8d568733d2e6af\"\nuuid = \"21216c6a-2e73-6563-6e65-726566657250\"\nversion = \"1.2.3\"\n\n[[PrettyPrinting]]\ngit-tree-sha1 = \"a5db8a42938bc65c2679406c51a8f5fe9597c6e7\"\nuuid = \"54e16d92-306c-5ea0-a30b-337be88ac337\"\nversion = \"0.3.2\"\n\n[[PrettyTables]]\ndeps = [\"Crayons\", \"Formatting\", \"Markdown\", \"Reexport\", \"Tables\"]\ngit-tree-sha1 = \"dfb54c4e414caa595a1f2ed759b160f5a3ddcba5\"\nuuid = \"08abe8d2-0d0c-5749-adfa-8a2ac140af0d\"\nversion = \"1.3.1\"\n\n[[Printf]]\ndeps = [\"Unicode\"]\nuuid = \"de0858da-6303-5e67-8744-51eddeeeb8d7\"\n\n[[ProgressMeter]]\ndeps = [\"Distributed\", \"Printf\"]\ngit-tree-sha1 = \"afadeba63d90ff223a6a48d2009434ecee2ec9e8\"\nuuid = \"92933f4c-e287-5a05-a399-4b506db050ca\"\nversion = \"1.7.1\"\n\n[[QuadGK]]\ndeps = [\"DataStructures\", \"LinearAlgebra\"]\ngit-tree-sha1 = \"78aadffb3efd2155af139781b8a8df1ef279ea39\"\nuuid = \"1fd47b50-473d-5c70-9696-f719f8f3bcdc\"\nversion = \"2.4.2\"\n\n[[REPL]]\ndeps = [\"InteractiveUtils\", \"Markdown\", \"Sockets\", \"Unicode\"]\nuuid = \"3fa0cd96-eef1-5676-8a61-b3b8758bbffb\"\n\n[[Random]]\ndeps = [\"Serialization\"]\nuuid = \"9a3f8284-a2c9-5f02-9a11-845980a1fd5c\"\n\n[[Random123]]\ndeps = [\"Libdl\", \"Random\", \"RandomNumbers\"]\ngit-tree-sha1 = \"0e8b146557ad1c6deb1367655e052276690e71a3\"\nuuid = \"74087812-796a-5b5d-8853-05524746bad3\"\nversion = \"1.4.2\"\n\n[[RandomNumbers]]\ndeps = [\"Random\", \"Requires\"]\ngit-tree-sha1 = \"043da614cc7e95c703498a491e2c21f58a2b8111\"\nuuid = \"e6cf234a-135c-5ec9-84dd-332b85af5143\"\nversion = \"1.5.3\"\n\n[[RecipesBase]]\ngit-tree-sha1 = \"6bf3f380ff52ce0832ddd3a2a7b9538ed1bcca7d\"\nuuid = \"3cdcf5f2-1ef4-517c-9805-6587b60abb01\"\nversion = \"1.2.1\"\n\n[[Reexport]]\ngit-tree-sha1 = \"45e428421666073eab6f2da5c9d310d99bb12f9b\"\nuuid = \"189a3867-3050-52da-a836-e630ba90ab69\"\nversion = \"1.2.2\"\n\n[[Requires]]\ndeps = [\"UUIDs\"]\ngit-tree-sha1 = \"8f82019e525f4d5c669692772a6f4b0a58b06a6a\"\nuuid = \"ae029012-a4dd-5104-9daa-d747884805df\"\nversion = \"1.2.0\"\n\n[[Rmath]]\ndeps = [\"Random\", \"Rmath_jll\"]\ngit-tree-sha1 = \"bf3188feca147ce108c76ad82c2792c57abe7b1f\"\nuuid = \"79098fc4-a85e-5d69-aa6a-4863f24498fa\"\nversion = \"0.7.0\"\n\n[[Rmath_jll]]\ndeps = [\"Artifacts\", \"JLLWrappers\", \"Libdl\", \"Pkg\"]\ngit-tree-sha1 = \"68db32dff12bb6127bac73c209881191bf0efbb7\"\nuuid = \"f50d1b31-88e8-58de-be2c-1cc44531875f\"\nversion = \"0.3.0+0\"\n\n[[SHA]]\nuuid = \"ea8e919c-243c-51af-8825-aaa63cd721ce\"\n\n[[ScientificTypes]]\ndeps = [\"CategoricalArrays\", \"ColorTypes\", \"Dates\", \"Distributions\", \"PrettyTables\", \"Reexport\", \"ScientificTypesBase\", \"StatisticalTraits\", \"Tables\"]\ngit-tree-sha1 = \"ba70c9a6e4c81cc3634e3e80bb8163ab5ef57eb8\"\nuuid = \"321657f4-b219-11e9-178b-2701a2544e81\"\nversion = \"3.0.0\"\n\n[[ScientificTypesBase]]\ngit-tree-sha1 = \"a8e18eb383b5ecf1b5e6fc237eb39255044fd92b\"\nuuid = \"30f210dd-8aff-4c5f-94ba-8e64358c1161\"\nversion = \"3.0.0\"\n\n[[SentinelArrays]]\ndeps = [\"Dates\", \"Random\"]\ngit-tree-sha1 = \"244586bc07462d22aed0113af9c731f2a518c93e\"\nuuid = \"91c51154-3ec4-41a3-a24f-3f23e20d615c\"\nversion = \"1.3.10\"\n\n[[Serialization]]\nuuid = \"9e88b42a-f829-5b0c-bbe9-9e923198166b\"\n\n[[SharedArrays]]\ndeps = [\"Distributed\", \"Mmap\", \"Random\", \"Serialization\"]\nuuid = \"1a1011a3-84de-559e-8e89-a11a2f7dc383\"\n\n[[Sockets]]\nuuid = \"6462fe0b-24de-5631-8697-dd941f90decc\"\n\n[[SortingAlgorithms]]\ndeps = [\"DataStructures\"]\ngit-tree-sha1 = \"b3363d7460f7d098ca0912c69b082f75625d7508\"\nuuid = \"a2af1166-a08f-5f64-846c-94a0d3cef48c\"\nversion = \"1.0.1\"\n\n[[SparseArrays]]\ndeps = [\"LinearAlgebra\", \"Random\"]\nuuid = \"2f01184e-e22b-5df5-ae63-d93ebab69eaf\"\n\n[[SpecialFunctions]]\ndeps = [\"ChainRulesCore\", \"IrrationalConstants\", \"LogExpFunctions\", \"OpenLibm_jll\", \"OpenSpecFun_jll\"]\ngit-tree-sha1 = \"e08890d19787ec25029113e88c34ec20cac1c91e\"\nuuid = \"276daf66-3868-5448-9aa4-cd146d93841b\"\nversion = \"2.0.0\"\n\n[[StableRNGs]]\ndeps = [\"Random\", \"Test\"]\ngit-tree-sha1 = \"3be7d49667040add7ee151fefaf1f8c04c8c8276\"\nuuid = \"860ef19b-820b-49d6-a774-d7a799459cd3\"\nversion = \"1.0.0\"\n\n[[Static]]\ndeps = [\"IfElse\"]\ngit-tree-sha1 = \"7f5a513baec6f122401abfc8e9c074fdac54f6c1\"\nuuid = \"aedffcd0-7271-4cad-89d0-dc628f76c6d3\"\nversion = \"0.4.1\"\n\n[[StaticArrays]]\ndeps = [\"LinearAlgebra\", \"Random\", \"Statistics\"]\ngit-tree-sha1 = \"de9e88179b584ba9cf3cc5edbb7a41f26ce42cda\"\nuuid = \"90137ffa-7385-5640-81b9-e52037218182\"\nversion = \"1.3.0\"\n\n[[StatisticalTraits]]\ndeps = [\"ScientificTypesBase\"]\ngit-tree-sha1 = \"271a7fea12d319f23d55b785c51f6876aadb9ac0\"\nuuid = \"64bff920-2084-43da-a3e6-9bb72801c0c9\"\nversion = \"3.0.0\"\n\n[[Statistics]]\ndeps = [\"LinearAlgebra\", \"SparseArrays\"]\nuuid = \"10745b16-79ce-11e8-11f9-7d13ad32a3b2\"\n\n[[StatsAPI]]\ngit-tree-sha1 = \"d88665adc9bcf45903013af0982e2fd05ae3d0a6\"\nuuid = \"82ae8749-77ed-4fe6-ae5f-f523153014b0\"\nversion = \"1.2.0\"\n\n[[StatsBase]]\ndeps = [\"DataAPI\", \"DataStructures\", \"LinearAlgebra\", \"LogExpFunctions\", \"Missings\", \"Printf\", \"Random\", \"SortingAlgorithms\", \"SparseArrays\", \"Statistics\", \"StatsAPI\"]\ngit-tree-sha1 = \"51383f2d367eb3b444c961d485c565e4c0cf4ba0\"\nuuid = \"2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91\"\nversion = \"0.33.14\"\n\n[[StatsFuns]]\ndeps = [\"ChainRulesCore\", \"InverseFunctions\", \"IrrationalConstants\", \"LogExpFunctions\", \"Reexport\", \"Rmath\", \"SpecialFunctions\"]\ngit-tree-sha1 = \"bedb3e17cc1d94ce0e6e66d3afa47157978ba404\"\nuuid = \"4c63d2b9-4356-54db-8cca-17b64c39e42c\"\nversion = \"0.9.14\"\n\n[[StructArrays]]\ndeps = [\"Adapt\", \"DataAPI\", \"StaticArrays\", \"Tables\"]\ngit-tree-sha1 = \"2ce41e0d042c60ecd131e9fb7154a3bfadbf50d3\"\nuuid = \"09ab397b-f2b6-538f-b94a-2f83cf4a842a\"\nversion = \"0.6.3\"\n\n[[SuiteSparse]]\ndeps = [\"Libdl\", \"LinearAlgebra\", \"Serialization\", \"SparseArrays\"]\nuuid = \"4607b0f0-06f3-5cda-b6b1-a6196a1729e9\"\n\n[[TOML]]\ndeps = [\"Dates\"]\nuuid = \"fa267f1f-6049-4f14-aa54-33bafae1ed76\"\n\n[[TableTraits]]\ndeps = [\"IteratorInterfaceExtensions\"]\ngit-tree-sha1 = \"c06b2f539df1c6efa794486abfb6ed2022561a39\"\nuuid = \"3783bdb8-4a98-5b6b-af9a-565f29a5fe9c\"\nversion = \"1.0.1\"\n\n[[Tables]]\ndeps = [\"DataAPI\", \"DataValueInterfaces\", \"IteratorInterfaceExtensions\", \"LinearAlgebra\", \"TableTraits\", \"Test\"]\ngit-tree-sha1 = \"bb1064c9a84c52e277f1096cf41434b675cd368b\"\nuuid = \"bd369af6-aec1-5ad0-b16a-f7cc5008161c\"\nversion = \"1.6.1\"\n\n[[Tar]]\ndeps = [\"ArgTools\", \"SHA\"]\nuuid = \"a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e\"\n\n[[Test]]\ndeps = [\"InteractiveUtils\", \"Logging\", \"Random\", \"Serialization\"]\nuuid = \"8dfed614-e22c-5e08-85e1-65c5234f0b40\"\n\n[[TimerOutputs]]\ndeps = [\"ExprTools\", \"Printf\"]\ngit-tree-sha1 = \"7cb456f358e8f9d102a8b25e8dfedf58fa5689bc\"\nuuid = \"a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f\"\nversion = \"0.5.13\"\n\n[[TranscodingStreams]]\ndeps = [\"Random\", \"Test\"]\ngit-tree-sha1 = \"216b95ea110b5972db65aa90f88d8d89dcb8851c\"\nuuid = \"3bb67fe8-82b1-5028-8e26-92a6c54297fa\"\nversion = \"0.9.6\"\n\n[[URIs]]\ngit-tree-sha1 = \"97bbe755a53fe859669cd907f2d96aee8d2c1355\"\nuuid = \"5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4\"\nversion = \"1.3.0\"\n\n[[UUIDs]]\ndeps = [\"Random\", \"SHA\"]\nuuid = \"cf7118a7-6976-5b1a-9a39-7adc72f591a4\"\n\n[[UnPack]]\ngit-tree-sha1 = \"387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b\"\nuuid = \"3a884ed6-31ef-47d7-9d2a-63182c4928ed\"\nversion = \"1.0.2\"\n\n[[Unicode]]\nuuid = \"4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5\"\n\n[[UnicodePlots]]\ndeps = [\"Crayons\", \"Dates\", \"SparseArrays\", \"StatsBase\"]\ngit-tree-sha1 = \"3cb994143aba28cfe66615702505b2d294cebd3e\"\nuuid = \"b8865327-cd53-5732-bb35-84acbb429228\"\nversion = \"2.5.1\"\n\n[[UrlDownload]]\ndeps = [\"HTTP\", \"ProgressMeter\"]\ngit-tree-sha1 = \"05f86730c7a53c9da603bd506a4fc9ad0851171c\"\nuuid = \"856ac37a-3032-4c1c-9122-f86d88358c8b\"\nversion = \"1.0.0\"\n\n[[WeakRefStrings]]\ndeps = [\"DataAPI\", \"InlineStrings\", \"Parsers\"]\ngit-tree-sha1 = \"c69f9da3ff2f4f02e811c3323c22e5dfcb584cfa\"\nuuid = \"ea10d353-3f73-51f8-a26c-33c1cb351aa5\"\nversion = \"1.4.1\"\n\n[[Zlib_jll]]\ndeps = [\"Libdl\"]\nuuid = \"83775a58-1f1d-513f-b197-d71354ab007a\"\n\n[[nghttp2_jll]]\ndeps = [\"Artifacts\", \"Libdl\"]\nuuid = \"8e850ede-7688-5339-a07c-302acd2aaf8d\"\n\n[[p7zip_jll]]\ndeps = [\"Artifacts\", \"Libdl\"]\nuuid = \"3f19e933-33d8-53b3-aaab-bd5110c3b7a0\"\n\"\"\"\n\n# ╔═╡ Cell order:\n# ╟─83a7b4d7-6442-44b2-9388-8330b19cd537\n# ╟─24abafc3-0e26-4cd2-9bca-7c69b794f8ce\n# ╟─b67c62c2-15ab-4328-b795-033f6f2a0674\n# ╟─bc689638-fd19-4c9f-935f-ddf6a6bfbbdd\n# ╟─197fd00e-9068-46ea-af2a-25235e544a31\n# ╠═f6d4f8c4-e441-45c4-8af5-148d95ea2900\n# ╟─45740c4d-b789-45dc-a6bf-47194d7e8e12\n# ╟─42b0f1e1-16c9-4238-828a-4cc485149963\n# ╠═bbe90636-9d1f-4ee0-8e35-c285f7b922d0\n# ╟─499cbc31-83ba-4583-ba1f-6363f43ec697\n# ╟─db5821e8-956a-4a46-95ea-2955abd45275\n# ╟─1e248249-5629-412f-b1b3-dd47e367ba54\n# ╟─d055d24f-1b2d-48a6-8d7e-8e449afd1c48\n# ╟─0dc40881-6163-4948-a949-7f3bd292fe31\n# ╟─0d066909-c9bf-4ae3-8514-99938a2932db\n# ╠═29ea6531-1337-4527-92bd-6ebccf75659a\n# ╠═ad63ad4b-04c0-491b-a0de-1721c1bc2df2\n# ╠═f86b62eb-6853-482a-bca8-7eec7950fd82\n# ╟─58686fe6-088a-4751-9873-1b1430e635cc\n# ╠═8b90b209-cb98-4116-b43e-d0ebe87da176\n# ╟─f1b47e75-0ce3-4e90-9009-4cfb2012998f\n# ╟─e904fcb3-7603-40d2-abd3-cb77d7a79683\n# ╟─e93966db-0dab-42ca-879e-dc128f3db7b3\n# ╟─2564f31e-4704-4820-a367-9aa3c6cf34d0\n# ╠═7e23f8f6-1634-45c8-bf32-94657e65284e\n# ╠═348ff9a2-89ab-434a-9afd-65a5b5facac9\n# ╟─c7e83ce7-f067-4049-b6c8-54f5ed90a964\n# ╠═a6106065-1baf-4720-9292-fe822525fc77\n# ╟─703d4ac3-116e-4e05-ae5e-4b83dcbc9675\n# ╠═5d976f7e-45ee-4cbb-8a29-32f11452654a\n# ╟─aad55579-14f3-439a-a5f1-151fcbe229a2\n# ╠═a6c1d3ea-6f43-42c7-8950-2f4327f23c1f\n# ╠═9f2f583a-e90a-43f6-81bc-2d5603785a09\n# ╟─828460a7-7d4e-444e-9d87-1d1fbb0e3997\n# ╟─12631f23-8262-475d-b950-fddef2a1fb10\n# ╠═d9069be8-d8c5-43ab-951b-64cb2a36c8e3\n# ╟─4dee7ef6-b472-4b9c-b0e6-441461cc8770\n# ╟─7a6df9e6-89f1-4117-8cb0-de601961bc02\n# ╟─8ff17b93-2830-41e2-a87d-950c50fb2955\n# ╟─d45a81ec-f978-4483-8448-4bcb089096cd\n# ╠═b454845b-3b3b-4c46-a012-a84240254fb6\n# ╟─28cf44d4-3f4b-485f-bbdd-9799f7bb2e60\n# ╠═1e780939-abf0-4203-97a7-88e3af4f10ee\n# ╠═09ece795-72e1-4240-a833-1b098ab27d3f\n# ╟─8e76b5a5-7c80-4684-b372-8c9866e51852\n# ╠═5ed77309-afa6-4c94-88c0-761fe6b5a5d4\n# ╟─d45ff6ec-2dd6-4a9c-a97e-79337b0be5c8\n# ╠═4a0b7419-d9ae-4570-b9b6-029e155045c0\n# ╠═3958b3df-51cd-4920-8f28-382c4a088a8f\n# ╟─e68044d8-42b4-49cd-86cf-35420d9e6995\n# ╠═26d649a8-3d96-4479-a29a-8d0445351914\n# ╟─7f60c74e-b708-46f4-be65-28d0fcca50a8\n# ╠═c8c960f0-2a46-42c2-8754-8bd531c8db8e\n# ╠═4e327bb5-8abc-4e68-9832-d4c16415df30\n# ╠═f96a84ec-1cc0-400c-9493-9c2a2e3c5b51\n# ╟─fbb24be1-fe01-4489-b5fa-cb79ebf595ef\n# ╠═958f9a9a-23d5-446b-aa54-f7a086cb0264\n# ╠═ea64dbb5-963a-4da4-91c5-524da38aa391\n# ╟─1ce36a90-ea25-48d6-ad90-b4405b216771\n# ╟─4270976f-1207-4086-895b-997a92b731e0\n# ╠═1d0bce6b-ffff-4f30-a525-e9b04a4bd246\n# ╠═64a648e0-d5c9-4c3d-80f0-ba7781e173cf\n# ╟─5dcd0d55-bb5d-459a-9cbc-9a2c39793333\n# ╟─234c586e-862f-4216-b887-2b16710e5502\n# ╠═b8e84a2c-2c7f-41f5-9452-5298a8a4a401\n# ╟─95b75a71-47b5-49b1-b017-96f1602f2cad\n# ╟─5de9f9a0-ad8f-47de-8be2-2a4017c45345\n# ╠═aa7bdff7-7d1b-43b1-a7ad-80d84f5b0070\n# ╠═92c5bc62-b430-41b8-8378-5aa686f0b407\n# ╟─adcb0506-e89d-43b0-9f43-49763e8691a1\n# ╟─667917e3-25d2-435c-bb0e-3a45761c733a\n# ╟─f71e4957-b6aa-480f-8acf-0c1d237fe9f9\n# ╠═dc119abd-72a1-4781-811d-5998beb56406\n# ╟─0398adfe-721a-4b97-910b-f8a9a217eff2\n# ╠═85f71232-0ec4-40a8-81b7-e11a56b42313\n# ╠═d1af0582-9074-4355-9d03-7ceec3db5d7f\n# ╠═06fac83d-ec17-4503-b3b1-670e16d4251a\n# ╠═9335bbb6-7169-47a2-8ccb-85c839a68433\n# ╟─fbe0163a-ed06-49ea-8faa-017fa7aeca69\n# ╟─4fd0807d-61e5-4b4b-a1cb-54e34396a855\n# ╠═1957f387-aee4-4c08-9838-327b915082f8\n# ╠═7b59b396-daac-4dea-bc51-54fafe346cd8\n# ╠═2efdfa9c-8e70-4c09-b9f9-85c873edc16a\n# ╠═dcf51860-a300-453e-87fc-345e741f94d0\n# ╠═c54f41ee-75e6-4181-8de7-d194004c9700\n# ╠═cb026565-6c5c-4f7a-91b6-417cfea74d41\n# ╠═e073f936-f2a0-4609-83fe-bd8afb87cfc1\n# ╠═91cca9cb-db5f-4d9f-983b-3f2b20444662\n# ╟─a0488295-9642-4156-b7cc-46f4ef988c68\n# ╟─d59d9e91-b26d-4342-90fb-7f2721f6fcc7\n# ╟─c4f30527-c9b4-44e9-af65-ccd25ecb9818\n# ╟─25a6fd3c-60d1-44dd-8890-979691212d9b\n# ╟─aed2b274-cc0c-42f2-a6fa-eaf14df5d44b\n# ╠═0df6be04-24fe-4417-8025-5084804a9f6c\n# ╟─9abf25a8-7231-43f5-9e90-09023d201062\n# ╟─6cce6530-0d12-4862-af4f-11c7de9e21dd\n# ╟─135dac9b-0bd9-4e1d-8dba-241d9b744683\n# ╟─00000000-0000-0000-0000-000000000001\n# ╟─00000000-0000-0000-0000-000000000002\n", "meta": {"hexsha": "d59159be7a9a67ac535d279bbba945fe1b8d33ed", "size": 51801, "ext": "jl", "lang": "Julia", "max_stars_repo_path": "notebooks/03_pipelines/notebook.pluto.jl", "max_stars_repo_name": "roland-KA/MLJTutorial.jl", "max_stars_repo_head_hexsha": "00d2294dbe458504f7e2d200b1ed84097b9ff3e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-11-02T10:46:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T23:36:21.000Z", "max_issues_repo_path": "notebooks/03_pipelines/notebook.pluto.jl", "max_issues_repo_name": "roland-KA/MLJTutorial.jl", "max_issues_repo_head_hexsha": "00d2294dbe458504f7e2d200b1ed84097b9ff3e7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2021-11-11T14:36:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:31:54.000Z", "max_forks_repo_path": "notebooks/03_pipelines/notebook.pluto.jl", "max_forks_repo_name": "roland-KA/MLJTutorial.jl", "max_forks_repo_head_hexsha": "00d2294dbe458504f7e2d200b1ed84097b9ff3e7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:08:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-30T14:27:30.000Z", "avg_line_length": 32.8269961977, "max_line_length": 403, "alphanum_fraction": 0.7415880002, "num_tokens": 22818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.4882833952958347, "lm_q2_score": 0.2018132174596823, "lm_q1q2_score": 0.0985420430367903}} {"text": "\n # Functions and methods for cascade computation\n\n\n \"\"\"\n `Cascade.computeSteps(scheme::Cascade.PhotonIonizationScheme, comp::Cascade.Computation, stepList::Array{Cascade.Step,1})` \n ... computes in turn all the requested transition amplitudes as well as PhotoIonization.Line's, etc. for all pre-specified \n (photo-) ionizing steps of the cascade. When compared with standard computations of these atomic processes, however, \n the amount of output is largely reduced and often just printed into the summary file. A set of \n data::Cascade.PhotoIonData is returned.\n \"\"\"\n function computeSteps(scheme::Cascade.PhotonIonizationScheme, comp::Cascade.Computation, stepList::Array{Cascade.Step,1})\n data = Cascade.PhotoIonData[]\n printSummary, iostream = Defaults.getDefaults(\"summary flag/stream\")\n \n # Perform computations in turn for all photon energies\n for photonEnergy in scheme.photonEnergies\n nt = 0; st = 0; linesP = PhotoIonization.Line[] \n settings = PhotoIonization.Settings(PhotoIonization.Settings(), photonEnergies=[Defaults.convertUnits(\"energy: from atomic\", photonEnergy)])\n println(\"\\n\\n* Perform ionizing computations for the photon energy $photonEnergy [a.u.]\")\n if printSummary println(iostream, \"\\n\\n* Perform ionizing computations for the photon energy $photonEnergy [a.u.]\") end \n #\n for step in stepList\n st = st + 1\n nc = length(step.initialMultiplet.levels) * length(step.finalMultiplet.levels)\n println(\"\\n $st) Perform $(string(step.process)) amplitude computations for up to $nc ionizing lines (without selection rules): \")\n if printSummary println(iostream, \"\\n* $st) Perform $(string(step.process)) amplitude computations for \" *\n \"up to $nc ionizing lines (without selection rules): \") end \n \n if step.process == Basics.Photo()\n newLines = PhotoIonization.computeLinesCascade(step.finalMultiplet, step.initialMultiplet, comp.nuclearModel, comp.grid, \n settings, output=true, printout=true) \n append!(linesP, newLines); nt = length(linesP)\n else error(\"Unsupported atomic process for cascade computations.\")\n end\n println(\" Step $st:: A total of $(length(newLines)) $(string(step.process)) lines are calculated, giving now rise \" *\n \"to a total of $nt $(string(step.process)) ionizing lines.\" )\n if printSummary println(iostream, \"\\n* Step $st:: A total of $(length(newLines)) $(string(step.process)) lines are calculated, \" *\n \"giving now rise to a total of $nt $(string(step.process)) ionizing lines.\" ) end \n end\n #\n push!(data, Cascade.PhotoIonData(photonEnergy, linesP))\n end\n \n return( data )\n end\n\n\n \"\"\"\n `Cascade.determineSteps(scheme::Cascade.PhotonIonizationScheme, comp::Cascade.Computation, \n initialList::Array{Cascade.Block,1}, ionizedList::Array{Cascade.Block,1})` \n ... determines all steps::Cascade.Step's that need to be computed for this ionizing cascade. It cycles through all processes \n of the given ionizing scheme and selects all pairs of initial and ionized blocks due to the selected photon energies and \n cascade approaches. It also checks that the (averaged) energies of the configuration support a photoionization \n energetically. A stepList::Array{Cascade.Step,1} is returned\n \"\"\"\n function determineSteps(scheme::Cascade.PhotonIonizationScheme, comp::Cascade.Computation, \n initialList::Array{Cascade.Block,1}, ionizedList::Array{Cascade.Block,1})\n stepList = Cascade.Step[]\n if comp.approach in [Cascade.AverageSCA(), Cascade.SCA()]\n for initialBlock in initialList\n for ionizedBlock in ionizedList\n for process in comp.scheme.processes\n if process == Basics.Photo() \n if initialBlock.NoElectrons == ionizedBlock.NoElectrons + 1\n settings = PhotoIonization.Settings() ##x settings, photonEnergies=[1.0], printBefore=false)\n push!( stepList, Cascade.Step(process, settings, initialBlock.confs, ionizedBlock.confs, \n initialBlock.multiplet, ionizedBlock.multiplet) )\n end\n else error(\"stop a\")\n end\n end\n end\n end\n #\n else error(\"Unsupported cascade approach.\")\n end\n return( stepList )\n end\n\n\n \"\"\"\n `Cascade.generateConfigurationsForPhotoionization(multiplets::Array{Multiplet,1}, maxPhotoElectrons::Int64, \n maxPhotonEnergy::Float64, nm::Nuclear.Model)` \n ... generates all possible (photoionized) configurations with upto maxPhotoElectrons less electrons and whose averaged energy\n is NOT higher than maxPhotoEnergy above of the given configuration. In the present version, no shake contributions are taken\n into account. A Tuple(initialConfList::Array{Configuration,1}, confList::Array{Configuration,1}) is returned.\n \"\"\"\n function generateConfigurationsForPhotoionization(multiplets::Array{Multiplet,1}, maxPhotoElectrons::Int64, maxPhotonEnergy::Float64, \n nm::Nuclear.Model)\n # Determine all (different) configurations from multiplets\n newconfList = Configuration[]\n for mp in multiplets \n confList = Basics.extractNonrelativisticConfigurations(mp.levels[1].basis)\n for conf in confList if conf in newconfList nothing else push!(newconfList, conf) end end\n end\n en = Float64[]; for conf in confList push!(en, -Semiempirical.estimate(\"binding energy\", round(Int64, nm.Z), conf)) end\n maxen = maximum(en)\n shList = Basics.generate(\"shells: ordered list for NR configurations\", newconfList)\n \n # Collect all configuration with up to maxPhotoElectrons less electrons\n initialConfList = deepcopy(newconfList); \n allnewconfList = Configuration[]; confList = deepcopy(newconfList); newconfList = Configuration[]\n for ne = 1:maxPhotoElectrons\n for sh in shList\n for conf in confList\n shells = deepcopy(conf.shells); \n if shells[sh] > 0 shells[sh] = shells[sh] - 1; push!(newconfList, Configuration(shells, conf.NoElectrons - 1)) end\n end\n end\n append!(allnewconfList, newconfList)\n confList = deepcopy(newconfList); newconfList = Configuration[]\n end\n \n # Exclude double configurations as well as those with too high average energy\n ##x confList = Basics.excludeDoubles(allnewconfList)\n confList = unique(allnewconfList)\n newconfList = Configuration[]\n for conf in confList \n enconf = -Semiempirical.estimate(\"binding energy\", round(Int64, nm.Z), conf)\n if enconf - maxen < maxPhotonEnergy push!(newconfList, conf) end\n end\n\n return( (initialConfList, newconfList) )\n end\n\n\n \"\"\"\n `Cascade.perform(scheme::PhotonIonizationScheme, comp::Cascade.Computation)` \n ... to set-up and perform a cascade computation that starts from a given set of initial configurations xor initial multiplets\n and proceeds via photoionizing processes to configurations with a given No of photoelectrons. The results of all individual \n photoionization steps are comprised into (output) data::PhotoIonData, although all data are only printed and nothing \n is returned.\n\n `Cascade.perform(scheme::PhotonIonizationScheme, comp::Cascade.Computation; output=true, outputToFile::Bool=true)` \n ... to perform the same but to return the complete output in a dictionary that is written to disk and can be used in subsequent\n cascade simulation. The particular output also depends on the specifications of the cascade.\n \"\"\"\n function perform(scheme::PhotonIonizationScheme, comp::Cascade.Computation; output::Bool=false, outputToFile::Bool=true)\n if output results = Dict{String, Any}() else results = nothing end\n printSummary, iostream = Defaults.getDefaults(\"summary flag/stream\")\n #\n # Perform the SCF and CI computation for the intial-state multiplets if initial configurations are given\n if comp.initialConfigs != Configuration[]\n basis = Basics.performSCF(comp.initialConfigs, comp.nuclearModel, comp.grid, comp.asfSettings; printout=false)\n multiplet = Basics.performCI(basis, comp.nuclearModel, comp.grid, comp.asfSettings; printout=false)\n multiplets = [Multiplet(\"initial states\", multiplet.levels)]\n else\n multiplets = comp.initialMultiplets\n end\n # Print out initial configurations and levels \n Cascade.displayLevels(stdout, multiplets, sa=\"initial \")\n if printSummary Cascade.displayLevels(iostream, multiplets, sa=\"initial \") end\n #\n # Generate subsequent cascade configurations as well as display and group them together\n maxen = maximum(comp.scheme.photonEnergies) + 20\n wa = Cascade.generateConfigurationsForPhotoionization(multiplets, comp.scheme.maxPhotoElectrons, maxen, comp.nuclearModel)\n wb1 = Cascade.groupDisplayConfigurationList(comp.nuclearModel.Z, wa[1], sa=\"(initial part of the) ionizing \")\n wb2 = Cascade.groupDisplayConfigurationList(comp.nuclearModel.Z, wa[2], sa=\"(generated part of the) ionizing \")\n #\n # Determine first all configuration 'blocks' and from them the individual steps of the cascade\n wc1 = Cascade.generateBlocks(comp, wb1, basis.orbitals, sa=\"for the ionizing cascade \")\n wc2 = Cascade.generateBlocks(comp, wb2, basis.orbitals, sa=\"for the ionizing cascade \", printout=false)\n Cascade.displayBlocks(stdout, wc1, sa=\"for the (initial part of the) ionizing cascade \"); \n Cascade.displayBlocks(stdout, wc2, sa=\"for the (generated part of the) ionizing cascade \")\n if printSummary Cascade.displayBlocks(iostream, wc1, sa=\"for the (initial part of the) ionizing cascade \")\n Cascade.displayBlocks(iostream, wc2, sa=\"for the (generated part of the) ionizing cascade \") end \n # Determine, modify and compute the transition data for all steps, ie. the PhotoIonization.Line's, etc.\n gMultiplets = Multiplet[]; for block in wc2 push!(gMultiplets, block.multiplet) end\n we = Cascade.determineSteps(scheme, comp, wc1, wc2)\n Cascade.displaySteps(stdout, we, sa=\"ionizing \")\n if printSummary Cascade.displaySteps(iostream, we, sa=\"ionizing \") end \n wf = Cascade.modifySteps(we)\n data = Cascade.computeSteps(scheme, comp, wf)\n if output \n results = Base.merge( results, Dict(\"name\" => comp.name) ) \n results = Base.merge( results, Dict(\"cascade scheme\" => comp.scheme) ) \n results = Base.merge( results, Dict(\"initial multiplets:\" => multiplets) ) \n results = Base.merge( results, Dict(\"generated multiplets:\" => gMultiplets) ) \n results = Base.merge( results, Dict(\"photo-ionizing line data:\" => data) )\n #\n # Write out the result to file to later continue with simulations on the cascade data\n filename = \"zzz-cascade-ionizing-computations-\" * string(Dates.now())[1:13] * \".jld\"\n println(\"\\n* Write all results to disk; use:\\n JLD.save(''$filename'', results) \\n using JLD \" *\n \"\\n results = JLD.load(''$filename'') ... to load the results back from file.\")\n if printSummary println(iostream, \"\\n* Write all results to disk; use:\\n JLD.save(''$filename'', results) \\n using JLD \" *\n \"\\n results = JLD.load(''$filename'') ... to load the results back from file.\" ) end \n JLD2.@save filename results\n end\n ## return( results )\n return( results )\n end\n", "meta": {"hexsha": "ea8e49837c5b7ca0d98763770f52939492428a19", "size": 12982, "ext": "jl", "lang": "Julia", "max_stars_repo_path": "src/module-Cascade-inc-photoionization.jl", "max_stars_repo_name": "mfherbst/JAC.jl", "max_stars_repo_head_hexsha": "43563c049a995817ada86ce82908714d4e1a034b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2019-03-11T11:24:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T22:33:28.000Z", "max_issues_repo_path": "src/module-Cascade-inc-photoionization.jl", "max_issues_repo_name": "mfherbst/JAC.jl", "max_issues_repo_head_hexsha": "43563c049a995817ada86ce82908714d4e1a034b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-04-02T22:04:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T06:21:57.000Z", "max_forks_repo_path": "src/module-Cascade-inc-photoionization.jl", "max_forks_repo_name": "mfherbst/JAC.jl", "max_forks_repo_head_hexsha": "43563c049a995817ada86ce82908714d4e1a034b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2019-03-20T10:28:48.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T12:51:19.000Z", "avg_line_length": 67.2642487047, "max_line_length": 152, "alphanum_fraction": 0.6188568788, "num_tokens": 2805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.17781086512112404, "lm_q1q2_score": 0.09583707275624684}} {"text": "import Flatten: flattenable\n@metadata initial_value nothing\nimport FieldMetadata: @units, units\nimport FieldMetadata: @limits, limits\nimport FieldMetadata: @prior, prior\nimport FieldMetadata: @description, description\n@metadata bounds nothing\nimport FieldMetadata: @logscaled, logscaled\n@metadata reference nothing\n\n\n\"\"\"\n AbstractParameters{T} <: AbstractVector{T}\n\nAn abstract type for AIBECS model parameters.\n\nParameters in AIBECS use the following convenience packages:\n\n- Parameters\n- FieldMetadata\n- FieldDefaults\n- Flatten\n- Unitful\n- DataFrames\n- Distributions\n\nThese aim to allow for some nice features, which include\n\n- nice syntax for unpacking parameters in functions via the `@unpack` macro (fron UnPack.jl)\n- additional metadata on parameters\n- easy conversion to and from vectors\n- use of units and automatic conversions if necessary\n- pretty table-format displays\n- loading and saving to and from CSV files\n- prior estimates for bayesian inference and optimization\n\nSee the list of examples to get an idea of how to generate parameters for your model.\n\n# Examples\n\nGenerate a simple parameter type via\n\n```jldoctest\njulia> struct SimpleParams{T} <: AbstractParameters{T}\n α::T\n β::T\n γ::T\n end\nSimpleParams\n```\n\nTo create an instance of the `SimpleParams(Float64)` type, you can do\n\n```jldoctest\njulia> p = SimpleParams(1.0, 2.0, 3.0)\nSimpleParams{Float64}\n│ Row │ Symbol │ Value │\n│ │ Symbol │ Float64 │\n├─────┼────────┼─────────┤\n│ 1 │ α │ 1.0 │\n│ 2 │ β │ 2.0 │\n│ 3 │ γ │ 3.0 │\n```\n\nOne of the core features from Parameters is unpacking in functions, e.g.,\n\n```jldoctest\njulia> function simplef(p)\n @unpack α, γ = p\n return α + γ\n end\nsimplef (generic function with 1 method)\n\njulia> simplef(p) # 1.0 + 3.0\n4.0\n```\n\nMore complex examples are permitted by adding metadata (thanks to FieldMetadata.jl).\nYou can add units\n\n```jldoctest\njulia> @units struct UnitParams{T} <: AbstractParameters{T}\n α::T | u\"km\"\n β::T | u\"hr\"\n γ::T | u\"m/s\"\n end ;\n\njulia> p = UnitParams(1.0, 2.0, 3.0)\nUnitParams{Float64}\n│ Row │ Symbol │ Value │ Unit │\n│ │ Symbol │ Float64 │ Unitful… │\n├─────┼────────┼─────────┼──────────┤\n│ 1 │ α │ 1.0 │ km │\n│ 2 │ β │ 2.0 │ hr │\n│ 3 │ γ │ 3.0 │ m s^-1 │\n```\n\nNote that when adding units to your parameters, they will be converted to SI\nwhen unpacked, as in, e.g.,\n\n```jldoctest\njulia> function speed(p)\n @unpack α, β, γ = p\n return α / β + γ\n end\nspeed (generic function with 1 method)\n\njulia> speed(p) # (1.0 km / 2.0 hr + 3 m/s) in m/s\n3.138888888888889\n```\n\nAnother example for optimizable/flattenable parameters\n\n```jldoctest\njulia> @initial_value @units @flattenable struct OptParams{T} <: AbstractParameters{T}\n α::T | 3.6 | u\"km\" | true\n β::T | 1.0 | u\"hr\" | false\n γ::T | 1.0 | u\"m/s\" | true\n end ;\n\njulia> p = OptParams(initial_value(OptParams)...)\nOptParams{Float64}\n│ Row │ Symbol │ Value │ Initial value │ Unit │ Optimizable │\n│ │ Symbol │ Float64 │ Float64 │ Unitful… │ Bool │\n├─────┼────────┼─────────┼───────────────┼──────────┼─────────────┤\n│ 1 │ α │ 3.6 │ 3.6 │ km │ 1 │\n│ 2 │ β │ 1.0 │ 1.0 │ hr │ 0 │\n│ 3 │ γ │ 1.0 │ 1.0 │ m s^-1 │ 1 │\n```\n\nThanks to the FieldMetaData interface, you can chain the following preloaded metadata:\n\n- initial_value\n- units (from Unitful.jl)\n- prior (from Distributions.jl)\n- description (`String`)\n- bounds (2-element `Tuple`)\n- logscaled (`Bool`)\n- flattenable (to convert to vectors of optimizable parameters only)\n- reference (`String`)\n\nHere is an example of parameter with all the possible metadata available in AIBECS:\n\n```jldoctest\njulia> @initial_value @units @prior @description @bounds @logscaled @flattenable @reference struct FullParams{T} <: AbstractParameters{T}\n α::T | 1.0 | u\"km\" | Normal(0,1) | \"The distance\" | (-Inf, Inf) | false | false | \"Jean et al., 2042\"\n β::T | 2.0 | u\"hr\" | LogNormal(0,1) | \"The time\" | ( 0, Inf) | true | true | \"Claude et al. 1983\"\n γ::T | 3.0 | u\"mol\" | Normal(1,2) | \"The # of moles\" | ( -1, 1) | false | true | \"Dusse et al. 2000\"\n end ;\n\njulia> FullParams(4.0, 5.0, 6.0)\nFullParams{Float64}\n│ Row │ Symbol │ Value │ Initial value │ Unit │ Prior │ Description │ Bounds │ Logscaled │ Optimizable │ Reference │\n│ │ Symbol │ Float64 │ Float64 │ Unitful… │ Distribu… │ String │ Tuple… │ Bool │ Bool │ String │\n├─────┼────────┼─────────┼───────────────┼──────────┼──────────────────────────────────┼────────────────┼─────────────┼───────────┼─────────────┼────────────────────┤\n│ 1 │ α │ 4.0 │ 1.0 │ km │ Normal{Float64}(μ=0.0, σ=1.0) │ The distance │ (-Inf, Inf) │ 0 │ 0 │ Jean et al., 2042 │\n│ 2 │ β │ 5.0 │ 2.0 │ hr │ LogNormal{Float64}(μ=0.0, σ=1.0) │ The time │ (0, Inf) │ 1 │ 1 │ Claude et al. 1983 │\n│ 3 │ γ │ 6.0 │ 3.0 │ mol │ Normal{Float64}(μ=1.0, σ=2.0) │ The # of moles │ (-1, 1) │ 0 │ 1 │ Dusse et al. 2000 │\n```\n\nNote that there is no check that the metadata you give is consistent.\nThese metadata will hopefully be useful for advanced usage of AIBECS, e.g., using prior information and/or bounds for optimization.\n\"\"\"\nabstract type AbstractParameters{T} <: AbstractVector{T} end\n\n\"\"\"\n symbols(p)\n\nReturns the symbols in `p`.\n\nCan also be used directly on the type of `p`\n(because the symbols of `p::T` are contained in the type `T`).\n\"\"\"\nsymbols(::Type{T}) where {T <: AbstractParameters} = fieldnames(T)\nsymbols(::T) where {T <: AbstractParameters} = symbols(T)\n\n\"\"\"\n flattenable_symbols(p)\n\nReturns the flattenable symbols in `p`.\n\nThe flattenable symbols are those symbols that are kepth when using `p` as a vector,\ne.g., when doing `vec(p)`.\n(Useful when passing parameters to an optimization routine expeting a vector of optimizable parameters.)\n\nCan also be used directly on the type of `p`\n(because the flattenable symbols of `p::T` are contained in the type `T`).\n\"\"\"\nflattenable_symbols(::T) where {T <: AbstractParameters} = flattenable_symbols(T)\nflattenable_symbols(::Type{T}) where {T <: AbstractParameters} = fieldnames(T)[collect(flattenable(T))]\n\n\"\"\"\n values(p::T) where {T <: AbstractParameters}\n\nReturns a vector of **all** the values of `p`.\n\nNote that `values(p)` is different from `vec(p)`.\n\"\"\"\nBase.values(p::T) where {T <: AbstractParameters} = [getfield(p, s) for s in symbols(T)]\n\n\"\"\"\n flattenable_values(p::T) where {T <: AbstractParameters}\n\nReturns a vector of the **flattenable** values of `p`.\n\nNote that `vec(p)` is different from `values(p)`.\n\"\"\"\nflattenable_values(p::T) where {T <: AbstractParameters} = [getfield(p, s) for s in flattenable_symbols(T)]\n\n\"\"\"\n vec(p::T) where {T <: AbstractParameters}\n\nReturns a **SI-unit-converted** vector of flattenable values of `p`.\n\nNote that `vec(p) ≠ flattenable_values(p)` if `p` has units.\n\"\"\"\nBase.vec(p::T) where {T <: AbstractParameters} = [UnPack.unpack(p, Val(s)) for s in flattenable_symbols(T)]\n\n\n\"\"\"\n length(p::AbstractParameter)\n\nReturns the length of the **flattened/optimzable** vector of `p`.\n\nMay be different from the number of parameters.\nCan also be used directly on the type of `p`.\n\"\"\"\nBase.length(::T) where {T <: AbstractParameters} = sum(flattenable(T))\nBase.length(::Type{T}) where {T <: AbstractParameters} = sum(flattenable(T))\n\n\"\"\"\n size(p::AbstractParameter)\n\nReturns the size of the **flattened/optimzable** vector of `p`.\n\nMay be different from the number of parameters.\nCan also be used directly on the type of `p`.\n\"\"\"\nBase.size(::T) where {T <: AbstractParameters} = (length(T),)\nBase.size(::Type{T}) where {T <: AbstractParameters} = (length(T),)\n\nfunction Base.show(io::IO, p::T) where T <: AbstractParameters\n print(T)\n t = table(p)\n show(io, t; summary=false)\nend\nfunction Base.show(io::IO, m::MIME\"text/plain\", p::T) where T <: AbstractParameters\n print(T)\n t = table(p)\n show(io, m, t; summary=false)\nend\n\nfunction table(p::T, nf::NamedTuple) where {T <: AbstractParameters}\n t = DataFrame(Symbol = collect(symbols(p)), Value = values(p))\n for (n,f) in zip(keys(nf), nf)\n setproperty!(t, n, collect(f(p)))\n end\n return t\nend\n\n\"\"\"\n table(p)\n\nReturns a `DataFrame` (a table) of `p`.\nUseful for printing and saving into an actual text/latex table.\n\"\"\"\nfunction table(p::AbstractParameters)\n ks, vs = Symbol[], Function[]\n all(isnothing, initial_value(p)) || (push!(ks, Symbol(\"Initial value\")); push!(vs, initial_value))\n all(isequal(1), units(p)) || (push!(ks, :Unit); push!(vs, units))\n all(isnothing, prior(p)) || (push!(ks, Symbol(\"Prior\")); push!(vs, prior))\n all(isempty, description(p)) || (push!(ks, Symbol(\"Description\")); push!(vs, description))\n all(isnothing, bounds(p)) || (push!(ks, Symbol(\"Bounds\")); push!(vs, bounds))\n any(logscaled(p)) && (push!(ks, Symbol(\"Logscaled\")); push!(vs, logscaled))\n all(flattenable(p)) || (push!(ks, Symbol(\"Optimizable\")); push!(vs, flattenable))\n all(isnothing, reference(p)) || (push!(ks, Symbol(\"Reference\")); push!(vs, reference))\n nf = (; zip(ks, vs)...)\n t = table(p, nf)\nend\n\n\n\"\"\"\n latex(p)\n\nReturns a LaTeX-formatted table of the parameters.\n\"\"\"\nlatex(p::AbstractParameters) = show(stdout, MIME(\"text/latex\"), table(p))\n\n\"\"\"\n unpack(p <: AbstractParameters, s)\n\nUnpacks the parameter `s` from `p`.\n\nNote this is specialized and will convert the parameter value to SI units.\n\"\"\"\n@inline UnPack.unpack(p::T, ::Val{f}) where {T<:AbstractParameters,f} = ustrip(upreferred(getproperty(p, f) * units(T, f)))\n\n\"\"\"\n +(p::T, v::Vector) where {T <: AbstractParameters}\n\nAdds the flattened vector `v` to `p`.\n\n**Warning:** This method for `+` is implemented only for differentiation\nusing dual and hyperdual numbers.\nIf you want to change the values of `p`, you should do so explicitly\nrather than use this `+` method.\n\"\"\"\nBase.:+(p::T, v::Vector) where {T <: AbstractParameters} = reconstruct(T, vec(p) + v)\n\n\"\"\"\n reconstruct(T, v)\n\nReconstructs the parameter of type `T` from flattenable vector `v`.\n\"\"\"\nfunction reconstruct(::Type{T}, v::Tv) where {T <: AbstractParameters, Tv <: Vector}\n all(isnothing, initial_value(T)) && error(\"Can't reconstruct without initial values\")\n vunits = units(T)[[flattenable(T)...]]\n v = @. v * upreferred(vunits) |> vunits |> ustrip\n reconstructed_v = convert(Tv, collect(initial_value(T)))\n reconstructed_v[collect(flattenable(T))] .= v\n return T.name.wrapper(reconstructed_v...)\nend\n\n\"\"\"\n getindex(p::T, i) where {T <: AbstractParameters}\n\nReturns the i-th element of vec(p).\n\nThis is not efficient and only used for testing the derivatives with ForwardDiff.\n\"\"\"\nBase.getindex(p::T, i) where {T <: AbstractParameters} = getindex(vec(p), i)\n\n\nfunction (::Type{T})(args::Quantity...) where {T <: AbstractParameters}\n all(isequal(1), units(T)) && error(\"$T needs `units` for this construction to work\")\n return T([ustrip(x |> units(T, f)) for (x,f) in zip(args, fieldnames(T))]...)\nend\n\nfunction (::Type{T})(;kwargs...) where {T <: AbstractParameters}\n all(isnothing, initial_value(T)) && length(kwargs) ≠ length(symbols(T)) && error(\"$T needs `initial_value` if one of the parameters is not supplied\")\n value(f::Symbol, v::Quantity) = ustrip(v |> units(T, f))\n value(f::Symbol, v) = v\n return T([f ∈ keys(kwargs) ? value(f, kwargs[f]) : initial_value(T, f) for f in fieldnames(T)]...)\nend\n\n#===============================\nWriting to savable formats\n===============================#\n\nfunction Base.Dict(p::T, s=symbols(p)) where {T<:AbstractParameters}\n v = [getfield(p,s) for s in s]\n u = [units(p,s) for s in s]\n return Dict([(s,v*u) for (s,v,u) in zip(s,v,u)])\nend\nfunction Base.NamedTuple(p::T, s=symbols(p)) where {T<:AbstractParameters}\n v = [getfield(p,s) for s in s]\n u = [units(p,s) for s in s]\n return (; zip(s, v .* u)...)\nend\n\n#=====================\nmismatch of parameters\n=====================#\n\"\"\"\n mismatch(p::AbstractParameters)\n\nReturns the sum of the negative log-likelihood of each flattenable parameter.\n\"\"\"\nfunction mismatch(p::AbstractParameters)\n return sum(-logpdf(prior(p,k), UnPack.unpack(p,Val(k))) for k in flattenable_symbols(p))\nend\nfunction ∇mismatch(p::AbstractParameters)\n return transpose([-gradlogpdf(prior(p,k), UnPack.unpack(p,Val(k))) for k in flattenable_symbols(p)])\nend\n\n# The functions below is just for ForwardDiff to work with vectors instead of p\n# which requires `mismatch` to know about the priors, which are containted in `T`\nfunction generate_objective(ωs, μx, σ²x, v, ωp, ::Type{T}) where {T<:AbstractParameters}\n nt, nb = length(ωs), length(v)\n tracers(x) = state_to_tracers(x, nb, nt)\n f(x, p) = ωp * mismatch(T, p) +\n sum([ωⱼ * mismatch(xⱼ, μⱼ, σⱼ², v) for (ωⱼ, xⱼ, μⱼ, σⱼ²) in zip(ωs, tracers(x), μx, σ²x)])\n return f\nend\nfunction mismatch(::Type{T}, v) where {T<:AbstractParameters}\n return sum(-logpdf(prior(T,k), v[i]) for (i,k) in enumerate(flattenable_symbols(T)))\nend\n\n#==================\nChange of variables\n==================#\n\"\"\"\n subfun\n\nReturns the substitution function for the change of variables of parameters.\n\nIf the prior of parameter `pᵢ` is `LogNormal`, then the substitution function is `exp`.\nIf the prior is `Uniform`, then the change of variables is the logit function.\nOtherwise, it's `identity`.\n\"\"\"\nfunction subfun(::Type{T}) where {T<:AbstractParameters}\n return λ -> reconstruct(T, [subfun(T, s)(λᵢ) for (λᵢ,s) in zip(λ, flattenable_symbols(T))])\nend\nfunction ∇subfun(::Type{T}) where {T<:AbstractParameters}\n return λ -> reconstruct(T, [∇subfun(T, s)(λᵢ) for (λᵢ,s) in zip(λ, flattenable_symbols(T))])\nend\nfunction ∇²subfun(::Type{T}) where {T<:AbstractParameters}\n return λ -> reconstruct(T, [∇²subfun(T, s)(λᵢ) for (λᵢ,s) in zip(λ, flattenable_symbols(T))])\nend\nfunction invsubfun(::Type{T}) where {T<:AbstractParameters}\n return p -> [invsubfun(T, s)(pᵢ) for (pᵢ,s) in zip(vec(p), flattenable_symbols(T))]\nend\n# substitution function (change of variables) is determined from prior distribution\nsubfun(::Type{T}, s::Symbol) where {T<:AbstractParameters} = subfun(prior(T,s))\n∇subfun(::Type{T}, s::Symbol) where {T<:AbstractParameters} = ∇subfun(prior(T,s))\n∇²subfun(::Type{T}, s::Symbol) where {T<:AbstractParameters} = ∇²subfun(prior(T,s))\ninvsubfun(::Type{T}, s::Symbol) where {T<:AbstractParameters} = invsubfun(prior(T,s))\n# Fallback rule for change of variables is identity\nsubfun(::Distribution) = identity\n∇subfun(::Distribution) = x -> one(x)\n∇²subfun(::Distribution) = x -> zero(x)\ninvsubfun(::Distribution) = identity\n# p = exp(λ) for LogNormal\nsubfun(::LogNormal) = exp\n∇subfun(::LogNormal) = exp\n∇²subfun(::LogNormal) = exp\ninvsubfun(::LogNormal) = log\n# p = logistic(λ) for Uniform\nsubfun(d::Uniform) = λ -> d.a + (d.b - d.a) / (exp(-λ) + 1)\n∇subfun(d::Uniform) = λ -> (d.b - d.a) * exp(-λ) / (exp(-λ) + 1)^2\n∇²subfun(d::Uniform) = λ -> (d.a - d.b) * exp(-λ) / (exp(-λ) + 1)^2 + 2(d.b - d.a) * exp(-2λ) / (exp(-λ) + 1)^3\ninvsubfun(d::Uniform) = p -> -log((d.b - d.a) / (p - d.a) - 1)\n\nexport subfun, ∇subfun, ∇²subfun, invsubfun\n\n\nexport AbstractParameters, latex\n\n", "meta": {"hexsha": "481fac812d70b9460d04e9336910f15128cc0216", "size": 15637, "ext": "jl", "lang": "Julia", "max_stars_repo_path": "src/Parameters.jl", "max_stars_repo_name": "seamanticscience/AIBECS.jl", "max_stars_repo_head_hexsha": "ff64544aa637a7324f513be697897384efbec4e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Parameters.jl", "max_issues_repo_name": "seamanticscience/AIBECS.jl", "max_issues_repo_head_hexsha": "ff64544aa637a7324f513be697897384efbec4e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Parameters.jl", "max_forks_repo_name": "seamanticscience/AIBECS.jl", "max_forks_repo_head_hexsha": "ff64544aa637a7324f513be697897384efbec4e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6195899772, "max_line_length": 166, "alphanum_fraction": 0.6213468057, "num_tokens": 4680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.5, "lm_q2_score": 0.18713268669577832, "lm_q1q2_score": 0.09356634334788916}} {"text": "################################################################################\n### Introduction to Scientific Programming and Machine Learning with Julia ###\n### ###\n### Run each script on a new clean Julia session ###\n### GitHub: https://github.com/sylvaticus/IntroSPMLJuliaCourse ###\n### Licence (apply to all material of the course: scripts, videos, quizes,..)###\n### Creative Commons By Attribution (CC BY 4.0), Antonello Lobianco ###\n################################################################################\n\n# # 0105 Custom Types\n\n\n# ## Some stuff to set-up the environment..\n\ncd(@__DIR__) \nusing Pkg \nPkg.activate(\".\") \n## If using a Julia version different than 1.7 please uncomment and run the following line (reproductibility guarantee will however be lost)\n## Pkg.resolve() \n## Pkg.instantiate() # run this if you didn't in Segment 01.01\nusing Random\nRandom.seed!(123)\nusing InteractiveUtils # loaded automatically when working... interactively\n\n# ## \"Type\" of types\n\n# In Julia primitive, composite and abstract types can all be defined by the user\n\nprimitive type APrimitiveType 819200 end # name and size in bit - multiple of 8 and below 8388608 (1MB)\nprimitive type APrimitiveType2 819200 end\n819200/(8*1024)\nstruct ACompositeType end # fields, constructors.. we'll see this later in details\nabstract type AnAbstractType end # no objects, no instantialisation of objects\n\n\n# ## Composite types\nmutable struct Foo # starting with a capital letter\n field1\n field2::String\n field3::ACompositeType\nend\n\n# mutable struct Foo # error! can't change a struct after I defined it\n# end\n\nfieldnames(Foo)\n\no = Foo(123,\"aaa\",ACompositeType()) # call the default constructor (available automatically) - order matters!\ntypeof(o)\n\n\n# Outer constructor\nfunction Foo(f2,f3=ACompositeType()) # \"normal\" functions just happens it has the name of the object to create\n if startswith(f2,\"Booo\") # put whatever logic you wish\n return nothing\n end\n return Foo(123,f2,f3) # call the default constructor\nend\n\no = Foo(123,\"aaa\", ACompositeType()) # call the default constructor\no = Foo(\"blaaaaa\") # call the outer constructor we defined\n\no.field1 # access fields\no.field1 = 321 # modify field (because type defined as \"mutable\" !!!)\no\n\n\nfunction Base.show(io::IO, x::Foo) # function(o) rather than o.function() \n println(io,\"My custom representation for Foo objects\")\n println(io,\"Field1: $(o.field1)\")\n println(io,\"Field2: $(o.field2)\")\nend\no\n\n# Inner constructor\nmutable struct Foo2\n field1::Int64\n field2::String\n function Foo2(f1,f2,f3)\n ## ... logic\n return new(f1+f2,f3)\n end\nend\nFoo2(1,2,\"aaa\")\n\n# !!! tip\n# If any inner constructor method is defined, no default constructor method is provided.\n\n## Foo2(1,\"aaa\") # Error, no default constructor !\n\n# ## Parametric types\n\nstruct Point{T<:Number} # T must be a child of type \"Number\"\n x::T\n y::T\nend\n\no = Point(1,2)\nPoint(1.0,2.)\n## Point(1,2.0) # error !\n\nfunction Point(x::T, y::T=zero(T)) where {T}\n return Point(x,y)\nend\nPoint(2)\nPoint(1.5)\n\nabstract type Figure{T<:Number} end\n\na = Array{Int64,2}(undef,2,2) # Array is nothing else than a parametric type with 2 parameters\ntypeof(a)\neltype(a)\n\n# As we see for arrays, parameters doesn't need to be _types_, but can be any value of a bits type (in practice an integer value) :\n\nstruct MyType{T,N}\n data::Array{T,N}\nend\n\nintMatrixInside = MyType([1 2 3; 4 5 6])\nfloatVectorInside = MyType([1 2 3])\n\nfunction getPlane(o::MyType{T,N},dim,pos) where {T,N}\nsizes = size(o.data)\nif length(sizes) > N\n error(\"Dim over the dimensions of the data\")\nelseif sizes[dim] < pos\n error(\"Non enought elements in dimension $dim to cut at $pos\")\nend\nreturn selectdim(o.data,dim,pos)\nend\n\ngetPlane(intMatrixInside,1,2)\n\n# A package where non-type parameters are emploied to boost speed is [StaticArray.jl](https://github.com/JuliaArrays/StaticArrays.jl) where one parameter is the _size_ of the array that hence become known at compile time\n\n\n# ## Inheritance\n\nabstract type MyOwnGenericAbstractType end # the highest-level\nabstract type MyOwnAbstractType1 <: MyOwnGenericAbstractType end # child of MyOwnGenericAbstractType \nabstract type MyOwnAbstractType2 <: MyOwnGenericAbstractType end # also child of MyOwnGenericAbstractType\nmutable struct AConcreteTypeA <: MyOwnAbstractType1\n f1::Int64\n f2::Int64\nend\nmutable struct AConcreteTypeB <: MyOwnAbstractType1\n f1::Float64\nend\nmutable struct AConcreteTypeZ <: MyOwnAbstractType2\n f1::String\nend\noA = AConcreteTypeA(2,10)\noB = AConcreteTypeB(1.5)\noZ = AConcreteTypeZ(\"aa\")\n\nsupertype(AConcreteTypeA)\nsubtypes(MyOwnAbstractType1)\n\n\n# !!! tip\n# When multiple methods are available for an object, function calls are dispatched to the most stricter method, i.e. the one defined over the exact parameter's type or their immediate parents\n\nfunction foo(a :: MyOwnGenericAbstractType) # good for everyone \n println(\"Default implementation: $(a.f1)\")\nend\nfoo(oA) # Default implementation: 2\nfoo(oB) # Default implementation: 1.5\nfoo(oZ) # Default implementation: aa\nfunction foo(a :: MyOwnAbstractType1) # specialisation for MyOwnAbstractType1\n println(\"A more specialised implementation: $(a.f1*4)\")\nend\nfoo(oA) # A more specialised implementation: 8\nfoo(oB) # A more specialised implementation: 6.0\nfoo(oZ) # Default implementation: aa # doesn't match the specialisation, default to foo(a :: MyOwnGenericAbstractType)\nfunction foo(a :: AConcreteTypeA)\n println(\"A even more specialised implementation: $(a.f1 + a.f2)\")\nend\nfoo(oA) # A even more specialised implementation: 12\nfoo(oB) # A more specialised implementation: 6.0\nfoo(oZ) # Default implementation: aa\n\n# !!! warning \n# Attention to the inheritance for parametric types. If it is true that `Vector{Int64} <: AbstractVector{Int64}` and `Int64 <: Number`, it is FALSE that `AbstractVector{Int64} <: AbstractVector{Number}`. If you want to allow a function parameter to be a vector of numbers, use instead templates explicitly, e.g. `foo(x::AbstractVector{T}) where {T<:Number} = return sum(x)`\n\nVector{Int64} <: AbstractVector{Int64}\nInt64 <: Number\nVector{Int64} <: Vector{Number}\nAbstractVector{Int64} <: AbstractVector{Number}\n\n\n# ## Object-oriented model\n\n# OO model based on _composition_ \n\nstruct Shoes\n shoesType::String\n colour::String\nend\nstruct Person\n myname::String\n age::Int64\nend\nstruct Student\n p::Person # by referencing a `Person`` object, we do not need to repeat its fields\n school::String\n shoes::Shoes # same for `shoes`\nend\nstruct Employee\n p::Person\n monthlyIncomes::Float64\n company::String\n shoes::Shoes\nend\ngymShoes = Shoes(\"gym\",\"white\")\nproShoes = Shoes(\"classical\",\"brown\")\nMarc = Student(Person(\"Marc\",15),\"Divine School\",gymShoes)\nMrBrown = Employee(Person(\"Brown\",45),3200.0,\"ABC Corporation Inc.\", proShoes)\n\nfunction printMyActivity(self::Student)\n println(\"Hi! I am $(self.p.myname), I study at $(self.school) school, and I wear $(self.shoes.colour) shoes\") # I can use the dot operator chained...\nend\nfunction printMyActivity(self::Employee)\n println(\"Good day. My name is $(self.p.myname), I work at $(self.company) company and I wear $(self.shoes.colour) shoes\")\nend\n\nprintMyActivity(Marc) # Hi! I am Marc, ...\nprintMyActivity(MrBrown) # Good day. My name is MrBrown, ...\n\n# OO models based on Specialisation (Person → Student) or Weack Relation (Person → Shoes) instead of Composition (Person → Arm) can be implemented using third party packages, like e.g. [SimpleTraits.jl](https://github.com/mauro3/SimpleTraits.jl) or [OOPMacro.jl](https://github.com/ipod825/OOPMacro.jl)\n", "meta": {"hexsha": "747b1b34f5c65b272b430a69702a7e19bf8bc3ab", "size": 7968, "ext": "jl", "lang": "Julia", "max_stars_repo_path": "lessonsSources/01_-_JULIA1_-_Basic_Julia_programming/0105_-_Custom_types.jl", "max_stars_repo_name": "sylvaticus/IntroSPMLJuliaCourse", "max_stars_repo_head_hexsha": "84ba4432548dcfe826353c03616c03e86f46e9eb", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-26T15:44:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T13:05:52.000Z", "max_issues_repo_path": "lessonsSources/01_-_JULIA1_-_Basic_Julia_programming/0105_-_Custom_types.jl", "max_issues_repo_name": "sylvaticus/IntroSPMLJuliaCourse", "max_issues_repo_head_hexsha": "84ba4432548dcfe826353c03616c03e86f46e9eb", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lessonsSources/01_-_JULIA1_-_Basic_Julia_programming/0105_-_Custom_types.jl", "max_forks_repo_name": "sylvaticus/IntroSPMLJuliaCourse", "max_forks_repo_head_hexsha": "84ba4432548dcfe826353c03616c03e86f46e9eb", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-26T08:06:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T08:06:40.000Z", "avg_line_length": 34.4935064935, "max_line_length": 377, "alphanum_fraction": 0.6848644578, "num_tokens": 2066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.33807711081162, "lm_q2_score": 0.2720245510940225, "lm_q1q2_score": 0.09196527430369504}} {"text": "## Exercise 6-6\n## A palindrome is a word that is spelled the same backward and forward, like “noon” and “redivider”. Recursively, a word is a palindrome if the first and last letters are the same and the middle is a palindrome.\n\n## The following are functions that take a string argument and return the first, last, and middle letters:\n\nfunction first(word)\n first = firstindex(word)\n word[first]\nend\n\nfunction last(word)\n last = lastindex(word)\n word[last]\nend\n\nfunction middle(word)\n first = firstindex(word)\n last = lastindex(word)\n word[nextind(word, first) : prevind(word, last)]\nend\n\n## We’ll see how they work in Strings\n\n## 1. Test these functions out. What happens if you call middle with a string with two letters? One letter? What about the empty string, which is written \"\" and contains no letters?\nprintln(\"Ans 1: \")\n\nprintln(first(\"first\")) # returns 'f'\nprintln(last(\"last\")) # returns 't'\nprintln(middle(\"middle\")) # returns \"iddl\"\n\nprintln(middle(\"as\")) # returns ''\nprintln(middle(\"A\")) # returns ''\n# println(middle(\"\")) # error, empty string\n\n## 2. Write a function called ispalindrome that takes a string argument and returns true if it is a palindrome and false otherwise. Remember that you can use the built-in function length to check the length of a string.\nprintln(\"Ans 2: \")\n\nfunction ispalindrome(word)\n if length(word) == 0\n return true\n end\n\n if first(word) == last(word)\n return ispalindrome(middle(word))\n else\n return false\n end\nend\n\nprintln(ispalindrome(\"noon\"))\nprintln(ispalindrome(\"redivider\"))\nprintln(ispalindrome(\"name\"))\n\nprintln(\"End.\")\n", "meta": {"hexsha": "b72d4e22099b0f281db1187a6c0a552962e5daa5", "size": 1637, "ext": "jl", "lang": "Julia", "max_stars_repo_path": "Chapter6/ex6.jl", "max_stars_repo_name": "yashppawar/ThinkJuliaExercises.jl", "max_stars_repo_head_hexsha": "72145b969dc51ebcac413a10004175ebc63cd5c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-13T14:11:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T14:11:30.000Z", "max_issues_repo_path": "Chapter6/ex6.jl", "max_issues_repo_name": "yashppawar/ThinkJuliaExercises.jl", "max_issues_repo_head_hexsha": "72145b969dc51ebcac413a10004175ebc63cd5c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter6/ex6.jl", "max_forks_repo_name": "yashppawar/ThinkJuliaExercises.jl", "max_forks_repo_head_hexsha": "72145b969dc51ebcac413a10004175ebc63cd5c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7636363636, "max_line_length": 219, "alphanum_fraction": 0.7067806964, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.46101677931231594, "lm_q2_score": 0.19930800503802076, "lm_q1q2_score": 0.09188433457379117}} {"text": "### A Pluto.jl notebook ###\n# v0.18.4\n\nusing Markdown\nusing InteractiveUtils\n\n# ╔═╡ 49a44e94-29c0-4004-8d0b-e37008eafc1c\nusing BenchmarkTools, PlutoUI, Wordlegames\n\n# ╔═╡ f9816eb0-078e-41f2-bf7c-29ed5c663fd0\n# hideall\ntitle = \"Scoring guesses in Wordle\";\n\n# ╔═╡ a9678ae8-48c0-4bb9-920d-7de176105bd0\n\"\"\"\n+++\ntitle = \"$title\"\n+++\n\"\"\" |> Base.Text\n\n# ╔═╡ 4eabf46e-f75c-4b15-8583-6abe17c0fd85\nmd\"\"\"\n# $title\n\n[Wordle](https://en.wikipedia.org/wiki/Wordle) is a recently developed, extremely popular word game that has already spawned many imitators such as [Primel](https://converged.yt/primel/).\n\nThese tutorials illustrate some [Julia](https://julialang.org) programming concepts using functions in the [Wordlegames](https://github.com/dmbates/Wordlegames.jl) package for illustration.\nPart of the purpose is to illustrate the unique nature of Julia as a dynamically-typed language with a just-in-time (JIT) compiler.\nIt allows you to write \"generic\", both in the common meaning of \"general purpose\" and in the technical meaning of generic functions, and performative code.\n\nThis posting originated from a conversation on the Julia [discourse channel](https://discourse.julialang.org/t/rust-julia-comparison-post/75403) referring to a case where Julia code to perform a certain Wordle-related task - determine the \"best\" initial guess in a Wordle game - was horribly slow.\nJulia code described in a [Hacker News](https://news.ycombinator.com/) posting took several hours to do this.\n\nIn situations like this the Julia community inevitably responds with suggested modifications to make the code run faster.\nSomeone joked that we wouldn't be satisfied until we could do that task in less than 1 second, and we did.\n\nThe code in these postings can be used to solve a Wordle game very rapidly, as well as related games like Primel.\n\nBefore beginning we attach some packages that will be used in this notebook.\n\"\"\"\n\n# ╔═╡ 03b41118-5756-447b-9900-15af37667529\nmd\"\"\"\n## Target pools\n\nIf you are not familiar with the rules of Wordle, please check the [Wikipedia page](https://en.wikipedia.org/wiki/Wordle).\nIt is a word game with the objective of guessing a 5-letter English word, which we will call the \"target\".\nThe target word is changed every day but it is always chosen from a set of 2315 words, which we will call the \"target pool\".\n\nThe original target pool is available with the `Wordlegames` package. (Apparently the New York Times removed a few of these words after they purchased the rights to Wordle.)\n\"\"\"\n\n# ╔═╡ 73e3e38b-0935-4ef9-97b1-8a8cdfa2feb7\ndatadir = joinpath(pkgdir(Wordlegames), \"data\");\n\n# ╔═╡ 4c5e781c-fd10-425f-95d2-1fec5bf1015f\nwordlestrings = collect(readlines(joinpath(datadir, \"Wordletargets.txt\")))\n\n# ╔═╡ 2046a4ca-c4d3-4804-9373-930d9cbb58fd\nmd\"We call this pool `wordlestrings` because it is stored as a vector of `String`s\"\n\n# ╔═╡ 560ad4d4-945c-4d21-8947-cac68c1880a1\ntypeof(wordlestrings)\n\n# ╔═╡ ddd7f90c-7cad-4279-a275-b1800b4ae83b\nmd\"\"\"\nThe `Wordlegames` package defines a `GamePool` struct for playing Wordle or related games.\nIn that `struct` the `String`s are converted to a more efficient storage mode as a vector of `NTuple{5,Char}`, which takes advantage of the fact that each string is exactly 5 characters long.\n\nSpeaking of which, it would be a good idea to check that this collection has the properties we were told it had.\nIt should be a vector of 2315 strings, each of which is 5 characters.\n\"\"\"\n\n# ╔═╡ 49500976-7ab8-43cc-9902-b25ad73ff42e\nlength(wordlestrings)\n\n# ╔═╡ f6681018-f729-48de-9342-a5bcb151aca2\nall(w -> length(w) == 5, wordlestrings)\n\n# ╔═╡ 22f7e1ad-3a2b-4a88-8f81-91feada88621\nmd\"\"\"\nThat last expression may look, well, \"interesting\".\nIt is a way of checking that a function, in this case an anonymous function expressed using the [stabby lambda](https://dev.to/keithrbennett/why-i-prefer-stabby-lambda-notation-5gcj) notation, returns `true` for each element of an iterator, in this case the vector `wordlestrings`.\nYou can read the whole expression as \"is `length(w)` equal to `5` for each word `w` in `wordlestrings`\".\n\nThese words are supposed to be exactly 5 letters long but it never hurts to check.\nI've been a data scientist for several decades and one of the first lessons in the field is to [trust, but verify](https://en.wikipedia.org/wiki/Trust%2C_but_verify) any claims about the data you are provided.\n\nIt turns out this check is redundant because the property is checked when creating a `GamePool`.\n\"\"\"\n\n# ╔═╡ 5787eef2-7a2c-46ad-8fa0-7313c07be84b\nwordle = GamePool(wordlestrings);\n\n# ╔═╡ 8df0e0c0-cdae-450c-abc1-5cea1d520ec9\npropertynames(wordle)\n\n# ╔═╡ 8580bdcf-24ce-4eb6-ac5a-4c77b729b38b\ntypeof(wordle.guesspool)\n\n# ╔═╡ 9ed9e8ab-3ebc-4c6e-b2c3-46ad1987561e\nfirst(wordle.guesspool, 3)\n\n# ╔═╡ fdd6631e-8b3a-4b4f-b8a7-11135f13cc23\nmd\"\"\"\n## Game play\n\nA Wordle game is a dialog between the player and an \"oracle\", which, for the official game, is the web site.\nThe player submits a question to the oracle and the oracle responds, using information to which the player does not have access.\nIn this case the information is the target word.\nThe question is the player's guess - a 5-letter word - and the response is a score for that word.\nThe score indicates, for each character, whether it matches the character in the same position in the target or it is in the target in another position or it is not in the target at all.\n\nUsing the sample game for Wordle #196 from the Wikipedia page for illustration\n\"\"\"\n\n# ╔═╡ 9b911b3c-17d5-42d5-b7e5-a4187ce5787c\nPlutoUI.Resource(\n \"https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Wordle_196_example.svg/440px-Wordle_196_example.svg.png\",\n)\n\n# ╔═╡ 4d5681f9-56a5-4f83-9b31-810bdef26d98\nmd\"\"\"\nThe target is \"rebus\".\n\nThe player's first guess is \"arise\" and the response, or score, from the oracle is coded as 🟫🟨🟫🟨🟨 where 🟫 indicates that the letter is not in the target (neither `a` nor `i` occur in \"rebus\") and 🟨 indicates that the letter is in the target but not at that position.\n(I'm using 🟫 instead of a gray square because I can't find a gray square Unicode character.)\n\nThe second guess is \"route\" for which the response is 🟩🟫🟨🟫🟨 indicating that the first letter in the guess occurs as the first letter in the target.\nNotice that this guess does not include an \"s\", which is known from the score of the first guess to be one of the characters in the target.\nThis guess would not be allowed if playing the game under the \"Hard Mode\" setting.\n\nOf course, the colors are just one way of summarizing the response to a guess.\nWithin a computer program it is easier to use an integer to represent each of the 243 = 3⁵ possible scores.\nAn obvious way of mapping the result to an integer in the (decimal) range 0:242 is by mapping the response for each character to 2 (in target at that position), 1 (in target not at that position), or 0 (not in target) and regarding the pattern as a base-3 number.\n\nIn this coding the response for the first guess, \"arise\", is 01011 in base-3 or 31 in decimal.\nThe response for the second guess, \"route\", is 20101 in base-3 or 172 in decimal.\n\nA function to evaluate this score can be written as\n\"\"\"\n\n# ╔═╡ db787d98-d2a4-4d4a-8e13-8b61e80e48dd\nfunction score(guess, target)\n s = 0\n for (g, t) in zip(guess, target)\n s *= 3\n s += (g == t) ? 2 : Int(g ∈ target)\n end\n return s\nend\n\n# ╔═╡ e9e23c37-e4d8-4b77-ab6f-264bcba4ebec\nmd\"\"\"\nThese numeric scores are not on a scale where \"smaller is better\" or \"larger is better\".\n(It happens that the best score is 242, corresponding to a perfect match, or five green tiles, but that's incidental.)\n\nThe score is just a way of representing each of the 243 patterns that can be produced.\n\nWe can convert back to colored tiles if desired using the `tiles` function from the `Wordlegames` package, defined as \n```julia\nfunction tiles(sc, ntiles)\n result = Char[] # initialize to an empty array of Char\n for _ in 1:ntiles # _ indicates the value of the iterator is not used\n sc, r = divrem(sc, 3)\n push!(result, iszero(r) ? '🟫' : (isone(r) ? '🟨' : '🟩'))\n end\n return String(reverse(result))\nend\n```\n\"\"\"\n\n# ╔═╡ b0970feb-103d-4560-b577-f611171e8da6\ntiles(31, 5)\n\n# ╔═╡ 39ae1224-9cdf-4d4b-b543-985a5667a601\nmd\"\"\"\n## Examining the score function\n\nIn the Sherlock Holmes story [The Adventure of Silver Blaze](thttps://en.wikipedia.org/wiki/The_Adventure_of_Silver_Blaze) there is a famous exchange where Holmes remarks on \"the curious incident of the dog in the night-time\" (see the link).\nThe critical clue in the case is not what happened but what didn't happen - the dog didn't bark.\n\nJust as Holmes found it interesting that the dog didn't bark, we should find some of the functions in this notebook interesting for what they don't include.\nIn many of the functions shown here the arguments aren't given explicit types.\n\nKnowing the concrete types of arguments is very important when compiling functions, as is done in Julia, but these functions are written without explicit types.\n\nConsider the `score` function which we reproduce here\n\n```julia\nfunction score(guess, target)\n s = 0\n for (g, t) in zip(guess, target)\n s *= 3\n s += (g == t) ? 2 : Int(g ∈ target)\n end\n return s\nend\n```\n\nThe arguments to `score` can be any type.\nIn fact, formally they are of an abstract type called `Any`.\n\nSo how do we make sure that the actual arguments make sense for this function?\nWell, the first thing that is done with the arguments is to pass them to `zip(guess, target)` to produce pairs of values, `g` and `t`, that can be compared for equality, `g == t`.\nIn a sense `score` delegates the task of checking that the arguments are sensible to the `zip` function.\n\nFor those unfamiliar with zipping two or more iterators, we can check what the result is.\n\"\"\"\n\n# ╔═╡ 8a1cc31b-f747-49b4-9860-a2c381d98c44\ncollect(zip(\"arise\", \"rebus\"))\n\n# ╔═╡ 6830dbd6-edc9-4193-8d73-becf3be3855a\nmd\"\"\"\nOne of the great advantages of dynamically-typed languages with a REPL (read-eval-print-loop) like Julia is that we can easily check what `zip` produces in a couple of examples (or even read the documentation returned by `?zip`, if we are desperate).\n\nThe rest of the function is a common pattern - initialize `s`, which will be the result, modify `s` in a loop, and return it.\nThe Julia expression\n```julia\ns *= 3\n```\nindicates, as in several other languages, that `s` is to be multiplied by 3 in-place.\n\nAn expression like\n```julia\n(g == t) ? 2 : Int(g ∈ target)\n```\nis a *ternary operator* expression (the name comes from the operator taking three operands).\nIt evaluates the condition, `g == t`, and returns `2` if the condition is `true`.\nIf `g == t` is `false` the operator returns the value of the Boolean expression `g ∈ target`, converted to an `Int`.\n(The expression could also be written `g in target`.\nIn the Julia REPL the `∈` character is created by typing `\\in\n\t
\n
| Value | \n\t\n\t\n\t\t|
|---|---|
| CO2 forcing parameter, a [W m⁻²] | \n\t\t$(a_slider) | \n\t\tFeedback parameter, λ [W m⁻² K⁻¹] | \n\t\t$(λ_slider) | \n\t\t\n\n\t\t
| Heat uptake rate, κ [W m⁻² K⁻¹] | \n\t\t$(κ_slider) | \n\t\t
| Deep ocean heat capacity, C₀ [W yr m⁻² K⁻¹] | \n\t\t$(Cd_slider) | \n\t\t