// Compute the gradient vector of the conditional log likelihood for a Gaussian-Binary model : void Grad_Cond_Bin(double rho,double pij, double p,int *flag, double *gradcor, double *grad, int *npar, double *nuis, double *thr, double u, double v) { // Initialization variables: double dpij=0.0, dij=0.0, rvar=0.0, dpdm=0.0, f=0.0; double q1=0.0, q2=0.0, q3=0.0, sh=0.0, vario=0.0, z=0; int h=0, i=0, j=0; //init variables: z=(nuis[0]-*thr)/sqrt(nuis[2]+nuis[1]); rvar=nuis[2]/(nuis[2]+nuis[1]); //set derivatives components: q1=dnorm(z,0,1,0);//stand normal pdf q2=pnorm(z*sqrt((1-rvar*rho)/(1+rvar*rho)),0,1,1,0);// stand norm cdf q3=d2norm(z,z,rvar*rho);// biv stand norm pdf //derivatives: dpdm=q1/sqrt(nuis[2]+nuis[1]);/*dp/dmu*/ dpij=2*dpdm*q2;/*dpij/dmu*/ f=-(0.5*(nuis[0]-*thr)*dpdm)/(nuis[2]+nuis[1]);/* dp/dsill*/ dij=2*f*q2;/* dpij/dsill*/ vario=2*(p-pij);//variogramma binario!!! sh=1/(1-2*p+pij); // Derivative of the difference respect with the mean if(flag[0]==1) { grad[i]=(dpij-2*dpdm)*(1-((u+v)*nij(dpij,dpdm,pij,p)+ (u*v)*mij(dpij,dpdm,pij,p)))*sh+dpdm*(1-(u+v)/(2*p))/(1-p); i++; } // Derivative of the difference respect with the nugget if(flag[1]==1) { grad[i]=1; i++; } // Derivative of the difference respect with the sill if(flag[2]==1) { grad[i]=(dij-2*f)*(1-((u+v)*nij(dij,f,pij,p)+ (u*v)*mij(dij,f,pij,p)))*sh+f*(1-(u+v)/(2*p))/(1-p); i++; } // Derivatives with respect to the correlation parameters for(j=i;j<*npar;j++) { grad[j]=gradcor[j]*q3*rvar*(1-((u+v)*2*(p-1)/vario + (u*v)*2*(pij-2*pow(p,2)+p)/(vario*pij)))*sh; h++; } return; }
double LCOrbits::ArmVelocity(int em, int rec, double trec) { LCVector ri(MT), rj(MT), vi(MT), vj(MT), rij(MT), nij(MT), n(MT); ri = position(rec, trec); vi = velocity(rec, trec); rj = position(em, trec); vj = velocity(em, trec); rij = rj-ri; nij = rij.unit(); n = nij * (-1.); return(vj*n-vi*n); }
double LCOrbits::ArmCompute(int em, int rec, double trec) { double tA(0.), tij; if ((em<1)||(em>NARMMAX)||((rec<1)&&(rec>NARMMAX))){ std::cerr << "ERROR in LCOrbits::ArmCompute : Spacecraft number must be in [0," << NARMMAX << "] ! " << Endl; throw std::invalid_argument ("ERROR in LCOrbits::ArmCompute : Spacecraft number must be in [0,NARMMAX] ! "); } /* if(OrderArm != -10) OrderArm = order_default; if ((OrderArm<-2)||(OrderArm>2)) throw std::invalid_argument ("ERROR in LCOrbits::ArmCompute : Order must be 0 (for 0), 1 (for 1/2), 2 (for 1) or -1 (for analytical MLDC eccentric formulation)"); */ if(OrderArm >= 0){ LCVector ri(MT), rj(MT), vi(MT), vj(MT), rij(MT), nij(MT), n(MT); /*! **** Read positions and velocities and compute related quantities * Index i refers to receiver and j to emitter * \f{eqnarray*}{ * \vec{r}_{ij} & = & \vec{r}_j - \vec{r}_i = \vec{r}_{em} - \vec{r}_{rec} \\ * \vec{n}_{ij} & = & \vec{r}_{ij} / | \vec{r}_{ij} | \\ * \hat{n} & = & - \vec{n}_{ij} \\ * t_{ij} & = & - | \vec{r}_{ij} | / c = - | \vec{r}_{em} - \vec{r}_{rec} | / c * \f} */ ri = position(rec, trec); vi = velocity(rec, trec); vi = vi/LC::c_SI; rj = position(em, trec); vj = velocity(em, trec); vj = vj/LC::c_SI; /* ri.p[0] = 5.e9; ri.p[1] = 0.; ri.p[2] = 0.; rj.p[0] = -1.e-5; rj.p[1] = 0.; rj.p[2] = 0.; rij = rj-ri; */ rij = rj-ri; nij = rij.unit(); n = nij*(-1.); tij = rij.norm()/LC::c_SI; tij = -tij; /* MT->o->precision(16); Cout << "em = " << em << " -> rec = " << rec << " : " << rij.norm() << " ==> " << tij << Endl; for(int i=0; i<3; i++) Cout << "\t\t" << ri.p[i] << "\t\t" << rj.p[i] << "\t\t" << rij.p[i] << Endl; */ if (OrderArm>=0) tA += ArmOrderContrib(0, tij, ri, rj, vi, vj, rij, nij, n); if (OrderArm>=1) tA += ArmOrderContrib(1, tij, ri, rj, vi, vj, rij, nij, n); if (OrderArm>=2) tA += ArmOrderContrib(2, tij, ri, rj, vi, vj, rij, nij, n); return (tA); }else{ return( ArmSpecific(em, rec, trec) ); } }