コード例 #1
0
 public override MatrixIndexer ExtractColumns(IList<int> columns)
 {
     SparseFloatVector[] r = new SparseFloatVector[vals.Length];
     for (int i = 0; i < vals.Length; i++){
         r[i] = (SparseFloatVector) vals[i].SubArray(columns);
     }
     return new SparseRowFloatMatrixIndexer{vals = r, ncolumns = columns.Count};
 }
コード例 #2
0
 public override object Clone()
 {
     if (vals == null){
         return new SparseRowFloatMatrixIndexer();
     }
     SparseFloatVector[] v = new SparseFloatVector[vals.Length];
     for (int i = 0; i < v.Length; i++){
         v[i] = (SparseFloatVector) vals[i].Clone();
     }
     return new SparseRowFloatMatrixIndexer{vals = v, ncolumns = ncolumns};
 }
コード例 #3
0
 public SparseRowFloatMatrixIndexer(SparseFloatVector[] vals, int ncolumns)
 {
     this.vals = vals;
     this.ncolumns = ncolumns;
 }
コード例 #4
0
 public override void Set(float[,] value)
 {
     ncolumns = value.GetLength(1);
     vals = new SparseFloatVector[value.GetLength(0)];
     for (int i = 0; i < vals.Length; i++){
         List<int> v = new List<int>();
         for (int j = 0; j < ncolumns; j++){
             if (value[i, j] == 0){
                 continue;
             }
             v.Add(j);
         }
         int[] v1 = v.ToArray();
         float[] x = new float[v1.Length];
         for (int j = 0; j < v1.Length; j++){
             x[j] = value[i, v1[j]];
         }
         vals[i] = new SparseFloatVector(v1, x, ncolumns);
     }
 }
コード例 #5
0
 public override void Init(int nrows, int ncolumns1)
 {
     ncolumns = ncolumns1;
     vals = new SparseFloatVector[nrows];
     for (int i = 0; i < nrows; i++){
         vals[i] = new SparseFloatVector(new int[0], new float[0], ncolumns);
     }
 }
コード例 #6
0
 internal static double SumSquaredDiffs(BoolArrayVector x, SparseFloatVector y)
 {
     double sum = 0;
     int xlen = x.Length;
     int ylen = y.indices.Length;
     int i = 0;
     int j = 0;
     while (i < xlen && j < ylen){
         if (i == y.indices[j]){
             double d = y.values[j++];
             if (x.values[i++]){
                 d -= 1;
             }
             sum += d*d;
         } else if (i > y.indices[j]){
             sum += y.values[j]*y.values[j];
             ++j;
         } else{
             if (x.values[i]){
                 sum += 1;
             }
             ++i;
         }
     }
     while (i < xlen){
         if (x.values[i]){
             sum += 1;
         }
         ++i;
     }
     while (j < ylen){
         sum += y.values[j]*y.values[j];
         ++j;
     }
     return sum;
 }
コード例 #7
0
 internal static double SumSquaredDiffs(SparseFloatVector x, SparseFloatVector y)
 {
     double sum = 0;
     int xlen = x.indices.Length;
     int ylen = y.indices.Length;
     int i = 0;
     int j = 0;
     while (i < xlen && j < ylen){
         if (x.indices[i] == y.indices[j]){
             double d = x.values[i++] - y.values[j++];
             sum += d*d;
         } else if (x.indices[i] > y.indices[j]){
             sum += y.values[j]*y.values[j];
             ++j;
         } else{
             sum += x.values[i]*x.values[i];
             ++i;
         }
     }
     while (i < xlen){
         sum += x.values[i]*x.values[i];
         ++i;
     }
     while (j < ylen){
         sum += y.values[j]*y.values[j];
         ++j;
     }
     return sum;
 }
コード例 #8
0
 internal static double Dot(DoubleArrayVector x, SparseFloatVector y)
 {
     double sum = 0;
     int xlen = x.Length;
     int ylen = y.indices.Length;
     int i = 0;
     int j = 0;
     while (i < xlen && j < ylen){
         if (i == y.indices[j]){
             sum += x.values[i++]*y.values[j++];
         } else{
             if (i > y.indices[j]){
                 ++j;
             } else{
                 ++i;
             }
         }
     }
     return sum;
 }