Output .sol file Gurobi and Julia JuMP - julia

How can I output a .sol file from JuMP? Im playing around with the lower level model but cant seem to figure this one out.
Using Gurobi and JuMP inside of Atom editor.

You can use one of the Gurobi parameters when you create the model and set the solver. The parameter is called ResultFile. More details about it can be found here:
http://www.gurobi.com/documentation/7.0/refman/resultfile.html#parameter:ResultFile
Here is an example that worked fine for me:
m = Model(solver=GurobiSolver(ResultFile="MySolution.sol"))

Related

unrecognized function Nn in R

I am learning R package SimInf to simulate data-driven stochastic epidemiological models. As I was reading the documentation I came across an unrecognized funcion Nn when defining a function for epicurves. Specifically, this line:
j <- sample(seq_len(Nn(model)), 1)
Values of model are integers. My guess is that Nn selects non-negative values, however my R does not recognize this function. From documentation it does not look like they pre-defined Nn either. Can someone please tell if they know what "Nn" is for? Thank you.
A way to go is always taking the package-name and triple-":" it, such that you can find nearly all functions inside the package. Maybe you are familiar with namespacing a function via packageName::functionFrompackageTocall. The packageName::: shows (nearly) all functions defined in this package. If you do this in R-Studio with SimInf:: and SimInf:::, you will see that the latter gives much more functions. But you can only find the functions SimInf:::Nd and SimInf:::Nc, not the Nn-function. Hence you will have to go to the github-sources of the package, in this case https://github.com/stewid/SimInf .Then search for Nn the whole repository. You will see that it seems like it is always an int, but this doesn't help you since you want to get ii as a function, not as a variable. Scrolling further down in the search-results, you will find the NEWS.md-file which mentions The 'Nn' function to determine the number of nodes in a model has been replaced with the S4 method 'n_nodes'. in the https://github.com/stewid/SimInf/blob/fd7eb4a29b82a4a97f64b528bb0e78e5474aa8a5/NEWS.md file under SimInf 8.0.0 (2020-09-13). Hence having a current version of SimInf installed, it shouldn't use the method Nn anymore. If you use it in your code, replace it by n_nodes. If you find it in current package code, you can email the package-maintainer that you found a bug in his code.
TLDR: Nn is an outdated version of n_nodes

R interface to Keras: how to debug custom loss function?

I'm using keras package in R, and would like to define a custom loss function.
While I was able to find a few examples (one of them), there was nothing on how to debug your own loss function. That is, even if I make it work, how could I verify that it works correctly (e.g. take some y_true and y_pred, and go through the calculations)?
I tried adding a print statement inside the function, but nothing came out.

I can't get fix() and names() to work (as intended in ISLR) on data set

I'm trying to work on data set Boston from MASS library following ISLR handbook. I am able to load MASS library with library() (I believe I can, because I ? Boston provides description of this data set), however I have problems with next steps.
ISLR is telling me to use
fix(Boston)
names(Boston)
First to learn more about data set, second to get names from it (I was able to perform both on previously used data set "Auto" few chapters before). However it doesn't work for me and when I run it:
fix(Boston) opens a Edit window containing only
function ()
{
}
names(Boston) returns simply NULL.
I read R documentation from stat.ethz.ch about both functions, but I don't know how to relate them to my problem. I wasn't able to use any Q&As I found on stack overflow about either function. From my understanding it seems like Boston isn't treated as data set or something like this, but I don't know where to go with this intuition either.
I'm using sixth printing of ISLR, related pages: 123-124.
If you do data("Boston") after loading the library, it fixes the problem.
The problem might be - R created an empty function Boston() because you might have run fix(Boston) before loading the required libraries.
So run
library(MASS)
library(ISLR)
data("Boston")
fix(Boston)
And everything works fine.

Is it possible to get R intellisense or console output in PowerBI?

I've been trying to get started using R in PowerBI. However, the lack of intellisense and the lack of console output is hindering me. As I can't develop the script in RStudio or in Visual Studio with those aids.
EDIT: PowerBI does a nice thing where you can import data into the application and then work with the drag and drop tools to play around with the data, then when you select data fields that you want to add to an R plot, it creates an R stub that pulls those fields into a data.frame which makes things easy. However, that data is "inside" Power BI, I can't do the same thing in R studio because that data context doesn't exist.
What options are there? Am I missing something?
Thanks.
I think that what you are looking for is R tools for VS. It should make intellisense pick up the context and tell you what you can do with each object. Then for the output, can't you print and check the results in the output window in VS?
This also has R interactive window so when you debug you have a window to place code in, and evaluate it in that context. Say you have a method and you want to debug a statement plot(x, exp(x), type="l", col="green"), instead of making a fix at a time and then re-running to check the results, you can just make the fix say plot(x, exp(x), type="l", col="red") and see how that evaluates. This comes in handy when you wanna try a couple of things and check the results, since you can do it in one go, instead of "making one change and running it" x times.
Let me know if this does the job for you.
The only data context you have in R inside Power BI are Tables, which you pass in parameters of the call of R.Execute. Behind the scene, these Tables will be just dropped on disk as csv and then R process will pick them in order to do whatever you want. Actually this is the only relation between R and PowerBI desktop, if we speak about Transformations using R.
You can easily save such a context from PowerBI using R script of just one function save.image(“filename.RData”), and then open it using load("filename.RData") in your target R development environment.
While you should always test out your R code elsewhere first, it is often not enough for debugging purposes.
for general purpose debugging, you can nest your whole script in a block like this:
out <- capture.ouput({...})
Any intermediate value can be captured in this block with a cat:
cat(intermediate_value_i_want_to_test,'\n')
After your script block is done, simply convert your output to a data.frame and each cat method call will be printed in a new row of out.

Is it possible to create a new model in RNetLogo or change the source code of sample models?

I am pretty new to the RNetLogo package in R, but so far all the examples of using RNetLogo I saw were about loading model samples and doing something with them. I did not see any examples which show that we can create our own model and write down rules according to which our agents will interact with each other (or see the code of sample models and change it). Is it possible to write these rules in R or does RNetLogo allow us to play with already implemented models (samples) only without changing the code?
For example, when we open in NetLogo Models Library-->Earth Science-->Climate Change (just random example) then we can go to the Code tab and see the code written in NetLogo prog.language:
globals [
sky-top ;; y coordinate of top row of sky
...
My question is: can we see this code in R and change it?
My answer, I do not think so :-) . You need to developpe your model in netlogo and with RNetlogo in R you can run it, play with data, send some data.frame to your model, change some variable.

Resources