I am using ROCR library and the prediction function for creating ROC curves. I am doing like this (copied from Stack Overflow)
p_Lr <- predict(Model_Lr,newdata=Tst,type="response")
pr_Lr <- prediction(p_Lr, Tst$Survived)
prf_Lr <- performance(pr_Lr, measure = "tpr", x.measure = "fpr")
This works - in the beginning. Suddenly after programming and running various code (I am unfortunately not able to say precisely which code) the line
pr_Lr <- prediction(p_Lr, Tst$Survived)
doesn't work any more and gives following error msg:
Error in nn$covariate : $ operator is invalid for atomic vectors using rocr library prediction
Then if I detach and add the ROCR library like this
detach(package:ROCR)
library(ROCR)
it works again! Anybody have any idea why and what to do?
Using the sos findFn function, it appears that two other packages have a function called prediction: bootPLS and frailtypack. Loading any of these packages after ROCR would mask ROCR's prediction function and prevent performance from working.
By re-attaching ROCR you put its prediction function back in front of the search path.
An alternative solution would be to use ROCR's prediction function explicitly:
p_Lr <- predict(Model_Lr,newdata=Tst,type="response")
pr_Lr <- ROCR::prediction(p_Lr, Tst$Survived)
prf_Lr <- ROCR::performance(pr_Lr, measure = "tpr", x.measure = "fpr")
Related
I am trying to do a logistic regression with robust clustered error using miceadds::glm.cluster:
model1 <- miceadds::glm.cluster(data=df_clean3, formula=recall ~ log(Population)+NoComplaintsReported+NoCrashesFiresReported+NoInjuriesReported+NoFatalityIncidentsReported+NoOtherFailuresReported+YearOpen+label, cluster="label", family="binomial")
I want to report a ready-to-publish regression table in Microsoft Word. I have tried the below methods, but each are not the "professionally prepared" version that I am looking for.
Can someone help me with this?
1-tab_df (from the sjPlot library): It stops with the error message that:
Error in UseMethod("family") :
no applicable method for 'family' applied to an object of class "NULL"
2- Stargazer: the output table does not look neat.
3- summ (from jtools library): the output table does not look neat.
4- apa.reg.table (from apaTables library): it stops with this error message:
Error in 2:last_model_number_predictors : argument of length 0
I am able to create and optimize neuralODEs in julia(1.3 and 1.2) using Flux.jl and DiffEqFlux.jl but it fails under a crucial important general case.
what works:
I can train the Neural net parameters if it is built out of the
provided Flux.jl layers like Dense().
I can include an arbitrary function as a layer in the network chain, e.g. x -> x.*x
What fails:
However if the arbitrary function has parameters I want to train then Flux. Train will not adjust these parameters causing it to fail.
I have tried making these added parameters Tracked and included in the list of parameters given to the training system but it ignores them and they remain unvaried.
The documentation says very cryptically that one can use Flux.#functor on a layer to make sure it's parameters get tracked. However functor was not included in Flux till version 0.10.0 and the only version of Flux compatible with NeuralODEs in DiffEqFlux is 0.9.0
So here's an toy example of a 2 layer neural net I want to use
p = param([1.0])
dudt = chain( x -> p[1]*x.*x, Dense(2,2) )
ps = Flux.params(dudt)
then I use the flux train on this. when I do this the parameter p is not varied, but the parameters in the Dense layer are.
I have tried explicitly including like this
ps = Flux.Params([p,dudt])
but that has the same result and the same problem
I think what I need to do is build a struct with an associted function that implements the
x->p[1]*x*x
then call #functor on this. That struct can then be used in the chain.
But as I noted the version of Flux with #functor is not compatible with DiffEqFlux of any version.
So I need a way to make flux pay attention to my custom parameters, not just the ones in Dense()
How???
I think I get what your question is, but please clarify if I am answering the wrong question here. The issue is that the p is only grabbing from a global reference and thus not differentiated during adjoints. A much better way to handle this in 2020 is to use FastChain. The FastChan interface lets you define layer functions and their parameter dependencies, so this is a nice way to make your neural network incorporate arbitrary functions with parameters. Here's what that looks like:
using DifferentialEquations
using Flux, Zygote
using DiffEqFlux
x = Float32[2.; 0.]
p = Float32[2.0]
tspan = (0.0f0,1.0f0)
mylayer(x,p) = p[1]*x
DiffEqFlux.paramlength(::typeof(mylayer)) = 1
DiffEqFlux.initial_params(::typeof(mylayer)) = rand(Float32,1)
dudt = FastChain(FastDense(2,50,tanh),FastDense(50,2),mylayer)
p = DiffEqFlux.initial_params(dudt)
function f(u,p,t)
dudt(u,p)
end
ex_neural_ode(x,p) = solve(ODEProblem(f,x,tspan,p),Tsit5())
solve(ODEProblem(f,x,tspan,p),Tsit5())
du0,dp = Zygote.gradient((x,p)->sum(ex_neural_ode(x,p)),x,p)
where the last value of p is the one parameter for p in mylayer. Or you can directly use Flux:
using DifferentialEquations
using Flux, Zygote
using DiffEqFlux
x = Float32[2.; 0.]
p2 = Float32[2.0]
tspan = (0.0f0,1.0f0)
dudt = Chain(Dense(2,50,tanh),Dense(50,2))
p,re = Flux.destructure(dudt)
function f(u,p,t)
re(p[1:end-1])(u) |> x-> p[end]*x
end
ex_neural_ode() = solve(ODEProblem(f,x,tspan,[p;p2]),Tsit5())
grads = Zygote.gradient(()->sum(ex_neural_ode()),Flux.params(x,p,p2))
grads[x]
grads[p]
grads[p2]
I try to convert these matlab scripts to octave. However in getGroundTruthBoxes.m, it has following code:
freq = cell2mat(accumarray(inst(inst>0), segm(inst>0), [], #(x){linIt(histc(x,1:numClass))'}, {zeros(1,numClass)}$
When i try to run with octave, it gives " linIt undefined" error. I googled "linIt" functions , but i can not reach any information about linIt. Can you give information about this "linIt" function?
Thanks.
The user s-gupta whose repository you're using seems to have another repository called utils, where he defines this function https://github.com/s-gupta/utils/blob/master/matlab/linIt.m
Essentially it seems to be a tiny helper function that converts an array to its linearly indexed column-vector, i.e.
function a = linIt(A)
a = A(:);
end
I'm porting matlab code to python and come across the code below. Looks like it creates a matrix but I'm not sure what the shape of the matrix would be. Can anybody help me understand what this code mean especially '...' and '].^2'?
somevarialbe = [var1...
var2...
var3].^2;
It is the item-wise operator and power each item to 2. In the other words, it is equivalent to the following code:
somevarialbe = [var1^2...
var2^2...
var3^2];
And ... means next line in the code. Hence, it is equivalent to the following code:
somevarialbe = [var1^2 var2^2 var3^2];
I wrote a set of nested for loops to conduct a parameter sweep in a third party software (Lumerical, it's an FDTD package) in Matlab. This code works perfectly well, but I can't seem to get the parallel version to work. My guess is that Matlab is having issues assigning workers in the parallel case, but I'm having issues resolving this. I've copied my code for the loop below and the line in the function I use to execute each Lumerical simulation. Does anyone have any suggestions for how to resolve this?
parfor ph = 1:PH
for p = 1:P
for bi = 1:BI
for pii = 1:PI
for r =1:R
poolobj = gcp;
addAttachedFiles(poolobj, FDTD_exec_pillars_parfor.m);
pitch = [PillarHeight(ph), Pitch(p), BackgroundIndex(bi),...
PillarIndex(pii), Radius(r)];
Transdata = FDTD_exec_pillars_parfor(pitch);
cellframe2(ph,p,bi,pii,r) = Transdata;
end
end
end
end
end
% Path used to execute simulation in FDTD package within function FDTD_exec_pillars_parfor
[x1,y1]=system('"C:\Program Files\Lumerical\FDTD\bin\fdtd-solutions.exe" -run NOMAD_script.lsf');
error message:
"Error: MATLAB cannot determine whether "FDTD_exec_pillars_parfor" refers to a function or variable. See Parallel for Loops in MATLAB, "Unambiguous Variable Names"."
This error message appeared after I added the two poolobj lines in attempt to resolve this error:
"An UndefinedFunction error was thrown on the workers for 'FDTD_exec_pillars_parfor'. This might be because the file containing 'FDTD_exec_pillars_parfor' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Caused by: Undefined function 'FDTD_exec_pillars_parfor' for input arguments of type 'double'"