"invalid or unexpected token scanned" model error in WinBugs - winbugs

by using
model {
for(i in 1:N){
n[i] ~ dpois(mu[i])
mu[i] <-­ pow(t[i]/beta, alpha)
}
alpha ~ dunif(1,100)
beta ~ dunif(1,100)
}
WinBugs give error"invalid or unexpected token scanned"
kindly consider the above model and give me the suitable solution to remove that error...

Related

Pedersen circom/circomlibjs inconsistency?

As a unit test for a larger use case, I am checking that indeed the pedersen hash I am doing in the frontend aligns with the expected hash done through a circom circuit. I am using a simple assert in the circuit and generating a witness and am feeding both the hashed and unhashed values to the circuit, recreating the hash to make sure that it goes through.
I am running a Pedersen hash in my frontend using circomlibjs. As a unit test, I have. a circuit with a simple assert that check whether the results from my frontend line up with the pedersen hash in the circom circuit.
The circuit I am using:
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/pedersen.circom";
template check() {
signal input unhashed;
signal input hashed;
signal output createdHash[2];
component hasher = Pedersen(256);
component unhashedBits = Num2Bits(256);
unhashedBits.in <== unhashed;
for (var i = 0; i < 256; i++){
hasher.in[i] <== unhashedBits.out[i];
}
createdHash[0] <== hasher.out[0];
createdHash[1] <== hasher.out[1];
hashed === createdHash[1];
}
component main = check();
In the frontend, I am running the following,
import { buildPedersenHash } from 'circomlibjs';
export function buff2hex(buff) {
function i2hex(i) {
return ('0' + i.toString(16)).slice(-2);
}
return '0x' + Array.from(buff).map(i2hex).join('');
}
const secret = (new TextEncoder(32)).encode("Hello");
var pedersen = await buildPedersenHash();
var h = pedersen.hash(secret);
console.log(buff2hex(secret));
console.log(buff2hex(h));
The values that are printed are:
0x48656c6c6f
0x0e90d7d613ab8b5ea7f4f8bc537db6bb0fa2e5e97bbac1c1f609ef9e6a35fd8b
Which are consistent with the test done here.
So I then create an input.json file which looks as follows,
{
"unhashed": "0x48656c6c6f",
"hashed": "0x0e90d7d613ab8b5ea7f4f8bc537db6bb0fa2e5e97bbac1c1f609ef9e6a35fd8b"
}
And lastly run the following script to create a witness, in the hopes that the assert will go through.
# Compile the circuit
circom ${CIRCUIT}.circom --r1cs --wasm --sym --c
# Generate the witness.wtns
node ${CIRCUIT}_js/generate_witness.js ${CIRCUIT}_js/${CIRCUIT}.wasm input.json ${CIRCUIT}_js/witness.wtns
However, I keep getting an assert error,
Error: Error: Assert Failed.
Error in template check_11 line: 26
Which describes the assert in the circuit, so I assume there is an inconsistency in the hash.
I am new to circom so any insights would be greatly appreciated!
For anyone who stumbles across this, it happens that the cause of issue is endianess. The issue was fixed by converting the unhashed to little endian in the input, I am not sure as to where exactly the problem is, but seems like the hasher reads it as big endian on the frontend but the input is expected little endian (or vice verse).
As I have managed to patch up a fix for this at the moment, I will stop investigating, but implore anyone who understand this further to give a better explanation.

Where to save the model file while using R2Winbugs?

I'm learning R2WinBUGS. I have few doubts. Can anyone please help me in solving it? when I run this example, I get a error saying "ratsmodel1.txt" does not exists. where am I suppose to save my model file code? And how am I suppose to call it from R using R2WinBUGS?
Modelfile code in WinBUGS
setwd("C:/Program Files/R/R-3.5.1/")
ratsmodel1<-function(){
for( i in 1:N){
for(j in 1:T){
Y[i,j]~dnorm(mu[i,j],tau.c)
mu[i,j]<-alpha[i]+beta[i]+(x[j]-xbar)
}
alpha[i]~dnorm(alpha.c,alpha.tau)
beta[i]~dnorm(beta.c,beta,tau)
}
tau.c~dgamma(0.001,0.001)
sigma<-1/sqrt(tau.c)
alpha.c~dnorm(0.0,1.0E-6)
alpha.tau~dgamma(0.001,0.001)
beta.c~dnorm(0.0,1.0E-6)
beta.tau~dgamma(0.001,0.001)
alpha0<-alpha.c-xbar*beta.c
}
if(is.R()){
filename<-file.path(getwd(),"ratsmodel1.txt")
}
write.model(ratsmodel,filename)
file.show(filename)
R coding
library(R2WinBUGS)
rats.data<-list(
x=c(8.0,15.0,22.0,29.0,36.0),
xbar=22,
N=30,
T=5,
Y= structure(.Data=c(...),.Dim=c(30,5)))
Y<-rats.data$Y
T<-rats.data$T
x<-rats.data$x
xbar<-rats.data$xbar
N<-rats.data$N
rats.data<-list(Y=Y,x=x,T=T,N=N,xbar=xbar)
rats.params<-c("sigma","beta.c","alpha0")
rats.inits<-
list(alpha=c(...),beta=c(...),alpha.c=c(150),beta.c=c(10),
tau.c=c(1),beta.tau=c(100),alpha.tau=c(100))
ratsfit=bugs(rats.data,rats.inits,parameters.to.save=rats.params,
model.file="rat smodel1.txt",n.chain=7,n.iter=2000,n.burnin=1000,
n.thin=1,debug= FALSE,codaPkg=TRUE,
bugs.directory="C:/Program Files/WinBUGS14/",program=="WinBUGS")
rats.coda=read.bugs(ratsfit)
summary(rats.coda)

how to use find count using raw method in query builder on laravel

I am trying to find count of gender using the raw statement but i get this error
Parse error: syntax error, unexpected '$total' (T_VARIABLE). Can someone please tell me whats my error
$collection='{gender:"Male"}'
$total = DB::collection('leads')->raw(function($collection)
{
return $collection->find();
});
return $total;
A semicolon is missing behind $collection='{gender:"Male"}'. (that should at least solve the error you get currently)

For...in is giving "SourceKitService Terminated"

Every time I typed "for x in variable" (trying to iterate over a textField) I get an error "SourceKitService Terminated"
Does anyone know if this is a known issue? Is there a fix? Thanks!
EDIT:
Code:
for token in expressionTextField.text {
pf.expression += token
}
Make sure that expressionTextField.text is non-nil before iterating through it.
if let str = expressionTextField.text{
for token in str{
pf.expression += token
}
}
That being said, this is also a bug with Xcode's parser that should be fixed by this fall.

CoffeeScript parse error - Unexpected "(" - But there's no "(" in the code

Here's the original code:
res.write JSON.stringify {"#{result.statusCode}": "OK"}
and here's the error that both the CoffeeScript linter in SublimeText 2 and the "Try CoffeeScript" interpreter on the CoffeeScript site give me:
PARSE ERROR ON LINE 1: UNEXPECTED '('
Obviously there's no open parens in the code, so I don't understand the error. Is it a bug in the CoffeeScript parser?
The smallest line of code that does this seems to be something like this:
{"#{a}": ""}
I'm assuming that string interpolation in an object's key is valid, but I don't know for sure.
EDIT:
After some investigation it seems that it's not valid to do the string interpolation in the key because the resulting JavaScript would be invalid.
This:
{"#{a}": "stuff}
would translate to something like:
{ "" + a: "stuff"}
which isn't valid.
But can someone explain why the error message it gives me is so wrong?
I'm assuming that string interpolation in an object's key is valid, but I don't know for sure.
Unfortunately it's not.
You'll have to do something like
(json = {})[result.statusCode] = 'OK'
res.write JSON.stringify json
or if you want a one-liner
res.write (-> ((json = {})[result.statusCode] = 'OK') and JSON.stringify json)()
As for the misleading error, CoffeeScript is trying to translate your {"#{a}": ''} into {("" + a): ""} which is not valid JavaScript. CoffeeScript is throwing the error at that left paren.