# UndefVarError: Order not defined Stacktrace: \[1\] top-level scope @ In\[22\]:23

**URL:** <https://discourse.julialang.org/t/undefvarerror-order-not-defined-stacktrace-1-top-level-scope-in-22-23/97538>\
**Category:** New to Julia\
**Created:** [April 16, 2023, 9:36am UTC](https://discourse.julialang.org/t/undefvarerror-order-not-defined-stacktrace-1-top-level-scope-in-22-23/97538 "2023-04-16T09:36:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vahagn](https://avatars.discourse-cdn.com/v4/letter/v/cc9497/32.png) [@Vahagn](https://discourse.julialang.org/u/Vahagn)\
**Post date:** [April 16, 2023, 9:36am UTC](https://discourse.julialang.org/t/undefvarerror-order-not-defined-stacktrace-1-top-level-scope-in-22-23/97538/1 "2023-04-16T09:36:00Z")

</div>

Hi everyone,  
I am new in using Julia and I want to replicate my neural network code that I have written in Matlab in Julia, so I ask ChatGPT to write a simple code, but when I run it in Julia it returns me an error, can anyone, please, help me to figure out how to solve the problem, below is the code and an error message.

> using Flux, Optim, LineSearches
> 
> # Define the input data and the target outputs
> 
> x = [0.1, 0.2, 0.3, 0.4]  
> y = [0.2, 0.4, 0.6, 0.8]
> 
> # Define the number of hidden neurons
> 
> num\_hidden = 5
> 
> # Define the neural network architecture
> 
> model = Chain(Dense(length(x), num\_hidden, relu), Dense(num\_hidden, 1))
> 
> # Define the loss function
> 
> loss(x, y) = Flux.mse(model(x), y)
> 
> # Define the initial parameter values
> 
> init\_params = Flux.params(model)
> 
> # Load the LineSearches package
> 
> using LineSearches
> 
> # Define the optimizer and set the options for the Levenberg-Marquardt algorithm
> 
> optimizer = LBFGS(linesearch = BackTracking(Order(3)), # set the line search  
> x\_tol=1e-12, # set the tolerance for the solution  
> g\_tol=1e-8, # set the tolerance for the gradient  
> iterations = 10000, # set the maximum number of iterations  
> alphaguess = 1.0, # set the initial step size  
> store\_trace = true) # store the history of optimization
> 
> # Train the neural network using the Levenberg-Marquardt algorithm
> 
> Flux.train!(loss, init\_params, [(x, y)], optimizer, cb = () → println("Training loss: ", loss(x, y)))

UndefVarError: Order not defined

Stacktrace:  
[1] top-level scope  
@ In[22]:23

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [April 19, 2023, 7:10pm UTC](https://discourse.julialang.org/t/undefvarerror-order-not-defined-stacktrace-1-top-level-scope-in-22-23/97538/2 "2023-04-19T19:10:53Z")

</div>

ChatGPT often produces broken code. The documentation for these packages is pretty good. I recommend using it. Here’s a code snippet from the readme [GitHub - FluxML/Flux.jl: Relax! Flux is the ML library that doesn't make you tensor](https://github.com/FluxML/Flux.jl)

```julia
using Flux, Plots
data = [([x], 2x-x^3) for x in -2:0.1f0:2]

model = Chain(Dense(1 => 23, tanh), Dense(23 => 1, bias=false), only)

optim = Flux.setup(Adam(), model)
for epoch in 1:1000
  Flux.train!((m,x,y) -> (m(x) - y)^2, model, data, optim)
end

plot(x -> 2x-x^3, -2, 2, legend=false)
scatter!(x -> model([x]), -2:0.1f0:2)

```

There’s much more available at [Quick Start · Flux](http://fluxml.ai/Flux.jl/stable/models/quickstart).
