示例#1
0
af::array Kernel::distanceSquared(const af::array& x , const af::array& y)
{
  int nx = x.dims(0);
  int ny = y.dims(0);

  af::array arg1 =  af::matmul(af::sum(af::pow(x,2.0),1), af::constant(1.0,1,ny));
  af::array arg2 =  af::matmul(af::constant(1.0,nx,1), af::sum(af::pow(y,2.0),1).T());
  af::array arg3 =  2.0 * (af::matmul(x,y.T()));
  af::array values = arg1 + arg2 - arg3;

  return  values;
}
示例#2
0
void MLP::setWeights(const af::array& weights)
{
    if (weights.dims() != this->weights.dims()) {
        BOOST_THROW_EXCEPTION(InvalidArgumentError() << EInfo_Name("weights"));
    }
    this->weights = weights;
}
示例#3
0
af::array Kernel::calculateGaussianKernel(const af::array& x1, const af::array& x2)
{
  int rowX1 = x1.dims(0);

  float eta = 1.0/(m_lengthScale*m_lengthScale);

  af::array temp = af::exp(-eta * distanceSquared(x1,x2) / 2.0);

  return m_useBias ? af::join(1, af::constant(1.0,rowX1,1),temp) : temp;
}
示例#4
0
af::array Kernel::calculateDistanceKernel(const af::array& x1, const af::array& x2)
{
  int rowX1 = x1.dims(0);

  double eta = 1.0/(m_lengthScale*m_lengthScale);

  af::array temp = sqrt(eta)*sqrt(distanceSquared(x1,x2));

  return m_useBias ? af::join(1, af::constant(1.0,rowX1,1),temp) : temp;

}
示例#5
0
af::array Kernel::calculatePolynomialKernel(const af::array& x1, const af::array& x2)
{
  int rowX1 = x1.dims(0);

  double eta = 1.0/(m_lengthScale*m_lengthScale);

  af::array temp =  af::pow(af::matmul(x1,(eta * x2).T()) + 1.0, m_polynomailPower);

  af_print(af::sum( af::sum( af::isNaN(temp) )),1);

  return m_useBias ? af::join(1, af::constant(1.0,rowX1,1),temp) : temp;
}
示例#6
0
af::array Kernel::calculateBubbleKernel(const af::array& x1, const af::array& x2)
{
  int rowX1 = x1.dims(0);

  double eta = 1/(m_lengthScale*m_lengthScale);

  af::array r2 = eta*distanceSquared(x1,x2) ;

  if(m_useBias)
    {
      return af::join(1, af::constant(1,rowX1,1), r2 < 1);
    }
  else
    {
      return r2 < 1;
    }
}
示例#7
0
af::array Kernel::calculateThinPlateSplineKernel(const af::array& x1, const af::array& x2)
{
  int rowX1 = x1.dims(0);

  double eta = 1.0/(m_lengthScale*m_lengthScale);

  af::array r2 = eta*distanceSquared(x1,x2);

  if(m_useBias)
    {
      return af::join(1, af::constant(1,rowX1,1), 0.5 * r2 * af::log(r2 + (r2 == 0)));
    }
  else
    {
      return 0.5 * r2 * af::log(r2 + (r2 == 0));
    }
}
示例#8
0
 virtual af::array dfn(const af::array &val)
 {
     return af::constant(1, val.dims());
 }
	void setElectricField(af::array e)
	{
		this->electric_field = e.as(ctype);
	}
	void setMask(af::array mask)
	{
		this->mask = mask.as(ctype);
	}
示例#11
0
 af::array dfn(const af::array &input)
 {
     return (input >= mVal).as(input.type());
 }