uninitialized variables and #Bugs:dic.set cannot be executed (is greyed out) issue in WinBUGS - variables

I am running the following model using r2WinBUGS package from R.
model{
for (i in 1:Nshim) {
y.SHIM[i]~ dnorm(mu[i], tau)
mu[i] <- zeta[PID[i]]+beta0[T[PID[i]]]+beta1[T[PID[i]]]*TIME[i]+beta2[T[PID[i]]]*pow(TIME[i],2)
}
for ( k in 1:Mshim){
zeta[k]~dnorm(0, prec.zeta)
}
for ( j in 1:Mshim){
T[j]~ dcat(p[])
}
for ( k in 1:2){
beta0[k]~dnorm(0.0,1.0E-6)
beta1[k]~dnorm(0.0, 1.0E-6)
beta2[k]~dnorm(0.0, 1.0E-6)
}
prec.zeta~dgamma(0.1,0.01)
p[1:2]~ ddirch(alpha[])
alpha[1] <- 1
alpha[2] <- 1
tau~dgamma(0.1,0.1)
sig2<-1/tau
sig2.zeta<-1/prec.zeta
}
Considering the following initials for 3-chains.
init_2quad.SHIM_RI=function(){list(beta0=c(10,15),beta1=rnorm(2),beta2=rnorm(2),zeta=rgamma(70,1,1),T=rbinom(70,1,0.5)+1)
list(beta0=c(12,18),beta1=rnorm(2),beta2=rnorm(2),zeta=rgamma(70,1,1),T=rbinom(70,1,0.5)+1)
list(beta0=c(15,20),beta1=rnorm(2),beta2=rnorm(2),zeta=rgamma(70,1,1),T=rbinom(70,1,0.5)+1)
}
setwd("C:/Users/mnudd/Desktop/IndStudy/WinBUGS14")
mix_2quad.RI_res=bugs(data = SHIM_2quad,model.file = "mix_2Q_SHIM_RI.bug",
inits = init_2quad.SHIM_RI, parameters.to.save = c("beta0","beta1", "beta2", "zeta","T","sig2"),
n.chains = 3, n.iter = n.iter_2q.RI, n.burnin = n.burnin_2q.RI, n.thin = n.thin_2q.RI,
bugs.directory = "C:/Users/mnudd/Desktop/IndStudy/WinBUGS14",
debug=T,codaPkg=F)
Unfortunately each time I run, getting the following warning
this chain contains uninitialized variables
inits(3,C:/Users/mnudd/AppData/Local/Temp/RtmpWQM8aq/inits3.txt)
this chain contains uninitialized variables
gen.inits()
initial values generated, model initialized
thin.updater(10)
update(100)
set(beta0)
set(beta1)
set(beta2)
set(zeta)
set(T)
set(sig2)
set(deviance)
dic.set()
command #Bugs:dic.set cannot be executed (is greyed out)
update(1000)
coda(*,C:/Users/mnudd/AppData/Local/Temp/RtmpWQM8aq/coda)
How can identify which one is uninitialized and why the bugs can not be executed(grayed out)?
Any suggestion or help would be appreciated.

Related

Revit: Cannot create dimensions when ViewSection is rotated

I'm trying to set dimension to the elements in a AssemblyInstance. The code operates with coordinates from the first element.
AssemblyInstance ass; //is found and is not null
ViewSection vsec = RevitAuxilaries.CreateAssemblyViewSection(uiapp, ass,
AssemblyDetailViewOrientation.ElevationFront, ElementId.InvalidElementId, 25);
//UIApplication,
AssemblyInstance, AssemblyDetailViewOrientation, TemplateId, scale // created
BoundingBoxXYZ bbox1 = ass.get_BoundingBox(uiapp.ActiveUIDocument.ActiveView);
XYZ ptmid = (bbox1.Max + bbox1.Min) * 0.5;
Element cropboxelm = RevitAuxilaries.GetViewCropBox(uiapp, vsec); //finds CropBox element,
//found
BoundingBoxXYZ bcropbox = vsec.CropBox;
XYZ center = new XYZ(ptmid.X, ptmid.Y, 0.5 * (bcropbox.Max.Z + bcropbox.Min.Z));
Line axis = Line.CreateBound(center, center + XYZ.BasisZ);
RevitAuxilaries.RotateElement2(uiapp, cropboxelm, axis, 0.6981); // UIApplication,, Element,
Line, angle// created
double dw = RevitAuxilaries.GetDimensionFromElement(uiapp, fi, Dimensions.enWidth); //found dw
// = 3.937
ptleft = new XYZ(31.501, -23.3878, 32.4803);
ptrght = new XYZ(31.501 + dw * Math.Cos(0.6981), -23.3878 + dw * Math.Sin(0.6981), 32.4803);
Line ln = RevitAuxilaries.CreateLineFromPoints(uiapp, ptleft, ptrght); //created
ReferenceArray refarr = new ReferenceArray();
refarr.Append(ln.GetEndPointReference(0));
refarr.Append(ln.GetEndPointReference(1));
Dimension dim = null;
using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document, "CreADim"))
{
trans.Start();
dim = uiapp.ActiveUIDocument.Document.Create.NewDimension(viewsec, line, refarr);
if (!issame)
{
try
{ dim.ValueOverride = Convert.ToInt32(UnitUtils.Convert(dim.Value.Value,
UnitTypeId.Feet, UnitTypeId.Millimeters)).ToString(); }
catch { }
}
trans.Commit();
uiapp.ActiveUIDocument.RefreshActiveView();
}
ERROR: The direction of dimension is invalid
Error in function checkDir, line 939
What is here wrong?
Have you tried to create the exact same dimension in the exact same context manually through the end user interface? Does that complete as expected? If not, what error message does that generate? If yes, you can analyse the resulting model, its elements and their properties using RevitLookup and possibly discover some required settings that can be added to your API approach.

Tensorflow: I keep getting undefined

I am trying to run an analysis with Tensorflow and I keep getting undefined. I attempted to modify my versions and require statements and even refactored knn a bit and nothing I have tried has solved the continued undefined as a result.
testLabels should be an array of arrays, so I am getting the rows and the dollar value out of there.
require("#tensorflow/tfjs-node");
const tf = require("#tensorflow/tfjs");
const loadCSV = require("./load-csv");
function knn(features, labels, predictionPoint, k) {
features
.sub(predictionPoint)
.pow(2)
.sum(1)
.pow(0.5)
.expandDims(1)
.concat(labels, 1)
.unstack()
.sort((a, b) => (a.get(0) > b.get(0) ? 1 : -1))
.slice(0, k)
.reduce((acc, pair) => acc + pair.get(1), 0) / k;
}
let { features, labels, testFeatures, testLabels } = loadCSV(
"kc_house_data.csv",
{
shuffle: true,
splitTest: 10,
dataColumns: ["lat", "long"],
labelColumns: ["price"]
}
);
features = tf.tensor(features);
labels = tf.tensor(labels);
const result = knn(features, labels, tf.tensor(testFeatures[0]), 10);
console.log("Guess", result, testLabels[0][0]);
I continue to get this result:
Guess undefined 1085000
I have console logged all over the place and nothing is returning except the variable result:
console.log("Guess", result, testLabels[0][0]);
So the problem seems to be the knn algorithm itself, but I can't figure out what it is.

dlm package - Error in optim(parm, logLik, method = method, ...) : L-BFGS-B needs finite values of 'fn'

require(dlm)
start.vals = c(0,0,0)
names(start.vals) = c("lns2_obs", "lns2_alpha", "lns2_beta")
buildTVP <- function(parm, x.mat){
parm <- exp(parm)
return( dlmModReg(X=x.mat, dV=parm[1], dW=c(parm[2], parm[3])) )
}
TVP.mle = dlmMLE(y=k[,1], parm=start.vals, x.mat=k[,2], build=buildTVP, hessian=T)
in this code, k[,1] and k[,2] are 2 stocks prices. on TVP.mle line I got
Error in optim(parm, logLik, method = method, ...) : L-BFGS-B needs finite values of 'fn' " error.
k file link: https://drive.google.com/open?id=1scLaKRpSdmp-1T9qTp_5cEcBFnWKDAus
I could not find my mistake. Could you help me please?

issue accessing lexical scope using B

For debugging purposes I'd like to Access the lexical scope of different subroutines with a specific Attribute set. That works fine. I get a Problem when the first variable stores a string, then I get a empty string. I do something like this:
$pad = $cv->PADLIST; # $cv is the coderef to the sub
#scatchpad = $pad->ARRAY; # getting the scratchpad
#varnames = $scratchpad[0]->ARRAY; # getting the variablenames
#varcontents = $scratchpad[1]->ARRAY; # getting the Content from the vars
for (0 .. $#varnames) {
eval {
my $name = $varnames[$_]->PV;
my $content;
# following line matches numbers, works so far
$content = $varcontent[$_]->IVX if (scalar($varcontent[$_]) =~ /PVIV=/);
# should match strings, but does give me undef
$content = B::perlstring($varcontent[$_]->PV) if (scalar($varcontent[$_]) =~ /PV=/);
print "DEBUGGER> Local variable: ", $name, " = ", $content, "\n";
}; # there are Special vars that throw a error, but i don't care about them
}
Like I said in the comment the eval is to prevent the Errors from the B::Special objects in the scratchpad.
Output:
Local variable: $test = 42
Local variable: $text = 0
The first Output is okay, the second should Output "TEXT" instead of 0.
What am I doing wrong?
EDIT: With a little bit of coding I got all values of the variables , but not stored in the same indexes of #varnames and #varcontents. So now is the question how (in which order) the values are stored in #varcontents.
use strict;
use warnings;
use B;
sub testsub {
my $testvar1 = 42;
my $testvar2 = 21;
my $testvar3 = "testval3";
print "printtest1";
my $testvar4 = "testval4";
print "printtest2";
return "returnval";
}
no warnings "uninitialized";
my $coderef = \&testsub;
my $cv = B::svref_2object ( $coderef );
my $pad = $cv->PADLIST; # get scratchpad object
my #scratchpad = $pad->ARRAY;
my #varnames = $scratchpad[0]->ARRAY; # get varnames out of scratchpad
my #varcontents = $scratchpad[1]->ARRAY; # get content array out of scratchpad
my #vars; # array to store variable names adn "undef" for special objects (print-values, return-values, etc.)
for (0 .. $#varnames) {
eval { push #vars, $varnames[$_]->PV; };
if ($#) { push #vars, "undef"; }
}
my #cont; # array to store the content of the variables and special objects
for (0 .. $#varcontents) {
eval { push #cont, $varcontents[$_]->IV; };
eval { push #cont, $varcontents[$_]->PV; };
}
print $vars[$_], "\t\t\t", $cont[$_], "\n" for (0 .. $#cont);
EDIT2: Added runnable script to demonstrate the issue: Variablenames and variablevalues are not stored in the same index of the two Arrays (#varnames and #varcontents).

Calculating the load time of page elements using Rcurl? (R)

I started playing with the idea of testing a webpage load time using R. I have devised a tiny R code to do so:
page.load.time <- function(theURL, N = 10, wait_time = 0.05)
{
require(RCurl)
require(XML)
TIME <- numeric(N)
for(i in seq_len(N))
{
Sys.sleep(wait_time)
TIME[i] <- system.time(webpage <- getURL(theURL, header=FALSE,
verbose=TRUE) )[3]
}
return(TIME)
}
And would welcome your help in several ways:
Is it possible to do the same, but to also know which parts of the page took what parts to load? (something like Yahoo's YSlow)
I sometime run into the following error -
Error in curlPerform(curl = curl,
.opts = opts, .encoding = .encoding) :
Failure when receiving data from the
peer Timing stopped at: 0.03 0 43.72
Any suggestions on what is causing this and how to catch such errors and discard them?
Can you think of ways to improve the above function?
Update: I redid the function. It is now painfully slow...
one.page.load.time <- function(theURL, HTML = T, JavaScript = T, Images = T, CSS = T)
{
require(RCurl)
require(XML)
TIME <- NULL
if(HTML) TIME["HTML"] <- system.time(doc <- htmlParse(theURL))[3]
if(JavaScript) {
theJS <- xpathSApply(doc, "//script/#src") # find all JavaScript files
TIME["JavaScript"] <- system.time(getBinaryURL(theJS))[3]
} else ( TIME["JavaScript"] <- NA)
if(Images) {
theIMG <- xpathSApply(doc, "//img/#src") # find all image files
TIME["Images"] <- system.time(getBinaryURL(theIMG))[3]
} else ( TIME["Images"] <- NA)
if(CSS) {
theCSS <- xpathSApply(doc, "//link/#href") # find all "link" types
ss_CSS <- str_detect(tolower(theCSS), ".css") # find the CSS in them
theCSS <- theCSS[ss_CSS]
TIME["CSS"] <- system.time(getBinaryURL(theCSS))[3]
} else ( TIME["CSS"] <- NA)
return(TIME)
}
page.load.time <- function(theURL, N = 3, wait_time = 0.05,...)
{
require(RCurl)
require(XML)
TIME <- vector(length = N, "list")
for(i in seq_len(N))
{
Sys.sleep(wait_time)
TIME[[i]] <- one.page.load.time(theURL,...)
}
require(plyr)
TIME <- data.frame(URL = theURL, ldply(TIME, function(x) {x}))
return(TIME)
}
a <- page.load.time("http://www.r-bloggers.com/", 2)
a
your getURL call will only do one request and get the source HTML for the web page. It won't get the CSS or Javascript or other elements. If this is what you mean by 'parts' of the web page then you'll have to scrape the source HTML for those parts (in SCRIPT tags, or css references etc) and getURL them separately with timing.
Perhaps Spidermonkey from Omegahat could work.
http://www.omegahat.org/SpiderMonkey/