Package com.rapidminer.data

Examples of com.rapidminer.data.Matrix


    protected void InitModel()
    {
      super.InitModel();

      // init factor matrices
      user_factors = new Matrix(GetRatings().GetMaxUserID() + 1, NumFactors);
      item_factors = new Matrix(GetRatings().GetMaxItemID() + 1, NumFactors);
      MatrixUtils.RowInitNormal(user_factors, InitMean, InitStdev);
      MatrixUtils.RowInitNormal(item_factors, InitMean, InitStdev)
    }
View Full Code Here


  // TODO push upwards in class hierarchy
  ///
  protected void InitModel()
  {
    user_factors = new Matrix(MaxUserID + 1, GetNumFactors());
    item_factors = new Matrix(MaxItemID + 1, GetNumFactors());

    MatrixUtils.RowInitNormal(user_factors, InitMean, InitStdev);
    MatrixUtils.RowInitNormal(item_factors, InitMean, InitStdev);
  }
View Full Code Here

  protected void InitModel()
  {
    super.InitModel();

    // init factor matrices
    user_factors = new Matrix(GetRatings().GetMaxUserID() + 1, NumFactors);
    item_factors = new Matrix(GetRatings().GetMaxItemID() + 1, NumFactors);

    // init global effects model
    global_effects.SetRatings(this.GetRatings());
    global_effects.SetMinRating(GetMinRating());
    global_effects.SetMaxRating(GetMaxRating());
View Full Code Here

    /// <param name="data">data</param>
    /// <param name="W">W</param>
    /// <param name="H">H</param>
    protected void Optimize(IBooleanMatrix data, Matrix W, Matrix H)
    {
      Matrix HH          = new Matrix(num_factors, num_factors);
      Matrix HC_minus_IH = new Matrix(num_factors, num_factors);
      double[] HCp         = new double[num_factors];
     
      cern.colt.matrix.DoubleMatrix2D m=new cern.colt.matrix.impl.DenseDoubleMatrix2D(num_factors,num_factors);
     
      cern.colt.matrix.DoubleMatrix2D m_inv;
      // TODO speed up using more parts of that library

      // source code comments are in terms of computing the user factors
      // works the same with users and items exchanged

      // (1) create HH in O(f^2|Items|)
      // HH is symmetric
      for (int f_1 = 0; f_1 < num_factors; f_1++)
        for (int f_2 = 0; f_2 < num_factors; f_2++)
        {
          double d = 0;
          for (int i = 0; i < H.dim1; i++)
            d += H.getLocation(i, f_1) * H.getLocation(i, f_2);
          HH.setLocation(f_1, f_2,d);
        }
      // (2) optimize all U
      // HC_minus_IH is symmetric
      for (int u = 0; u < W.dim1; u++)
      {
        List<Integer> row = data.GetEntriesByRow(u);
        // create HC_minus_IH in O(f^2|S_u|)
        for (int f_1 = 0; f_1 < num_factors; f_1++)
          for (int f_2 = 0; f_2 < num_factors; f_2++)
          {
            double d = 0;
            for(int i1=0;i1<row.size();i1++){
              int i=row.get(i1);
              d += H.getLocation(i, f_1) * H.getLocation(i, f_2) * c_pos;
            }
            HC_minus_IH.setLocation(f_1, f_2, d);
          }
        // create HCp in O(f|S_u|)
        for (int f = 0; f < num_factors; f++)
        {
          double d = 0;
         
          for(int i1=0;i1<row.size();i1++){
            int i=row.get(i1);
            d += H.getLocation(i, f) * (1 + c_pos);
          }
          HCp[f] = d;
        }
        // create m = HH + HC_minus_IH + reg*I
        // m is symmetric
        // the inverse m_inv is symmetric
       
        cern.colt.matrix.linalg.Algebra a=new cern.colt.matrix.linalg.Algebra();
       
        for (int f_1 = 0; f_1 < num_factors; f_1++)
          for (int f_2 = 0; f_2 < num_factors; f_2++)
          {
            double d = HH.getLocation(f_1, f_2) + HC_minus_IH.getLocation(f_1, f_2);
            if (f_1 == f_2)
              d += regularization;
            m.set(f_1, f_2, d);
          }
        m_inv = a.inverse(m);
View Full Code Here

   
   
   
    protected void OptimizeUpdate(IBooleanMatrix data,List<Integer> entities, Matrix W, Matrix H)
    {
      Matrix HH          = new Matrix(num_factors, num_factors);
      Matrix HC_minus_IH = new Matrix(num_factors, num_factors);
      double[] HCp         = new double[num_factors];
     
      cern.colt.matrix.DoubleMatrix2D m=new cern.colt.matrix.impl.DenseDoubleMatrix2D(num_factors,num_factors);
     
      cern.colt.matrix.DoubleMatrix2D m_inv;
      // TODO speed up using more parts of that library

      // source code comments are in terms of computing the user factors
      // works the same with users and items exchanged

      // (1) create HH in O(f^2|Items|)
      // HH is symmetric
      for (int f_1 = 0; f_1 < num_factors; f_1++)
        for (int f_2 = 0; f_2 < num_factors; f_2++)
        {
          double d = 0;
          for (int i = 0; i < H.dim1; i++)
            d += H.getLocation(i, f_1) * H.getLocation(i, f_2);
          HH.setLocation(f_1, f_2,d);
        }
      // (2) optimize all U
      // HC_minus_IH is symmetric
      for (int u = W.dim1-entities.size(); u < W.dim1; u++)
      {
        List<Integer> row = data.GetEntriesByRow(u);
        // create HC_minus_IH in O(f^2|S_u|)
        for (int f_1 = 0; f_1 < num_factors; f_1++)
          for (int f_2 = 0; f_2 < num_factors; f_2++)
          {
            double d = 0;
            for(int i1=0;i1<row.size();i1++){
              int i=row.get(i1);
              d += H.getLocation(i, f_1) * H.getLocation(i, f_2) * c_pos;
            }
            HC_minus_IH.setLocation(f_1, f_2, d);
          }
        // create HCp in O(f|S_u|)
        for (int f = 0; f < num_factors; f++)
        {
          double d = 0;
         
          for(int i1=0;i1<row.size();i1++){
            int i=row.get(i1);
            d += H.getLocation(i, f) * (1 + c_pos);
          }
          HCp[f] = d;
        }
        // create m = HH + HC_minus_IH + reg*I
        // m is symmetric
        // the inverse m_inv is symmetric
       
        cern.colt.matrix.linalg.Algebra a=new cern.colt.matrix.linalg.Algebra();
       
        for (int f_1 = 0; f_1 < num_factors; f_1++)
          for (int f_2 = 0; f_2 < num_factors; f_2++)
          {
            double d = HH.getLocation(f_1, f_2) + HC_minus_IH.getLocation(f_1, f_2);
            if (f_1 == f_2)
              d += regularization;
            m.set(f_1, f_2, d);
          }
        m_inv = a.inverse(m);
View Full Code Here

   
    public void AddUsers(List<Integer> users)
    {
      if(users.size()!=0){
      super.AddUsers(users);
      Matrix um=new Matrix(MaxUserID + 1, GetNumFactors());
      MatrixUtils.RowInitNormal(user_factors, InitMean, InitStdev);
     
      for(int i=0;i<this.user_factors.dim1;i++)
          for(int j=0;j<this.user_factors.dim2;j++)
              um.setLocation(i, j, this.user_factors.getLocation(i, j));   

      this.user_factors=new Matrix(MaxUserID+1,GetNumFactors());
     
      for(int i=0;i<this.user_factors.dim1;i++)
        for(int j=0;j<this.user_factors.dim2;j++)
            this.user_factors.setLocation(i, j, um.getLocation(i, j))
      }
     
    }
View Full Code Here

   
    public void AddItems(List<Integer> items)
    {
      if(items.size()!=0){
      super.AddItems(items);
      Matrix im=new Matrix(MaxItemID + 1, GetNumFactors());
      MatrixUtils.RowInitNormal(item_factors, InitMean, InitStdev);
     
      for(int i=0;i<this.item_factors.dim1;i++)
          for(int j=0;j<this.item_factors.dim2;j++)
              im.setLocation(i, j, this.item_factors.getLocation(i, j));   
     
      this.item_factors=new Matrix(MaxItemID+1,GetNumFactors());
     
      for(int i=0;i<this.item_factors.dim1;i++)
        for(int j=0;j<this.item_factors.dim2;j++)
            this.item_factors.setLocation(i, j, im.getLocation(i, j))
      }
    }
View Full Code Here

TOP

Related Classes of com.rapidminer.data.Matrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.