コード例 #1
0
ファイル: CAR_DKW_o.cpp プロジェクト: parb220/DKW
bool CAR_DKW_o::SetParameters_InitializeABOmega()
{
	if (!CAR_DKW::SetParameters_InitializeABOmega())
		return false; 

	TDenseMatrix lambda1 = SIGMA_inverse * SIGMAlambda1;
        TDenseVector KAPPAtheta = KAPPA * theta;
        TDenseVector theta_Q;

	aI_Q.Zeros(dataP->MATgrid_options.Dimension());
        bI_Q.Zeros(dataP->MATgrid_options.Dimension(), Nfac);
        
        for (int i=0; i<dataP->MATgrid_options.Dimension(); i++)
        {
                double MAT = dataP->MATgrid_options(i);
                TDenseVector temp_ay;
                TDenseMatrix temp_by;
                if (!YieldFacLoad(temp_ay, temp_by, KAPPA_rn, Inv_KAPPA_rn, Inv_Kron_KAPPA_rn, SIGMA, KAPPAtheta, rho0, rho1, lambda0,TDenseVector(1,MAT)))
                        return false;
                TDenseVector temp_by_vector = temp_by.RowVector(0); // -MAT * temp_by.RowVector(0);

                theta_Q = Multiply(Inv_KAPPA_rn, KAPPAtheta-SIGMA*lambda0+MultiplyTranspose(SIGMA,SIGMA)*temp_by_vector);

                double rho0_Q = rho0_pi - InnerProduct(lambda0, sigq)+InnerProduct(sigq, TransposeMultiply(SIGMA,temp_by_vector));
                TDenseVector rho1_Q = rho1_pi - TransposeMultiply(lambda1, sigq);

                double temp_aI_Q;
                TDenseVector temp_bI_Q;
                InfExpFacLoad(temp_aI_Q, temp_bI_Q, KAPPA_rn, Inv_KAPPA_rn, Inv_Kron_KAPPA_rn, SIGMA, theta_Q, sigq, sigqx, rho0_Q, rho1_Q, MAT);

                aI_Q(i) = temp_aI_Q;
                bI_Q.InsertRowMatrix(i, 0, temp_bI_Q);
        }
	return true; 
}
コード例 #2
0
void CompMod(zz_pX& x, const zz_pX& g, const zz_pXArgument& A, 
             const zz_pXModulus& F)
{
   if (deg(g) <= 0) {
      x = g;
      return;
   }


   zz_pX s, t;
   vec_zz_p scratch(INIT_SIZE, F.n);

   long m = A.H.length() - 1;
   long l = ((g.rep.length()+m-1)/m) - 1;

   zz_pXMultiplier M;
   build(M, A.H[m], F);

   InnerProduct(t, g.rep, l*m, l*m + m - 1, A.H, F.n, scratch);
   for (long i = l-1; i >= 0; i--) {
      InnerProduct(s, g.rep, i*m, i*m + m - 1, A.H, F.n, scratch);
      MulMod(t, t, M, F);
      add(t, t, s);
   }

   x = t;
}
コード例 #3
0
void PlainUpdateMap(vec_zz_p& xx, const vec_zz_p& a, 
                    const zz_pX& b, const zz_pX& f)
{
   long n = deg(f);
   long i, m;

   if (IsZero(b)) {
      xx.SetLength(0);
      return;
   }

   m = n-1 - deg(b);

   vec_zz_p x(INIT_SIZE, n);

   for (i = 0; i <= m; i++)
      InnerProduct(x[i], a, b.rep, i);

   if (deg(b) != 0) {
      zz_pX c(INIT_SIZE, n);
      LeftShift(c, b, m);

      for (i = m+1; i < n; i++) {
         MulByXMod(c, c, f);
         InnerProduct(x[i], a, c.rep);
      }
   }

   xx = x;
}
コード例 #4
0
void CompMod(ZZ_pX& x, const ZZ_pX& g, const ZZ_pXArgument& A, 
             const ZZ_pXModulus& F)
{
   if (deg(g) <= 0) {
      x = g;
      return;
   }


   ZZ_pX s, t;
   ZZVec scratch(F.n, ZZ_p::ExtendedModulusSize());

   long m = A.H.length() - 1;
   long l = ((g.rep.length()+m-1)/m) - 1;

   ZZ_pXMultiplier M;
   build(M, A.H[m], F);

   InnerProduct(t, g.rep, l*m, l*m + m - 1, A.H, F.n, scratch);
   for (long i = l-1; i >= 0; i--) {
      InnerProduct(s, g.rep, i*m, i*m + m - 1, A.H, F.n, scratch);
      MulMod(t, t, M, F);
      add(t, t, s);
   }

   x = t;
}
コード例 #5
0
ファイル: stageAB.c プロジェクト: oakfr/omni3d
double DoubleDeriv1 (edge *TheEdge, position *ThePosition, line *TheLine,
		     int index_x, int index_y)
{
  int index;
  double dv[3], v[3], newv[3], hat[3], temp1;

  if (!TheEdge || !ThePosition || !TheLine) return (0.0);

  if (index_y < index_x) {
    index = index_x; index_x = index_y; index_y = index;
  }

  ComputeV (v, *TheLine);
  RotateQuaternion (newv, ThePosition->q, v);
  temp1 = InnerProduct (newv, TheEdge->m);

  if ((index_x == THETA) && (index_y == THETA) ||
      (index_x == OMEGA) && (index_y == OMEGA))
    return (-2.0 * sqr(temp1));

  if ((index_x == THETA) && (index_y == OMEGA))
    return (0.0);

  if (((index_x == THETA) || (index_x == OMEGA)) &&
      ((index_y == ALPHA) || (index_y == BETA) || (index_y == GAMMA))) {

    if (index_x == THETA) {
      hat[0] = 0.0; hat[1] = -1.0; hat[2] = 0.0;
    } else {
      hat[0] = 1.0; hat[1] =  0.0; hat[2] = 0.0;
    }

    RotateQuaternion (v, TheLine->q, hat);
    RotateQuaternion (newv, ThePosition->q, v);

    DerivR (dv, newv, IndexToAxis (index_y));

    return (2.0 * temp1 * InnerProduct (dv, TheEdge->m));
  }

  if ( ((index_x == ALPHA) || (index_x == BETA) || (index_x == GAMMA)) &&
       ((index_y == ALPHA) || (index_y == BETA) || (index_y == GAMMA)) ) {
    
    ComputeV (v, *TheLine);
    RotateQuaternion (newv, ThePosition->q, v);

    DoubleDerivR (dv, newv, IndexToAxis (index_x), IndexToAxis (index_y));

    return (2.0 * temp1 * InnerProduct (dv, TheEdge->m));
  }

  pexit ("Bad Parameters to DoubleDeriv1");

  return 0.0;
}
コード例 #6
0
ファイル: LLL_XD.c プロジェクト: axelexic/NTL
static
void ComputeGS(mat_ZZ& B, xdouble **B1, xdouble **mu, xdouble *b, 
               xdouble *c, long k, xdouble bound, long st, xdouble *buf)
{
   long n = B.NumCols();
   long i, j;
   xdouble s, t1, y, t;
   ZZ T1;

   xdouble *mu_k = mu[k];

   if (st < k) {
      for (i = 1; i < st; i++)
         buf[i] = mu_k[i]*c[i];
   }

   for (j = st; j <= k-1; j++) {
      if (b[k]*b[j] < NTL_FDOUBLE_PRECISION*NTL_FDOUBLE_PRECISION) {
         double z = 0;
         xdouble *B1_k = B1[k];
         xdouble *B1_j = B1[j];

         for (i = 1; i <= n; i++)
            z += B1_k[i].x * B1_j[i].x;

         s = z;
      }
      else {
         s = InnerProduct(B1[k], B1[j], n);
   
         if (s*s <= b[k]*b[j]/bound) {
            InnerProduct(T1, B(k), B(j));
            conv(s, T1);
         }
      }

      xdouble *mu_j = mu[j];

      t1 = 0;
      for (i = 1; i <= j-1; i++)
         MulAdd(t1, t1, mu_j[i], buf[i]);

      mu_k[j] = (buf[j] = (s - t1))/c[j];
   }

   s = 0;
   for (j = 1; j <= k-1; j++)
      MulAdd(s, s, mu_k[j], buf[j]);

   c[k] = b[k] - s;
}
コード例 #7
0
ファイル: stageAB.c プロジェクト: oakfr/omni3d
double Deriv1 (edge *TheEdge, position *ThePosition, line *TheLine,
	       int index)
{
  double v[3], newv[3], dv[3], hat[3];

  if (!TheEdge || !ThePosition || !TheLine) return (0.0);

  switch (index) {
    case THETA :
      hat[0] = 0.0;  hat[1] = -1.0;  hat[2] = 0.0;
      RotateQuaternion (dv, TheLine->q, hat);
      RotateQuaternion (newv, ThePosition->q, dv);
      return (InnerProduct (newv, TheEdge->m));
      break;

    case OMEGA :
      hat[0] = 1.0;  hat[1] = 0.0;  hat[2] = 0.0;
      RotateQuaternion (dv, TheLine->q, hat);
      RotateQuaternion (newv, ThePosition->q, dv);
      return (InnerProduct (newv, TheEdge->m));
      break;

    case ALPHA :
      ComputeV (v, *TheLine);
      RotateQuaternion (newv, ThePosition->q, v);
      DerivR (dv, newv, 'x');
      return (InnerProduct (dv, TheEdge->m));
      break;

    case BETA :
      ComputeV (v, *TheLine);
      RotateQuaternion (newv, ThePosition->q, v);
      DerivR (dv, newv, 'y');
      return (InnerProduct (dv, TheEdge->m));
      break;

    case GAMMA :
      ComputeV (v, *TheLine);
      RotateQuaternion (newv, ThePosition->q, v);
      DerivR (dv, newv, 'z');
      return (InnerProduct (dv, TheEdge->m));
      break;

    default :
      pexit ("Bad parameters to Deriv1");
      break;
  }

  return 0.0;
}
コード例 #8
0
ファイル: sbvar.cpp プロジェクト: parb220/dsmh_package
double SBVAR::LogLikelihood(void)
{
  double log_likelihood=log_likelihood_constant + lambda_T*LogAbsDeterminant(A0);
  TDenseVector a0(n_vars), aplus(n_predetermined);

  for (int i=n_vars-1; i >= 0; i--)
    {
      a0.RowVector(A0,i);
      aplus.RowVector(Aplus,i);
      log_likelihood+=-0.5*(InnerProduct(a0,a0,YY) - 2.0*InnerProduct(aplus,a0,XY) + InnerProduct(aplus,aplus,XX));
    }

  return log_likelihood;
}
コード例 #9
0
ファイル: sbvar.cpp プロジェクト: parb220/dsmh_package
/*
   Computes the log of the integral of the tempered posterior.

         Integrate( (p(Y|Theta)*p(Theta))^(1/K) dTheta )
*/
double SBVAR_symmetric_linear::LogPosteriorIntegral(TDenseVector p, int ndraws, int thin, int burn_in)
{
  if (ndraws <= 0) throw dw_exception("PosteriorIntegral(): number of draws must be postive");
  if (thin <= 0) throw dw_exception("PosteriorIntegral(): thinning factor must be positive");
  if (p.dim != NumberParameters()) throw dw_exception("PosteriorIntegral(): Incorrect number of parameters");

  if (!simulation_info_set) SetSimulationInfo();

  SetParameters(p.vector);

  double integral=log_likelihood_constant + log_prior_constant;
  for (int i=0; i < n_vars; i++)
    integral+=0.5*dim_g[i]*1.837877066409345 + LogAbsDeterminant(Simulate_SqrtH[i]);  // 1.837877066409345 = log(2*pi)

  integral+=lambda_T*LogAbsDeterminant(A0);
  for (int i=0; i < n_vars; i++)
    {
      TDenseVector x=InverseMultiply(Simulate_SqrtS[i],p.SubVector(begin_b[i],begin_b[i]+dim_b[i]-1));
      integral+=-0.5*lambda_T*InnerProduct(x,x);
    }

  for (int i=0; i < n_vars; i++)
    integral-=LogConditionalA0_gibbs(p,i,ndraws,thin,burn_in);

  return integral;
}
コード例 #10
0
ファイル: sbvar.cpp プロジェクト: parb220/dsmh_package
double SBVAR_symmetric::LogPrior(void)
{
  if (flat_prior) return 0.0;

  double log_prior=log_prior_constant;
  TDenseVector a0(n_vars), aplus(n_predetermined);

  for (int i=n_vars-1; i >= 0; i--)
    {
      a0.RowVector(A0,i);
      aplus.RowVector(Aplus,i);
      log_prior+=-0.5*(InnerProduct(a0,a0,prior_YY) - 2.0*InnerProduct(aplus,a0,prior_XY) + InnerProduct(aplus,aplus,prior_XX));
    }

  return log_prior;
}
コード例 #11
0
ファイル: runtime.hpp プロジェクト: ddemidov/amgcl
    wrapper(size_t n, params prm = params(),
            const backend_params &bprm = backend_params(),
            const InnerProduct &inner_product = InnerProduct()
            )
        : s(prm.get("type", runtime::solver::bicgstab)), handle(0)
    {
        if (!prm.erase("type")) AMGCL_PARAM_MISSING("type");

        switch(s) {

#define AMGCL_RUNTIME_SOLVER(type) \
            case type: \
                handle = static_cast<void*>(new amgcl::solver::type<Backend, InnerProduct>(n, prm, bprm, inner_product)); \
                break

            AMGCL_RUNTIME_SOLVER(cg);
            AMGCL_RUNTIME_SOLVER(bicgstab);
            AMGCL_RUNTIME_SOLVER(bicgstabl);
            AMGCL_RUNTIME_SOLVER(gmres);
            AMGCL_RUNTIME_SOLVER(lgmres);
            AMGCL_RUNTIME_SOLVER(fgmres);
            AMGCL_RUNTIME_SOLVER(idrs);

#undef AMGCL_RUNTIME_SOLVER

            default:
                throw std::invalid_argument("Unsupported solver type");
        }
    }
コード例 #12
0
    double GillespiePetzold_Stepsize(Vector& x ,
                          Vector& a ,
                          double & a0 ,
                          const Matrix& nu ,
                          double tau,
                          double eps, 
                          PropensityJacobianFunc jacobian)
    {
	static Matrix f(x.Size(), x.Size()); 
	static Vector mu = a; 
	static Vector sigma = a; 
	static double r1, r2; 
	static double tau1, tau2; 

	f = jacobian(x)*nu; 
	mu = f*a; 
	sigma = InnerProduct(f, f)*a; 
	r1 = mu.Norm(); //Max norm
	r2 = sigma.Norm(); // Max norm
	tau1 = eps * a0; 
	tau2 = tau1 * tau1; 
	if (r1 > 0) 
	  tau1 = tau1/r1; 
	else 
	  tau1 = 100.; 
	if (r2 > 0) 
	  tau2 = tau2/r2; 
	else 
	  tau2 = 100.; 
 
	if (tau1 > tau2) 
	  return tau2; 
	else 
	  return tau1; 
    }
コード例 #13
0
NTL_START_IMPL

static
long CharPolyBound(const mat_ZZ& a)
// This bound is computed via interpolation
// through complex roots of unity.

{
   long n = a.NumRows();
   long i;
   ZZ res, t1, t2;

   set(res);

   for (i = 0; i < n; i++) {
      InnerProduct(t1, a[i], a[i]);
      abs(t2, a[i][i]);
      mul(t2, t2, 2);
      add(t2, t2, 1);
      add(t1, t1, t2);
      if (t1 > 1) {
         SqrRoot(t1, t1);
         add(t1, t1, 1);
      }
      mul(res, res, t1);
   }

   return NumBits(res);
}
コード例 #14
0
ファイル: t_cp0.cpp プロジェクト: kuailexs/symbiandump-os1
TInt DoCP0Test(TAny* aPtr)
	{
	TUint seed[2];
	seed[0]=(TUint)aPtr;
	seed[1]=0;
	TInt16 vec1[128];
	TInt16 vec2[128];
	TInt run;
	for (run=0; run<100000; ++run)
		{
		TInt n=(Random(seed)&63)+64;		// vector length
		TInt i;
		for (i=0; i<n; ++i)
			{
			vec1[i]=(TInt16)(Random(seed)&0xffff);
			vec2[i]=(TInt16)(Random(seed)&0xffff);
			TInt64 result, result2;
			InnerProduct(result,vec1,vec2,n);
			InnerProduct2(result2,vec1,vec2,n);
			if (result != result2)
				{
				User::Panic(_L("ERROR"),run);
				}
			}
		}
	return 0;
	}
コード例 #15
0
ファイル: scalarfe.cpp プロジェクト: mliertzer/ngsolve
 double ScalarFiniteElement<D> :: 
 Evaluate (const IntegrationPoint & ip, FlatVector<double> x) const
 {
   VectorMem<20, double> shape(ndof);
   CalcShape (ip, shape);
   return InnerProduct (shape, x);
 }  
コード例 #16
0
void ProjectPowers(vec_zz_p& x, const vec_zz_p& a, long k,
                   const zz_pXArgument& H, const zz_pXModulus& F)

{
   long n = F.n;

   if (a.length() > n || k < 0 || NTL_OVERFLOW(k, 1, 0))
      Error("ProjectPowers: bad args");

   long m = H.H.length()-1;
   long l = (k+m-1)/m - 1;

   zz_pXMultiplier M;
   build(M, H.H[m], F);

   vec_zz_p s(INIT_SIZE, n);
   s = a;
   StripZeroes(s);

   x.SetLength(k);

   for (long i = 0; i <= l; i++) {
      long m1 = min(m, k-i*m);
      zz_p* w = &x[i*m];
      for (long j = 0; j < m1; j++)
         InnerProduct(w[j], H.H[j].rep, s);
      if (i < l)
         UpdateMap(s, s, M, F);
   }
}
コード例 #17
0
ファイル: Solvers.cpp プロジェクト: exmatex/VPFFT
    //--------------------------------------------------------------------------------
    //
    //  CalculateHardening
    //     Current used for testing the other parts of the code.
    //
    //
    //  This is almost a direct translation from Ricardo's "HARDEN" routine from fft3.for
    //
    //--------------------------------------------------------------------------------
    vector<Float> CalculateHardening( Float & AccumulatedShear,
                                      const Float              & TimeStep,
                                      const EigenRep           & StressState,
                                      const vector<EigenRep>   & SchmidtTensors,
                                      const vector<Float>      & CRSS,
                                      const vector<Float>      & GammaDotBase,         // reference shear rate
                                      const vector<int>        & RateSensitivity,
                                      const vector< vector< Float > > & HardeningMatrix,
                                      const vector<Float> & Tau0,
                                      const vector<Float> & Tau1,
                                      const vector<Float> & Theta0,
                                      const vector<Float> & Theta1  )
    {

      vector<Float> UpdatedCRSS    = CRSS;
      Float LocalShearAccumulation = 0;
      std::vector<Float> GammaDot( SchmidtTensors.size(), 0 );            
      for( int i = 0; i < SchmidtTensors.size(); i ++ )
      {
        Float RSS = InnerProduct( SchmidtTensors[i], StressState) / CRSS[i];
        if( RateSensitivity[i] > 0 )
          GammaDot[i] = GammaDotBase[i] * std::pow( std::fabs( RSS ), static_cast<int>( RateSensitivity[i] ) );
        else
          GammaDot[i] = GammaDotBase[i];
        LocalShearAccumulation += std::fabs( GammaDot[i] ) * TimeStep;
      }



      for( int i = 0; i < SchmidtTensors.size(); i ++ )
      {
        Float DTau = 0;
        for( int j = 0; j < SchmidtTensors.size(); j ++ )
          DTau += HardeningMatrix[i][j] * std::fabs( GammaDot[j] ) * TimeStep;


        Float Tiny = 1e-4 * Tau0[i];
        Float VoceFactor = 0;
        if( std::fabs( Theta0[i] ) > Tiny  )
        {
          VoceFactor = Theta1[i] * LocalShearAccumulation;
          if( std::fabs( Tau1[i]) > Tiny )
          {
            Float fRatio = std::fabs( Theta0[i] / Tau1[i] );
            Float ExpIni = exp( -AccumulatedShear       * fRatio );
            Float ExpDel = exp( -LocalShearAccumulation * fRatio );

            VoceFactor = VoceFactor - (fRatio * Tau1[i] * Theta1[i])/ fRatio * ExpIni
              * ( ExpDel - static_cast<Float>(1) ) - Theta1[i]/fRatio * ExpIni
              * ( ExpDel * ( ( AccumulatedShear + LocalShearAccumulation)
                             * fRatio + static_cast<Float>(1) )
                  - ( AccumulatedShear * fRatio + static_cast<Float>(1) ) );
          }
        }
        UpdatedCRSS[i] += DTau * VoceFactor / LocalShearAccumulation;
      }

      AccumulatedShear += LocalShearAccumulation;
      return UpdatedCRSS;
    }
コード例 #18
0
complex stb_InnerProduct(stabiliser *phi1, stabiliser *phi2)
{
    affine_sp a = afp_Copy(phi1->a); //This won't work. I need to define a copy method
    stabiliser stab;
    stab.a = &a;
    stab.q = phi1->q;
    affine_sp *a1 = phi1->a, *a2 = phi2->a;
    quadratic_fm *q1 = phi1->q, *q2 = phi2->q;
    for (int i = a2->k +1; i < a2->n; i++){
        alpha = InnerProduct(a2->h, a2->GBar[i])
        res = shrink(&stab, a2->HBar[i], alpha);
        if (res == EMPTY){
            return (complex) 0;
        }
    }
    short *y = (short *)calloc(a2->k, sizeof(short));
    short *scratch_space = (short *)calloc(a2->n, sizeof(short));
    short res = 0;
    AddVectors(a2->n, scratch_space, a1->h);
    AddVectors(a2->n, scratch_space, a2->h);
    short **R = (short **)calloc(a2->n, sizeof(short*));
    for (int i=0; i<a2->n; i++){R[i] = (short *)calloc(a2->n, sizeof(short));}
    for (int i = 0; i < a2->k; i++){
        y[i] = InnerProduct(scratch_space, a2->Gbar[i]);
        for (int j = 0; j < a.k; j++){
            R[j][i] = InnerProduct(a.G[j], a2.GBar[i]);
        }

    }
    qfm_BasisChange(q2, R);
    qfm_ShiftChange(q2, y);
    for (int i = 0; i<a2->n; i++){a2->h[i] = a1->h[i];}
    //Cleanup
    for(int i = 0; i<q2->k; i++){free(R[i]);}
    free(scratch_space);
    free (R);
    free(y);
    //Find the final quadratic form q
    q.Q = Modulo(q1->Q - q2->Q, 8);
    for (int i = 0; i < q.K; i++){ 
        q.D[i] = Modulo(q1->D[i]-q2->D[i], 8);
        for (int j = 0; j<q.k; j++){
            q.J[i][j] = Modulo(q1->J[i][j] - q2->J[i][j], 8);
        }
    }
    return pow(2, -1*(a1->k - a2->k)/2)*ExponentialSum(q);
}
コード例 #19
0
ファイル: LLL.c プロジェクト: Macaulay2/Singular
static
void IncrementalGS(mat_ZZ& B, vec_long& P, vec_ZZ& D, vec_vec_ZZ& lam,
                   long& s, long k)
{
   long n = B.NumCols();
   long m = B.NumRows();

   static ZZ u, t1, t2;

   long i, j;

   for (j = 1; j <= k-1; j++) {
      long posj = P(j);
      if (posj == 0) continue;

      InnerProduct(u, B(k), B(j));
      for (i = 1; i <= posj-1; i++) {
         mul(t1, D[i], u);
         mul(t2, lam(k)(i), lam(j)(i));
         sub(t1, t1, t2);
         div(t1, t1, D[i-1]);
         u = t1;
      }

      lam(k)(posj) = u;
   }

   InnerProduct(u, B(k), B(k));
   for (i = 1; i <= s; i++) {
      mul(t1, D[i], u);
      mul(t2, lam(k)(i), lam(k)(i));
      sub(t1, t1, t2);
      div(t1, t1, D[i-1]);
      u = t1;
   }

   if (u == 0) {
      P(k) = 0;
   }
   else {
      s++;
      P(k) = s;
      D[s] = u;
   }
}
コード例 #20
0
ファイル: Fir.c プロジェクト: geniustom/HRVM
long Convolution(CircultBuffer *rb,int const *Hn,int ADC_Value){ //Input ADCoutput,Output FIR coef
  long Sum=0;
  rb->NewValue=ADC_Value;
  rb->Coef[rb->Front] = ADC_Value;
  rb->Front++;
  rb->Front &=(rb->len-1);  //modular operation
  Sum=InnerProduct((int*)Hn,rb->Coef,rb->len,rb->Front);
  return Sum;
}
コード例 #21
0
ファイル: kernels.cpp プロジェクト: caomw/r4r
double CMercerKernel<vec3>::Evaluate(vec3* x, vec3* y) {

    double result = 0;

    for(size_t i=0; i<m_n; i++)
        result += InnerProduct(x[i],y[i]);

    return result;

}
コード例 #22
0
ファイル: kernels.cpp プロジェクト: caomw/r4r
double CMercerKernel<vec3f>::Evaluate(vec3f* x, vec3f* y) {

    float result = 0;

    for(size_t i=0; i<m_n; i++)
        result += InnerProduct(x[i],y[i]);

    return static_cast<double>(result);

}
コード例 #23
0
ファイル: stageAB.c プロジェクト: oakfr/omni3d
double Error1 (edge *TheEdge, position *ThePosition, line *TheLine)
{
  double v[3], newv[3], temp;

  if (!TheEdge || !ThePosition || !TheLine) return (0.0);

  ComputeV (v, *TheLine);
  RotateQuaternion (newv, ThePosition->q, v);
  temp = InnerProduct (newv, TheEdge->m);

  return (sqr(temp) / (TheEdge->m_error));
}
コード例 #24
0
ファイル: LLL_XD.c プロジェクト: axelexic/NTL
static 
void BKZStatus(double tt, double enum_time, unsigned long NumIterations, 
               unsigned long NumTrivial, unsigned long NumNonTrivial, 
               unsigned long NumNoOps, long m, 
               const mat_ZZ& B)
{
   cerr << "---- BKZ_XD status ----\n";
   cerr << "elapsed time: ";
   PrintTime(cerr, tt-StartTime);
   cerr << ", enum time: ";
   PrintTime(cerr, enum_time);
   cerr << ", iter: " << NumIterations << "\n";
   cerr << "triv: " << NumTrivial;
   cerr << ", nontriv: " << NumNonTrivial;
   cerr << ", no ops: " << NumNoOps;
   cerr << ", rank: " << m;
   cerr << ", swaps: " << NumSwaps << "\n";



   ZZ t1;
   long i;
   double prodlen = 0;

   for (i = 1; i <= m; i++) {
      InnerProduct(t1, B(i), B(i));
      if (!IsZero(t1))
         prodlen += log(t1);
   }

   cerr << "log of prod of lengths: " << prodlen/(2.0*log(2.0)) << "\n";


   if (LLLDumpFile) {
      cerr << "dumping to " << LLLDumpFile << "...";

      ofstream f;
      OpenWrite(f, LLLDumpFile);
      
      f << "[";
      for (i = 1; i <= m; i++) {
         f << B(i) << "\n";
      }
      f << "]\n";

      f.close();

      cerr << "\n";
   }

   LastTime = tt;
   
}
コード例 #25
0
void TraceMod(zz_p& x, const zz_pX& a, const zz_pXModulus& F)
{
   long n = F.n;

   if (deg(a) >= n)
      Error("trace: bad args");

   if (F.tracevec.length() == 0) 
      ComputeTraceVec(F);

   InnerProduct(x, a.rep, F.tracevec);
}
コード例 #26
0
	uint64_t CGMethod(double *A, double *x, double *b, uint64_t dim, double eps, uint64_t max)
	{
		max = (max?max:dim);
		double *r = new double[dim];
		double *p = new double[dim];
		double *Ap = new double[dim];
		mul(A, x, Ap, dim);


		for(uint64_t i = 0; i < dim; ++i)
			r[i] = p[i] = b[i] - Ap[i];

		for(uint64_t k = 0; k < max; ++k)
		{
			mul(A, p, Ap, dim);
			double alpha = InnerProduct(r, 0, p, dim)/InnerProduct(p, 0, Ap, dim);
			double beta = 1./InnerProduct(r, 0, r, dim);

			for(uint64_t i = 0; i < dim; ++i)
				x[i] += alpha*p[i], r[i] -= alpha*Ap[i];

			double gamma = InnerProduct(r, 0, r, dim);
			if(gamma < eps)
			{
				delete [] r;
				delete [] p;
				delete [] Ap;
				return k + 1;
			}
			beta *= gamma;
			for(uint64_t i = 0; i < dim; ++i)
				p[i] = r[i] + beta*p[i];
		}
		delete [] r;
		delete [] p;
		delete [] Ap;
		return max;
	}
コード例 #27
0
ファイル: ex3.cpp プロジェクト: ICpachong/superstitchous2.0
/*!
 * \example SerialExample/ex1.cpp
 *
 * A simple example of MINRES() usage without preconditioner.
 */
int main()
{
	//(1) Define the size of the problem we want to solve
	int size(1000);
	//(2) Define the linear operator "op" we want to solve.
	SimpleOperator op(size);
    //(3) Generate a random linear system
    op.Randomize(0);
	//(3) Define the exact solution (at random)
	SimpleVector sol(size);
	sol.Randomize( 1 );

	//(4) Define the "rhs" as "rhs = op*sol"
	SimpleVector rhs(size);
	op.Apply(sol, rhs);
	double rhsNorm( sqrt(InnerProduct(rhs,rhs)) );
	std::cout << "|| rhs || = " << rhsNorm << "\n";

	//(5) We don't use any preconditioner. Let prec be a null pointer.
	Preconditioner * prec = NULL;

	//(6) Use an identically zero initial guess
	SimpleVector x(size);
	x = 0;

	//(7) Set the minres parameters
	double shift(0);
	int max_iter(10000);
	double tol(1e-6);
	bool show(false);

	//(8) Solve the problem with minres
	MINRES(op, x, rhs, prec, shift, max_iter, tol, show);

	//(9) Compute the error || x_ex - x_minres ||_2
	subtract(x, sol, x);
	double err2 = InnerProduct(x,x);
	std::cout<< "|| x_ex - x_n || = " << sqrt(err2) << "\n";

	std::ofstream fid("ex3.m");
	op.Print(fid);
	fid<< "rhs = [";
	for(int i(0); i<size-1; ++i)
		fid<<rhs[i] <<"; ";
	fid<<rhs[size-1] <<"]; \n";
	fid<<"[ x, istop, itn, rnorm, Arnorm, Anorm, Acond, ynorm ] = minres(Op, rhs, [], 0, true, false, 100, 1e-6);\n";
    

	return 0;
}
コード例 #28
0
ファイル: stageAB.c プロジェクト: oakfr/omni3d
double Gradient1 (edge *TheEdge, position *ThePosition, line *TheLine,
		  int index)
{
  double v[3], newv[3], temp1, temp2;

  if (!TheEdge || !ThePosition || !TheLine) return (0.0);

  ComputeV (v, *TheLine);
  RotateQuaternion (newv, ThePosition->q, v);
  temp1 = InnerProduct (newv, TheEdge->m);

  temp2 = Deriv1 (TheEdge, ThePosition, TheLine, index);

  return ( (2.0*temp1*temp2) / (TheEdge->m_error) );
}
コード例 #29
0
bool Sphere::Intersection(const ray& r, intersection_data& intersect)
{
	Vector3 result;
	Vector3 L;
	float Tca, Thc, d, T;

	L = center - r.origin;
	Tca = InnerProduct(L, r.direction);
	if (Tca < 0) return false;

	d = InnerProduct(L, L) + Tca * Tca;
	if (d > radius * radius) return false;

	Thc = sqrt(radius * radius - d);
	/* assuming T won't be negative, which should never happen in cases that matter (either we're inside the sphere and so we have bigger problems, or it's behind us)*/
	T = std::min(Tca - Thc, Tca + Thc);

	intersect.point = (Vector3)r.direction * T;
	intersect.col = this->mtl_diffuse; //change to something more complex next submission
	intersect.normal = intersect.point - this->center;
	intersect.T = T;

	return true;
}
コード例 #30
0
ファイル: mat_ZZ.c プロジェクト: tvtritin/Fuzzy-extractor
static
void hadamard(ZZ& num_bound, ZZ& den_bound,
              const mat_ZZ& A, const vec_ZZ& b)
{
    long n = A.NumRows();

    if (n == 0) Error("internal error: hadamard with n = 0");

    ZZ b_len, min_A_len, prod, t1;

    InnerProduct(min_A_len, A[0], A[0]);

    prod = min_A_len;

    long i;
    for (i = 1; i < n; i++) {
        InnerProduct(t1, A[i], A[i]);
        if (t1 < min_A_len)
            min_A_len = t1;
        mul(prod, prod, t1);
    }

    if (min_A_len == 0) {
        num_bound = 0;
        den_bound = 0;
        return;
    }

    InnerProduct(b_len, b, b);

    div(t1, prod, min_A_len);
    mul(t1, t1, b_len);

    SqrRoot(num_bound, t1);
    SqrRoot(den_bound, prod);
}