parabolic_squaremesh not defined in DifferentialEquations - julia

I'm trying to reproduce an example from a tutorial and I get stuck with meshes not being defined:
using DiffEqBase
using DiffEqPDEBase
f(t,x,u) = ones(size(x,1)) - .5u
u0_func(x) = zeros(size(x,1))
tspan = (0.0,1.0)
dx = 1//2^(3)
dt = 1//2^(7)
# THE FOLLOWING LINE IS FAILING
mesh = parabolic_squaremesh([0 1 0 1],dx,dt,tspan,:neumann)
u0 = u0_func(mesh.node)
prob = HeatProblem(u0,f,mesh)
sol = solve(prob,FEMDiffEqHeatImplicitEuler())
The code fails at the line where I try to create the mesh with the error message:
*UndefVarError: parabolic_squaremesh not defined
top-level scope at test.jl:22
All packages are installed without errors. However, I was not able to install the
using FiniteElementDiffEq which seems to be depreciated.

This functionality has not existed in many years. It was found because of a Google search turning up DifferentialEquations.jl v3.0, while v6.0 is the first version to support Julia 1.0. There's not much else to say about this other than you won't make it work on a modern version of Julia, and if you want to use it you'd have to drop back to something like Julia v0.6.

Related

ProgressBar in IJulia printing every new line

I am currently learning Julia and have been practicing in the Jupyter notebook environment. However, the ProgressBar package (similar to TQDM in python) is updated every new line instead of updating on the same line (picture attached). Is there any way to fix this? Thanks.
UPDATE : Here is the full function that I wrote.
function spike_rate(raw_dat, width)
N = size(raw_dat)[1]
domain = collect(1:N);
spike_rat = zeros(N);
for i in ProgressBar(1:N)
dx = i .- domain;
window = gaussian.(dx, width);
spike_rat[i] = sum(window .* raw_dat) ./ width;
end
return spike_rat;
end
This seems to be a known issue with ProgressBars.jl, unfortunately. It's not clear what changed to make these progress bars not work properly anymore, but the maintainer's comment says that tqdm uses "a custom ipywidget" to make this work for the Python library, and that hasn't been implemented for the Julia package yet.
To expand on #Zitzero's mention of ] up, that calls Pkg.update() which also prints a progress bar - so the suggestion is to use the mechanism Pkg uses for it. Pkg has an internal module called MiniProgressBars which handles this output.
Edit: Tim Holy's ProgressMeter package seems well-maintained, and is a much better option than relying on an internal non-exported Pkg submodule with no docs. So I'd recommend ProgressMeter over the below.
The Readme mentions a caveat regarding printing additional information with the progress bar when in Jupyter, which likely applies to MiniProgressBar as well. So, using ProgressMeter, and separating the progress output vs other relevant output to different cells, seems like the best option.
(not recommended)
using Pkg.MiniProgressBars
bar = MiniProgressBar(; indent=2, header = "Progress", color = Base.info_color(),
percentage=false, always_reprint=true)
bar.max = 100
# start_progress(stdout, bar)
for i in 1:100
sleep(0.05) # replace this with your code
# print_progress_bottom(stdout)
bar.current = i
show_progress(stdout, bar)
end
# end_progress(stdout, bar)
This is based on how Pkg uses it, from this file. The commented out lines (with start_progress, print_progress_bottom, and end_progress) are in the original usage in Pkg, but it's not clear what they do and here they just seem to mess up the output - maybe I'm using them wrongly, or maybe Jupyter notebooks only support a subset of the ANSI codes that MiniProgressBars uses.
There is a way, the package module does that as far as I know when you do:
] up
Could you share a little of your code?
For example, where you define what is written to the console.
One guess is that
print("text and progressbar")
instead of
println("text and progressbar")
could help, because println() always creates a new line, while print() should just overwrite you current line.

Julia VegaLite.jl - How to disable the warninigs?

When using the VegaLite.jl library for Julia, it is common to get several warnings when the visualization is not fully specified. For example, if I run the following code:
using VegaLite
α = rand(10,2)
β = rand(10,2)
v1 = #vlplot(:circle,x=α[:,1],y=α[:,2])
v2 = #vlplot(mark={"type"=:circle,color="red"},x=β[:,1],y=β[:,2])
#vlplot()+v1+v2
This will plot things correctly, but I get several warnings saying "QARN Missing type for channel "x", using "quantitative" instead".
Is there a way to disable this warnings? I mean, is there a way to suppress them? Note that I'm using Jupyter Notebook.
You can use Suppressor.jl to suppress all warnings.
Your code would like like this:
using Suppressor
#suppress begin
v1 = #vlplot(:circle,x=α[:,1],y=α[:,2])
v2 = #vlplot(mark={"type"=:circle,color="red"},x=β[:,1],y=β[:,2])
#vlplot()+v1+v2
end
See other usage examples here: https://github.com/JuliaIO/Suppressor.jl#usage

MXNet Time-series Example - Dropout Error when running locally

I am looking into using MXNet LSTM modelling for time-series analysis for a problem i am currently working on.
As a way of understanding how to implement this, I am following the example code given by xnNet from the link: https://mxnet.incubator.apache.org/tutorials/r/MultidimLstm.html
When running this script after downloading the necessary data to my local source, i am able to execute the code fine until i get to the following section to train the model:
## train the network
system.time(model <- mx.model.buckets(symbol = symbol,
train.data = train.data,
eval.data = eval.data,
num.round = 100,
ctx = ctx,
verbose = TRUE,
metric = mx.metric.mse.seq,
initializer = initializer,
optimizer = optimizer,
batch.end.callback = NULL,
epoch.end.callback = epoch.end.callback))
When running this section, the following error occurs once gaining connection to the API.
Error in mx.nd.internal.as.array(nd) :
[14:22:53] c:\jenkins\workspace\mxnet\mxnet\src\operator\./rnn-inl.h:359:
Check failed: param_.p == 0 (0.2 vs. 0) Dropout is not supported at the moment.
Is there currently a problem internally within the XNNet R package which is unable to run this code? I can't imagine they would provide a tutorial example for the package that is not executable.
My other thought is that it is something to do with my local device execution and connection to the API. I haven't been able to find any information about this being a problem for other users though.
Any inputs or suggestions would be greatly appreciated thanks.
Looks like you're running an old version of R package. I think following instructions on this page to build a recent R-package should resolve this issue.

How do I resolve LoadError while trying to make a png on Windows using Julia Studio and Gadfly?

I'm currently working through this tutorial and I'm having trouble getting the png image to display. This is my program.
using DataFrames
using Gadfly
train_df = readtable("winequality-red.csv", separator=';')
_, count = hist(train_df["quality"])
class = sort(unique(train_df["quality"]))
value_counts = DataFrame(count=count, class=class)
#value_counts
p = plot(value_counts, x="class", y="count", Geom.bar(), Guide.title("Class distributions (\"quality\")"))
draw(PNG(14cm, 10cm), p)
the error I get is
LoadError("C:/Users/John/Desktop/helloworld.jl",12,MethodError(PNG,(140.0mm,100.0mm)))
I've tried some of the things mentioned in this discussion, however I haven't made any observable progress.
I was able to solve my problem by installing Cairo.
Pkg.add("Cairo")
and changing this line
draw(PNG(14cm, 10cm), p)
to
draw(PNG("chart.png", 14cm, 10cm), p)
and then opening chart.png with Julia Studio

Editing Fortran referenced code from R

I would like to be able to edit the Fortran code that is referred to in the fGarch package.
More specifically I would like to edit the available conditional distributions that can be used by fGarch::garchFit, i.e. including the stable distribution and the generalised hyperbolic distribution.
So having looked into the garchFit() function, I have delved (deepish) into the code, and .aparchLLH.internal() is referred to from the garchFit() function and there is a line in there that refers to Fortran written code.
The specific line that I am referring to is the following bit of code:
fit <- .Fortran("garchllh", N = as.integer(N), Y = as.double(.series$x),
Z = as.double(.series$z), H = as.double(.series$h),
NF = as.integer(NF), X = as.double(params), DPARM = as.double(DPARM),
MDIST = as.integer(MDIST), MYPAR = as.integer(MYPAR),
F = as.double(0), PACKAGE = "fGarch")
I believe that the Fortran function garchllh is what I would like to edit, but do not know how to go about editing it so that I can introduce new distributions into the garchFit() function.
N.B. Just as a note, I do not have much experience in Fortran code, but would like to have a look at it to see if it can be edited and altered to fit for my purpose, so any help on the Fortran editing of code section would be much appreciated...
As mentioned in comments, you need to download the source -- a good place would be to start with install.packages("fGarch",type="source") and see that everything compiles properly. Then, look at the package source -- seems like you would need to do a pretty straightforward adjustment to dist.f, and probably add more changes to various places where MDIST is set -- start with grep MDIST *.R in the R directory of the extracted source. After you're done and tested, you could also talk to the package maintainers -- perhaps they would include your additions in the next version :)

Resources