Random generation of problems
RAFF.jl
contains several methods for the generation of artificial datasets, in order to simulate noisy data with outliers. See the API for details about the possibilities of random generation of data with outliers.
Simple example - the exponential function
First, it is necessary to load RAFF.jl
and the desired model to generate the problem.
julia> using RAFF
julia> n, model, = RAFF.model_list["expon"]
(3, RAFF.var"#7#13"(), "(x, θ) -> θ[1] + θ[2] * exp(- θ[3] * x[1])")
If an exact solution is not provided, RAFF.jl
will generate a random one, but this can destroy the shape of some models. Therefore, in this example, we will provide a hint for a nice exponential model. In this example, we will generate 20 random points with 2 outliers in the interval $[1, 30]$.
julia> exact_sol = [5000.0, 4000.0, 0.2]
3-element Array{Float64,1}:
5000.0
4000.0
0.2
julia> interv = (1.0, 30.0)
(1.0, 30.0)
julia> np = 20
20
julia> p = 18
18
Before calling the generating function, we fix the random seed, so this example is the same everywhere.
julia> using Random
julia> Random.seed!(12345678)
Random.MersenneTwister(UInt32[0x00bc614e], Random.DSFMT.DSFMT_state(Int32[485623157, 1073372256, 2105707176, 1072895099, -358862088, 1072969518, -2079238882, 1072755656, 281589009, 1073732136 … 1282907862, 1073649830, 1572678779, 1073436642, 124694191, -1919844179, -1265579980, 1299186829, 382, 0]), [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], UInt128[0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000 … 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000, 0x00000000000000000000000000000000], 1002, 0)
julia> data, = generate_noisy_data(model, n, np, p, x_interval=interv, θSol=exact_sol)
([1.0 8276.299953579275 0.0; 2.526315789473684 7187.6727483012755 0.0; … ; 28.473684210526315 4944.132821435767 0.0; 30.0 5322.831585720618 0.0], [5000.0, 4000.0, 0.2], [7, 3])
Now we use the script test/script/draw.jl
(see Advanced section) to visualize the data generated. draw.jl
uses the PyPlot.jl
package, so it is necessary to install it before running this example.
julia> include("test/scripts/draw.jl")
julia> draw_problem(data, model_str="expon")
If you are interested in running RAFF
, just call the raff
method. Attention: we have to drop the last column of data
, since it contains information regarding the noise added to the outliers.
julia> r = raff(model, data[:, 1:end - 1], n, MAXMS=10)
** RAFFOutput **
Status (.status) = 1
Solution (.solution) = [5114.187397346694, 3825.3568115955695, 0.21401697533774086]
Number of iterations (.iter) = 501
Number of trust points (.p) = 13
Objective function value (.f) = 181698.80745279836
Number of function evaluations (.nf) = 501
Number of Jacobian evaluations (.nj) = 284
Index of outliers (.outliers) = [3, 4, 6, 7, 9, 13, 15]
If all the steps were successful, after command
julia> draw_problem(data, model_str="expon", raff_output=r)
the following picture should appear