multiple definition of node xi1[1,1] - bayesian

i have a problem in the code below the problem is occured in compiling process " multiple definition of node xi1[1,1]", anyone help me to solve this problem please.
many thanks in advance
model {
for(i in 1:N){
#measurement equation model
for(j in 1:P){y[i,j]~dnorm(mu[i,j],psi[j])I(thd[j,z[i,j]],thd[j,z[i,j]+1])}
xi[i,1]<-mu[i,1]+lam[1]*mu[i,2]+lam[2]*mu[i,3]+lam[3]*mu[i,4]+lam[4]*mu[i,5]+lam[5]*mu[i,6]
xi[i,2]<-mu[i,1]+lam[1]*mu[i,2]+lam[2]*mu[i,3]+lam[3]*mu[i,4]+lam[4]*mu[i,5]+lam[5]*mu[i,6]+xi[i,1]
#structural equation model
xi[i,1:2]~dmnorm(zero2[1:2],phi[1:2,1:2])
eta[i]~dnorm(nu[i],psd1)
nu[i]<-gam[1]*xi[i,1]
mu[i,1:6]~dnorm(0.8,4.0)
}# end of i
for(i in 1:2){zero2[i]<-0.0}
#priors on loadings and coefficients
for(i in 1:5){lam[i]~dnorm(0.8,4.0)}
for(i in 1:1){gam[i]~dnorm(0.6,4.0)}
#priors on precisions
for(j in 1:P){
psi[j]~dgamma(10,8)
sgm[j]<-1/psi[j]}
psd~dgamma(10,8)
sgd<-1/psd
phi[1:2,1:2]~dwish(R[1:2,1:2], 30)
phx[1:2,1:2]<-inverse(phi[1:2,1:2])
} #end of model

You have these two lines:
xi[i,1]<-mu[i,1]+lam[1]*mu[i,2]+lam[2]*mu[i,3]+lam[3]*mu[i,4]+lam[4]*mu[i,5]+lam[5]*mu[i,6]
...
xi[i,1:2]~dmnorm(zero2[1:2],phi[1:2,1:2])
Since both are in the i loop, you have defined xi[1,1] twice: once as a deterministic quantity and once as a random variable (data?).

Related

Time complexity of recursive function with input halved

For those Big O experts out there... I'm trying to deduce the time complexity of a function with two recursive calls, where the input is halved each time:
function myFunc(n) {
if (n > 1) {
let something = 0
for (let i=0; i < n; i++) {
// Do some linear stuff in here
}
myFunc(n/2)
myFunc(n/2)
}
return something;
}
I'm unsure how, exactly, the halving effects the analysis. Any help super appreciated!
The first step in the analysis of a recursive function would be to write down the recurrence relation. In this case you have:
T(n) = 2T(n/2) + O(n)
This is one of the most common forms of recurrence relations, so we can immediately state the solution without any further calculations:
T(n) = O(n log n)
It's easy to prove this result by induction. See e.g. here.

ampl display variable depending on a condition

suppose we have the following ampl model:
set objects;
set sacks;
...
var Take{objects, sacks} binary;
...
display Take;
after solving the optimization problem I want to display only the lines of Take that equal 1
You can do something like this:
for{o in objects, s in sacks: Take[o,s] = 1} {
printf "\n %s %s", o,s;
}

how do you calculate the complexity in Big-O notation? can any body explain that on this code below

void KeyExpansion(unsigned char key[N_KEYS], unsigned int* w)
{
unsigned int temp;
for(int i=0; i< N_KEYS; i++)
{
w[i] = (key[N_KEYS*i]<<24) + (key[N_KEYS*i+1]<<16) + (key[N_KEYS*i+2]<<8) + key[N_KEYS*i+3];
}
for(int i = 4; i< EXPANDED_KEY_COUNT; i++)
{
temp = w[i-1];
if(i % 4 == 0)
temp = SubWord(RotWord(temp)) ^ Rcon[i/4];
w[i] = temp ^ w[i-4] ;
}
}
Big-O helps us do analysis based on the input. The issue with your question is that there seems to be several inputs, which may or may not relate with each other.
Input variables look like N_KEYS, and EXPANDED_KEY_COUNT. We also don't know what SubWord() or RotWord() do based on what is provided.
Since SubWord() and RotWord() aren't provided, lets assume they are constant for easy calculations.
You have basic loops and iterate over each value, so its pretty straight forward. This means you have O(N_KEYS) + O(EXPANDED_KEY_COUNT). So the overall time complexity depends on two inputs, and would be bound by the larger.
If SubWord() or RotWord() do anything special that aren't constant time, then that would affect the time complexity of O(EXPANDED_KEY_COUNT) portion of code. You could adjust the time complexity by multiplied against it. But by the names of the methods, it sounds like their time complexity would be based on the length of the string, would would be yet another different input variable.
So this isn't a clear answer, because the question isn't fully clear, but I tried to break things down for you as best as I could.

shared memory allocation and forking child processes

I got some doubt about how to allocate shared memory
using some shmget function.what's the syntax exactly ?
also i want to know how to fork child processes in pair which perform different functions individually and then output of processes is given by parent process.
Yeah i under stood your question. Here is the syntax for allocating shared memory for different functions.
thread_identifier = shmget(IPC_PRIVATE, num * sizeof(int), 0777|IPC_CREAT)
And for forking.
if (fork()==0) { printf("desired output "); for(i = 0; i < num; i++) { x[i] = 1 + (rand() % max); printf("%d \n", x[i]); *output *= x[i]; } printf("output %d", *output);
You can use then else loop for entering in another child process.

Asymmetric Distance Matrix for VRP in the OptaPlanner don't work correctly

I implemented an asymmetric distance matrix for VRP in the examples of OptaPlanner as suggested in option B of answer https://stackoverflow.com/a/19420978/3743175
However the values of soft constraints does not coincide with the total value of the calculated distance of routes in the tests.
Anyone have any idea of the cause of this? I've checked several times, my matrix is correct and the problem does not occur for symmetric instances.
Any help is welcome.
Thanks.
Solution Found:
I found problem in lines with softScore calculation of the examples: the softscore is calculated with reverse arcs.
I replaced this lines in VehicleRoutingIncrementalScoreCalculator class:
...
softScore -= vehicle.getLocation().getDistance(customer.getLocation());
...
softScore += vehicle.getLocation().getDistance(customer.getLocation());
with:
...
softScore -= customer.getLocation().getDistance(vehicle.getLocation());
...
softScore += customer.getLocation().getDistance(vehicle.getLocation());
and I fixed the Customer class with following method:
public int getDistanceToPreviousStandstill() {
if (previousStandstill == null) {
return 0;
}
return previousStandstill.getLocation().getDistance(location);
}